Deprecate utility tag

This commit is contained in:
Angelos Chalaris
2020-04-16 23:07:33 +03:00
parent 5e42f0aaa4
commit e31aea403d
60 changed files with 118 additions and 117 deletions

View File

@ -1,6 +1,6 @@
--- ---
title: functionName title: functionName
tags: utility,intermediate tags: array,intermediate
--- ---
Explain briefly what the snippet does. Explain briefly what the snippet does.

View File

@ -1,6 +1,6 @@
--- ---
title: CSVToArray title: CSVToArray
tags: string,array,utility,intermediate tags: string,array,intermediate
--- ---
Converts a comma-separated values (CSV) string to a 2D array. Converts a comma-separated values (CSV) string to a 2D array.
@ -22,4 +22,4 @@ const CSVToArray = (data, delimiter = ',', omitFirstRow = false) =>
CSVToArray('a,b\nc,d'); // [['a','b'],['c','d']]; CSVToArray('a,b\nc,d'); // [['a','b'],['c','d']];
CSVToArray('a;b\nc;d', ';'); // [['a','b'],['c','d']]; CSVToArray('a;b\nc;d', ';'); // [['a','b'],['c','d']];
CSVToArray('col1,col2\na,b\nc,d', ',', true); // [['a','b'],['c','d']]; CSVToArray('col1,col2\na,b\nc,d', ',', true); // [['a','b'],['c','d']];
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: RGBToHex title: RGBToHex
tags: utility,intermediate tags: string,math,intermediate
--- ---
Converts the values of RGB components to a color code. Converts the values of RGB components to a color code.
@ -13,4 +13,4 @@ const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6
```js ```js
RGBToHex(255, 165, 1); // 'ffa501' RGBToHex(255, 165, 1); // 'ffa501'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: URLJoin title: URLJoin
tags: string,utility,regexp,advanced tags: string,regexp,advanced
--- ---
Joins all given URL segments together, then normalizes the resulting URL. Joins all given URL segments together, then normalizes the resulting URL.
@ -21,4 +21,4 @@ const URLJoin = (...args) =>
```js ```js
URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo'); // 'http://www.google.com/a/b/cd?foo=123&bar=foo' URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo'); // 'http://www.google.com/a/b/cd?foo=123&bar=foo'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: UUIDGeneratorBrowser title: UUIDGeneratorBrowser
tags: browser,utility,random,intermediate tags: browser,random,intermediate
--- ---
Generates a UUID in a browser. Generates a UUID in a browser.
@ -16,4 +16,4 @@ const UUIDGeneratorBrowser = () =>
```js ```js
UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d' UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: UUIDGeneratorNode title: UUIDGeneratorNode
tags: node,utility,random,intermediate tags: node,random,intermediate
--- ---
Generates a UUID in Node.JS. Generates a UUID in Node.JS.
@ -17,4 +17,4 @@ const UUIDGeneratorNode = () =>
```js ```js
UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc' UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: arrayToCSV title: arrayToCSV
tags: array,string,utility,intermediate tags: array,string,intermediate
--- ---
Converts a 2D array to a comma-separated values (CSV) string. Converts a 2D array to a comma-separated values (CSV) string.
@ -20,4 +20,4 @@ const arrayToCSV = (arr, delimiter = ',') =>
arrayToCSV([['a', 'b'], ['c', 'd']]); // '"a","b"\n"c","d"' arrayToCSV([['a', 'b'], ['c', 'd']]); // '"a","b"\n"c","d"'
arrayToCSV([['a', 'b'], ['c', 'd']], ';'); // '"a";"b"\n"c";"d"' arrayToCSV([['a', 'b'], ['c', 'd']], ';'); // '"a";"b"\n"c";"d"'
arrayToCSV([['a', '"b" great'], ['c', 3.1415]]); // '"a","""b"" great"\n"c",3.1415' arrayToCSV([['a', '"b" great'], ['c', 3.1415]]); // '"a","""b"" great"\n"c",3.1415'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: atob title: atob
tags: node,string,utility,beginner tags: node,string,beginner
--- ---
Decodes a string of data which has been encoded using base-64 encoding. Decodes a string of data which has been encoded using base-64 encoding.
@ -13,4 +13,4 @@ const atob = str => Buffer.from(str, 'base64').toString('binary');
```js ```js
atob('Zm9vYmFy'); // 'foobar' atob('Zm9vYmFy'); // 'foobar'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: btoa title: btoa
tags: node,string,utility,beginner tags: node,string,beginner
--- ---
Creates a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data. Creates a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data.
@ -13,4 +13,4 @@ const btoa = str => Buffer.from(str, 'binary').toString('base64');
```js ```js
btoa('foobar'); // 'Zm9vYmFy' btoa('foobar'); // 'Zm9vYmFy'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: castArray title: castArray
tags: utility,array,type,beginner tags: type,array,beginner
--- ---
Casts the provided value as an array if it's not one. Casts the provided value as an array if it's not one.
@ -14,4 +14,4 @@ const castArray = val => (Array.isArray(val) ? val : [val]);
```js ```js
castArray('foo'); // ['foo'] castArray('foo'); // ['foo']
castArray([1]); // [1] castArray([1]); // [1]
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: checkProp title: checkProp
tags: function,object,utility,beginner tags: function,object,beginner
--- ---
Given a `predicate` function and a `prop` string, this curried function will then take an `object` to inspect by calling the property and passing it to the predicate. Given a `predicate` function and a `prop` string, this curried function will then take an `object` to inspect by calling the property and passing it to the predicate.

View File

@ -1,6 +1,6 @@
--- ---
title: cloneRegExp title: cloneRegExp
tags: utility,regexp,intermediate tags: type,string,regexp,intermediate
--- ---
Clones a regular expression. Clones a regular expression.
@ -14,4 +14,4 @@ const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
```js ```js
const regExp = /lorem ipsum/gi; const regExp = /lorem ipsum/gi;
const regExp2 = cloneRegExp(regExp); // /lorem ipsum/gi const regExp2 = cloneRegExp(regExp); // /lorem ipsum/gi
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: coalesce title: coalesce
tags: utility,beginner tags: type,beginner
--- ---
Returns the first defined, non-null argument. Returns the first defined, non-null argument.

View File

@ -1,6 +1,6 @@
--- ---
title: coalesceFactory title: coalesceFactory
tags: utility,intermediate tags: type,intermediate
--- ---
Returns a customized coalesce function that returns the first argument that returns `true` from the provided argument validation function. Returns a customized coalesce function that returns the first argument that returns `true` from the provided argument validation function.
@ -14,4 +14,4 @@ const coalesceFactory = valid => (...args) => args.find(valid);
```js ```js
const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_)); const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_));
customCoalesce(undefined, null, NaN, '', 'Waldo'); // "Waldo" customCoalesce(undefined, null, NaN, '', 'Waldo'); // "Waldo"
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: colorize title: colorize
tags: node,utility,string,intermediate tags: node,string,intermediate
--- ---
Add special characters to text to print in color in the console (combined with `console.log()`). Add special characters to text to print in color in the console (combined with `console.log()`).
@ -33,4 +33,4 @@ const colorize = (...args) => ({
console.log(colorize('foo').red); // 'foo' (red letters) console.log(colorize('foo').red); // 'foo' (red letters)
console.log(colorize('foo', 'bar').bgBlue); // 'foo bar' (blue background) console.log(colorize('foo', 'bar').bgBlue); // 'foo bar' (blue background)
console.log(colorize(colorize('foo').yellow, colorize('foo').green).bgWhite); // 'foo bar' (first word in yellow letters, second word in green letters, white background for both) console.log(colorize(colorize('foo').yellow, colorize('foo').green).bgWhite); // 'foo bar' (first word in yellow letters, second word in green letters, white background for both)
``` ```

View File

@ -1,13 +1,13 @@
--- ---
title: createElement title: createElement
tags: browser,utility,beginner tags: browser,beginner
--- ---
Creates an element from a string (without appending it to the document). Creates an element from a string (without appending it to the document).
If the given string contains multiple elements, only the first one will be returned. If the given string contains multiple elements, only the first one will be returned.
Use `document.createElement()` to create a new element. Use `document.createElement()` to create a new element.
Set its `innerHTML` to the string supplied as the argument. Set its `innerHTML` to the string supplied as the argument.
Use `ParentNode.firstElementChild` to return the element version of the string. Use `ParentNode.firstElementChild` to return the element version of the string.
```js ```js
@ -25,4 +25,4 @@ const el = createElement(
</div>` </div>`
); );
console.log(el.className); // 'container' console.log(el.className); // 'container'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: extendHex title: extendHex
tags: utility,string,intermediate tags: string,intermediate
--- ---
Extends a 3-digit color code to a 6-digit color code. Extends a 3-digit color code to a 6-digit color code.
@ -21,4 +21,4 @@ const extendHex = shortHex =>
```js ```js
extendHex('#03f'); // '#0033ff' extendHex('#03f'); // '#0033ff'
extendHex('05a'); // '#0055aa' extendHex('05a'); // '#0055aa'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: formatDuration title: formatDuration
tags: date,math,string,utility,intermediate tags: date,math,string,intermediate
--- ---
Returns the human readable format of the given number of milliseconds. Returns the human readable format of the given number of milliseconds.
@ -30,4 +30,4 @@ const formatDuration = ms => {
```js ```js
formatDuration(1001); // '1 second, 1 millisecond' formatDuration(1001); // '1 second, 1 millisecond'
formatDuration(34325055574); // '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds' formatDuration(34325055574); // '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: functionName title: functionName
tags: function,utility,beginner tags: function,beginner
--- ---
Logs the name of a function. Logs the name of a function.
@ -13,4 +13,4 @@ const functionName = fn => (console.debug(fn.name), fn);
```js ```js
functionName(Math.max); // max (logged in debug channel of console) functionName(Math.max); // max (logged in debug channel of console)
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: getURLParameters title: getURLParameters
tags: utility,browser,string,url,intermediate tags: browser,string,url,intermediate
--- ---
Returns an object containing the parameters of the current URL. Returns an object containing the parameters of the current URL.
@ -19,4 +19,4 @@ const getURLParameters = url =>
```js ```js
getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'} getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'}
getURLParameters('google.com'); // {} getURLParameters('google.com'); // {}
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: hashBrowser title: hashBrowser
tags: browser,utility,advanced,promise,advanced tags: browser,advanced,promise,advanced
--- ---
Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise. Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.
@ -20,4 +20,4 @@ const hashBrowser = val =>
```js ```js
hashBrowser(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393' hashBrowser(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: hashNode title: hashNode
tags: node,utility,promise,intermediate tags: node,promise,intermediate
--- ---
Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise. Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.
@ -26,4 +26,4 @@ const hashNode = val =>
```js ```js
hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393' hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: hexToRGB title: hexToRGB
tags: utility,string,math,advanced tags: string,math,advanced
--- ---
Converts a color code to a `rgb()` or `rgba()` string if alpha value is provided. Converts a color code to a `rgb()` or `rgba()` string if alpha value is provided.
@ -33,4 +33,4 @@ const hexToRGB = hex => {
hexToRGB('#27ae60ff'); // 'rgba(39, 174, 96, 255)' hexToRGB('#27ae60ff'); // 'rgba(39, 174, 96, 255)'
hexToRGB('27ae60'); // 'rgb(39, 174, 96)' hexToRGB('27ae60'); // 'rgb(39, 174, 96)'
hexToRGB('#fff'); // 'rgb(255, 255, 255)' hexToRGB('#fff'); // 'rgb(255, 255, 255)'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: httpDelete title: httpDelete
tags: utility,url,browser,intermediate tags: browser,url,intermediate
--- ---
Makes a `DELETE` request to the passed URL. Makes a `DELETE` request to the passed URL.

View File

@ -1,6 +1,6 @@
--- ---
title: httpGet title: httpGet
tags: utility,url,browser,intermediate tags: browser,url,intermediate
--- ---
Makes a `GET` request to the passed URL. Makes a `GET` request to the passed URL.
@ -32,4 +32,4 @@ Logs: {
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto" "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
} }
*/ */
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: httpPost title: httpPost
tags: utility,url,browser,intermediate tags: browser,url,intermediate
--- ---
Makes a `POST` request to the passed URL. Makes a `POST` request to the passed URL.
@ -52,4 +52,4 @@ Logs: {
"id": 101 "id": 101
} }
*/ */
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: httpPut title: httpPut
tags: utility,url,browser,intermediate tags: browser,url,intermediate
--- ---
Makes a `PUT` request to the passed URL. Makes a `PUT` request to the passed URL.

View File

@ -1,6 +1,6 @@
--- ---
title: indentString title: indentString
tags: string,utility,beginner tags: string,beginner
--- ---
Indents each line in the provided string. Indents each line in the provided string.
@ -15,4 +15,4 @@ const indentString = (str, count, indent = ' ') => str.replace(/^/gm, indent.rep
```js ```js
indentString('Lorem\nIpsum', 2); // ' Lorem\n Ipsum' indentString('Lorem\nIpsum', 2); // ' Lorem\n Ipsum'
indentString('Lorem\nIpsum', 2, '_'); // '__Lorem\n__Ipsum' indentString('Lorem\nIpsum', 2, '_'); // '__Lorem\n__Ipsum'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: isAbsoluteURL title: isAbsoluteURL
tags: string,utility,browser,url,intermediate tags: string,browser,url,intermediate
--- ---
Returns `true` if the given string is an absolute URL, `false` otherwise. Returns `true` if the given string is an absolute URL, `false` otherwise.
@ -15,4 +15,4 @@ const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
isAbsoluteURL('https://google.com'); // true isAbsoluteURL('https://google.com'); // true
isAbsoluteURL('ftp://www.myserver.net'); // true isAbsoluteURL('ftp://www.myserver.net'); // true
isAbsoluteURL('/foo/bar'); // false isAbsoluteURL('/foo/bar'); // false
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: isAfterDate title: isAfterDate
tags: date,utility,beginner tags: date,beginner
--- ---
Check if a date is after another date. Check if a date is after another date.
@ -13,4 +13,4 @@ const isAfterDate = (dateA, dateB) => dateA > dateB;
```js ```js
isAfterDate(new Date(2010, 10, 21), new Date(2010, 10, 20)); // true isAfterDate(new Date(2010, 10, 21), new Date(2010, 10, 20)); // true
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: isBeforeDate title: isBeforeDate
tags: date,utility,beginner tags: date,beginner
--- ---
Check if a date is before another date. Check if a date is before another date.
@ -13,4 +13,4 @@ const isBeforeDate = (dateA, dateB) => dateA < dateB;
```js ```js
isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21)); // true isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21)); // true
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: isBrowser title: isBrowser
tags: utility,browser,intermediate tags: browser,intermediate
--- ---
Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors. Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors.
@ -16,4 +16,4 @@ const isBrowser = () => ![typeof window, typeof document].includes('undefined');
```js ```js
isBrowser(); // true (browser) isBrowser(); // true (browser)
isBrowser(); // false (Node) isBrowser(); // false (Node)
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: isLowerCase title: isLowerCase
tags: string,utility,beginner tags: string,beginner
--- ---
Checks if a string is lower case. Checks if a string is lower case.
@ -15,4 +15,4 @@ const isLowerCase = str => str === str.toLowerCase();
isLowerCase('abc'); // true isLowerCase('abc'); // true
isLowerCase('a3@$'); // true isLowerCase('a3@$'); // true
isLowerCase('Ab4'); // false isLowerCase('Ab4'); // false
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: isNegativeZero title: isNegativeZero
tags: math,utility,beginner tags: math,beginner
--- ---
Checks if the given value is equal to negative zero (`-0`). Checks if the given value is equal to negative zero (`-0`).
@ -14,4 +14,4 @@ const isNegativeZero = val => val === 0 && 1 / val === -Infinity;
```js ```js
isNegativeZero(-0); // true isNegativeZero(-0); // true
isNegativeZero(0); // false isNegativeZero(0); // false
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: isSameDate title: isSameDate
tags: date,utility,beginner tags: date,beginner
--- ---
Check if a date is the same as another date. Check if a date is the same as another date.
@ -13,4 +13,4 @@ const isSameDate = (dateA, dateB) => dateA.toISOString() === dateB.toISOString()
```js ```js
isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 20)); // true isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 20)); // true
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: isUpperCase title: isUpperCase
tags: string,utility,beginner tags: string,beginner
--- ---
Checks if a string is upper case. Checks if a string is upper case.

View File

@ -1,6 +1,6 @@
--- ---
title: longestItem title: longestItem
tags: array,string,utility,intermediate tags: array,string,intermediate
--- ---
Takes any number of iterable objects or objects with a `length` property and returns the longest one. Takes any number of iterable objects or objects with a `length` property and returns the longest one.
@ -19,4 +19,4 @@ longestItem(...['a', 'ab', 'abc']); // 'abc'
longestItem(...['a', 'ab', 'abc'], 'abcd'); // 'abcd' longestItem(...['a', 'ab', 'abc'], 'abcd'); // 'abcd'
longestItem([1, 2, 3], [1, 2], [1, 2, 3, 4, 5]); // [1, 2, 3, 4, 5] longestItem([1, 2, 3], [1, 2], [1, 2, 3, 4, 5]); // [1, 2, 3, 4, 5]
longestItem([1, 2, 3], 'foobar'); // 'foobar' longestItem([1, 2, 3], 'foobar'); // 'foobar'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: luhnCheck title: luhnCheck
tags: math,utility,advanced tags: math,advanced
--- ---
Implementation of the [Luhn Algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm) used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers etc. Implementation of the [Luhn Algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm) used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers etc.
@ -27,4 +27,4 @@ const luhnCheck = num => {
luhnCheck('4485275742308327'); // true luhnCheck('4485275742308327'); // true
luhnCheck(6011329933655299); // false luhnCheck(6011329933655299); // false
luhnCheck(123456789); // false luhnCheck(123456789); // false
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: mapString title: mapString
tags: string,array,function,utility,beginner tags: string,array,function,beginner
--- ---
Creates a new string with the results of calling a provided function on every character in the calling string. Creates a new string with the results of calling a provided function on every character in the calling string.
@ -19,4 +19,4 @@ const mapString = (str, fn) =>
```js ```js
mapString('lorem ipsum', c => c.toUpperCase()); // 'LOREM IPSUM' mapString('lorem ipsum', c => c.toUpperCase()); // 'LOREM IPSUM'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: mask title: mask
tags: string,utility,intermediate tags: string,intermediate
--- ---
Replaces all but the last `num` of characters with the specified mask character. Replaces all but the last `num` of characters with the specified mask character.

View File

@ -1,6 +1,6 @@
--- ---
title: mostPerformant title: mostPerformant
tags: utility,function tags: function,intermediate
--- ---
Returns the index of the function in an array of functions which executed the fastest. Returns the index of the function in an array of functions which executed the fastest.
@ -31,4 +31,4 @@ mostPerformant([
[1, '2', 3, 4, 5, 6, 7, 8, 9, 10].every(el => typeof el === 'number'); [1, '2', 3, 4, 5, 6, 7, 8, 9, 10].every(el => typeof el === 'number');
} }
]); // 1 ]); // 1
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: nthArg title: nthArg
tags: utility,function,beginner tags: function,beginner
--- ---
Creates a function that gets the argument at index `n`. If `n` is negative, the nth argument from the end is returned. Creates a function that gets the argument at index `n`. If `n` is negative, the nth argument from the end is returned.
@ -17,4 +17,4 @@ third(1, 2, 3); // 3
third(1, 2); // undefined third(1, 2); // undefined
const last = nthArg(-1); const last = nthArg(-1);
last(1, 2, 3, 4, 5); // 5 last(1, 2, 3, 4, 5); // 5
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: objectToQueryString title: objectToQueryString
tags: utility,object,function,intermediate tags: object,function,intermediate
--- ---
Returns a query string generated from the key-value pairs of the given object. Returns a query string generated from the key-value pairs of the given object.

View File

@ -1,6 +1,6 @@
--- ---
title: parseCookie title: parseCookie
tags: utility,string,intermediate tags: browser,string,intermediate
--- ---
Parse an HTTP Cookie header string and return an object of all cookie name-value pairs. Parse an HTTP Cookie header string and return an object of all cookie name-value pairs.
@ -22,4 +22,4 @@ const parseCookie = str =>
```js ```js
parseCookie('foo=bar; equation=E%3Dmc%5E2'); // { foo: 'bar', equation: 'E=mc^2' } parseCookie('foo=bar; equation=E%3Dmc%5E2'); // { foo: 'bar', equation: 'E=mc^2' }
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: prefix title: prefix
tags: browser,utility,intermediate tags: browser,intermediate
--- ---
Returns the prefixed version (if necessary) of a CSS property that the browser supports. Returns the prefixed version (if necessary) of a CSS property that the browser supports.
@ -21,4 +21,4 @@ const prefix = prop => {
```js ```js
prefix('appearance'); // 'appearance' on a supported browser, otherwise 'webkitAppearance', 'mozAppearance', 'msAppearance' or 'oAppearance' prefix('appearance'); // 'appearance' on a supported browser, otherwise 'webkitAppearance', 'mozAppearance', 'msAppearance' or 'oAppearance'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: prettyBytes title: prettyBytes
tags: utility,string,math,advanced tags: string,math,advanced
--- ---
Converts a number in bytes to a human-readable string. Converts a number in bytes to a human-readable string.
@ -25,4 +25,4 @@ const prettyBytes = (num, precision = 3, addSpace = true) => {
prettyBytes(1000); // "1 KB" prettyBytes(1000); // "1 KB"
prettyBytes(-27145424323.5821, 5); // "-27.145 GB" prettyBytes(-27145424323.5821, 5); // "-27.145 GB"
prettyBytes(123456789, 3, false); // "123MB" prettyBytes(123456789, 3, false); // "123MB"
``` ```

View File

@ -1,11 +1,12 @@
--- ---
title: randomHexColorCode title: randomHexColorCode
tags: utility,random,beginner tags: math,random,beginner
--- ---
Generates a random hexadecimal color code. Generates a random hexadecimal color code.
Use `Math.random` to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using `toString(16)`. Use `Math.random` to generate a random 24-bit(6x4bits) hexadecimal number.
Use bit shifting and then convert it to an hexadecimal String using `toString(16)`.
```js ```js
const randomHexColorCode = () => { const randomHexColorCode = () => {
@ -16,4 +17,4 @@ const randomHexColorCode = () => {
```js ```js
randomHexColorCode(); // "#e34155" randomHexColorCode(); // "#e34155"
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: randomIntArrayInRange title: randomIntArrayInRange
tags: math,utility,random,intermediate tags: math,random,intermediate
--- ---
Returns an array of n random integers in the specified range. Returns an array of n random integers in the specified range.
@ -14,4 +14,4 @@ const randomIntArrayInRange = (min, max, n = 1) =>
```js ```js
randomIntArrayInRange(12, 35, 10); // [ 34, 14, 27, 17, 30, 27, 20, 26, 21, 14 ] randomIntArrayInRange(12, 35, 10); // [ 34, 14, 27, 17, 30, 27, 20, 26, 21, 14 ]
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: randomIntegerInRange title: randomIntegerInRange
tags: math,utility,random,beginner tags: math,random,beginner
--- ---
Returns a random integer in the specified range. Returns a random integer in the specified range.
@ -13,4 +13,4 @@ const randomIntegerInRange = (min, max) => Math.floor(Math.random() * (max - min
```js ```js
randomIntegerInRange(0, 5); // 2 randomIntegerInRange(0, 5); // 2
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: randomNumberInRange title: randomNumberInRange
tags: math,utility,random,beginner tags: math,random,beginner
--- ---
Returns a random number in the specified range. Returns a random number in the specified range.
@ -13,4 +13,4 @@ const randomNumberInRange = (min, max) => Math.random() * (max - min) + min;
```js ```js
randomNumberInRange(2, 10); // 6.0211363285087005 randomNumberInRange(2, 10); // 6.0211363285087005
``` ```

View File

@ -1,13 +1,13 @@
--- ---
title: recordAnimationFrames title: recordAnimationFrames
tags: browser,utility,intermediate tags: browser,intermediate
--- ---
Invokes the provided callback on each animation frame. Invokes the provided callback on each animation frame.
Use recursion. Use recursion.
Provided that `running` is `true`, continue invoking `window.requestAnimationFrame()` which invokes the provided callback. Provided that `running` is `true`, continue invoking `window.requestAnimationFrame()` which invokes the provided callback.
Return an object with two methods `start` and `stop` to allow manual control of the recording. Return an object with two methods `start` and `stop` to allow manual control of the recording.
Omit the second argument, `autoStart`, to implicitly call `start` when the function is invoked. Omit the second argument, `autoStart`, to implicitly call `start` when the function is invoked.
```js ```js
@ -39,4 +39,4 @@ const recorder = recordAnimationFrames(cb); // logs 'Animation frame fired' on e
recorder.stop(); // stops logging recorder.stop(); // stops logging
recorder.start(); // starts again recorder.start(); // starts again
const recorder2 = recordAnimationFrames(cb, false); // `start` needs to be explicitly called to begin recording frames const recorder2 = recordAnimationFrames(cb, false); // `start` needs to be explicitly called to begin recording frames
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: sdbm title: sdbm
tags: math,utility,intermediate tags: math,intermediate
--- ---
Hashes the input string into a whole number. Hashes the input string into a whole number.
@ -20,4 +20,4 @@ const sdbm = str => {
```js ```js
sdbm('name'); // -3521204949 sdbm('name'); // -3521204949
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: serializeCookie title: serializeCookie
tags: utility,string,intermediate tags: browser,string,intermediate
--- ---
Serialize a cookie name-value pair into a Set-Cookie header string. Serialize a cookie name-value pair into a Set-Cookie header string.
@ -13,4 +13,4 @@ const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIC
```js ```js
serializeCookie('foo', 'bar'); // 'foo=bar' serializeCookie('foo', 'bar'); // 'foo=bar'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: stripHTMLTags title: stripHTMLTags
tags: string,utility,regexp,beginner tags: string,regexp,beginner
--- ---
Removes HTML/XML tags from string. Removes HTML/XML tags from string.
@ -13,4 +13,4 @@ const stripHTMLTags = str => str.replace(/<[^>]*>/g, '');
```js ```js
stripHTMLTags('<p><em>lorem</em> <strong>ipsum</strong></p>'); // 'lorem ipsum' stripHTMLTags('<p><em>lorem</em> <strong>ipsum</strong></p>'); // 'lorem ipsum'
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: timeTaken title: timeTaken
tags: utility,beginner tags: function,beginner
--- ---
Measures the time taken by a function to execute. Measures the time taken by a function to execute.
@ -18,4 +18,4 @@ const timeTaken = callback => {
```js ```js
timeTaken(() => Math.pow(2, 10)); // 1024, (logged): timeTaken: 0.02099609375ms timeTaken(() => Math.pow(2, 10)); // 1024, (logged): timeTaken: 0.02099609375ms
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: toCurrency title: toCurrency
tags: utility,intermediate tags: math,string,intermediate
--- ---
Take a number and return specified currency formatting. Take a number and return specified currency formatting.
@ -18,4 +18,4 @@ toCurrency(123456.789, 'USD', 'en-us'); // $123,456.79 | currency: US Dollar |
toCurrency(123456.789, 'USD', 'fa'); // ۱۲۳٬۴۵۶٫۷۹ ؜$ | currency: US Dollar | currencyLangFormat: Farsi toCurrency(123456.789, 'USD', 'fa'); // ۱۲۳٬۴۵۶٫۷۹ ؜$ | currency: US Dollar | currencyLangFormat: Farsi
toCurrency(322342436423.2435, 'JPY'); // ¥322,342,436,423 | currency: Japanese Yen | currencyLangFormat: Local toCurrency(322342436423.2435, 'JPY'); // ¥322,342,436,423 | currency: Japanese Yen | currencyLangFormat: Local
toCurrency(322342436423.2435, 'JPY', 'fi'); // 322 342 436 423 ¥ | currency: Japanese Yen | currencyLangFormat: Finnish toCurrency(322342436423.2435, 'JPY', 'fi'); // 322 342 436 423 ¥ | currency: Japanese Yen | currencyLangFormat: Finnish
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: toDecimalMark title: toDecimalMark
tags: utility,math,beginner tags: math,beginner
--- ---
Converts a number to a decimal mark formatted string. Converts a number to a decimal mark formatted string.

View File

@ -1,6 +1,6 @@
--- ---
title: toOrdinalSuffix title: toOrdinalSuffix
tags: utility,math,intermediate tags: math,intermediate
--- ---
Adds an ordinal suffix to a number. Adds an ordinal suffix to a number.
@ -24,4 +24,4 @@ const toOrdinalSuffix = num => {
```js ```js
toOrdinalSuffix('123'); // "123rd" toOrdinalSuffix('123'); // "123rd"
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: validateNumber title: validateNumber
tags: utility,math,intermediate tags: math,intermediate
--- ---
Returns `true` if the given value is a number, `false` otherwise. Returns `true` if the given value is a number, `false` otherwise.
@ -15,4 +15,4 @@ const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) ==
```js ```js
validateNumber('10'); // true validateNumber('10'); // true
``` ```

View File

@ -1,6 +1,6 @@
--- ---
title: yesNo title: yesNo
tags: utility,regexp,intermediate tags: string,regexp,intermediate
--- ---
Returns `true` if the string is `y`/`yes` or `false` if the string is `n`/`no`. Returns `true` if the string is `y`/`yes` or `false` if the string is `n`/`no`.
@ -18,4 +18,4 @@ yesNo('Y'); // true
yesNo('yes'); // true yesNo('yes'); // true
yesNo('No'); // false yesNo('No'); // false
yesNo('Foo', true); // true yesNo('Foo', true); // true
``` ```