diff --git a/README.md b/README.md index 0ad824575..f03694e55 100644 --- a/README.md +++ b/README.md @@ -84,9 +84,9 @@ average(1, 2, 3); ### 🔌 Adapter
- View contents - - * [`ary`](#ary) +View contents + +* [`ary`](#ary) * [`call`](#call) * [`collectInto`](#collectinto) * [`flip`](#flip) @@ -104,9 +104,9 @@ average(1, 2, 3); ### 📚 Array
- View contents - - * [`all`](#all) +View contents + +* [`all`](#all) * [`allEqual`](#allequal) * [`any`](#any) * [`arrayToCSV`](#arraytocsv) @@ -203,9 +203,9 @@ average(1, 2, 3); ### 🌐 Browser
- View contents - - * [`arrayToHtmlList`](#arraytohtmllist) +View contents + +* [`arrayToHtmlList`](#arraytohtmllist) * [`bottomVisible`](#bottomvisible) * [`copyToClipboard`](#copytoclipboard-) * [`counter`](#counter-) @@ -246,9 +246,9 @@ average(1, 2, 3); ### ⏱️ Date
- View contents - - * [`formatDuration`](#formatduration) +View contents + +* [`formatDuration`](#formatduration) * [`getColonTimeFromDate`](#getcolontimefromdate) * [`getDaysDiffBetweenDates`](#getdaysdiffbetweendates) * [`getMeridiemSuffixOfInteger`](#getmeridiemsuffixofinteger) @@ -259,9 +259,9 @@ average(1, 2, 3); ### 🎛️ Function
- View contents - - * [`attempt`](#attempt) +View contents + +* [`attempt`](#attempt) * [`bind`](#bind) * [`bindKey`](#bindkey) * [`chainAsync`](#chainasync) @@ -292,9 +292,9 @@ average(1, 2, 3); ### ➗ Math
- View contents - - * [`approximatelyEqual`](#approximatelyequal) +View contents + +* [`approximatelyEqual`](#approximatelyequal) * [`average`](#average) * [`averageBy`](#averageby) * [`binomialCoefficient`](#binomialcoefficient) @@ -337,9 +337,9 @@ average(1, 2, 3); ### 📦 Node
- View contents - - * [`atob`](#atob) +View contents + +* [`atob`](#atob) * [`btoa`](#btoa) * [`colorize`](#colorize) * [`hasFlags`](#hasflags) @@ -355,9 +355,9 @@ average(1, 2, 3); ### 🗃️ Object
- View contents - - * [`bindAll`](#bindall) +View contents + +* [`bindAll`](#bindall) * [`deepClone`](#deepclone) * [`deepFreeze`](#deepfreeze) * [`defaults`](#defaults) @@ -397,9 +397,9 @@ average(1, 2, 3); ### 📜 String
- View contents - - * [`byteSize`](#bytesize) +View contents + +* [`byteSize`](#bytesize) * [`capitalize`](#capitalize) * [`capitalizeEveryWord`](#capitalizeeveryword) * [`CSVToArray`](#csvtoarray) @@ -436,9 +436,9 @@ average(1, 2, 3); ### 📃 Type
- View contents - - * [`getType`](#gettype) +View contents + +* [`getType`](#gettype) * [`is`](#is) * [`isArrayLike`](#isarraylike) * [`isBoolean`](#isboolean) @@ -462,9 +462,9 @@ average(1, 2, 3); ### 🔧 Utility
- View contents - - * [`castArray`](#castarray) +View contents + +* [`castArray`](#castarray) * [`cloneRegExp`](#cloneregexp) * [`coalesce`](#coalesce) * [`coalesceFactory`](#coalescefactory) @@ -506,9 +506,9 @@ const ary = (fn, n) => (...args) => fn(...args.slice(0, n)); ```
- Examples - - ```js +Examples + +```js const firstTwoMax = ary(Math.max, 2); [[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)); // [6, 8, 10] ``` @@ -528,9 +528,9 @@ const call = (key, ...args) => context => context[key](...args); ```
- Examples - - ```js +Examples + +```js Promise.resolve([1, 2, 3]) .then(call('map', x => 2 * x)) .then(console.log); //[ 2, 4, 6 ] @@ -555,9 +555,9 @@ const collectInto = fn => (...args) => fn(args); ```
- Examples - - ```js +Examples + +```js const Pall = collectInto(Promise.all.bind(Promise)); let p1 = Promise.resolve(1); let p2 = Promise.resolve(2); @@ -580,9 +580,9 @@ const flip = fn => (first, ...rest) => fn(...rest, first); ```
- Examples - - ```js +Examples + +```js let a = { name: 'John Smith' }; let b = {}; const mergeFrom = flip(Object.assign); @@ -607,9 +607,9 @@ const over = (...fns) => (...args) => fns.map(fn => fn.apply(null, args)); ```
- Examples - - ```js +Examples + +```js const minMax = over(Math.min, Math.max); minMax(1, 2, 3, 4, 5); // [1,5] ``` @@ -629,9 +629,9 @@ const overArgs = (fn, transforms) => (...args) => fn(...args.map((val, i) => tra ```
- Examples - - ```js +Examples + +```js const square = n => n * n; const double = n => n * 2; const fn = overArgs((x, y) => [x, y], [square, double]); @@ -655,9 +655,9 @@ const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Pr ```
- Examples - - ```js +Examples + +```js const sum = pipeAsyncFunctions( x => x + 1, x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)), @@ -685,9 +685,9 @@ const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args) ```
- Examples - - ```js +Examples + +```js const add5 = x => x + 5; const multiply = (x, y) => x * y; const multiplyAndAdd5 = pipeFunctions(multiply, add5); @@ -715,9 +715,9 @@ const promisify = func => (...args) => ```
- Examples - - ```js +Examples + +```js const delay = promisify((d, cb) => setTimeout(cb, d)); delay(2000).then(() => console.log('Hi!')); // // Promise resolves after 2s ``` @@ -737,9 +737,9 @@ const rearg = (fn, indexes) => (...args) => fn(...indexes.map(i => args[i])); ```
- Examples - - ```js +Examples + +```js var rearged = rearg( function(a, b, c) { return [a, b, c]; @@ -764,9 +764,9 @@ const spreadOver = fn => argsArr => fn(...argsArr); ```
- Examples - - ```js +Examples + +```js const arrayMax = spreadOver(Math.max); arrayMax([1, 2, 3]); // 3 ``` @@ -786,9 +786,9 @@ const unary = fn => val => fn(val); ```
- Examples - - ```js +Examples + +```js ['6', '8', '10'].map(unary(parseInt)); // [6, 8, 10] ``` @@ -813,9 +813,9 @@ const all = (arr, fn = Boolean) => arr.every(fn); ```
- Examples - - ```js +Examples + +```js all([4, 2, 3], x => x > 1); // true all([1, 2, 3]); // true ``` @@ -835,9 +835,9 @@ const allEqual = arr => arr.every(val => val === arr[0]); ```
- Examples - - ```js +Examples + +```js allEqual([1, 2, 3, 4, 5, 6]); // false allEqual([1, 1, 1, 1]); // true ``` @@ -858,9 +858,9 @@ const any = (arr, fn = Boolean) => arr.some(fn); ```
- Examples - - ```js +Examples + +```js any([0, 1, 2, 0], x => x >= 2); // true any([0, 0, 1, 0]); // true ``` @@ -883,9 +883,9 @@ const arrayToCSV = (arr, delimiter = ',') => ```
- Examples - - ```js +Examples + +```js arrayToCSV([['a', 'b'], ['c', 'd']]); // '"a","b"\n"c","d"' arrayToCSV([['a', 'b'], ['c', 'd']], ';'); // '"a";"b"\n"c";"d"' ``` @@ -906,9 +906,9 @@ const bifurcate = (arr, filter) => ```
- Examples - - ```js +Examples + +```js bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); // [ ['beep', 'boop', 'bar'], ['foo'] ] ``` @@ -928,9 +928,9 @@ const bifurcateBy = (arr, fn) => ```
- Examples - - ```js +Examples + +```js bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ] ``` @@ -954,9 +954,9 @@ const chunk = (arr, size) => ```
- Examples - - ```js +Examples + +```js chunk([1, 2, 3, 4, 5], 2); // [[1,2],[3,4],[5]] ``` @@ -975,9 +975,9 @@ const compact = arr => arr.filter(Boolean); ```
- Examples - - ```js +Examples + +```js compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]); // [ 1, 2, 3, 'a', 's', 34 ] ``` @@ -1001,9 +1001,9 @@ const countBy = (arr, fn) => ```
- Examples - - ```js +Examples + +```js countBy([6.1, 4.2, 6.3], Math.floor); // {4: 1, 6: 2} countBy(['one', 'two', 'three'], 'length'); // {3: 2, 5: 1} ``` @@ -1023,9 +1023,9 @@ const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : ```
- Examples - - ```js +Examples + +```js countOccurrences([1, 1, 2, 1, 2, 3], 1); // 3 ``` @@ -1046,9 +1046,9 @@ const deepFlatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? deepFla ```
- Examples - - ```js +Examples + +```js deepFlatten([1, [2], [[3], 4], 5]); // [1,2,3,4,5] ``` @@ -1070,9 +1070,9 @@ const difference = (a, b) => { ```
- Examples - - ```js +Examples + +```js difference([1, 2, 3], [1, 2, 4]); // [3] ``` @@ -1094,9 +1094,9 @@ const differenceBy = (a, b, fn) => { ```
- Examples - - ```js +Examples + +```js differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [1.2] differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x); // [ { x: 2 } ] ``` @@ -1116,9 +1116,9 @@ const differenceWith = (arr, val, comp) => arr.filter(a => val.findIndex(b => co ```
- Examples - - ```js +Examples + +```js differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b)); // [1, 1.2] ``` @@ -1137,9 +1137,9 @@ const drop = (arr, n = 1) => arr.slice(n); ```
- Examples - - ```js +Examples + +```js drop([1, 2, 3]); // [2,3] drop([1, 2, 3], 2); // [3] drop([1, 2, 3], 42); // [] @@ -1160,9 +1160,9 @@ const dropRight = (arr, n = 1) => arr.slice(0, -n); ```
- Examples - - ```js +Examples + +```js dropRight([1, 2, 3]); // [1,2] dropRight([1, 2, 3], 2); // [1] dropRight([1, 2, 3], 42); // [] @@ -1187,9 +1187,9 @@ const dropRightWhile = (arr, func) => { ```
- Examples - - ```js +Examples + +```js dropRightWhile([1, 2, 3, 4], n => n < 3); // [1, 2] ``` @@ -1212,9 +1212,9 @@ const dropWhile = (arr, func) => { ```
- Examples - - ```js +Examples + +```js dropWhile([1, 2, 3, 4], n => n >= 3); // [3,4] ``` @@ -1233,9 +1233,9 @@ const everyNth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1); ```
- Examples - - ```js +Examples + +```js everyNth([1, 2, 3, 4, 5, 6], 2); // [ 2, 4, 6 ] ``` @@ -1254,9 +1254,9 @@ const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexO ```
- Examples - - ```js +Examples + +```js filterNonUnique([1, 2, 2, 3, 4, 4, 5]); // [1,3,5] ``` @@ -1277,9 +1277,9 @@ const filterNonUniqueBy = (arr, fn) => ```
- Examples - - ```js +Examples + +```js filterNonUniqueBy( [ { id: 0, value: 'a' }, @@ -1307,9 +1307,9 @@ const findLast = (arr, fn) => arr.filter(fn).pop(); ```
- Examples - - ```js +Examples + +```js findLast([1, 2, 3, 4], n => n % 2 === 1); // 3 ``` @@ -1333,9 +1333,9 @@ const findLastIndex = (arr, fn) => ```
- Examples - - ```js +Examples + +```js findLastIndex([1, 2, 3, 4], n => n % 2 === 1); // 2 (index of the value 3) ``` @@ -1358,9 +1358,9 @@ const flatten = (arr, depth = 1) => ```
- Examples - - ```js +Examples + +```js flatten([1, [2], 3, 4]); // [1, 2, 3, 4] flatten([1, [2, [3, [4, 5], 6], 7], 8], 2); // [1, 2, 3, [4, 5], 6, 7, 8] ``` @@ -1384,9 +1384,9 @@ const forEachRight = (arr, callback) => ```
- Examples - - ```js +Examples + +```js forEachRight([1, 2, 3, 4], val => console.log(val)); // '4', '3', '2', '1' ``` @@ -1410,9 +1410,9 @@ const groupBy = (arr, fn) => ```
- Examples - - ```js +Examples + +```js groupBy([6.1, 4.2, 6.3], Math.floor); // {4: [4.2], 6: [6.1, 6.3]} groupBy(['one', 'two', 'three'], 'length'); // {3: ['one', 'two'], 5: ['three']} ``` @@ -1432,9 +1432,9 @@ const head = arr => arr[0]; ```
- Examples - - ```js +Examples + +```js head([1, 2, 3]); // 1 ``` @@ -1454,9 +1454,9 @@ const indexOfAll = (arr, val) => arr.reduce((acc, el, i) => (el === val ? [...ac ```
- Examples - - ```js +Examples + +```js indexOfAll([1, 2, 3, 1, 2, 3], 1); // [0,3] indexOfAll([1, 2, 3], 4); // [] ``` @@ -1476,9 +1476,9 @@ const initial = arr => arr.slice(0, -1); ```
- Examples - - ```js +Examples + +```js initial([1, 2, 3]); // [1,2] ``` @@ -1498,9 +1498,9 @@ const initialize2DArray = (w, h, val = null) => ```
- Examples - - ```js +Examples + +```js initialize2DArray(2, 2, 0); // [[0,0], [0,0]] ``` @@ -1522,9 +1522,9 @@ const initializeArrayWithRange = (end, start = 0, step = 1) => ```
- Examples - - ```js +Examples + +```js initializeArrayWithRange(5); // [0,1,2,3,4,5] initializeArrayWithRange(7, 3); // [3,4,5,6,7] initializeArrayWithRange(9, 0, 2); // [0,2,4,6,8] @@ -1550,9 +1550,9 @@ const initializeArrayWithRangeRight = (end, start = 0, step = 1) => ```
- Examples - - ```js +Examples + +```js initializeArrayWithRangeRight(5); // [5,4,3,2,1,0] initializeArrayWithRangeRight(7, 3); // [7,6,5,4,3] initializeArrayWithRangeRight(9, 0, 2); // [8,6,4,2,0] @@ -1574,9 +1574,9 @@ const initializeArrayWithValues = (n, val = 0) => Array(n).fill(val); ```
- Examples - - ```js +Examples + +```js initializeArrayWithValues(5, 2); // [2,2,2,2,2] ``` @@ -1599,9 +1599,9 @@ const initializeNDArray = (val, ...args) => ```
- Examples - - ```js +Examples + +```js initializeNDArray(1, 3); // [1,1,1] initializeNDArray(5, 2, 2, 2); // [[[5,5],[5,5]],[[5,5],[5,5]]] ``` @@ -1624,9 +1624,9 @@ const intersection = (a, b) => { ```
- Examples - - ```js +Examples + +```js intersection([1, 2, 3], [4, 3, 2]); // [2,3] ``` @@ -1648,9 +1648,9 @@ const intersectionBy = (a, b, fn) => { ```
- Examples - - ```js +Examples + +```js intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [2.1] ``` @@ -1669,9 +1669,9 @@ const intersectionWith = (a, b, comp) => a.filter(x => b.findIndex(y => comp(x, ```
- Examples - - ```js +Examples + +```js intersectionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1.5, 3, 0] ``` @@ -1699,9 +1699,9 @@ const isSorted = arr => { ```
- Examples - - ```js +Examples + +```js isSorted([0, 1, 2, 2]); // 1 isSorted([4, 3, 2]); // -1 isSorted([4, 3, 5]); // 0 @@ -1733,9 +1733,9 @@ const join = (arr, separator = ',', end = separator) => ```
- Examples - - ```js +Examples + +```js join(['pen', 'pineapple', 'apple', 'pen'], ',', '&'); // "pen,pineapple,apple&pen" join(['pen', 'pineapple', 'apple', 'pen'], ','); // "pen,pineapple,apple,pen" join(['pen', 'pineapple', 'apple', 'pen']); // "pen,pineapple,apple,pen" @@ -1768,9 +1768,9 @@ const JSONtoCSV = (arr, columns, delimiter = ',') => ```
- Examples - - ```js +Examples + +```js JSONtoCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b']); // 'a,b\n"1","2"\n"3","4"\n"6",""\n"","7"' JSONtoCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b'], ';'); // 'a;b\n"1";"2"\n"3";"4"\n"6";""\n"";"7"' ``` @@ -1790,9 +1790,9 @@ const last = arr => arr[arr.length - 1]; ```
- Examples - - ```js +Examples + +```js last([1, 2, 3]); // 3 ``` @@ -1814,9 +1814,9 @@ const longestItem = (val, ...vals) => ```
- Examples - - ```js +Examples + +```js longestItem('this', 'is', 'a', 'testcase'); // 'testcase' longestItem(...['a', 'ab', 'abc']); // 'abc' longestItem(...['a', 'ab', 'abc'], 'abcd'); // 'abcd' @@ -1842,9 +1842,9 @@ const mapObject = (arr, fn) => ```
- Examples - - ```js +Examples + +```js const squareIt = arr => mapObject(arr, a => a * a); squareIt([1, 2, 3]); // { 1: 1, 2: 4, 3: 9 } ``` @@ -1866,9 +1866,9 @@ const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n); ```
- Examples - - ```js +Examples + +```js maxN([1, 2, 3]); // [3] maxN([1, 2, 3], 2); // [3,2] ``` @@ -1890,9 +1890,9 @@ const minN = (arr, n = 1) => [...arr].sort((a, b) => a - b).slice(0, n); ```
- Examples - - ```js +Examples + +```js minN([1, 2, 3]); // [1] minN([1, 2, 3], 2); // [1,2] ``` @@ -1913,9 +1913,9 @@ const none = (arr, fn = Boolean) => !arr.some(fn); ```
- Examples - - ```js +Examples + +```js none([0, 1, 3, 0], x => x == 2); // true none([0, 0, 0]); // true ``` @@ -1937,9 +1937,9 @@ const nthElement = (arr, n = 0) => (n === -1 ? arr.slice(n) : arr.slice(n, n + 1 ```
- Examples - - ```js +Examples + +```js nthElement(['a', 'b', 'c'], 1); // 'b' nthElement(['a', 'b', 'b'], -3); // 'a' ``` @@ -1961,9 +1961,9 @@ const offset = (arr, offset) => [...arr.slice(offset), ...arr.slice(0, offset)]; ```
- Examples - - ```js +Examples + +```js offset([1, 2, 3, 4, 5], 2); // [3, 4, 5, 1, 2] offset([1, 2, 3, 4, 5], -2); // [4, 5, 1, 2, 3] ``` @@ -1991,9 +1991,9 @@ const partition = (arr, fn) => ```
- Examples - - ```js +Examples + +```js const users = [{ user: 'barney', age: 36, active: false }, { user: 'fred', age: 40, active: true }]; partition(users, o => o.active); // [[{ 'user': 'fred', 'age': 40, 'active': true }],[{ 'user': 'barney', 'age': 36, 'active': false }]] ``` @@ -2027,9 +2027,9 @@ const permutations = arr => { ```
- Examples - - ```js +Examples + +```js permutations([1, 33, 5]); // [ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ] ``` @@ -2056,9 +2056,9 @@ const pull = (arr, ...args) => { ```
- Examples - - ```js +Examples + +```js let myArray = ['a', 'b', 'c', 'a', 'b', 'c']; pull(myArray, 'a', 'c'); // myArray = [ 'b', 'b' ] ``` @@ -2088,9 +2088,9 @@ const pullAtIndex = (arr, pullArr) => { ```
- Examples - - ```js +Examples + +```js let myArray = ['a', 'b', 'c', 'd']; let pulled = pullAtIndex(myArray, [1, 3]); // myArray = [ 'a', 'c' ] , pulled = [ 'b', 'd' ] ``` @@ -2119,9 +2119,9 @@ const pullAtValue = (arr, pullArr) => { ```
- Examples - - ```js +Examples + +```js let myArray = ['a', 'b', 'c', 'd']; let pulled = pullAtValue(myArray, ['b', 'd']); // myArray = [ 'a', 'c' ] , pulled = [ 'b', 'd' ] ``` @@ -2152,9 +2152,9 @@ const pullBy = (arr, ...args) => { ```
- Examples - - ```js +Examples + +```js var myArray = [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 1 }]; pullBy(myArray, [{ x: 1 }, { x: 3 }], o => o.x); // myArray = [{ x: 2 }] ``` @@ -2181,9 +2181,9 @@ const reducedFilter = (data, keys, fn) => ```
- Examples - - ```js +Examples + +```js const data = [ { id: 1, @@ -2216,9 +2216,9 @@ const reduceSuccessive = (arr, fn, acc) => ```
- Examples - - ```js +Examples + +```js reduceSuccessive([1, 2, 3, 4, 5, 6], (acc, val) => acc + val, 0); // [0, 1, 3, 6, 10, 15, 21] ``` @@ -2239,9 +2239,9 @@ const reduceWhich = (arr, comparator = (a, b) => a - b) => ```
- Examples - - ```js +Examples + +```js reduceWhich([1, 3, 2]); // 1 reduceWhich([1, 3, 2], (a, b) => b - a); // 3 reduceWhich( @@ -2263,9 +2263,9 @@ const reject = (pred, array) => array.filter((...args) => !pred(...args)); ```
- Examples - - ```js +Examples + +```js reject(x => x % 2 === 0, [1, 2, 3, 4, 5]); // [1, 3, 5] reject(word => word.length > 4, ['Apple', 'Pear', 'Kiwi', 'Banana']); // ['Pear', 'Kiwi'] ``` @@ -2292,9 +2292,9 @@ const remove = (arr, func) => ```
- Examples - - ```js +Examples + +```js remove([1, 2, 3, 4], n => n % 2 === 0); // [2, 4] ``` @@ -2314,9 +2314,9 @@ const sample = arr => arr[Math.floor(Math.random() * arr.length)]; ```
- Examples - - ```js +Examples + +```js sample([3, 7, 9, 11]); // 9 ``` @@ -2344,9 +2344,9 @@ const sampleSize = ([...arr], n = 1) => { ```
- Examples - - ```js +Examples + +```js sampleSize([1, 2, 3], 2); // [3,1] sampleSize([1, 2, 3], 4); // [2,3,1] ``` @@ -2373,9 +2373,9 @@ const shuffle = ([...arr]) => { ```
- Examples - - ```js +Examples + +```js const foo = [1, 2, 3]; shuffle(foo); // [2,3,1], foo = [1,2,3] ``` @@ -2395,9 +2395,9 @@ const similarity = (arr, values) => arr.filter(v => values.includes(v)); ```
- Examples - - ```js +Examples + +```js similarity([1, 2, 3], [1, 2, 4]); // [1,2] ``` @@ -2421,9 +2421,9 @@ const sortedIndex = (arr, n) => { ```
- Examples - - ```js +Examples + +```js sortedIndex([5, 3, 2, 1], 4); // 1 sortedIndex([30, 50], 40); // 1 ``` @@ -2449,9 +2449,9 @@ const sortedIndexBy = (arr, n, fn) => { ```
- Examples - - ```js +Examples + +```js sortedIndexBy([{ x: 4 }, { x: 5 }], { x: 4 }, o => o.x); // 0 ``` @@ -2475,9 +2475,9 @@ const sortedLastIndex = (arr, n) => { ```
- Examples - - ```js +Examples + +```js sortedLastIndex([10, 20, 30, 30, 40], 30); // 4 ``` @@ -2506,9 +2506,9 @@ const sortedLastIndexBy = (arr, n, fn) => { ```
- Examples - - ```js +Examples + +```js sortedLastIndexBy([{ x: 4 }, { x: 5 }], { x: 4 }, o => o.x); // 1 ``` @@ -2534,9 +2534,9 @@ const stableSort = (arr, compare) => ```
- Examples - - ```js +Examples + +```js const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const stable = stableSort(arr, () => 0); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ``` @@ -2560,9 +2560,9 @@ const symmetricDifference = (a, b) => { ```
- Examples - - ```js +Examples + +```js symmetricDifference([1, 2, 3], [1, 2, 4]); // [3, 4] symmetricDifference([1, 2, 2], [1, 3, 1]); // [2, 2, 3] ``` @@ -2586,9 +2586,9 @@ const symmetricDifferenceBy = (a, b, fn) => { ```
- Examples - - ```js +Examples + +```js symmetricDifferenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // [ 1.2, 3.4 ] ``` @@ -2610,9 +2610,9 @@ const symmetricDifferenceWith = (arr, val, comp) => [ ```
- Examples - - ```js +Examples + +```js symmetricDifferenceWith( [1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], @@ -2635,9 +2635,9 @@ const tail = arr => (arr.length > 1 ? arr.slice(1) : arr); ```
- Examples - - ```js +Examples + +```js tail([1, 2, 3]); // [2,3] tail([1]); // [1] ``` @@ -2657,9 +2657,9 @@ const take = (arr, n = 1) => arr.slice(0, n); ```
- Examples - - ```js +Examples + +```js take([1, 2, 3], 5); // [1, 2, 3] take([1, 2, 3], 0); // [] ``` @@ -2679,9 +2679,9 @@ const takeRight = (arr, n = 1) => arr.slice(arr.length - n, arr.length); ```
- Examples - - ```js +Examples + +```js takeRight([1, 2, 3], 2); // [ 2, 3 ] takeRight([1, 2, 3]); // [3] ``` @@ -2706,9 +2706,9 @@ const takeRightWhile = (arr, func) => { ```
- Examples - - ```js +Examples + +```js takeRightWhile([1, 2, 3, 4], n => n < 3); // [3, 4] ``` @@ -2731,9 +2731,9 @@ const takeWhile = (arr, func) => { ```
- Examples - - ```js +Examples + +```js takeWhile([1, 2, 3, 4], n => n >= 3); // [1, 2] ``` @@ -2757,9 +2757,9 @@ const toHash = (object, key) => ```
- Examples - - ```js +Examples + +```js toHash([4, 3, 2, 1]); // { 0: 4, 1: 3, 2: 2, 1: 1 } toHash([{ a: 'label' }], 'a'); // { label: { a: 'label' } } // A more in depth example: @@ -2790,9 +2790,9 @@ const union = (a, b) => Array.from(new Set([...a, ...b])); ```
- Examples - - ```js +Examples + +```js union([1, 2, 3], [4, 3, 2]); // [1,2,3,4] ``` @@ -2816,9 +2816,9 @@ const unionBy = (a, b, fn) => { ```
- Examples - - ```js +Examples + +```js unionBy([2.1], [1.2, 2.3], Math.floor); // [2.1, 1.2] ``` @@ -2838,9 +2838,9 @@ const unionWith = (a, b, comp) => ```
- Examples - - ```js +Examples + +```js unionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)); // [1, 1.2, 1.5, 3, 0, 3.9] ``` @@ -2859,9 +2859,9 @@ const uniqueElements = arr => [...new Set(arr)]; ```
- Examples - - ```js +Examples + +```js uniqueElements([1, 2, 2, 3, 4, 4, 5]); // [1,2,3,4,5] ``` @@ -2885,9 +2885,9 @@ const uniqueElementsBy = (arr, fn) => ```
- Examples - - ```js +Examples + +```js uniqueElementsBy( [ { id: 0, value: 'a' }, @@ -2920,9 +2920,9 @@ const uniqueElementsByRight = (arr, fn) => ```
- Examples - - ```js +Examples + +```js uniqueElementsByRight( [ { id: 0, value: 'a' }, @@ -2952,9 +2952,9 @@ const uniqueSymmetricDifference = (a, b) => [ ```
- Examples - - ```js +Examples + +```js uniqueSymmetricDifference([1, 2, 3], [1, 2, 4]); // [3, 4] uniqueSymmetricDifference([1, 2, 2], [1, 3, 1]); // [2, 3] ``` @@ -2981,9 +2981,9 @@ const unzip = arr => ```
- Examples - - ```js +Examples + +```js unzip([['a', 1, true], ['b', 2, false]]); //[['a', 'b'], [1, 2], [true, false]] unzip([['a', 1, true], ['b', 2]]); //[['a', 'b'], [1, 2], [true]] ``` @@ -3013,9 +3013,9 @@ const unzipWith = (arr, fn) => ```
- Examples - - ```js +Examples + +```js unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)); // [3, 30, 300] ``` @@ -3036,9 +3036,9 @@ const without = (arr, ...args) => arr.filter(v => !args.includes(v)); ```
- Examples - - ```js +Examples + +```js without([2, 1, 2, 3], 1, 2); // [3] ``` @@ -3057,9 +3057,9 @@ const xProd = (a, b) => a.reduce((acc, x) => acc.concat(b.map(y => [x, y])), []) ```
- Examples - - ```js +Examples + +```js xProd([1, 2], ['a', 'b']); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] ``` @@ -3085,9 +3085,9 @@ const zip = (...arrays) => { ```
- Examples - - ```js +Examples + +```js zip(['a', 'b'], [1, 2], [true, false]); // [['a', 1, true], ['b', 2, false]] zip(['a'], [1, 2], [true, false]); // [['a', 1, true], [undefined, 2, false]] ``` @@ -3108,9 +3108,9 @@ const zipObject = (props, values) => ```
- Examples - - ```js +Examples + +```js zipObject(['a', 'b', 'c'], [1, 2]); // {a: 1, b: 2, c: undefined} zipObject(['a', 'b'], [1, 2, 3]); // {a: 1, b: 2} ``` @@ -3140,9 +3140,9 @@ const zipWith = (...array) => { ```
- Examples - - ```js +Examples + +```js zipWith([1, 2], [10, 20], [100, 200], (a, b, c) => a + b + c); // [111,222] zipWith( [1, 2, 3], @@ -3176,9 +3176,9 @@ const arrayToHtmlList = (arr, listID) => ```
- Examples - - ```js +Examples + +```js arrayToHtmlList(['item 1', 'item 2'], 'myListID'); ``` @@ -3199,9 +3199,9 @@ const bottomVisible = () => ```
- Examples - - ```js +Examples + +```js bottomVisible(); // true ``` @@ -3242,9 +3242,9 @@ const copyToClipboard = str => { ```
- Examples - - ```js +Examples + +```js copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard. ``` @@ -3277,9 +3277,9 @@ const counter = (selector, start, end, step = 1, duration = 2000) => { ```
- Examples - - ```js +Examples + +```js counter('#my-id', 1, 1000, 5, 2000); // Creates a 2-second timer for the element with id="my-id" ``` @@ -3305,9 +3305,9 @@ const createElement = str => { ```
- Examples - - ```js +Examples + +```js const el = createElement( `

Hello!

@@ -3348,9 +3348,9 @@ const createEventHub = () => ({ ```
- Examples - - ```js +Examples + +```js const handler = data => console.log(data); const hub = createEventHub(); let increment = 0; @@ -3384,9 +3384,9 @@ const currentURL = () => window.location.href; ```
- Examples - - ```js +Examples + +```js currentURL(); // 'https://google.com' ``` @@ -3408,9 +3408,9 @@ const detectDeviceType = () => ```
- Examples - - ```js +Examples + +```js detectDeviceType(); // "Mobile" or "Desktop" ``` @@ -3429,9 +3429,9 @@ const elementContains = (parent, child) => parent !== child && parent.contains(c ```
- Examples - - ```js +Examples + +```js elementContains(document.querySelector('head'), document.querySelector('title')); // true elementContains(document.querySelector('body'), document.querySelector('body')); // false ``` @@ -3461,9 +3461,9 @@ const elementIsVisibleInViewport = (el, partiallyVisible = false) => { ```
- Examples - - ```js +Examples + +```js // e.g. 100x100 viewport and a 10x10px element at position {top: -1, left: 0, bottom: 9, right: 10} elementIsVisibleInViewport(el); // false - (not fully visible) elementIsVisibleInViewport(el, true); // true - (partially visible) @@ -3488,9 +3488,9 @@ const getScrollPosition = (el = window) => ({ ```
- Examples - - ```js +Examples + +```js getScrollPosition(); // {x: 0, y: 200} ``` @@ -3509,9 +3509,9 @@ const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName]; ```
- Examples - - ```js +Examples + +```js getStyle(document.querySelector('p'), 'font-size'); // '16px' ``` @@ -3530,9 +3530,9 @@ const hasClass = (el, className) => el.classList.contains(className); ```
- Examples - - ```js +Examples + +```js hasClass(document.querySelector('p.special'), 'special'); // true ``` @@ -3558,9 +3558,9 @@ const hashBrowser = val => ```
- Examples - - ```js +Examples + +```js hashBrowser(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393' ``` @@ -3579,9 +3579,9 @@ const hide = els => els.forEach(e => (e.style.display = 'none')); ```
- Examples - - ```js +Examples + +```js hide(document.querySelectorAll('img')); // Hides all elements on the page ``` @@ -3602,9 +3602,9 @@ const httpsRedirect = () => { ```
- Examples - - ```js +Examples + +```js httpsRedirect(); // If you are on http://mydomain.com, you are redirected to https://mydomain.com ``` @@ -3623,9 +3623,9 @@ const insertAfter = (el, htmlString) => el.insertAdjacentHTML('afterend', htmlSt ```
- Examples - - ```js +Examples + +```js insertAfter(document.getElementById('myId'), '

after

'); //
...

after

``` @@ -3644,9 +3644,9 @@ const insertBefore = (el, htmlString) => el.insertAdjacentHTML('beforebegin', ht ```
- Examples - - ```js +Examples + +```js insertBefore(document.getElementById('myId'), '

before

'); //

before

...
``` @@ -3665,9 +3665,9 @@ const isBrowserTabFocused = () => !document.hidden; ```
- Examples - - ```js +Examples + +```js isBrowserTabFocused(); // true ``` @@ -3686,9 +3686,9 @@ const nodeListToArray = nodeList => [...nodeList]; ```
- Examples - - ```js +Examples + +```js nodeListToArray(document.childNodes); // [ , html ] ``` @@ -3726,9 +3726,9 @@ const observeMutations = (element, callback, options) => { ```
- Examples - - ```js +Examples + +```js const obs = observeMutations(document, console.log); // Logs all mutations that happen on the page obs.disconnect(); // Disconnects the observer and stops logging mutations on the page ``` @@ -3749,9 +3749,9 @@ const off = (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts) ```
- Examples - - ```js +Examples + +```js const fn = () => console.log('!'); document.body.addEventListener('click', fn); off(document.body, 'click', fn); // no longer logs '!' upon clicking on the page @@ -3778,9 +3778,9 @@ const on = (el, evt, fn, opts = {}) => { ```
- Examples - - ```js +Examples + +```js const fn = () => console.log('!'); on(document.body, 'click', fn); // logs '!' upon clicking the body on(document.body, 'click', fn, { target: 'p' }); // logs '!' upon clicking a `p` element child of the body @@ -3817,9 +3817,9 @@ const onUserInputChange = callback => { ```
- Examples - - ```js +Examples + +```js onUserInputChange(type => { console.log('The user is now using', type, 'as an input method.'); }); @@ -3848,9 +3848,9 @@ const prefix = prop => { ```
- Examples - - ```js +Examples + +```js prefix('appearance'); // 'appearance' on a supported browser, otherwise 'webkitAppearance', 'mozAppearance', 'msAppearance' or 'oAppearance' ``` @@ -3891,9 +3891,9 @@ const recordAnimationFrames = (callback, autoStart = true) => { ```
- Examples - - ```js +Examples + +```js const cb = () => console.log('Animation frame fired'); const recorder = recordAnimationFrames(cb); // logs 'Animation frame fired' on each animation frame recorder.stop(); // stops logging @@ -3918,9 +3918,9 @@ const redirect = (url, asLink = true) => ```
- Examples - - ```js +Examples + +```js redirect('https://google.com'); ``` @@ -3955,9 +3955,9 @@ const runAsync = fn => { ```
- Examples - - ```js +Examples + +```js const longRunningFunction = () => { let result = 0; for (let i = 0; i < 1000; i++) { @@ -4002,9 +4002,9 @@ const scrollToTop = () => { ```
- Examples - - ```js +Examples + +```js scrollToTop(); ``` @@ -4023,9 +4023,9 @@ const setStyle = (el, ruleName, val) => (el.style[ruleName] = val); ```
- Examples - - ```js +Examples + +```js setStyle(document.querySelector('p'), 'font-size', '20px'); // The first

element on the page will have a font-size of 20px ``` @@ -4044,9 +4044,9 @@ const show = (...el) => [...el].forEach(e => (e.style.display = '')); ```

- Examples - - ```js +Examples + +```js show(...document.querySelectorAll('img')); // Shows all elements on the page ``` @@ -4069,9 +4069,9 @@ const smoothScroll = element => ```
- Examples - - ```js +Examples + +```js smoothScroll('#fooBar'); // scrolls smoothly to the element with the id fooBar smoothScroll('.fooBar'); // scrolls smoothly to the first element with a class of fooBar ``` @@ -4091,9 +4091,9 @@ const toggleClass = (el, className) => el.classList.toggle(className); ```
- Examples - - ```js +Examples + +```js toggleClass(document.querySelector('p.special'), 'special'); // The paragraph will not have the 'special' class anymore ``` @@ -4115,9 +4115,9 @@ const triggerEvent = (el, eventType, detail = undefined) => ```
- Examples - - ```js +Examples + +```js triggerEvent(document.getElementById('myId'), 'click'); triggerEvent(document.getElementById('myId'), 'click', { username: 'bob' }); ``` @@ -4140,9 +4140,9 @@ const UUIDGeneratorBrowser = () => ```
- Examples - - ```js +Examples + +```js UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d' ``` @@ -4182,9 +4182,9 @@ const formatDuration = ms => { ```
- Examples - - ```js +Examples + +```js formatDuration(1001); // '1 second, 1 millisecond' formatDuration(34325055574); // '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds' ``` @@ -4204,9 +4204,9 @@ const getColonTimeFromDate = date => date.toTimeString().slice(0, 8); ```
- Examples - - ```js +Examples + +```js getColonTimeFromDate(new Date()); // "08:38:00" ``` @@ -4226,9 +4226,9 @@ const getDaysDiffBetweenDates = (dateInitial, dateFinal) => ```
- Examples - - ```js +Examples + +```js getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')); // 9 ``` @@ -4254,9 +4254,9 @@ const getMeridiemSuffixOfInteger = num => ```
- Examples - - ```js +Examples + +```js getMeridiemSuffixOfInteger(0); // "12am" getMeridiemSuffixOfInteger(11); // "11am" getMeridiemSuffixOfInteger(13); // "1pm" @@ -4284,9 +4284,9 @@ const tomorrow = (long = false) => { ```
- Examples - - ```js +Examples + +```js tomorrow(); // 2017-12-27 (if current date is 2017-12-26) tomorrow(true); // 2017-12-27T00:00:00 (if current date is 2017-12-26) ``` @@ -4317,9 +4317,9 @@ const attempt = (fn, ...args) => { ```
- Examples - - ```js +Examples + +```js var elements = attempt(function(selector) { return document.querySelectorAll(selector); }, '>_>'); @@ -4342,9 +4342,9 @@ const bind = (fn, context, ...boundArgs) => (...args) => fn.apply(context, [...b ```
- Examples - - ```js +Examples + +```js function greet(greeting, punctuation) { return greeting + ' ' + this.user + punctuation; } @@ -4370,9 +4370,9 @@ const bindKey = (context, fn, ...boundArgs) => (...args) => ```
- Examples - - ```js +Examples + +```js const freddy = { user: 'fred', greet: function(greeting, punctuation) { @@ -4402,9 +4402,9 @@ const chainAsync = fns => { ```
- Examples - - ```js +Examples + +```js chainAsync([ next => { console.log('0 seconds'); @@ -4432,9 +4432,9 @@ const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))); ```
- Examples - - ```js +Examples + +```js const add5 = x => x + 5; const multiply = (x, y) => x * y; const multiplyAndAdd5 = compose( @@ -4460,9 +4460,9 @@ const composeRight = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)) ```
- Examples - - ```js +Examples + +```js const add = (x, y) => x + y; const square = x => x * x; const addAndSquare = composeRight(add, square); @@ -4485,9 +4485,9 @@ const converge = (converger, fns) => (...args) => converger(...fns.map(fn => fn. ```
- Examples - - ```js +Examples + +```js const average = converge((a, b) => a / b, [ arr => arr.reduce((a, v) => a + v, 0), arr => arr.length @@ -4514,9 +4514,9 @@ const curry = (fn, arity = fn.length, ...args) => ```
- Examples - - ```js +Examples + +```js curry(Math.pow)(2)(10); // 1024 curry(Math.min, 3)(10)(50)(2); // 2 ``` @@ -4543,9 +4543,9 @@ const debounce = (fn, ms = 0) => { ```
- Examples - - ```js +Examples + +```js window.addEventListener( 'resize', debounce(() => { @@ -4570,9 +4570,9 @@ const defer = (fn, ...args) => setTimeout(fn, 1, ...args); ```
- Examples - - ```js +Examples + +```js // Example A: defer(console.log, 'a'), console.log('b'); // logs 'b' then 'a' @@ -4598,9 +4598,9 @@ const delay = (fn, wait, ...args) => setTimeout(fn, wait, ...args); ```
- Examples - - ```js +Examples + +```js delay( function(text) { console.log(text); @@ -4625,9 +4625,9 @@ const functionName = fn => (console.debug(fn.name), fn); ```
- Examples - - ```js +Examples + +```js functionName(Math.max); // max (logged in debug channel of console) ``` @@ -4653,9 +4653,9 @@ const hz = (fn, iterations = 100) => { ```
- Examples - - ```js +Examples + +```js // 10,000 element array const numbers = Array(10000) .fill() @@ -4698,9 +4698,9 @@ const memoize = fn => { ```
- Examples - - ```js +Examples + +```js // See the `anagrams` snippet. const anagramsCached = memoize(anagrams); anagramsCached('javascript'); // takes a long time @@ -4723,9 +4723,9 @@ const negate = func => (...args) => !func(...args); ```
- Examples - - ```js +Examples + +```js [1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0)); // [ 1, 3, 5 ] ``` @@ -4752,9 +4752,9 @@ const once = fn => { ```
- Examples - - ```js +Examples + +```js const startApp = function(event) { console.log(this, event); // document.body, MouseEvent }; @@ -4776,9 +4776,9 @@ const partial = (fn, ...partials) => (...args) => fn(...partials, ...args); ```
- Examples - - ```js +Examples + +```js const greet = (greeting, name) => greeting + ' ' + name + '!'; const greetHello = partial(greet, 'Hello'); greetHello('John'); // 'Hello John!' @@ -4799,9 +4799,9 @@ const partialRight = (fn, ...partials) => (...args) => fn(...args, ...partials); ```
- Examples - - ```js +Examples + +```js const greet = (greeting, name) => greeting + ' ' + name + '!'; const greetJohn = partialRight(greet, 'John'); greetJohn('Hello'); // 'Hello John!' @@ -4822,9 +4822,9 @@ const runPromisesInSeries = ps => ps.reduce((p, next) => p.then(next), Promise.r ```
- Examples - - ```js +Examples + +```js const delay = d => new Promise(r => setTimeout(r, d)); runPromisesInSeries([() => delay(1000), () => delay(2000)]); // Executes each promise sequentially, taking a total of 3 seconds to complete ``` @@ -4844,9 +4844,9 @@ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); ```
- Examples - - ```js +Examples + +```js async function sleepyWork() { console.log("I'm going to sleep for 1 second."); await sleep(1000); @@ -4891,9 +4891,9 @@ const throttle = (fn, wait) => { ```
- Examples - - ```js +Examples + +```js window.addEventListener( 'resize', throttle(function(evt) { @@ -4922,9 +4922,9 @@ const times = (n, fn, context = undefined) => { ```
- Examples - - ```js +Examples + +```js var output = ''; times(5, i => (output += i)); console.log(output); // 01234 @@ -4953,9 +4953,9 @@ const uncurry = (fn, n = 1) => (...args) => { ```
- Examples - - ```js +Examples + +```js const add = x => y => z => x + y + z; const uncurriedAdd = uncurry(add, 3); uncurriedAdd(1, 2, 3); // 6 @@ -4982,9 +4982,9 @@ const unfold = (fn, seed) => { ```
- Examples - - ```js +Examples + +```js var f = n => (n > 50 ? false : [-n, n + 10]); unfold(f, 10); // [-10, -20, -30, -40, -50] ``` @@ -5004,9 +5004,9 @@ const when = (pred, whenTrue) => x => (pred(x) ? whenTrue(x) : x); ```
- Examples - - ```js +Examples + +```js const doubleEvenNumbers = when(x => x % 2 === 0, x => x * 2); doubleEvenNumbers(2); // 4 doubleEvenNumbers(1); // 1 @@ -5033,9 +5033,9 @@ const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsi ```
- Examples - - ```js +Examples + +```js approximatelyEqual(Math.PI / 2.0, 1.5708); // true ``` @@ -5054,9 +5054,9 @@ const average = (...nums) => nums.reduce((acc, val) => acc + val, 0) / nums.leng ```
- Examples - - ```js +Examples + +```js average(...[1, 2, 3]); // 2 average(1, 2, 3); // 2 ``` @@ -5078,9 +5078,9 @@ const averageBy = (arr, fn) => ```
- Examples - - ```js +Examples + +```js averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 5 averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 5 ``` @@ -5113,9 +5113,9 @@ const binomialCoefficient = (n, k) => { ```
- Examples - - ```js +Examples + +```js binomialCoefficient(8, 2); // 28 ``` @@ -5135,9 +5135,9 @@ const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math. ```
- Examples - - ```js +Examples + +```js clampNumber(2, 3, 5); // 3 clampNumber(1, -1, -5); // -1 ``` @@ -5157,9 +5157,9 @@ const degreesToRads = deg => (deg * Math.PI) / 180.0; ```
- Examples - - ```js +Examples + +```js degreesToRads(90.0); // ~1.5708 ``` @@ -5179,9 +5179,9 @@ const digitize = n => [...`${n}`].map(i => parseInt(i)); ```
- Examples - - ```js +Examples + +```js digitize(123); // [1, 2, 3] ``` @@ -5200,9 +5200,9 @@ const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0); ```
- Examples - - ```js +Examples + +```js distance(1, 1, 2, 3); // 2.23606797749979 ``` @@ -5242,9 +5242,9 @@ const elo = ([...ratings], kFactor = 32, selfRating) => { ```
- Examples - - ```js +Examples + +```js // Standard 1v1s elo([1200, 1200]); // [1216, 1184] elo([1200, 1200], 64); // [1232, 1168] @@ -5282,9 +5282,9 @@ const factorial = n => ```
- Examples - - ```js +Examples + +```js factorial(6); // 720 ``` @@ -5308,9 +5308,9 @@ const fibonacci = n => ```
- Examples - - ```js +Examples + +```js fibonacci(6); // [0, 1, 1, 2, 3, 5] ``` @@ -5334,9 +5334,9 @@ const gcd = (...arr) => { ```
- Examples - - ```js +Examples + +```js gcd(8, 36); // 4 gcd(...[12, 8, 32]); // 4 ``` @@ -5362,9 +5362,9 @@ const geometricProgression = (end, start = 1, step = 2) => ```
- Examples - - ```js +Examples + +```js geometricProgression(256); // [1, 2, 4, 8, 16, 32, 64, 128, 256] geometricProgression(256, 3); // [3, 6, 12, 24, 48, 96, 192] geometricProgression(256, 1, 4); // [1, 4, 16, 64, 256] @@ -5386,9 +5386,9 @@ const hammingDistance = (num1, num2) => ((num1 ^ num2).toString(2).match(/1/g) | ```
- Examples - - ```js +Examples + +```js hammingDistance(2, 3); // 1 ``` @@ -5411,9 +5411,9 @@ const inRange = (n, start, end = null) => { ```
- Examples - - ```js +Examples + +```js inRange(3, 2, 5); // true inRange(3, 4); // true inRange(2, 3, 5); // false @@ -5435,9 +5435,9 @@ const isDivisible = (dividend, divisor) => dividend % divisor === 0; ```
- Examples - - ```js +Examples + +```js isDivisible(6, 3); // true ``` @@ -5457,9 +5457,9 @@ const isEven = num => num % 2 === 0; ```
- Examples - - ```js +Examples + +```js isEven(3); // false ``` @@ -5483,9 +5483,9 @@ const isPrime = num => { ```
- Examples - - ```js +Examples + +```js isPrime(11); // true ``` @@ -5509,9 +5509,9 @@ const lcm = (...arr) => { ```
- Examples - - ```js +Examples + +```js lcm(12, 7); // 84 lcm(...[1, 3, 4, 5]); // 60 ``` @@ -5544,9 +5544,9 @@ const luhnCheck = num => { ```
- Examples - - ```js +Examples + +```js luhnCheck('4485275742308327'); // true luhnCheck(6011329933655299); // false luhnCheck(123456789); // false @@ -5567,9 +5567,9 @@ const maxBy = (arr, fn) => Math.max(...arr.map(typeof fn === 'function' ? fn : v ```
- Examples - - ```js +Examples + +```js maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 8 maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 8 ``` @@ -5594,9 +5594,9 @@ const median = arr => { ```
- Examples - - ```js +Examples + +```js median([5, 6, 50, 1, -5]); // 5 ``` @@ -5615,9 +5615,9 @@ const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : v ```
- Examples - - ```js +Examples + +```js minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 2 minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 2 ``` @@ -5638,9 +5638,9 @@ const percentile = (arr, val) => ```
- Examples - - ```js +Examples + +```js percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6); // 55 ``` @@ -5659,9 +5659,9 @@ const powerset = arr => arr.reduce((a, v) => a.concat(a.map(r => [v].concat(r))) ```
- Examples - - ```js +Examples + +```js powerset([1, 2]); // [[], [1], [2], [2,1]] ``` @@ -5686,9 +5686,9 @@ const primes = num => { ```
- Examples - - ```js +Examples + +```js primes(10); // [2,3,5,7] ``` @@ -5707,9 +5707,9 @@ const radsToDegrees = rad => (rad * 180.0) / Math.PI; ```
- Examples - - ```js +Examples + +```js radsToDegrees(Math.PI / 2); // 90 ``` @@ -5729,9 +5729,9 @@ const randomIntArrayInRange = (min, max, n = 1) => ```
- Examples - - ```js +Examples + +```js randomIntArrayInRange(12, 35, 10); // [ 34, 14, 27, 17, 30, 27, 20, 26, 21, 14 ] ``` @@ -5750,9 +5750,9 @@ const randomIntegerInRange = (min, max) => Math.floor(Math.random() * (max - min ```
- Examples - - ```js +Examples + +```js randomIntegerInRange(0, 5); // 2 ``` @@ -5771,9 +5771,9 @@ const randomNumberInRange = (min, max) => Math.random() * (max - min) + min; ```
- Examples - - ```js +Examples + +```js randomNumberInRange(2, 10); // 6.0211363285087005 ``` @@ -5793,9 +5793,9 @@ const round = (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${ ```
- Examples - - ```js +Examples + +```js round(1.005, 2); // 1.01 ``` @@ -5821,9 +5821,9 @@ const sdbm = str => { ```
- Examples - - ```js +Examples + +```js sdbm('name'); // -3521204949 ``` @@ -5850,9 +5850,9 @@ const standardDeviation = (arr, usePopulation = false) => { ```
- Examples - - ```js +Examples + +```js standardDeviation([10, 2, 38, 23, 38, 23, 21]); // 13.284434142114991 (sample) standardDeviation([10, 2, 38, 23, 38, 23, 21], true); // 12.29899614287479 (population) ``` @@ -5872,9 +5872,9 @@ const sum = (...arr) => [...arr].reduce((acc, val) => acc + val, 0); ```
- Examples - - ```js +Examples + +```js sum(...[1, 2, 3, 4]); // 10 ``` @@ -5894,9 +5894,9 @@ const sumBy = (arr, fn) => ```
- Examples - - ```js +Examples + +```js sumBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 20 sumBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 20 ``` @@ -5922,9 +5922,9 @@ const sumPower = (end, power = 2, start = 1) => ```
- Examples - - ```js +Examples + +```js sumPower(10); // 385 sumPower(10, 3); //3025 sumPower(10, 3, 5); //2925 @@ -5947,9 +5947,9 @@ const toSafeInteger = num => ```
- Examples - - ```js +Examples + +```js toSafeInteger('3.2'); // 3 toSafeInteger(Infinity); // 9007199254740991 ``` @@ -5974,9 +5974,9 @@ const atob = str => new Buffer(str, 'base64').toString('binary'); ```
- Examples - - ```js +Examples + +```js atob('Zm9vYmFy'); // 'foobar' ``` @@ -5995,9 +5995,9 @@ const btoa = str => new Buffer(str, 'binary').toString('base64'); ```
- Examples - - ```js +Examples + +```js btoa('foobar'); // 'Zm9vYmFy' ``` @@ -6034,9 +6034,9 @@ const colorize = (...args) => ({ ```
- Examples - - ```js +Examples + +```js 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) @@ -6059,9 +6059,9 @@ const hasFlags = (...flags) => ```
- Examples - - ```js +Examples + +```js // node myScript.js -s --test --cool=true hasFlags('-s'); // true hasFlags('--test', 'cool=true', '-s'); // true @@ -6096,9 +6096,9 @@ const hashNode = val => ```
- Examples - - ```js +Examples + +```js hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(console.log); // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393' ``` @@ -6117,9 +6117,9 @@ const isTravisCI = () => 'TRAVIS' in process.env && 'CI' in process.env; ```
- Examples - - ```js +Examples + +```js isTravisCI(); // true (if code is running on Travis CI) ``` @@ -6140,9 +6140,9 @@ const JSONToFile = (obj, filename) => ```
- Examples - - ```js +Examples + +```js JSONToFile({ test: 'is passed' }, 'testJsonFile'); // writes the object to 'testJsonFile.json' ``` @@ -6168,9 +6168,9 @@ const readFileLines = filename => ```
- Examples - - ```js +Examples + +```js /* contents of test.txt : line1 @@ -6198,9 +6198,9 @@ const untildify = str => str.replace(/^~($|\/|\\)/, `${require('os').homedir()}$ ```
- Examples - - ```js +Examples + +```js untildify('~/node'); // '/Users/aUser/node' ``` @@ -6223,9 +6223,9 @@ const UUIDGeneratorNode = () => ```
- Examples - - ```js +Examples + +```js UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc' ``` @@ -6257,9 +6257,9 @@ const bindAll = (obj, ...fns) => ```
- Examples - - ```js +Examples + +```js var view = { label: 'docs', click: function() { @@ -6293,9 +6293,9 @@ const deepClone = obj => { ```
- Examples - - ```js +Examples + +```js const a = { foo: 'bar', obj: { a: 1, b: 2 } }; const b = deepClone(a); // a !== b, a.obj !== b.obj ``` @@ -6319,9 +6319,9 @@ const deepFreeze = obj => ```
- Examples - - ```js +Examples + +```js 'use strict'; const o = deepFreeze([1, [2, 3]]); @@ -6345,9 +6345,9 @@ const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj ```
- Examples - - ```js +Examples + +```js defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }); // { a: 1, b: 2 } ``` @@ -6373,9 +6373,9 @@ const dig = (obj, target) => ```
- Examples - - ```js +Examples + +```js const data = { level1: { level2: { @@ -6413,9 +6413,9 @@ const equals = (a, b) => { ```
- Examples - - ```js +Examples + +```js equals({ a: [2, { e: 3 }], b: [4], c: 'foo' }, { a: [2, { e: 3 }], b: [4], c: 'foo' }); // true ``` @@ -6434,9 +6434,9 @@ const findKey = (obj, fn) => Object.keys(obj).find(key => fn(obj[key], key, obj) ```
- Examples - - ```js +Examples + +```js findKey( { barney: { age: 36, active: true }, @@ -6465,9 +6465,9 @@ const findLastKey = (obj, fn) => ```
- Examples - - ```js +Examples + +```js findLastKey( { barney: { age: 36, active: true }, @@ -6503,9 +6503,9 @@ const flattenObject = (obj, prefix = '') => ```
- Examples - - ```js +Examples + +```js flattenObject({ a: { b: { c: 1 } }, d: 1 }); // { 'a.b.c': 1, d: 1 } ``` @@ -6524,9 +6524,9 @@ const forOwn = (obj, fn) => Object.keys(obj).forEach(key => fn(obj[key], key, ob ```
- Examples - - ```js +Examples + +```js forOwn({ foo: 'bar', a: 1 }, v => console.log(v)); // 'bar', 1 ``` @@ -6548,9 +6548,9 @@ const forOwnRight = (obj, fn) => ```
- Examples - - ```js +Examples + +```js forOwnRight({ foo: 'bar', a: 1 }, v => console.log(v)); // 1, 'bar' ``` @@ -6576,9 +6576,9 @@ const functions = (obj, inherited = false) => ```
- Examples - - ```js +Examples + +```js function Foo() { this.a = () => 1; this.b = () => 2; @@ -6610,9 +6610,9 @@ const get = (from, ...selectors) => ```
- Examples - - ```js +Examples + +```js const obj = { selector: { to: { val: 'val to select' } }, target: [1, 2, { a: 'test' }] }; get(obj, 'selector.to.val', 'target[0]', 'target[2].a'); // ['val to select', 1, 'test'] ``` @@ -6639,9 +6639,9 @@ const invertKeyValues = (obj, fn) => ```
- Examples - - ```js +Examples + +```js invertKeyValues({ a: 1, b: 2, c: 1 }); // { 1: [ 'a', 'c' ], 2: [ 'b' ] } invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value); // { group1: [ 'a', 'c' ], group2: [ 'b' ] } ``` @@ -6666,9 +6666,9 @@ const lowercaseKeys = obj => ```
- Examples - - ```js +Examples + +```js const myObj = { Name: 'Adam', sUrnAME: 'Smith' }; const myObjLower = lowercaseKeys(myObj); // {name: 'Adam', surname: 'Smith'}; ``` @@ -6693,9 +6693,9 @@ const mapKeys = (obj, fn) => ```
- Examples - - ```js +Examples + +```js mapKeys({ a: 1, b: 2 }, (val, key) => key + val); // { a1: 1, b2: 2 } ``` @@ -6719,9 +6719,9 @@ const mapValues = (obj, fn) => ```
- Examples - - ```js +Examples + +```js const users = { fred: { user: 'fred', age: 40 }, pebbles: { user: 'pebbles', age: 1 } @@ -6745,9 +6745,9 @@ const matches = (obj, source) => ```
- Examples - - ```js +Examples + +```js matches({ age: 25, hair: 'long', beard: true }, { hair: 'long', beard: true }); // true matches({ hair: 'long', beard: true }, { age: 25, hair: 'long', beard: true }); // false ``` @@ -6774,9 +6774,9 @@ const matchesWith = (obj, source, fn) => ```
- Examples - - ```js +Examples + +```js const isGreeting = val => /^h(?:i|ello)$/.test(val); matchesWith( { greeting: 'hello' }, @@ -6809,9 +6809,9 @@ const merge = (...objs) => ```
- Examples - - ```js +Examples + +```js const object = { a: [{ x: 2 }, { y: 4 }], b: 1 @@ -6846,9 +6846,9 @@ const nest = (items, id = null, link = 'parent_id') => ```
- Examples - - ```js +Examples + +```js // One top level comment const comments = [ { id: 1, parent_id: null }, @@ -6876,9 +6876,9 @@ const objectFromPairs = arr => arr.reduce((a, [key, val]) => ((a[key] = val), a) ```
- Examples - - ```js +Examples + +```js objectFromPairs([['a', 1], ['b', 2]]); // {a: 1, b: 2} ``` @@ -6897,9 +6897,9 @@ const objectToPairs = obj => Object.keys(obj).map(k => [k, obj[k]]); ```
- Examples - - ```js +Examples + +```js objectToPairs({ a: 1, b: 2 }); // [['a',1],['b',2]] ``` @@ -6922,9 +6922,9 @@ const omit = (obj, arr) => ```
- Examples - - ```js +Examples + +```js omit({ a: 1, b: '2', c: 3 }, ['b']); // { 'a': 1, 'c': 3 } ``` @@ -6947,9 +6947,9 @@ const omitBy = (obj, fn) => ```
- Examples - - ```js +Examples + +```js omitBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number'); // { b: '2' } ``` @@ -6978,9 +6978,9 @@ const orderBy = (arr, props, orders) => ```
- Examples - - ```js +Examples + +```js const users = [{ name: 'fred', age: 48 }, { name: 'barney', age: 36 }, { name: 'fred', age: 40 }]; orderBy(users, ['name', 'age'], ['asc', 'desc']); // [{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred', age: 40}] orderBy(users, ['name', 'age']); // [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}] @@ -7002,9 +7002,9 @@ const pick = (obj, arr) => ```
- Examples - - ```js +Examples + +```js pick({ a: 1, b: '2', c: 3 }, ['a', 'c']); // { 'a': 1, 'c': 3 } ``` @@ -7027,9 +7027,9 @@ const pickBy = (obj, fn) => ```
- Examples - - ```js +Examples + +```js pickBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number'); // { 'a': 1, 'c': 3 } ``` @@ -7055,9 +7055,9 @@ const renameKeys = (keysMap, obj) => ```
- Examples - - ```js +Examples + +```js const obj = { name: 'Bobo', job: 'Front-End Master', shoeSize: 100 }; renameKeys({ name: 'firstName', job: 'passion' }, obj); // { firstName: 'Bobo', passion: 'Front-End Master', shoeSize: 100 } ``` @@ -7077,9 +7077,9 @@ const shallowClone = obj => Object.assign({}, obj); ```
- Examples - - ```js +Examples + +```js const a = { x: true, y: 1 }; const b = shallowClone(a); // a !== b ``` @@ -7111,9 +7111,9 @@ const size = val => ```
- Examples - - ```js +Examples + +```js size([1, 2, 3, 4, 5]); // 5 size('size'); // 4 size({ one: 1, two: 2, three: 3 }); // 3 @@ -7134,9 +7134,9 @@ const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[ ```
- Examples - - ```js +Examples + +```js transform( { a: 1, b: 2, c: 1 }, (r, v, k) => { @@ -7162,9 +7162,9 @@ const truthCheckCollection = (collection, pre) => collection.every(obj => obj[pr ```
- Examples - - ```js +Examples + +```js truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex: 'male' }], 'sex'); // true ``` @@ -7200,9 +7200,9 @@ const unflattenObject = obj => ```
- Examples - - ```js +Examples + +```js unflattenObject({ 'a.b.c': 1, d: 1 }); // { a: { b: { c: 1 } }, d: 1 } ``` @@ -7226,9 +7226,9 @@ const byteSize = str => new Blob([str]).size; ```
- Examples - - ```js +Examples + +```js byteSize('😀'); // 4 byteSize('Hello World'); // 11 ``` @@ -7250,9 +7250,9 @@ const capitalize = ([first, ...rest], lowerRest = false) => ```
- Examples - - ```js +Examples + +```js capitalize('fooBar'); // 'FooBar' capitalize('fooBar', true); // 'Foobar' ``` @@ -7272,9 +7272,9 @@ const capitalizeEveryWord = str => str.replace(/\b[a-z]/g, char => char.toUpperC ```
- Examples - - ```js +Examples + +```js capitalizeEveryWord('hello world!'); // 'Hello World!' ``` @@ -7300,9 +7300,9 @@ const CSVToArray = (data, delimiter = ',', omitFirstRow = false) => ```
- Examples - - ```js +Examples + +```js 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']]; @@ -7336,9 +7336,9 @@ const CSVToJSON = (data, delimiter = ',') => { ```
- Examples - - ```js +Examples + +```js CSVToJSON('col1,col2\na,b\nc,d'); // [{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]; CSVToJSON('col1;col2\na;b\nc;d', ';'); // [{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]; ``` @@ -7360,9 +7360,9 @@ const decapitalize = ([first, ...rest], upperRest = false) => ```
- Examples - - ```js +Examples + +```js decapitalize('FooBar'); // 'fooBar' decapitalize('FooBar', true); // 'fOOBAR' ``` @@ -7393,9 +7393,9 @@ const escapeHTML = str => ```
- Examples - - ```js +Examples + +```js escapeHTML('Me & you'); // '<a href="#">Me & you</a>' ``` @@ -7414,9 +7414,9 @@ const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); ```
- Examples - - ```js +Examples + +```js escapeRegExp('(test)'); // \\(test\\) ``` @@ -7440,9 +7440,9 @@ const fromCamelCase = (str, separator = '_') => ```
- Examples - - ```js +Examples + +```js fromCamelCase('someDatabaseFieldName', ' '); // 'some database field name' fromCamelCase('someLabelThatNeedsToBeCamelized', '-'); // 'some-label-that-needs-to-be-camelized' fromCamelCase('someJavascriptProperty', '_'); // 'some_javascript_property' @@ -7463,9 +7463,9 @@ const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str); ```
- Examples - - ```js +Examples + +```js isAbsoluteURL('https://google.com'); // true isAbsoluteURL('ftp://www.myserver.net'); // true isAbsoluteURL('/foo/bar'); // false @@ -7495,9 +7495,9 @@ const isAnagram = (str1, str2) => { ```
- Examples - - ```js +Examples + +```js isAnagram('iceman', 'cinema'); // true ``` @@ -7516,9 +7516,9 @@ const isLowerCase = str => str === str.toLowerCase(); ```
- Examples - - ```js +Examples + +```js isLowerCase('abc'); // true isLowerCase('a3@$'); // true isLowerCase('Ab4'); // false @@ -7540,9 +7540,9 @@ const isUpperCase = str => str === str.toUpperCase(); ```
- Examples - - ```js +Examples + +```js isUpperCase('ABC'); // true isLowerCase('A3@$'); // true isLowerCase('aB4'); // false @@ -7569,9 +7569,9 @@ const mapString = (str, fn) => ```
- Examples - - ```js +Examples + +```js mapString('lorem ipsum', c => c.toUpperCase()); // 'LOREM IPSUM' ``` @@ -7594,9 +7594,9 @@ const mask = (cc, num = 4, mask = '*') => ```
- Examples - - ```js +Examples + +```js mask(1234567890); // '******7890' mask(1234567890, 3); // '*******890' mask(1234567890, -4, '$'); // '$$$$567890' @@ -7619,9 +7619,9 @@ const pad = (str, length, char = ' ') => ```
- Examples - - ```js +Examples + +```js pad('cat', 8); // ' cat ' pad(String(42), 6, '0'); // '004200' pad('foobar', 3); // 'foobar' @@ -7646,9 +7646,9 @@ const palindrome = str => { ```
- Examples - - ```js +Examples + +```js palindrome('taco cat'); // true ``` @@ -7672,9 +7672,9 @@ const pluralize = (val, word, plural = word + 's') => { ```
- Examples - - ```js +Examples + +```js pluralize(0, 'apple'); // 'apples' pluralize(1, 'apple'); // 'apple' pluralize(2, 'apple'); // 'apples' @@ -7703,9 +7703,9 @@ const removeNonASCII = str => str.replace(/[^\x20-\x7E]/g, ''); ```
- Examples - - ```js +Examples + +```js removeNonASCII('äÄçÇéÉêlorem-ipsumöÖÐþúÚ'); // 'lorem-ipsum' ``` @@ -7725,9 +7725,9 @@ const reverseString = str => [...str].reverse().join(''); ```
- Examples - - ```js +Examples + +```js reverseString('foobar'); // 'raboof' ``` @@ -7746,9 +7746,9 @@ const sortCharactersInString = str => [...str].sort((a, b) => a.localeCompare(b) ```
- Examples - - ```js +Examples + +```js sortCharactersInString('cabbage'); // 'aabbceg' ``` @@ -7767,9 +7767,9 @@ const splitLines = str => str.split(/\r?\n/); ```
- Examples - - ```js +Examples + +```js splitLines('This\nis a\nmultiline\nstring.\n'); // ['This', 'is a', 'multiline', 'string.' , ''] ``` @@ -7802,9 +7802,9 @@ const stringPermutations = str => { ```
- Examples - - ```js +Examples + +```js stringPermutations('abc'); // ['abc','acb','bac','bca','cab','cba'] ``` @@ -7823,9 +7823,9 @@ const stripHTMLTags = str => str.replace(/<[^>]*>/g, ''); ```
- Examples - - ```js +Examples + +```js stripHTMLTags('

lorem ipsum

'); // 'lorem ipsum' ``` @@ -7852,9 +7852,9 @@ const toCamelCase = str => { ```
- Examples - - ```js +Examples + +```js toCamelCase('some_database_field_name'); // 'someDatabaseFieldName' toCamelCase('Some label that needs to be camelized'); // 'someLabelThatNeedsToBeCamelized' toCamelCase('some-javascript-property'); // 'someJavascriptProperty' @@ -7881,9 +7881,9 @@ const toKebabCase = str => ```
- Examples - - ```js +Examples + +```js toKebabCase('camelCase'); // 'camel-case' toKebabCase('some text'); // 'some-text' toKebabCase('some-mixed_string With spaces_underscores-and-hyphens'); // 'some-mixed-string-with-spaces-underscores-and-hyphens' @@ -7911,9 +7911,9 @@ const toSnakeCase = str => ```
- Examples - - ```js +Examples + +```js toSnakeCase('camelCase'); // 'camel_case' toSnakeCase('some text'); // 'some_text' toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens'); // 'some_mixed_string_with_spaces_underscores_and_hyphens' @@ -7938,9 +7938,9 @@ const truncateString = (str, num) => ```
- Examples - - ```js +Examples + +```js truncateString('boomerang', 7); // 'boom...' ``` @@ -7970,9 +7970,9 @@ const unescapeHTML = str => ```
- Examples - - ```js +Examples + +```js unescapeHTML('<a href="#">Me & you</a>'); // 'Me & you' ``` @@ -7999,9 +7999,9 @@ const URLJoin = (...args) => ```
- Examples - - ```js +Examples + +```js URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo'); // 'http://www.google.com/a/b/cd?foo=123&bar=foo' ``` @@ -8021,9 +8021,9 @@ const words = (str, pattern = /[^a-zA-Z-]+/) => str.split(pattern).filter(Boolea ```
- Examples - - ```js +Examples + +```js words('I love javaScript!!'); // ["I", "love", "javaScript"] words('python, javaScript & coffee'); // ["python", "javaScript", "coffee"] ``` @@ -8049,9 +8049,9 @@ const getType = v => ```
- Examples - - ```js +Examples + +```js getType(new Set([1, 2, 3])); // 'set' ``` @@ -8070,9 +8070,9 @@ const is = (type, val) => ![, null].includes(val) && val.constructor === type; ```
- Examples - - ```js +Examples + +```js is(Array, [1]); // true is(ArrayBuffer, new ArrayBuffer()); // true is(Map, new Map()); // true @@ -8103,9 +8103,9 @@ const isArrayLike = obj => obj != null && typeof obj[Symbol.iterator] === 'funct ```
- Examples - - ```js +Examples + +```js isArrayLike(document.querySelectorAll('.className')); // true isArrayLike('abc'); // true isArrayLike(null); // false @@ -8126,9 +8126,9 @@ const isBoolean = val => typeof val === 'boolean'; ```
- Examples - - ```js +Examples + +```js isBoolean(null); // false isBoolean(false); // true ``` @@ -8148,9 +8148,9 @@ const isEmpty = val => val == null || !(Object.keys(val) || val).length; ```
- Examples - - ```js +Examples + +```js isEmpty(new Map()); // true isEmpty(new Set()); // true isEmpty([]); // true @@ -8178,9 +8178,9 @@ const isFunction = val => typeof val === 'function'; ```
- Examples - - ```js +Examples + +```js isFunction('x'); // false isFunction(x => x); // true ``` @@ -8200,9 +8200,9 @@ const isNil = val => val === undefined || val === null; ```
- Examples - - ```js +Examples + +```js isNil(null); // true isNil(undefined); // true ``` @@ -8222,9 +8222,9 @@ const isNull = val => val === null; ```
- Examples - - ```js +Examples + +```js isNull(null); // true ``` @@ -8243,9 +8243,9 @@ const isNumber = val => typeof val === 'number'; ```
- Examples - - ```js +Examples + +```js isNumber('1'); // false isNumber(1); // true ``` @@ -8266,9 +8266,9 @@ const isObject = obj => obj === Object(obj); ```
- Examples - - ```js +Examples + +```js isObject([1, 2, 3, 4]); // true isObject([]); // true isObject(['Hello!']); // true @@ -8292,9 +8292,9 @@ const isObjectLike = val => val !== null && typeof val === 'object'; ```
- Examples - - ```js +Examples + +```js isObjectLike({}); // true isObjectLike([1, 2, 3]); // true isObjectLike(x => x); // false @@ -8316,9 +8316,9 @@ const isPlainObject = val => !!val && typeof val === 'object' && val.constructor ```
- Examples - - ```js +Examples + +```js isPlainObject({ a: 1 }); // true isPlainObject(new Map()); // false ``` @@ -8340,9 +8340,9 @@ const isPrimitive = val => !['object', 'function'].includes(typeof val) || val = ```
- Examples - - ```js +Examples + +```js isPrimitive(null); // true isPrimitive(50); // true isPrimitive('Hello!'); // true @@ -8369,9 +8369,9 @@ const isPromiseLike = obj => ```
- Examples - - ```js +Examples + +```js isPromiseLike({ then: function() { return ''; @@ -8396,9 +8396,9 @@ const isString = val => typeof val === 'string'; ```
- Examples - - ```js +Examples + +```js isString('10'); // true ``` @@ -8417,9 +8417,9 @@ const isSymbol = val => typeof val === 'symbol'; ```
- Examples - - ```js +Examples + +```js isSymbol(Symbol('x')); // true ``` @@ -8438,9 +8438,9 @@ const isUndefined = val => val === undefined; ```
- Examples - - ```js +Examples + +```js isUndefined(undefined); // true ``` @@ -8466,9 +8466,9 @@ const isValidJSON = obj => { ```
- Examples - - ```js +Examples + +```js isValidJSON('{"name":"Adam","age":20}'); // true isValidJSON('{"name":"Adam",age:"20"}'); // false isValidJSON(null); // true @@ -8494,9 +8494,9 @@ const castArray = val => (Array.isArray(val) ? val : [val]); ```
- Examples - - ```js +Examples + +```js castArray('foo'); // ['foo'] castArray([1]); // [1] ``` @@ -8516,9 +8516,9 @@ const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags); ```
- Examples - - ```js +Examples + +```js const regExp = /lorem ipsum/gi; const regExp2 = cloneRegExp(regExp); // /lorem ipsum/gi ``` @@ -8538,9 +8538,9 @@ const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_)); ```
- Examples - - ```js +Examples + +```js coalesce(null, undefined, '', NaN, 'Waldo'); // "" ``` @@ -8559,9 +8559,9 @@ const coalesceFactory = valid => (...args) => args.find(valid); ```
- Examples - - ```js +Examples + +```js const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_)); customCoalesce(undefined, null, NaN, '', 'Waldo'); // "Waldo" ``` @@ -8588,9 +8588,9 @@ const extendHex = shortHex => ```
- Examples - - ```js +Examples + +```js extendHex('#03f'); // '#0033ff' extendHex('05a'); // '#0055aa' ``` @@ -8615,9 +8615,9 @@ const getURLParameters = url => ```
- Examples - - ```js +Examples + +```js getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'} getURLParameters('google.com'); // {} ``` @@ -8655,9 +8655,9 @@ const hexToRGB = hex => { ```
- Examples - - ```js +Examples + +```js hexToRGB('#27ae60ff'); // 'rgba(39, 174, 96, 255)' hexToRGB('27ae60'); // 'rgb(39, 174, 96)' hexToRGB('#fff'); // 'rgb(255, 255, 255)' @@ -8687,9 +8687,9 @@ const httpGet = (url, callback, err = console.error) => { ```
- Examples - - ```js +Examples + +```js httpGet( 'https://jsonplaceholder.typicode.com/posts/1', console.log @@ -8730,9 +8730,9 @@ const httpPost = (url, data, callback, err = console.error) => { ```
- Examples - - ```js +Examples + +```js const newPost = { userId: 1, id: 1337, @@ -8780,9 +8780,9 @@ const isBrowser = () => ![typeof window, typeof document].includes('undefined'); ```
- Examples - - ```js +Examples + +```js isBrowser(); // true (browser) isBrowser(); // false (Node) ``` @@ -8811,9 +8811,9 @@ const mostPerformant = (fns, iterations = 10000) => { ```
- Examples - - ```js +Examples + +```js mostPerformant([ () => { // Loops through the entire array before returning `false` @@ -8841,9 +8841,9 @@ const nthArg = n => (...args) => args.slice(n)[0]; ```
- Examples - - ```js +Examples + +```js const third = nthArg(2); third(1, 2, 3); // 3 third(1, 2); // undefined @@ -8875,9 +8875,9 @@ const parseCookie = str => ```
- Examples - - ```js +Examples + +```js parseCookie('foo=bar; equation=E%3Dmc%5E2'); // { foo: 'bar', equation: 'E=mc^2' } ``` @@ -8906,9 +8906,9 @@ const prettyBytes = (num, precision = 3, addSpace = true) => { ```
- Examples - - ```js +Examples + +```js prettyBytes(1000); // "1 KB" prettyBytes(-27145424323.5821, 5); // "-27.145 GB" prettyBytes(123456789, 3, false); // "123MB" @@ -8932,9 +8932,9 @@ const randomHexColorCode = () => { ```
- Examples - - ```js +Examples + +```js randomHexColorCode(); // "#e34155" ``` @@ -8953,9 +8953,9 @@ const RGBToHex = (r, g, b) => ((r << 16) + (g << 8) + b).toString(16).padStart(6 ```
- Examples - - ```js +Examples + +```js RGBToHex(255, 165, 1); // 'ffa501' ``` @@ -8974,9 +8974,9 @@ const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIC ```
- Examples - - ```js +Examples + +```js serializeCookie('foo', 'bar'); // 'foo=bar' ``` @@ -9000,9 +9000,9 @@ const timeTaken = callback => { ```
- Examples - - ```js +Examples + +```js timeTaken(() => Math.pow(2, 10)); // 1024, (logged): timeTaken: 0.02099609375ms ``` @@ -9022,9 +9022,9 @@ const toCurrency = (n, curr, LanguageFormat = undefined) => ```
- Examples - - ```js +Examples + +```js toCurrency(123456.789, 'EUR'); // €123,456.79 | currency: Euro | currencyLangFormat: Local toCurrency(123456.789, 'USD', 'en-us'); // $123,456.79 | currency: US Dollar | currencyLangFormat: English (United States) toCurrency(123456.789, 'USD', 'fa'); // ۱۲۳٬۴۵۶٫۷۹ ؜$ | currency: US Dollar | currencyLangFormat: Farsi @@ -9045,9 +9045,9 @@ const toDecimalMark = num => num.toLocaleString('en-US'); ```
- Examples - - ```js +Examples + +```js toDecimalMark(12305030388.9087); // "12,305,030,388.909" ``` @@ -9077,9 +9077,9 @@ const toOrdinalSuffix = num => { ```
- Examples - - ```js +Examples + +```js toOrdinalSuffix('123'); // "123rd" ``` @@ -9100,9 +9100,9 @@ const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == ```
- Examples - - ```js +Examples + +```js validateNumber('10'); // true ``` @@ -9123,9 +9123,9 @@ const yesNo = (val, def = false) => ```
- Examples - - ```js +Examples + +```js yesNo('Y'); // true yesNo('yes'); // true yesNo('No'); // false diff --git a/package-lock.json b/package-lock.json index a1a8dbdde..991795cd9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -207,6 +207,7 @@ "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, "requires": { "sprintf-js": "1.0.3" } @@ -1533,7 +1534,8 @@ "builtin-modules": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", - "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=" + "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", + "dev": true }, "cache-base": { "version": "1.0.1", @@ -1896,6 +1898,7 @@ "version": "5.0.6", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-5.0.6.tgz", "integrity": "sha512-6DWfizHriCrFWURP1/qyhsiFvYdlJzbCzmtFWh744+KyWsJo5+kPzUZZaMRSSItoYc0pxFX7gEO7ZC1/gN/7AQ==", + "dev": true, "requires": { "is-directory": "0.3.1", "js-yaml": "3.12.0", @@ -1906,6 +1909,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", "integrity": "sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=", + "dev": true, "requires": { "error-ex": "1.3.1", "json-parse-better-errors": "1.0.2" @@ -2223,6 +2227,7 @@ "version": "1.3.1", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.1.tgz", "integrity": "sha1-+FWobOYa3E6GIcPNoh56dhLDqNw=", + "dev": true, "requires": { "is-arrayish": "0.2.1" } @@ -2576,7 +2581,8 @@ "esprima": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz", - "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==" + "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==", + "dev": true }, "esquery": { "version": "1.0.1", @@ -3698,12 +3704,14 @@ "get-stdin": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", - "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==" + "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", + "dev": true }, "get-stream": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", - "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" + "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", + "dev": true }, "get-value": { "version": "2.0.6", @@ -4024,7 +4032,8 @@ "hosted-git-info": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.6.0.tgz", - "integrity": "sha512-lIbgIIQA3lz5XaB6vxakj6sDHADJiZadYEJB+FgA+C4nubM1NwcuvUr9EJPmnH1skZqpqUzWborWo8EIUi0Sdw==" + "integrity": "sha512-lIbgIIQA3lz5XaB6vxakj6sDHADJiZadYEJB+FgA+C4nubM1NwcuvUr9EJPmnH1skZqpqUzWborWo8EIUi0Sdw==", + "dev": true }, "html-encoding-sniffer": { "version": "1.0.2", @@ -4065,6 +4074,7 @@ "version": "1.0.0-rc.14", "resolved": "https://registry.npmjs.org/husky/-/husky-1.0.0-rc.14.tgz", "integrity": "sha512-lxdl0+FrKhRXvhOW978oCHCiaXQAtwoR0hdaPY1CwKd+dgbtktepEvk/3DXwQ7L1YriuG/9HDc4AHlzQ0T6cNw==", + "dev": true, "requires": { "cosmiconfig": "5.0.6", "execa": "0.9.0", @@ -4081,12 +4091,14 @@ "ci-info": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-1.5.1.tgz", - "integrity": "sha512-fKFIKXaYiL1exImwJ0AhR/6jxFPSKQBk2ayV5NiNoruUs2+rxC2kNw0EG+1Z9dugZRdCrppskQ8DN2cyaUM1Hw==" + "integrity": "sha512-fKFIKXaYiL1exImwJ0AhR/6jxFPSKQBk2ayV5NiNoruUs2+rxC2kNw0EG+1Z9dugZRdCrppskQ8DN2cyaUM1Hw==", + "dev": true }, "cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", + "dev": true, "requires": { "lru-cache": "4.1.2", "shebang-command": "1.2.0", @@ -4097,6 +4109,7 @@ "version": "0.9.0", "resolved": "https://registry.npmjs.org/execa/-/execa-0.9.0.tgz", "integrity": "sha512-BbUMBiX4hqiHZUA5+JujIjNb6TyAlp2D5KLheMjMluwOuzcnylDL4AxZYLLn1n2AGB49eSWwyKvvEQoRpnAtmA==", + "dev": true, "requires": { "cross-spawn": "5.1.0", "get-stream": "3.0.0", @@ -4111,6 +4124,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "dev": true, "requires": { "locate-path": "3.0.0" } @@ -4119,6 +4133,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.2.1.tgz", "integrity": "sha512-s6tfsaQaQi3JNciBH6shVqEDvhGut0SUXr31ag8Pd8BBbVVlcGfWhpPmEOoM6RJ5TFhbypvf5yyRw/VXW1IiWg==", + "dev": true, "requires": { "ci-info": "1.5.1" } @@ -4127,6 +4142,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "dev": true, "requires": { "p-locate": "3.0.0", "path-exists": "3.0.0" @@ -4136,6 +4152,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.0.0.tgz", "integrity": "sha512-fl5s52lI5ahKCernzzIyAP0QAZbGIovtVHGwpcu1Jr/EpzLVDI2myISHwGqK7m8uQFugVWSrbxH7XnhGtvEc+A==", + "dev": true, "requires": { "p-try": "2.0.0" } @@ -4144,6 +4161,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "dev": true, "requires": { "p-limit": "2.0.0" } @@ -4151,12 +4169,14 @@ "p-try": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.0.0.tgz", - "integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==" + "integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==", + "dev": true }, "parse-json": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", "integrity": "sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=", + "dev": true, "requires": { "error-ex": "1.3.1", "json-parse-better-errors": "1.0.2" @@ -4165,17 +4185,20 @@ "path-exists": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", + "dev": true }, "pify": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", - "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=" + "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", + "dev": true }, "pkg-dir": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz", "integrity": "sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==", + "dev": true, "requires": { "find-up": "3.0.0" } @@ -4184,6 +4207,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-4.0.1.tgz", "integrity": "sha1-ljYlN48+HE1IyFhytabsfV0JMjc=", + "dev": true, "requires": { "normalize-package-data": "2.4.0", "parse-json": "4.0.0", @@ -4193,7 +4217,8 @@ "slash": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-2.0.0.tgz", - "integrity": "sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==" + "integrity": "sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==", + "dev": true } } }, @@ -4331,7 +4356,8 @@ "is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", - "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=" + "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", + "dev": true }, "is-buffer": { "version": "1.1.6", @@ -4343,6 +4369,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz", "integrity": "sha1-VAVy0096wxGfj3bDDLwbHgN6/74=", + "dev": true, "requires": { "builtin-modules": "1.1.1" } @@ -4399,7 +4426,8 @@ "is-directory": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/is-directory/-/is-directory-0.3.1.tgz", - "integrity": "sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE=" + "integrity": "sha1-YTObbyR1/Hcv2cnYP1yFddwVSuE=", + "dev": true }, "is-dotfile": { "version": "1.0.3", @@ -4578,7 +4606,8 @@ "is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", + "dev": true }, "is-symbol": { "version": "1.0.1", @@ -4613,7 +4642,8 @@ "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", + "dev": true }, "isobject": { "version": "3.0.1", @@ -5359,6 +5389,7 @@ "version": "3.12.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz", "integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==", + "dev": true, "requires": { "argparse": "1.0.10", "esprima": "4.0.0" @@ -5414,7 +5445,8 @@ "json-parse-better-errors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", - "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==" + "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", + "dev": true }, "json-schema": { "version": "0.2.3", @@ -5651,6 +5683,7 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.2.tgz", "integrity": "sha512-wgeVXhrDwAWnIF/yZARsFnMBtdFXOg1b8RIrhilp+0iDYN4mdQcNZElDZ0e4B64BhaxeQ5zN7PMyvu7we1kPeQ==", + "dev": true, "requires": { "pseudomap": "1.0.2", "yallist": "2.1.2" @@ -5696,9 +5729,10 @@ } }, "markdown-builder": { - "version": "0.8.3-dev", - "resolved": "https://registry.npmjs.org/markdown-builder/-/markdown-builder-0.8.3-dev.tgz", - "integrity": "sha512-NJp9MW/odYYP8z1lEEwDW3k+iVnzW1xaJqwWbjlzsAAA1kZohi6Cf3bQkWKZsxPJTZACgYd/aKpmunLSD1u2Bw==", + "version": "0.8.4-dev", + "resolved": "https://registry.npmjs.org/markdown-builder/-/markdown-builder-0.8.4-dev.tgz", + "integrity": "sha512-egn7ENFiFmc1E/xcRGgXi2Q6oPxWUPYtSJY7RSb3WOdjyVoRQ3JVGMykiM98kMdrRb1QqNYoa+OI/4GdqGsTYw==", + "dev": true, "requires": { "husky": "1.0.0-rc.14" } @@ -6233,6 +6267,7 @@ "version": "2.4.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", "integrity": "sha512-9jjUFbTPfEy3R/ad/2oNbKtW9Hgovl5O1FvFWKkKblNXoN/Oou6+9+KKohPK13Yc3/TyunyWhJp6gvRNR/PPAw==", + "dev": true, "requires": { "hosted-git-info": "2.6.0", "is-builtin-module": "1.0.0", @@ -6253,6 +6288,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", + "dev": true, "requires": { "path-key": "2.0.1" } @@ -6458,7 +6494,8 @@ "p-finally": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", - "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=" + "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", + "dev": true }, "p-limit": { "version": "1.3.0", @@ -6550,7 +6587,8 @@ "path-key": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", - "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=" + "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", + "dev": true }, "path-parse": { "version": "1.0.5", @@ -6680,6 +6718,7 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/please-upgrade-node/-/please-upgrade-node-3.1.1.tgz", "integrity": "sha512-KY1uHnQ2NlQHqIJQpnh/i54rKkuxCEBx+voJIS/Mvb+L2iYd2NMotwduhKTMjfC1uKoX3VXOxLjIYG66dfJTVQ==", + "dev": true, "requires": { "semver-compare": "1.0.0" } @@ -6797,7 +6836,8 @@ "pseudomap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", - "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" + "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", + "dev": true }, "punycode": { "version": "2.1.0", @@ -7238,7 +7278,8 @@ "run-node": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/run-node/-/run-node-1.0.0.tgz", - "integrity": "sha512-kc120TBlQ3mih1LSzdAJXo4xn/GWS2ec0l3S+syHDXP9uRr0JAT8Qd3mdMuyjqCzeZktgP3try92cEgf9Nks8A==" + "integrity": "sha512-kc120TBlQ3mih1LSzdAJXo4xn/GWS2ec0l3S+syHDXP9uRr0JAT8Qd3mdMuyjqCzeZktgP3try92cEgf9Nks8A==", + "dev": true }, "run-parallel": { "version": "1.1.9", @@ -7389,12 +7430,14 @@ "semver": { "version": "5.4.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz", - "integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg==" + "integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg==", + "dev": true }, "semver-compare": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz", - "integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=" + "integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=", + "dev": true }, "set-blocking": { "version": "2.0.0", @@ -7435,6 +7478,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", + "dev": true, "requires": { "shebang-regex": "1.0.0" } @@ -7442,7 +7486,8 @@ "shebang-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", - "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" + "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", + "dev": true }, "shellwords": { "version": "0.1.1", @@ -7453,7 +7498,8 @@ "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", + "dev": true }, "slash": { "version": "1.0.0", @@ -7628,6 +7674,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.0.0.tgz", "integrity": "sha512-N19o9z5cEyc8yQQPukRCZ9EUmb4HUpnrmaL/fxS2pBo2jbfcFRVuFZ/oFC+vZz0MNNk0h80iMn5/S6qGZOL5+g==", + "dev": true, "requires": { "spdx-expression-parse": "3.0.0", "spdx-license-ids": "3.0.0" @@ -7636,12 +7683,14 @@ "spdx-exceptions": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.1.0.tgz", - "integrity": "sha512-4K1NsmrlCU1JJgUrtgEeTVyfx8VaYea9J9LvARxhbHtVtohPs/gFGG5yy49beySjlIMhhXZ4QqujIZEfS4l6Cg==" + "integrity": "sha512-4K1NsmrlCU1JJgUrtgEeTVyfx8VaYea9J9LvARxhbHtVtohPs/gFGG5yy49beySjlIMhhXZ4QqujIZEfS4l6Cg==", + "dev": true }, "spdx-expression-parse": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz", "integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==", + "dev": true, "requires": { "spdx-exceptions": "2.1.0", "spdx-license-ids": "3.0.0" @@ -7650,7 +7699,8 @@ "spdx-license-ids": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.0.tgz", - "integrity": "sha512-2+EPwgbnmOIl8HjGBXXMd9NAu02vLjOO1nWw4kmeRDFyHn+M/ETfHxQUK0oXg8ctgVnl9t3rosNVsZ1jG61nDA==" + "integrity": "sha512-2+EPwgbnmOIl8HjGBXXMd9NAu02vLjOO1nWw4kmeRDFyHn+M/ETfHxQUK0oXg8ctgVnl9t3rosNVsZ1jG61nDA==", + "dev": true }, "split-string": { "version": "3.1.0", @@ -7664,7 +7714,8 @@ "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", + "dev": true }, "sshpk": { "version": "1.14.1", @@ -7845,7 +7896,8 @@ "strip-eof": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", - "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" + "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", + "dev": true }, "strip-indent": { "version": "1.0.1", @@ -8304,6 +8356,7 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.3.tgz", "integrity": "sha512-63ZOUnL4SIXj4L0NixR3L1lcjO38crAbgrTpl28t8jjrfuiOBL5Iygm+60qPs/KsZGzPNg6Smnc/oY16QTjF0g==", + "dev": true, "requires": { "spdx-correct": "3.0.0", "spdx-expression-parse": "3.0.0" @@ -8396,6 +8449,7 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz", "integrity": "sha512-xcJpopdamTuY5duC/KnTTNBraPK54YwpenP4lzxU8H91GudWpFv38u0CKjclE1Wi2EH2EDz5LRcHcKbCIzqGyg==", + "dev": true, "requires": { "isexe": "2.0.0" } @@ -8539,7 +8593,8 @@ "yallist": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", - "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" + "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", + "dev": true }, "yargs": { "version": "7.1.0", diff --git a/package.json b/package.json index 5f9b4105e..063572c9c 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "html-minifier": "^3.5.15", "jest": "^23.1.0", "jest-tap-reporter": "^1.9.0", + "markdown-builder": "^0.8.4-dev", "markdown-it": "^8.4.1", "mini.css": "^2.3.7", "node-sass": "^4.9.0", @@ -15,8 +16,7 @@ "rollup": "^0.58.2", "rollup-plugin-babel": "^3.0.4", "rollup-plugin-babel-minify": "^4.0.0", - "semistandard": "^12.0.1", - "markdown-builder": "^0.8.3-dev" + "semistandard": "^12.0.1" }, "name": "30-seconds-of-code", "description": "A collection of useful JavaScript snippets.",