Deprecate utility tag
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: functionName
|
||||
tags: utility,intermediate
|
||||
tags: array,intermediate
|
||||
---
|
||||
|
||||
Explain briefly what the snippet does.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: CSVToArray
|
||||
tags: string,array,utility,intermediate
|
||||
tags: string,array,intermediate
|
||||
---
|
||||
|
||||
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('col1,col2\na,b\nc,d', ',', true); // [['a','b'],['c','d']];
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: RGBToHex
|
||||
tags: utility,intermediate
|
||||
tags: string,math,intermediate
|
||||
---
|
||||
|
||||
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
|
||||
RGBToHex(255, 165, 1); // 'ffa501'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: URLJoin
|
||||
tags: string,utility,regexp,advanced
|
||||
tags: string,regexp,advanced
|
||||
---
|
||||
|
||||
Joins all given URL segments together, then normalizes the resulting URL.
|
||||
@ -21,4 +21,4 @@ const URLJoin = (...args) =>
|
||||
|
||||
```js
|
||||
URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo'); // 'http://www.google.com/a/b/cd?foo=123&bar=foo'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: UUIDGeneratorBrowser
|
||||
tags: browser,utility,random,intermediate
|
||||
tags: browser,random,intermediate
|
||||
---
|
||||
|
||||
Generates a UUID in a browser.
|
||||
@ -16,4 +16,4 @@ const UUIDGeneratorBrowser = () =>
|
||||
|
||||
```js
|
||||
UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: UUIDGeneratorNode
|
||||
tags: node,utility,random,intermediate
|
||||
tags: node,random,intermediate
|
||||
---
|
||||
|
||||
Generates a UUID in Node.JS.
|
||||
@ -17,4 +17,4 @@ const UUIDGeneratorNode = () =>
|
||||
|
||||
```js
|
||||
UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: arrayToCSV
|
||||
tags: array,string,utility,intermediate
|
||||
tags: array,string,intermediate
|
||||
---
|
||||
|
||||
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" great'], ['c', 3.1415]]); // '"a","""b"" great"\n"c",3.1415'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: atob
|
||||
tags: node,string,utility,beginner
|
||||
tags: node,string,beginner
|
||||
---
|
||||
|
||||
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
|
||||
atob('Zm9vYmFy'); // 'foobar'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
@ -13,4 +13,4 @@ const btoa = str => Buffer.from(str, 'binary').toString('base64');
|
||||
|
||||
```js
|
||||
btoa('foobar'); // 'Zm9vYmFy'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: castArray
|
||||
tags: utility,array,type,beginner
|
||||
tags: type,array,beginner
|
||||
---
|
||||
|
||||
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
|
||||
castArray('foo'); // ['foo']
|
||||
castArray([1]); // [1]
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: cloneRegExp
|
||||
tags: utility,regexp,intermediate
|
||||
tags: type,string,regexp,intermediate
|
||||
---
|
||||
|
||||
Clones a regular expression.
|
||||
@ -14,4 +14,4 @@ const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
|
||||
```js
|
||||
const regExp = /lorem ipsum/gi;
|
||||
const regExp2 = cloneRegExp(regExp); // /lorem ipsum/gi
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: coalesce
|
||||
tags: utility,beginner
|
||||
tags: type,beginner
|
||||
---
|
||||
|
||||
Returns the first defined, non-null argument.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
@ -14,4 +14,4 @@ const coalesceFactory = valid => (...args) => args.find(valid);
|
||||
```js
|
||||
const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_));
|
||||
customCoalesce(undefined, null, NaN, '', 'Waldo'); // "Waldo"
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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()`).
|
||||
@ -33,4 +33,4 @@ const colorize = (...args) => ({
|
||||
console.log(colorize('foo').red); // 'foo' (red letters)
|
||||
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)
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
---
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
```js
|
||||
@ -25,4 +25,4 @@ const el = createElement(
|
||||
</div>`
|
||||
);
|
||||
console.log(el.className); // 'container'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: extendHex
|
||||
tags: utility,string,intermediate
|
||||
tags: string,intermediate
|
||||
---
|
||||
|
||||
Extends a 3-digit color code to a 6-digit color code.
|
||||
@ -21,4 +21,4 @@ const extendHex = shortHex =>
|
||||
```js
|
||||
extendHex('#03f'); // '#0033ff'
|
||||
extendHex('05a'); // '#0055aa'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: formatDuration
|
||||
tags: date,math,string,utility,intermediate
|
||||
tags: date,math,string,intermediate
|
||||
---
|
||||
|
||||
Returns the human readable format of the given number of milliseconds.
|
||||
@ -30,4 +30,4 @@ const formatDuration = ms => {
|
||||
```js
|
||||
formatDuration(1001); // '1 second, 1 millisecond'
|
||||
formatDuration(34325055574); // '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: functionName
|
||||
tags: function,utility,beginner
|
||||
tags: function,beginner
|
||||
---
|
||||
|
||||
Logs the name of a function.
|
||||
@ -13,4 +13,4 @@ const functionName = fn => (console.debug(fn.name), fn);
|
||||
|
||||
```js
|
||||
functionName(Math.max); // max (logged in debug channel of console)
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: getURLParameters
|
||||
tags: utility,browser,string,url,intermediate
|
||||
tags: browser,string,url,intermediate
|
||||
---
|
||||
|
||||
Returns an object containing the parameters of the current URL.
|
||||
@ -19,4 +19,4 @@ const getURLParameters = url =>
|
||||
```js
|
||||
getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'}
|
||||
getURLParameters('google.com'); // {}
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
@ -20,4 +20,4 @@ const hashBrowser = val =>
|
||||
|
||||
```js
|
||||
hashBrowser(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
@ -26,4 +26,4 @@ const hashNode = val =>
|
||||
|
||||
```js
|
||||
hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
@ -33,4 +33,4 @@ const hexToRGB = hex => {
|
||||
hexToRGB('#27ae60ff'); // 'rgba(39, 174, 96, 255)'
|
||||
hexToRGB('27ae60'); // 'rgb(39, 174, 96)'
|
||||
hexToRGB('#fff'); // 'rgb(255, 255, 255)'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: httpDelete
|
||||
tags: utility,url,browser,intermediate
|
||||
tags: browser,url,intermediate
|
||||
---
|
||||
|
||||
Makes a `DELETE` request to the passed URL.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: httpGet
|
||||
tags: utility,url,browser,intermediate
|
||||
tags: browser,url,intermediate
|
||||
---
|
||||
|
||||
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"
|
||||
}
|
||||
*/
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: httpPost
|
||||
tags: utility,url,browser,intermediate
|
||||
tags: browser,url,intermediate
|
||||
---
|
||||
|
||||
Makes a `POST` request to the passed URL.
|
||||
@ -52,4 +52,4 @@ Logs: {
|
||||
"id": 101
|
||||
}
|
||||
*/
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: httpPut
|
||||
tags: utility,url,browser,intermediate
|
||||
tags: browser,url,intermediate
|
||||
---
|
||||
|
||||
Makes a `PUT` request to the passed URL.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: indentString
|
||||
tags: string,utility,beginner
|
||||
tags: string,beginner
|
||||
---
|
||||
|
||||
Indents each line in the provided string.
|
||||
@ -15,4 +15,4 @@ const indentString = (str, count, indent = ' ') => str.replace(/^/gm, indent.rep
|
||||
```js
|
||||
indentString('Lorem\nIpsum', 2); // ' Lorem\n Ipsum'
|
||||
indentString('Lorem\nIpsum', 2, '_'); // '__Lorem\n__Ipsum'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
@ -15,4 +15,4 @@ const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str);
|
||||
isAbsoluteURL('https://google.com'); // true
|
||||
isAbsoluteURL('ftp://www.myserver.net'); // true
|
||||
isAbsoluteURL('/foo/bar'); // false
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: isAfterDate
|
||||
tags: date,utility,beginner
|
||||
tags: date,beginner
|
||||
---
|
||||
|
||||
Check if a date is after another date.
|
||||
@ -13,4 +13,4 @@ const isAfterDate = (dateA, dateB) => dateA > dateB;
|
||||
|
||||
```js
|
||||
isAfterDate(new Date(2010, 10, 21), new Date(2010, 10, 20)); // true
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: isBeforeDate
|
||||
tags: date,utility,beginner
|
||||
tags: date,beginner
|
||||
---
|
||||
|
||||
Check if a date is before another date.
|
||||
@ -13,4 +13,4 @@ const isBeforeDate = (dateA, dateB) => dateA < dateB;
|
||||
|
||||
```js
|
||||
isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21)); // true
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
@ -16,4 +16,4 @@ const isBrowser = () => ![typeof window, typeof document].includes('undefined');
|
||||
```js
|
||||
isBrowser(); // true (browser)
|
||||
isBrowser(); // false (Node)
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: isLowerCase
|
||||
tags: string,utility,beginner
|
||||
tags: string,beginner
|
||||
---
|
||||
|
||||
Checks if a string is lower case.
|
||||
@ -15,4 +15,4 @@ const isLowerCase = str => str === str.toLowerCase();
|
||||
isLowerCase('abc'); // true
|
||||
isLowerCase('a3@$'); // true
|
||||
isLowerCase('Ab4'); // false
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: isNegativeZero
|
||||
tags: math,utility,beginner
|
||||
tags: math,beginner
|
||||
---
|
||||
|
||||
Checks if the given value is equal to negative zero (`-0`).
|
||||
@ -14,4 +14,4 @@ const isNegativeZero = val => val === 0 && 1 / val === -Infinity;
|
||||
```js
|
||||
isNegativeZero(-0); // true
|
||||
isNegativeZero(0); // false
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: isSameDate
|
||||
tags: date,utility,beginner
|
||||
tags: date,beginner
|
||||
---
|
||||
|
||||
Check if a date is the same as another date.
|
||||
@ -13,4 +13,4 @@ const isSameDate = (dateA, dateB) => dateA.toISOString() === dateB.toISOString()
|
||||
|
||||
```js
|
||||
isSameDate(new Date(2010, 10, 20), new Date(2010, 10, 20)); // true
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: isUpperCase
|
||||
tags: string,utility,beginner
|
||||
tags: string,beginner
|
||||
---
|
||||
|
||||
Checks if a string is upper case.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
@ -19,4 +19,4 @@ longestItem(...['a', 'ab', 'abc']); // 'abc'
|
||||
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], 'foobar'); // 'foobar'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
@ -27,4 +27,4 @@ const luhnCheck = num => {
|
||||
luhnCheck('4485275742308327'); // true
|
||||
luhnCheck(6011329933655299); // false
|
||||
luhnCheck(123456789); // false
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
@ -19,4 +19,4 @@ const mapString = (str, fn) =>
|
||||
|
||||
```js
|
||||
mapString('lorem ipsum', c => c.toUpperCase()); // 'LOREM IPSUM'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: mask
|
||||
tags: string,utility,intermediate
|
||||
tags: string,intermediate
|
||||
---
|
||||
|
||||
Replaces all but the last `num` of characters with the specified mask character.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: mostPerformant
|
||||
tags: utility,function
|
||||
tags: function,intermediate
|
||||
---
|
||||
|
||||
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
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
@ -17,4 +17,4 @@ third(1, 2, 3); // 3
|
||||
third(1, 2); // undefined
|
||||
const last = nthArg(-1);
|
||||
last(1, 2, 3, 4, 5); // 5
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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.
|
||||
@ -22,4 +22,4 @@ const parseCookie = str =>
|
||||
|
||||
```js
|
||||
parseCookie('foo=bar; equation=E%3Dmc%5E2'); // { foo: 'bar', equation: 'E=mc^2' }
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: prefix
|
||||
tags: browser,utility,intermediate
|
||||
tags: browser,intermediate
|
||||
---
|
||||
|
||||
Returns the prefixed version (if necessary) of a CSS property that the browser supports.
|
||||
@ -21,4 +21,4 @@ const prefix = prop => {
|
||||
|
||||
```js
|
||||
prefix('appearance'); // 'appearance' on a supported browser, otherwise 'webkitAppearance', 'mozAppearance', 'msAppearance' or 'oAppearance'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: prettyBytes
|
||||
tags: utility,string,math,advanced
|
||||
tags: string,math,advanced
|
||||
---
|
||||
|
||||
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(-27145424323.5821, 5); // "-27.145 GB"
|
||||
prettyBytes(123456789, 3, false); // "123MB"
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
---
|
||||
title: randomHexColorCode
|
||||
tags: utility,random,beginner
|
||||
tags: math,random,beginner
|
||||
---
|
||||
|
||||
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
|
||||
const randomHexColorCode = () => {
|
||||
@ -16,4 +17,4 @@ const randomHexColorCode = () => {
|
||||
|
||||
```js
|
||||
randomHexColorCode(); // "#e34155"
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: randomIntArrayInRange
|
||||
tags: math,utility,random,intermediate
|
||||
tags: math,random,intermediate
|
||||
---
|
||||
|
||||
Returns an array of n random integers in the specified range.
|
||||
@ -14,4 +14,4 @@ const randomIntArrayInRange = (min, max, n = 1) =>
|
||||
|
||||
```js
|
||||
randomIntArrayInRange(12, 35, 10); // [ 34, 14, 27, 17, 30, 27, 20, 26, 21, 14 ]
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: randomIntegerInRange
|
||||
tags: math,utility,random,beginner
|
||||
tags: math,random,beginner
|
||||
---
|
||||
|
||||
Returns a random integer in the specified range.
|
||||
@ -13,4 +13,4 @@ const randomIntegerInRange = (min, max) => Math.floor(Math.random() * (max - min
|
||||
|
||||
```js
|
||||
randomIntegerInRange(0, 5); // 2
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: randomNumberInRange
|
||||
tags: math,utility,random,beginner
|
||||
tags: math,random,beginner
|
||||
---
|
||||
|
||||
Returns a random number in the specified range.
|
||||
@ -13,4 +13,4 @@ const randomNumberInRange = (min, max) => Math.random() * (max - min) + min;
|
||||
|
||||
```js
|
||||
randomNumberInRange(2, 10); // 6.0211363285087005
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
---
|
||||
title: recordAnimationFrames
|
||||
tags: browser,utility,intermediate
|
||||
tags: browser,intermediate
|
||||
---
|
||||
|
||||
Invokes the provided callback on each animation frame.
|
||||
|
||||
Use recursion.
|
||||
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.
|
||||
Use recursion.
|
||||
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.
|
||||
Omit the second argument, `autoStart`, to implicitly call `start` when the function is invoked.
|
||||
|
||||
```js
|
||||
@ -39,4 +39,4 @@ const recorder = recordAnimationFrames(cb); // logs 'Animation frame fired' on e
|
||||
recorder.stop(); // stops logging
|
||||
recorder.start(); // starts again
|
||||
const recorder2 = recordAnimationFrames(cb, false); // `start` needs to be explicitly called to begin recording frames
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: sdbm
|
||||
tags: math,utility,intermediate
|
||||
tags: math,intermediate
|
||||
---
|
||||
|
||||
Hashes the input string into a whole number.
|
||||
@ -20,4 +20,4 @@ const sdbm = str => {
|
||||
|
||||
```js
|
||||
sdbm('name'); // -3521204949
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: serializeCookie
|
||||
tags: utility,string,intermediate
|
||||
tags: browser,string,intermediate
|
||||
---
|
||||
|
||||
Serialize a cookie name-value pair into a Set-Cookie header string.
|
||||
@ -13,4 +13,4 @@ const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIC
|
||||
|
||||
```js
|
||||
serializeCookie('foo', 'bar'); // 'foo=bar'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: stripHTMLTags
|
||||
tags: string,utility,regexp,beginner
|
||||
tags: string,regexp,beginner
|
||||
---
|
||||
|
||||
Removes HTML/XML tags from string.
|
||||
@ -13,4 +13,4 @@ const stripHTMLTags = str => str.replace(/<[^>]*>/g, '');
|
||||
|
||||
```js
|
||||
stripHTMLTags('<p><em>lorem</em> <strong>ipsum</strong></p>'); // 'lorem ipsum'
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: timeTaken
|
||||
tags: utility,beginner
|
||||
tags: function,beginner
|
||||
---
|
||||
|
||||
Measures the time taken by a function to execute.
|
||||
@ -18,4 +18,4 @@ const timeTaken = callback => {
|
||||
|
||||
```js
|
||||
timeTaken(() => Math.pow(2, 10)); // 1024, (logged): timeTaken: 0.02099609375ms
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: toCurrency
|
||||
tags: utility,intermediate
|
||||
tags: math,string,intermediate
|
||||
---
|
||||
|
||||
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(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
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: toDecimalMark
|
||||
tags: utility,math,beginner
|
||||
tags: math,beginner
|
||||
---
|
||||
|
||||
Converts a number to a decimal mark formatted string.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: toOrdinalSuffix
|
||||
tags: utility,math,intermediate
|
||||
tags: math,intermediate
|
||||
---
|
||||
|
||||
Adds an ordinal suffix to a number.
|
||||
@ -24,4 +24,4 @@ const toOrdinalSuffix = num => {
|
||||
|
||||
```js
|
||||
toOrdinalSuffix('123'); // "123rd"
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: validateNumber
|
||||
tags: utility,math,intermediate
|
||||
tags: math,intermediate
|
||||
---
|
||||
|
||||
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
|
||||
validateNumber('10'); // true
|
||||
```
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
---
|
||||
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`.
|
||||
@ -18,4 +18,4 @@ yesNo('Y'); // true
|
||||
yesNo('yes'); // true
|
||||
yesNo('No'); // false
|
||||
yesNo('Foo', true); // true
|
||||
```
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user