Travis build: 944 [cron]

This commit is contained in:
30secondsofcode
2019-01-10 14:48:42 +00:00
parent ec24d224fd
commit a943631e27
7 changed files with 92 additions and 53 deletions

8
dist/_30s.es5.js vendored
View File

@ -491,6 +491,9 @@
return timer; return timer;
}; };
var createDirIfNotExists = function createDirIfNotExists(dir) {
return !fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined;
};
var createElement = function createElement(str) { var createElement = function createElement(str) {
var el = document.createElement('div'); var el = document.createElement('div');
el.innerHTML = str; el.innerHTML = str;
@ -2373,11 +2376,9 @@
return el.classList.toggle(className); return el.classList.toggle(className);
}; };
var tomorrow = function tomorrow() { var tomorrow = function tomorrow() {
var long = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var t = new Date(); var t = new Date();
t.setDate(t.getDate() + 1); t.setDate(t.getDate() + 1);
var ret = "".concat(t.getFullYear(), "-").concat(String(t.getMonth() + 1).padStart(2, '0'), "-").concat(String(t.getDate()).padStart(2, '0')); return t.toISOString().split('T')[0];
return !long ? ret : "".concat(ret, "T00:00:00");
}; };
var transform = function transform(obj, fn, acc) { var transform = function transform(obj, fn, acc) {
return Object.keys(obj).reduce(function (a, k) { return Object.keys(obj).reduce(function (a, k) {
@ -2650,6 +2651,7 @@
exports.countBy = countBy; exports.countBy = countBy;
exports.countOccurrences = countOccurrences; exports.countOccurrences = countOccurrences;
exports.counter = counter; exports.counter = counter;
exports.createDirIfNotExists = createDirIfNotExists;
exports.createElement = createElement; exports.createElement = createElement;
exports.createEventHub = createEventHub; exports.createEventHub = createEventHub;
exports.currentURL = currentURL; exports.currentURL = currentURL;

File diff suppressed because one or more lines are too long

20
dist/_30s.esm.js vendored
View File

@ -181,6 +181,7 @@ const counter = (selector, start, end, step = 1, duration = 2000) => {
}, Math.abs(Math.floor(duration / (end - start)))); }, Math.abs(Math.floor(duration / (end - start))));
return timer; return timer;
}; };
const createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined);
const createElement = str => { const createElement = str => {
const el = document.createElement('div'); const el = document.createElement('div');
el.innerHTML = str; el.innerHTML = str;
@ -259,9 +260,9 @@ const dig = (obj, target) =>
target in obj target in obj
? obj[target] ? obj[target]
: Object.values(obj).reduce((acc, val) => { : Object.values(obj).reduce((acc, val) => {
if (acc !== undefined) return acc; if (acc !== undefined) return acc;
if (typeof val === 'object') return dig(val, target); if (typeof val === 'object') return dig(val, target);
}, undefined); }, undefined);
const digitize = n => [...`${n}`].map(i => parseInt(i)); const digitize = n => [...`${n}`].map(i => parseInt(i));
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0); const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
const drop = (arr, n = 1) => arr.slice(n); const drop = (arr, n = 1) => arr.slice(n);
@ -333,8 +334,8 @@ const extendHex = shortHex =>
const factorial = n => const factorial = n =>
n < 0 n < 0
? (() => { ? (() => {
throw new TypeError('Negative numbers are not allowed!'); throw new TypeError('Negative numbers are not allowed!');
})() })()
: n <= 1 : n <= 1
? 1 ? 1
: n * factorial(n - 1); : n * factorial(n - 1);
@ -1224,13 +1225,10 @@ const toTitleCase = str =>
.map(x => x.charAt(0).toUpperCase() + x.slice(1)) .map(x => x.charAt(0).toUpperCase() + x.slice(1))
.join(' '); .join(' ');
const toggleClass = (el, className) => el.classList.toggle(className); const toggleClass = (el, className) => el.classList.toggle(className);
const tomorrow = (long = false) => { const tomorrow = () => {
let t = new Date(); let t = new Date();
t.setDate(t.getDate() + 1); t.setDate(t.getDate() + 1);
const ret = `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String( return t.toISOString().split('T')[0];
t.getDate()
).padStart(2, '0')}`;
return !long ? ret : `${ret}T00:00:00`;
}; };
const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc); const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc);
const triggerEvent = (el, eventType, detail) => const triggerEvent = (el, eventType, detail) =>
@ -1339,4 +1337,4 @@ const zipWith = (...array) => {
); );
}; };
export { CSVToArray, CSVToJSON, JSONToFile, JSONtoCSV, RGBToHex, URLJoin, UUIDGeneratorBrowser, UUIDGeneratorNode, all, allEqual, any, approximatelyEqual, arrayToCSV, arrayToHtmlList, ary, atob, attempt, average, averageBy, bifurcate, bifurcateBy, bind, bindAll, bindKey, binomialCoefficient, bottomVisible, btoa, byteSize, call, capitalize, capitalizeEveryWord, castArray, chainAsync, chunk, clampNumber, cloneRegExp, coalesce, coalesceFactory, collectInto, colorize, compact, compactWhitespace, compose, composeRight, converge, copyToClipboard, countBy, countOccurrences, counter, createElement, createEventHub, currentURL, curry, dayOfYear, debounce, decapitalize, deepClone, deepFlatten, deepFreeze, deepMapKeys, defaults, defer, degreesToRads, delay, detectDeviceType, difference, differenceBy, differenceWith, dig, digitize, distance, drop, dropRight, dropRightWhile, dropWhile, elementContains, elementIsVisibleInViewport, elo, equals, escapeHTML, escapeRegExp, everyNth, extendHex, factorial, fibonacci, filterFalsy, filterNonUnique, filterNonUniqueBy, findKey, findLast, findLastIndex, findLastKey, flatten, flattenObject, flip, forEachRight, forOwn, forOwnRight, formatDuration, fromCamelCase, functionName, functions, gcd, geometricProgression, get, getColonTimeFromDate, getDaysDiffBetweenDates, getImages, getMeridiemSuffixOfInteger, getScrollPosition, getStyle, getType, getURLParameters, groupBy, hammingDistance, hasClass, hasFlags, hashBrowser, hashNode, head, hexToRGB, hide, httpGet, httpPost, httpsRedirect, hz, inRange, indentString, indexOfAll, initial, initialize2DArray, initializeArrayWithRange, initializeArrayWithRangeRight, initializeArrayWithValues, initializeNDArray, insertAfter, insertBefore, intersection, intersectionBy, intersectionWith, invertKeyValues, is, isAbsoluteURL, isAfterDate, isAnagram, isArrayLike, isBeforeDate, isBoolean, isBrowser, isBrowserTabFocused, isDivisible, isDuplexStream, isEmpty, isEven, isFunction, isLowerCase, isNegativeZero, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isPrime, isPrimitive, isPromiseLike, isReadableStream, isSameDate, isSorted, isStream, isString, isSymbol, isTravisCI, isUndefined, isUpperCase, isValidJSON, isWritableStream, join, last, lcm, longestItem, lowercaseKeys, luhnCheck, mapKeys, mapObject, mapString, mapValues, mask, matches, matchesWith, maxBy, maxDate, maxN, median, memoize, merge, midpoint, minBy, minDate, minN, mostPerformant, negate, nest, nodeListToArray, none, nthArg, nthElement, objectFromPairs, objectToPairs, observeMutations, off, offset, omit, omitBy, on, onUserInputChange, once, orderBy, over, overArgs, pad, palindrome, parseCookie, partial, partialRight, partition, percentile, permutations, pick, pickBy, pipeAsyncFunctions, pipeFunctions, pluralize, powerset, prefix, prettyBytes, primes, promisify, pull, pullAtIndex, pullAtValue, pullBy, radsToDegrees, randomHexColorCode, randomIntArrayInRange, randomIntegerInRange, randomNumberInRange, readFileLines, rearg, recordAnimationFrames, redirect, reduceSuccessive, reduceWhich, reducedFilter, reject, remove, removeNonASCII, renameKeys, reverseString, round, runAsync, runPromisesInSeries, sample, sampleSize, scrollToTop, sdbm, serializeCookie, setStyle, shallowClone, shank, show, shuffle, similarity, size, sleep, smoothScroll, sortCharactersInString, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, splitLines, spreadOver, stableSort, standardDeviation, stringPermutations, stripHTMLTags, sum, sumBy, sumPower, symmetricDifference, symmetricDifferenceBy, symmetricDifferenceWith, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeTaken, times, toCamelCase, toCurrency, toDecimalMark, toHash, toKebabCase, toOrdinalSuffix, toSafeInteger, toSnakeCase, toTitleCase, toggleClass, tomorrow, transform, triggerEvent, truncateString, truthCheckCollection, unary, uncurry, unescapeHTML, unflattenObject, unfold, union, unionBy, unionWith, uniqueElements, uniqueElementsBy, uniqueElementsByRight, uniqueSymmetricDifference, untildify, unzip, unzipWith, validateNumber, when, without, words, xProd, yesNo, zip, zipObject, zipWith }; export { CSVToArray, CSVToJSON, JSONToFile, JSONtoCSV, RGBToHex, URLJoin, UUIDGeneratorBrowser, UUIDGeneratorNode, all, allEqual, any, approximatelyEqual, arrayToCSV, arrayToHtmlList, ary, atob, attempt, average, averageBy, bifurcate, bifurcateBy, bind, bindAll, bindKey, binomialCoefficient, bottomVisible, btoa, byteSize, call, capitalize, capitalizeEveryWord, castArray, chainAsync, chunk, clampNumber, cloneRegExp, coalesce, coalesceFactory, collectInto, colorize, compact, compactWhitespace, compose, composeRight, converge, copyToClipboard, countBy, countOccurrences, counter, createDirIfNotExists, createElement, createEventHub, currentURL, curry, dayOfYear, debounce, decapitalize, deepClone, deepFlatten, deepFreeze, deepMapKeys, defaults, defer, degreesToRads, delay, detectDeviceType, difference, differenceBy, differenceWith, dig, digitize, distance, drop, dropRight, dropRightWhile, dropWhile, elementContains, elementIsVisibleInViewport, elo, equals, escapeHTML, escapeRegExp, everyNth, extendHex, factorial, fibonacci, filterFalsy, filterNonUnique, filterNonUniqueBy, findKey, findLast, findLastIndex, findLastKey, flatten, flattenObject, flip, forEachRight, forOwn, forOwnRight, formatDuration, fromCamelCase, functionName, functions, gcd, geometricProgression, get, getColonTimeFromDate, getDaysDiffBetweenDates, getImages, getMeridiemSuffixOfInteger, getScrollPosition, getStyle, getType, getURLParameters, groupBy, hammingDistance, hasClass, hasFlags, hashBrowser, hashNode, head, hexToRGB, hide, httpGet, httpPost, httpsRedirect, hz, inRange, indentString, indexOfAll, initial, initialize2DArray, initializeArrayWithRange, initializeArrayWithRangeRight, initializeArrayWithValues, initializeNDArray, insertAfter, insertBefore, intersection, intersectionBy, intersectionWith, invertKeyValues, is, isAbsoluteURL, isAfterDate, isAnagram, isArrayLike, isBeforeDate, isBoolean, isBrowser, isBrowserTabFocused, isDivisible, isDuplexStream, isEmpty, isEven, isFunction, isLowerCase, isNegativeZero, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isPrime, isPrimitive, isPromiseLike, isReadableStream, isSameDate, isSorted, isStream, isString, isSymbol, isTravisCI, isUndefined, isUpperCase, isValidJSON, isWritableStream, join, last, lcm, longestItem, lowercaseKeys, luhnCheck, mapKeys, mapObject, mapString, mapValues, mask, matches, matchesWith, maxBy, maxDate, maxN, median, memoize, merge, midpoint, minBy, minDate, minN, mostPerformant, negate, nest, nodeListToArray, none, nthArg, nthElement, objectFromPairs, objectToPairs, observeMutations, off, offset, omit, omitBy, on, onUserInputChange, once, orderBy, over, overArgs, pad, palindrome, parseCookie, partial, partialRight, partition, percentile, permutations, pick, pickBy, pipeAsyncFunctions, pipeFunctions, pluralize, powerset, prefix, prettyBytes, primes, promisify, pull, pullAtIndex, pullAtValue, pullBy, radsToDegrees, randomHexColorCode, randomIntArrayInRange, randomIntegerInRange, randomNumberInRange, readFileLines, rearg, recordAnimationFrames, redirect, reduceSuccessive, reduceWhich, reducedFilter, reject, remove, removeNonASCII, renameKeys, reverseString, round, runAsync, runPromisesInSeries, sample, sampleSize, scrollToTop, sdbm, serializeCookie, setStyle, shallowClone, shank, show, shuffle, similarity, size, sleep, smoothScroll, sortCharactersInString, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, splitLines, spreadOver, stableSort, standardDeviation, stringPermutations, stripHTMLTags, sum, sumBy, sumPower, symmetricDifference, symmetricDifferenceBy, symmetricDifferenceWith, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeTaken, times, toCamelCase, toCurrency, toDecimalMark, toHash, toKebabCase, toOrdinalSuffix, toSafeInteger, toSnakeCase, toTitleCase, toggleClass, tomorrow, transform, triggerEvent, truncateString, truthCheckCollection, unary, uncurry, unescapeHTML, unflattenObject, unfold, union, unionBy, unionWith, uniqueElements, uniqueElementsBy, uniqueElementsByRight, uniqueSymmetricDifference, untildify, unzip, unzipWith, validateNumber, when, without, words, xProd, yesNo, zip, zipObject, zipWith };

19
dist/_30s.js vendored
View File

@ -187,6 +187,7 @@
}, Math.abs(Math.floor(duration / (end - start)))); }, Math.abs(Math.floor(duration / (end - start))));
return timer; return timer;
}; };
const createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined);
const createElement = str => { const createElement = str => {
const el = document.createElement('div'); const el = document.createElement('div');
el.innerHTML = str; el.innerHTML = str;
@ -265,9 +266,9 @@
target in obj target in obj
? obj[target] ? obj[target]
: Object.values(obj).reduce((acc, val) => { : Object.values(obj).reduce((acc, val) => {
if (acc !== undefined) return acc; if (acc !== undefined) return acc;
if (typeof val === 'object') return dig(val, target); if (typeof val === 'object') return dig(val, target);
}, undefined); }, undefined);
const digitize = n => [...`${n}`].map(i => parseInt(i)); const digitize = n => [...`${n}`].map(i => parseInt(i));
const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0); const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
const drop = (arr, n = 1) => arr.slice(n); const drop = (arr, n = 1) => arr.slice(n);
@ -339,8 +340,8 @@
const factorial = n => const factorial = n =>
n < 0 n < 0
? (() => { ? (() => {
throw new TypeError('Negative numbers are not allowed!'); throw new TypeError('Negative numbers are not allowed!');
})() })()
: n <= 1 : n <= 1
? 1 ? 1
: n * factorial(n - 1); : n * factorial(n - 1);
@ -1230,13 +1231,10 @@
.map(x => x.charAt(0).toUpperCase() + x.slice(1)) .map(x => x.charAt(0).toUpperCase() + x.slice(1))
.join(' '); .join(' ');
const toggleClass = (el, className) => el.classList.toggle(className); const toggleClass = (el, className) => el.classList.toggle(className);
const tomorrow = (long = false) => { const tomorrow = () => {
let t = new Date(); let t = new Date();
t.setDate(t.getDate() + 1); t.setDate(t.getDate() + 1);
const ret = `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String( return t.toISOString().split('T')[0];
t.getDate()
).padStart(2, '0')}`;
return !long ? ret : `${ret}T00:00:00`;
}; };
const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc); const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc);
const triggerEvent = (el, eventType, detail) => const triggerEvent = (el, eventType, detail) =>
@ -1394,6 +1392,7 @@
exports.countBy = countBy; exports.countBy = countBy;
exports.countOccurrences = countOccurrences; exports.countOccurrences = countOccurrences;
exports.counter = counter; exports.counter = counter;
exports.createDirIfNotExists = createDirIfNotExists;
exports.createElement = createElement; exports.createElement = createElement;
exports.createEventHub = createEventHub; exports.createEventHub = createEventHub;
exports.currentURL = currentURL; exports.currentURL = currentURL;

View File

@ -605,6 +605,20 @@
"hash": "f4471dcfb3a53fe8fd2f9e5566d5cf028aa69f4ddba69d6b5acd94c6e6aee133" "hash": "f4471dcfb3a53fe8fd2f9e5566d5cf028aa69f4ddba69d6b5acd94c6e6aee133"
} }
}, },
{
"id": "createDirIfNotExists",
"type": "snippetListing",
"attributes": {
"tags": [
"node",
"beginner"
],
"archived": false
},
"meta": {
"hash": "62317874ea1df5043926b63d6ff24e861b2f23ab76e5de79af10766844f4f9c7"
}
},
{ {
"id": "createElement", "id": "createElement",
"type": "snippetListing", "type": "snippetListing",
@ -927,7 +941,7 @@
"archived": false "archived": false
}, },
"meta": { "meta": {
"hash": "828a6f2f3b94cc537ef0ee30c5ebda28fff688fea65030e47d5721831bdb48ce" "hash": "f982b4e8e3ec3c8b0c2ef4f19b38dac90df6ebe2dd4daa0126c917ebc07d3e62"
} }
}, },
{ {
@ -1148,7 +1162,7 @@
"archived": false "archived": false
}, },
"meta": { "meta": {
"hash": "383ed61e69b8f63ae42d0746a1995057f4f65b4af6ca7778d8f1771144802acd" "hash": "319e1a8fb41490965ee6e28db3e139e65c4ea5b7f43e332bc7216cd790e5d409"
} }
}, },
{ {
@ -3363,7 +3377,7 @@
"archived": false "archived": false
}, },
"meta": { "meta": {
"hash": "4815876fd6dbb17ad34c0d8918e7a72d837104f9beee7dc51b0fa73057b9e83e" "hash": "dcdf66e8d0eb4a1761c6b767b8cc350757087ae817ec371436faab0fff7c0051"
} }
}, },
{ {
@ -3735,7 +3749,7 @@
"archived": false "archived": false
}, },
"meta": { "meta": {
"hash": "ec9cb9384817f84cf0bacd62a23b69b2304fa2cf0352b16d3950b21d48c04f11" "hash": "536833a64ce0c000b82327ed1bb9bcb82e35b237f75aefcca0e0d2def4e9cb63"
} }
}, },
{ {
@ -4517,7 +4531,7 @@
"archived": false "archived": false
}, },
"meta": { "meta": {
"hash": "4794ae637e65b9c1ac43f6c964555a98cda83e1410684e11ed34753c81db35fb" "hash": "ab65540435058b1e9dbe3f42bed312ad9095254065f8d711d4211e20fed371a7"
} }
}, },
{ {

View File

@ -892,6 +892,27 @@
"hash": "f4471dcfb3a53fe8fd2f9e5566d5cf028aa69f4ddba69d6b5acd94c6e6aee133" "hash": "f4471dcfb3a53fe8fd2f9e5566d5cf028aa69f4ddba69d6b5acd94c6e6aee133"
} }
}, },
{
"id": "createDirIfNotExists",
"type": "snippet",
"attributes": {
"fileName": "createDirIfNotExists.md",
"text": "Creates a directory, if it does not exist.\n\nUse `fs.existsSync()` to check if the directory exists, `fs.mkdirSync()` to create it.",
"codeBlocks": {
"es6": "const fs = require('fs');\nconst createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined);",
"es5": "var fs = require('fs');\n\nvar createDirIfNotExists = function createDirIfNotExists(dir) {\n return !fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined;\n};",
"example": "createDirIfNotExists('test'); // creates the directory 'test', if it doesn't exist"
},
"tags": [
"node",
"beginner"
]
},
"meta": {
"archived": false,
"hash": "62317874ea1df5043926b63d6ff24e861b2f23ab76e5de79af10766844f4f9c7"
}
},
{ {
"id": "createElement", "id": "createElement",
"type": "snippet", "type": "snippet",
@ -1356,7 +1377,7 @@
"fileName": "dig.md", "fileName": "dig.md",
"text": "Returns the target value in a nested JSON object, based on the given key.\n\nUse the `in` operator to check if `target` exists in `obj`.\nIf found, return the value of `obj[target]`, otherwise use `Object.values(obj)` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found.", "text": "Returns the target value in a nested JSON object, based on the given key.\n\nUse the `in` operator to check if `target` exists in `obj`.\nIf found, return the value of `obj[target]`, otherwise use `Object.values(obj)` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found.",
"codeBlocks": { "codeBlocks": {
"es6": "const dig = (obj, target) =>\n target in obj\n ? obj[target]\n : Object.values(obj).reduce((acc, val) => {\n if (acc !== undefined) return acc;\n if (typeof val === 'object') return dig(val, target);\n }, undefined);", "es6": "const dig = (obj, target) =>\n target in obj\n ? obj[target]\n : Object.values(obj).reduce((acc, val) => {\n if (acc !== undefined) return acc;\n if (typeof val === 'object') return dig(val, target);\n }, undefined);",
"es5": "function _typeof(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nvar dig = function dig(obj, target) {\n return target in obj ? obj[target] : Object.values(obj).reduce(function (acc, val) {\n if (acc !== undefined) return acc;\n if (_typeof(val) === 'object') return dig(val, target);\n }, undefined);\n};", "es5": "function _typeof(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nvar dig = function dig(obj, target) {\n return target in obj ? obj[target] : Object.values(obj).reduce(function (acc, val) {\n if (acc !== undefined) return acc;\n if (_typeof(val) === 'object') return dig(val, target);\n }, undefined);\n};",
"example": "const data = {\n level1: {\n level2: {\n level3: 'some data'\n }\n }\n};\ndig(data, 'level3'); // 'some data'\ndig(data, 'level4'); // undefined" "example": "const data = {\n level1: {\n level2: {\n level3: 'some data'\n }\n }\n};\ndig(data, 'level3'); // 'some data'\ndig(data, 'level4'); // undefined"
}, },
@ -1368,7 +1389,7 @@
}, },
"meta": { "meta": {
"archived": false, "archived": false,
"hash": "828a6f2f3b94cc537ef0ee30c5ebda28fff688fea65030e47d5721831bdb48ce" "hash": "f982b4e8e3ec3c8b0c2ef4f19b38dac90df6ebe2dd4daa0126c917ebc07d3e62"
} }
}, },
{ {
@ -1682,7 +1703,7 @@
"fileName": "factorial.md", "fileName": "factorial.md",
"text": "Calculates the factorial of a number.\n\nUse recursion.\nIf `n` is less than or equal to `1`, return `1`.\nOtherwise, return the product of `n` and the factorial of `n - 1`.\nThrows an exception if `n` is a negative number.", "text": "Calculates the factorial of a number.\n\nUse recursion.\nIf `n` is less than or equal to `1`, return `1`.\nOtherwise, return the product of `n` and the factorial of `n - 1`.\nThrows an exception if `n` is a negative number.",
"codeBlocks": { "codeBlocks": {
"es6": "const factorial = n =>\n n < 0\n ? (() => {\n throw new TypeError('Negative numbers are not allowed!');\n })()\n : n <= 1\n ? 1\n : n * factorial(n - 1);", "es6": "const factorial = n =>\n n < 0\n ? (() => {\n throw new TypeError('Negative numbers are not allowed!');\n })()\n : n <= 1\n ? 1\n : n * factorial(n - 1);",
"es5": "var factorial = function factorial(n) {\n return n < 0 ? function () {\n throw new TypeError('Negative numbers are not allowed!');\n }() : n <= 1 ? 1 : n * factorial(n - 1);\n};", "es5": "var factorial = function factorial(n) {\n return n < 0 ? function () {\n throw new TypeError('Negative numbers are not allowed!');\n }() : n <= 1 ? 1 : n * factorial(n - 1);\n};",
"example": "factorial(6); // 720" "example": "factorial(6); // 720"
}, },
@ -1694,7 +1715,7 @@
}, },
"meta": { "meta": {
"archived": false, "archived": false,
"hash": "383ed61e69b8f63ae42d0746a1995057f4f65b4af6ca7778d8f1771144802acd" "hash": "319e1a8fb41490965ee6e28db3e139e65c4ea5b7f43e332bc7216cd790e5d409"
} }
}, },
{ {
@ -4941,7 +4962,7 @@
"codeBlocks": { "codeBlocks": {
"es6": "const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Promise.resolve(arg));", "es6": "const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Promise.resolve(arg));",
"es5": "var pipeAsyncFunctions = function pipeAsyncFunctions() {\n for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {\n fns[_key] = arguments[_key];\n }\n\n return function (arg) {\n return fns.reduce(function (p, f) {\n return p.then(f);\n }, Promise.resolve(arg));\n };\n};", "es5": "var pipeAsyncFunctions = function pipeAsyncFunctions() {\n for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {\n fns[_key] = arguments[_key];\n }\n\n return function (arg) {\n return fns.reduce(function (p, f) {\n return p.then(f);\n }, Promise.resolve(arg));\n };\n};",
"example": "const sum = pipeAsyncFunctions(\n x => x + 1,\n x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),\n x => x + 3,\n async x => (await x) + 4\n);\n(async() => {\n console.log(await sum(5)); // 15 (after one second)\n})();" "example": "const sum = pipeAsyncFunctions(\n x => x + 1,\n x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),\n x => x + 3,\n async x => (await x) + 4\n);\n(async () => {\n console.log(await sum(5)); // 15 (after one second)\n})();"
}, },
"tags": [ "tags": [
"adapter", "adapter",
@ -4952,7 +4973,7 @@
}, },
"meta": { "meta": {
"archived": false, "archived": false,
"hash": "4815876fd6dbb17ad34c0d8918e7a72d837104f9beee7dc51b0fa73057b9e83e" "hash": "dcdf66e8d0eb4a1761c6b767b8cc350757087ae817ec371436faab0fff7c0051"
} }
}, },
{ {
@ -5499,7 +5520,7 @@
}, },
"meta": { "meta": {
"archived": false, "archived": false,
"hash": "ec9cb9384817f84cf0bacd62a23b69b2304fa2cf0352b16d3950b21d48c04f11" "hash": "536833a64ce0c000b82327ed1bb9bcb82e35b237f75aefcca0e0d2def4e9cb63"
} }
}, },
{ {
@ -6639,11 +6660,11 @@
"type": "snippet", "type": "snippet",
"attributes": { "attributes": {
"fileName": "tomorrow.md", "fileName": "tomorrow.md",
"text": "Results in a string representation of tomorrow's date.\n\nUse `new Date()` to get today's date, adding one day using `Date.getDate()` and `Date.setDate()`, and converting the Date object to a string.", "text": "Results in a string representation of tomorrow's date.\n\nUse `new Date()` to get the current date, increment by one using `Date.getDate()` and set the value to the result using `Date.setDate()`. \nUse `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format.",
"codeBlocks": { "codeBlocks": {
"es6": "const tomorrow = (long = false) => {\n let t = new Date();\n t.setDate(t.getDate() + 1);\n const ret = `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String(\n t.getDate()\n ).padStart(2, '0')}`;\n return !long ? ret : `${ret}T00:00:00`;\n};", "es6": "const tomorrow = () => {\n let t = new Date();\n t.setDate(t.getDate() + 1);\n return t.toISOString().split('T')[0];\n};",
"es5": "var tomorrow = function tomorrow() {\n var long = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n var t = new Date();\n t.setDate(t.getDate() + 1);\n var ret = \"\".concat(t.getFullYear(), \"-\").concat(String(t.getMonth() + 1).padStart(2, '0'), \"-\").concat(String(t.getDate()).padStart(2, '0'));\n return !long ? ret : \"\".concat(ret, \"T00:00:00\");\n};", "es5": "var tomorrow = function tomorrow() {\n var t = new Date();\n t.setDate(t.getDate() + 1);\n return t.toISOString().split('T')[0];\n};",
"example": "tomorrow(); // 2017-12-27 (if current date is 2017-12-26)\ntomorrow(true); // 2017-12-27T00:00:00 (if current date is 2017-12-26)" "example": "tomorrow(); // 2018-10-18 (if current date is 2018-10-18)"
}, },
"tags": [ "tags": [
"date", "date",
@ -6652,7 +6673,7 @@
}, },
"meta": { "meta": {
"archived": false, "archived": false,
"hash": "4794ae637e65b9c1ac43f6c964555a98cda83e1410684e11ed34753c81db35fb" "hash": "ab65540435058b1e9dbe3f42bed312ad9095254065f8d711d4211e20fed371a7"
} }
}, },
{ {

View File

@ -380,6 +380,14 @@
], ],
"description": "Counts the occurrences of a value in an array.\n\nUse `Array.prototype.reduce()` to increment a counter each time you encounter the specific value inside the array" "description": "Counts the occurrences of a value in an array.\n\nUse `Array.prototype.reduce()` to increment a counter each time you encounter the specific value inside the array"
}, },
"createDirIfNotExists": {
"prefix": "30s_createDirIfNotExists",
"body": [
"const fs = require('fs');",
"const createDirIfNotExists = dir => (!fs.existsSync(dir) ? fs.mkdirSync(dir) : undefined);"
],
"description": "Creates a directory, if it does not exist.\n\nUse `fs.existsSync()` to check if the directory exists, `fs.mkdirSync()` to create it"
},
"createElement": { "createElement": {
"prefix": "30s_createElement", "prefix": "30s_createElement",
"body": [ "body": [
@ -602,9 +610,9 @@
" target in obj", " target in obj",
" ? obj[target]", " ? obj[target]",
" : Object.values(obj).reduce((acc, val) => {", " : Object.values(obj).reduce((acc, val) => {",
" if (acc !== undefined) return acc;", " if (acc !== undefined) return acc;",
" if (typeof val === 'object') return dig(val, target);", " if (typeof val === 'object') return dig(val, target);",
" }, undefined);" " }, undefined);"
], ],
"description": "Returns the target value in a nested JSON object, based on the given key.\n\nUse the `in` operator to check if `target` exists in `obj`.\nIf found, return the value of `obj[target]`, otherwise use `Object.values(obj)` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found" "description": "Returns the target value in a nested JSON object, based on the given key.\n\nUse the `in` operator to check if `target` exists in `obj`.\nIf found, return the value of `obj[target]`, otherwise use `Object.values(obj)` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found"
}, },
@ -766,8 +774,8 @@
"const factorial = n =>", "const factorial = n =>",
" n < 0", " n < 0",
" ? (() => {", " ? (() => {",
" throw new TypeError('Negative numbers are not allowed!');", " throw new TypeError('Negative numbers are not allowed!');",
" })()", " })()",
" : n <= 1", " : n <= 1",
" ? 1", " ? 1",
" : n * factorial(n - 1);" " : n * factorial(n - 1);"
@ -3012,16 +3020,13 @@
"tomorrow": { "tomorrow": {
"prefix": "30s_tomorrow", "prefix": "30s_tomorrow",
"body": [ "body": [
"const tomorrow = (long = false) => {", "const tomorrow = () => {",
" let t = new Date();", " let t = new Date();",
" t.setDate(t.getDate() + 1);", " t.setDate(t.getDate() + 1);",
" const ret = `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String(", " return t.toISOString().split('T')[0];",
" t.getDate()",
" ).padStart(2, '0')}`;",
" return !long ? ret : `${ret}T00:00:00`;",
"};" "};"
], ],
"description": "Results in a string representation of tomorrow's date.\n\nUse `new Date()` to get today's date, adding one day using `Date.getDate()` and `Date.setDate()`, and converting the Date object to a string" "description": "Results in a string representation of tomorrow's date.\n\nUse `new Date()` to get the current date, increment by one using `Date.getDate()` and set the value to the result using `Date.setDate()`. \nUse `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format"
}, },
"toOrdinalSuffix": { "toOrdinalSuffix": {
"prefix": "30s_toOrdinalSuffix", "prefix": "30s_toOrdinalSuffix",