diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json index e703473a9..8912ab17f 100644 --- a/snippet_data/snippetList.json +++ b/snippet_data/snippetList.json @@ -72,12 +72,11 @@ "tags": [ "array", "string", - "utility", "intermediate" ] }, "meta": { - "hash": "aeabb3d1d2be2d44fd8a20da3b069fdd1a8ad963f27e3e1ae9f5e8b40a8908cb" + "hash": "e5c607cd29800661ad8ea0506afaa42cd3f3936f835714939ceba49a5bd95638" } }, { @@ -120,12 +119,11 @@ "tags": [ "node", "string", - "utility", "beginner" ] }, "meta": { - "hash": "32988360d63d6d62251314a88d3f4482ec3a265d67154a92a86d4140bd61c54b" + "hash": "6b8f586d9f697e08949128ec6774022484444daa8575c45a28fb1f9c8ba2c2bc" } }, { @@ -294,12 +292,11 @@ "tags": [ "node", "string", - "utility", "beginner" ] }, "meta": { - "hash": "1c7836009987b8b1097b54a84c38144f6cb643477f08f00b1a37e274cf0c9f78" + "hash": "afb23f750b1460a89dca8424056fa581a7befd6e4f8b369ac2e93d50c94d9749" } }, { @@ -371,14 +368,13 @@ "attributes": { "text": "Casts the provided value as an array if it's not one.\n\nUse `Array.prototype.isArray()` to determine if `val` is an array and return it as-is or encapsulated in an array accordingly.\n\n", "tags": [ - "utility", - "array", "type", + "array", "beginner" ] }, "meta": { - "hash": "307add91ea4d5c2a122256f799120f580ac235567523dddeeadd6500f1e81e94" + "hash": "2f0d1b37cbcc8d6646fda98864848a41cb6ecaec02f7a0ba52bb45c87a210441" } }, { @@ -420,7 +416,6 @@ "tags": [ "function", "object", - "utility", "beginner" ] }, @@ -465,13 +460,14 @@ "attributes": { "text": "Clones a regular expression.\n\nUse `new RegExp()`, `RegExp.source` and `RegExp.flags` to clone the given regular expression.\n\n", "tags": [ - "utility", + "type", + "string", "regexp", "intermediate" ] }, "meta": { - "hash": "3b7e9a506c229c792da093336574e3524cd1a8c794d18fc450f469f171ff83cf" + "hash": "8a748ad892a46df9ff2a5e64aba3b9a35fbd9a0d0351c21e2c2bf1d40a39c046" } }, { @@ -481,7 +477,7 @@ "attributes": { "text": "Returns the first defined, non-null argument.\n\nUse `Array.prototype.find()` and `Array.prototype.includes()` to find the first value that is not equal to `undefined` or `null`.\n\n", "tags": [ - "utility", + "type", "beginner" ] }, @@ -496,12 +492,12 @@ "attributes": { "text": "Returns a customized coalesce function that returns the first argument that returns `true` from the provided argument validation function.\n\nUse `Array.prototype.find()` to return the first argument that returns `true` from the provided argument validation function.\n\n", "tags": [ - "utility", + "type", "intermediate" ] }, "meta": { - "hash": "b85ec57d815ff34ba3906195440fce5d2ad9f33b64d7d96159c0e1125fee283c" + "hash": "26bbe0fe97b8a037808ae4b7310e54cd3a31f6a0f0a0d9c6a2ae733046501132" } }, { @@ -528,13 +524,12 @@ "text": "Add special characters to text to print in color in the console (combined with `console.log()`).\n\nUse template literals and special characters to add the appropriate color code to the string output.\nFor background colors, add a special character that resets the background color at the end of the string.\n\n", "tags": [ "node", - "utility", "string", "intermediate" ] }, "meta": { - "hash": "1ce726b8cbc9f87ff8ff6d68e0678325523b1118fa038b97f53ddad9031dbe23" + "hash": "d33a3685273eb81bf2a224330007c5425f434c2292859bdfebbe1fbafd5da48c" } }, { @@ -711,15 +706,14 @@ "type": "snippetListing", "title": "createElement", "attributes": { - "text": "Creates an element from a string (without appending it to the document). \nIf the given string contains multiple elements, only the first one will be returned.\n\nUse `document.createElement()` to create a new element.\nSet its `innerHTML` to the string supplied as the argument. \nUse `ParentNode.firstElementChild` to return the element version of the string.\n\n", + "text": "Creates an element from a string (without appending it to the document).\nIf the given string contains multiple elements, only the first one will be returned.\n\nUse `document.createElement()` to create a new element.\nSet its `innerHTML` to the string supplied as the argument.\nUse `ParentNode.firstElementChild` to return the element version of the string.\n\n", "tags": [ "browser", - "utility", "beginner" ] }, "meta": { - "hash": "d162fbc50166f304216db6ea700e5fc7f428ea33d50b204ae921e1c58552a4e0" + "hash": "de8ab0037be4b5d74805237ea414516a1ca227fa2b693b01190bd50f01d362bb" } }, { @@ -747,12 +741,11 @@ "tags": [ "string", "array", - "utility", "intermediate" ] }, "meta": { - "hash": "3169ab83e588063262fa6a01f7d7df7bd9521345c65a7c7f874f577478c90305" + "hash": "e53a8dfbb2ab55c1678e462164268773fbc3876ce9cd8326fb44428694fb9f72" } }, { @@ -863,7 +856,7 @@ ] }, "meta": { - "hash": "77a01af8797ecbe71b9c9412d21c144c03a46a49dd3d0e7d869c3df38b39b2b4" + "hash": "0a4684d6fc79bdbbac31df3af6c493ba7c881936ada5bc52824b4f26ca177459" } }, { @@ -926,7 +919,7 @@ ] }, "meta": { - "hash": "6fa14364405f7b99aa49c2157bdc08c02b4ce2f288db29a4348a6983460933c7" + "hash": "a4e1e33c0688dbf1ca231d9d8ea315ffed93b7f83f5d8cbf0714f10fdfeda8cf" } }, { @@ -1065,7 +1058,7 @@ ] }, "meta": { - "hash": "bdc202436bee09f06a353d31841c6cfff33e8efead34c6c56ae1a1413284976d" + "hash": "484bd222e636e8a8409c30ddb1fe6e3fe72ab7a43f2edf089b2758d5e9bee528" } }, { @@ -1279,13 +1272,12 @@ "attributes": { "text": "Extends a 3-digit color code to a 6-digit color code.\n\nUse `Array.prototype.map()`, `String.prototype.split()` and `Array.prototype.join()` to join the mapped array for converting a 3-digit RGB notated hexadecimal color-code to the 6-digit form.\n`Array.prototype.slice()` is used to remove `#` from string start since it's added once.\n\n", "tags": [ - "utility", "string", "intermediate" ] }, "meta": { - "hash": "34df599e00a3541dfecf1c0780514006d8d6cadfe28905ead9e782cc3903902c" + "hash": "6435af35454a85174aee2740e4a628f47b7fd5efbb73ca11044c78ac5340fc19" } }, { @@ -1301,7 +1293,7 @@ ] }, "meta": { - "hash": "6e9710c9117f500e74e65c0ee36b39fb80bd55537fa5ff9c4b1136b2667096f2" + "hash": "0eac852db7a7add352b0d36677b22718b342ed9dc12f11780cac87e3b8260a05" } }, { @@ -1501,12 +1493,11 @@ "date", "math", "string", - "utility", "intermediate" ] }, "meta": { - "hash": "176cd07a9486286924a7393fe631e83471e7123e3b6349309a7c1cee7746d764" + "hash": "b69c2666e5ce5a98b4c91b7efcbd715209381716d9f274e42f1b8b333ae3fb3f" } }, { @@ -1593,12 +1584,11 @@ "text": "Logs the name of a function.\n\nUse `console.debug()` and the `name` property of the passed method to log the method's name to the `debug` channel of the console.\n\n", "tags": [ "function", - "utility", "beginner" ] }, "meta": { - "hash": "9f8947652b9c2faba5f1bda82f992bdc81a71c67374fcc843e96ce2a327a28db" + "hash": "4919ad66b88f64d19d2bb661db604ccfd7544d2265ac0d8708a06204746e4439" } }, { @@ -1720,7 +1710,7 @@ ] }, "meta": { - "hash": "f9e6687cc28cd80e68f7a6776f893c7478aaa942710e0eb7144f105eba574a54" + "hash": "9e39c6a3a8ec5b51c5e16f69107fc9e90b2697b2cf2689850872071bb968723e" } }, { @@ -1776,7 +1766,6 @@ "attributes": { "text": "Returns an object containing the parameters of the current URL.\n\nUse `String.match()` with an appropriate regular expression to get all key-value pairs, `Array.prototype.reduce()` to map and combine them into a single object.\nPass `location.search` as the argument to apply to the current `url`.\n\n", "tags": [ - "utility", "browser", "string", "url", @@ -1784,7 +1773,7 @@ ] }, "meta": { - "hash": "460d0f75a526126cabbc1a0b7b727b78999332bec7876959519c187cd8db96db" + "hash": "6478f1648c76af5261784e25b95f1d344ecad8ff7886f049cd1c5c184fbf8444" } }, { @@ -1858,13 +1847,12 @@ "text": "Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.\n\nUse the [SubtleCrypto](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) API to create a hash for the given value.\n\n", "tags": [ "browser", - "utility", "advanced", "promise" ] }, "meta": { - "hash": "beb6f68f5a8b63fd90a671758556aa72b5c061b681df049779cdf5631837966c" + "hash": "2a9b9f2743606d247f1074840edcabadb880c2c79f4e6deb3f2982bca2fe3307" } }, { @@ -1875,13 +1863,12 @@ "text": "Creates a hash for a value using the [SHA-256](https://en.wikipedia.org/wiki/SHA-2) algorithm. Returns a promise.\n\nUse `crypto` API to create a hash for the given value, `setTimeout` to prevent blocking on a long operation, and a `Promise` to give it a familiar interface.\n\n", "tags": [ "node", - "utility", "promise", "intermediate" ] }, "meta": { - "hash": "e7b6164cfaacf4869f997747df3e135a1ec4342abf5a56498586513332272a96" + "hash": "66caf1183c70728fa7e9dd6256fc46cc49b3699decbaea8ec1269a2eec07992f" } }, { @@ -1936,14 +1923,13 @@ "attributes": { "text": "Converts a color code to a `rgb()` or `rgba()` string if alpha value is provided.\n\nUse bitwise right-shift operator and mask bits with `&` (and) operator to convert a hexadecimal color code (with or without prefixed with `#`) to a string with the RGB values. If it's 3-digit color code, first convert to 6-digit version. If an alpha value is provided alongside 6-digit hex, give `rgba()` string in return.\n\n", "tags": [ - "utility", "string", "math", "advanced" ] }, "meta": { - "hash": "f61b08541372ded95a947cc570f57f7bbc9c7908ede569d59f294c5b9ef6feb1" + "hash": "b373e046d50f40ac11b6a538668cdcba6342afe7f92701a36ffe156a6e572edd" } }, { @@ -1969,9 +1955,8 @@ "attributes": { "text": "Makes a `DELETE` request to the passed URL.\n\nUse `XMLHttpRequest` web api to make a `delete` request to the given `url`.\nHandle the `onload` event, by running the provided `callback` function.\nHandle the `onerror` event, by running the provided `err` function.\nOmit the third argument, `err` to log the request to the console's error stream by default.\n\n", "tags": [ - "utility", - "url", "browser", + "url", "intermediate" ] }, @@ -1986,14 +1971,13 @@ "attributes": { "text": "Makes a `GET` request to the passed URL.\n\nUse [`XMLHttpRequest`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest) web api to make a `get` request to the given `url`.\nHandle the `onload` event, by calling the given `callback` the `responseText`.\nHandle the `onerror` event, by running the provided `err` function.\nOmit the third argument, `err`, to log errors to the console's `error` stream by default.\n\n", "tags": [ - "utility", - "url", "browser", + "url", "intermediate" ] }, "meta": { - "hash": "c138c0e5f16d48997691a98de7c0bc43b228a0b4285f0ab2b26d230e209d1530" + "hash": "4c412ce4ed5d0573b7a87c273e07aa200c0151a564d41f828e6601202ea06416" } }, { @@ -2003,14 +1987,13 @@ "attributes": { "text": "Makes a `POST` request to the passed URL.\n\nUse [`XMLHttpRequest`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest) web api to make a `post` request to the given `url`.\nSet the value of an `HTTP` request header with `setRequestHeader` method.\nHandle the `onload` event, by calling the given `callback` the `responseText`.\nHandle the `onerror` event, by running the provided `err` function.\nOmit the third argument, `data`, to send no data to the provided `url`.\nOmit the fourth argument, `err`, to log errors to the console's `error` stream by default.\n\n", "tags": [ - "utility", - "url", "browser", + "url", "intermediate" ] }, "meta": { - "hash": "5b29941074f19769531b3320ec8d61e2b2bdc69735fb781bf7e880ff2080ec04" + "hash": "d842ebdfd968b1dfdd8a8aaa0d27e69608c4c02078b180c8439da72bfa558ec1" } }, { @@ -2020,9 +2003,8 @@ "attributes": { "text": "Makes a `PUT` request to the passed URL.\n\nUse `XMLHttpRequest` web api to make a `put` request to the given `url`.\nSet the value of an `HTTP` request header with `setRequestHeader` method.\nHandle the `onload` event, by running the provided `callback` function.\nHandle the `onerror` event, by running the provided `err` function.\nOmit the last argument, `err` to log the request to the console's error stream by default.\n\n", "tags": [ - "utility", - "url", "browser", + "url", "intermediate" ] }, @@ -2099,12 +2081,11 @@ "text": "Indents each line in the provided string.\n\nUse `String.replace` and a regular expression to add the character specified by `indent` `count` times at the start of each line.\nOmit the third parameter, `indent`, to use a default indentation character of `' '`.\n\n", "tags": [ "string", - "utility", "beginner" ] }, "meta": { - "hash": "544ebe19f71cab5f4b4ad5a6121d4327ebf2b09f04451151e7339c90c8924789" + "hash": "e744d3d9c040feecdd17afc470078ea47047250ed521e138936d1434eba7898a" } }, { @@ -2350,14 +2331,13 @@ "text": "Returns `true` if the given string is an absolute URL, `false` otherwise.\n\nUse a regular expression to test if the string is an absolute URL.\n\n", "tags": [ "string", - "utility", "browser", "url", "intermediate" ] }, "meta": { - "hash": "7523c5d3ab85075efa61efc135bb1c8d85e2a2e5407ddc5768099993d46f13b5" + "hash": "71c32c111d21f3ed9c1af2c7216b6f81e8ab652b353ab3f938418738c2a00ac7" } }, { @@ -2368,12 +2348,11 @@ "text": "Check if a date is after another date.\n\nUse the greater than operator (`>`) to check if the first date comes after the second one.\n\n", "tags": [ "date", - "utility", "beginner" ] }, "meta": { - "hash": "19efe22718bca00459c41fa9df56c3574270c500bdd670873358052ccc870f5b" + "hash": "6e1abb3cac28b9ccf95e55db3daec18aeff50735be56cce96ffb326ff99f7669" } }, { @@ -2416,12 +2395,11 @@ "text": "Check if a date is before another date.\n\nUse the less than operator (`<`) to check if the first date comes before the second one.\n\n", "tags": [ "date", - "utility", "beginner" ] }, "meta": { - "hash": "e0d70480b239a585f907c965214a037ce23ae15f5484ab80930ea9f57cbe529e" + "hash": "3c6950661df4657fc49636fc97050e5a46a9337caaae3f5dd584d3aaf436b451" } }, { @@ -2446,13 +2424,12 @@ "attributes": { "text": "Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors.\n\nUse `Array.prototype.includes()` on the `typeof` values of both `window` and `document` (globals usually only available in a browser environment unless they were explicitly defined), which will return `true` if one of them is `undefined`.\n`typeof` allows globals to be checked for existence without throwing a `ReferenceError`.\nIf both of them are not `undefined`, then the current environment is assumed to be a browser.\n\n", "tags": [ - "utility", "browser", "intermediate" ] }, "meta": { - "hash": "6fb24837c043a0cc320a46695ef0e286a558aaf06e9354407569ae61c4a8d0bd" + "hash": "8aa110b4d9adf4e44eb0b770309dacb3b372268143223e862749519e6a896f1c" } }, { @@ -2588,12 +2565,11 @@ "text": "Checks if a string is lower case.\n\nConvert the given string to lower case, using `String.toLowerCase()` and compare it to the original.\n\n", "tags": [ "string", - "utility", "beginner" ] }, "meta": { - "hash": "e47bc176d868f3aab83f762997bf9d355258607594648573d2482faf7fc08826" + "hash": "a665c8ada73822926f03aa49bf65551ce20459dc4466ce5d5306690d53e04285" } }, { @@ -2604,12 +2580,11 @@ "text": "Checks if the given value is equal to negative zero (`-0`).\n\nChecks whether a passed value is equal to `0` and if `1` divided by the value equals `-Infinity`.\n\n", "tags": [ "math", - "utility", "beginner" ] }, "meta": { - "hash": "ec55fd2848f1443613e33d59634ecaefc9dc82b721424b5416830a7389e1ce6e" + "hash": "c8af31822c3b74d0e3e3099ff770aa467825ecd8edc3e6fb07f84a5af9d615af" } }, { @@ -2811,12 +2786,11 @@ "text": "Check if a date is the same as another date.\n\nUse `Date.prototype.toISOString()` and strict equality checking (`===`) to check if the first date is the same as the second one.\n\n", "tags": [ "date", - "utility", "beginner" ] }, "meta": { - "hash": "4accb95c8fb5ac770c73c78b6236938773499c74617df09a1f73a60abd6f44d7" + "hash": "f2cef555daea23fb46e93ad5bd556840c55f343924578b26329983c0407d88d5" } }, { @@ -2919,7 +2893,6 @@ "text": "Checks if a string is upper case.\n\nConvert the given string to upper case, using `String.prototype.toUpperCase()` and compare it to the original.\n\n", "tags": [ "string", - "utility", "beginner" ] }, @@ -3001,7 +2974,7 @@ ] }, "meta": { - "hash": "3db3faac666ee61ab86c70766d2ab5d1293ffd818da87edb971bfff7a366364a" + "hash": "362fddaa6244404741e84bca6fc442a101fdb642af53b299e8b9994d0d7162d8" } }, { @@ -3077,12 +3050,11 @@ "tags": [ "array", "string", - "utility", "intermediate" ] }, "meta": { - "hash": "1277ce52444adcbc3a7b62d5c9019aa3cf01293e7749b8d0e1871ae2aa6a8c88" + "hash": "bc43866db3708c27d333faa8a71f9075af24899a7785496ca28206061d4910d1" } }, { @@ -3108,12 +3080,11 @@ "text": "Implementation of the [Luhn Algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm) used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers etc.\n\nUse `String.prototype.split('')`, `Array.prototype.reverse()` and `Array.prototype.map()` in combination with `parseInt()` to obtain an array of digits.\nUse `Array.prototype.splice(0,1)` to obtain the last digit.\nUse `Array.prototype.reduce()` to implement the Luhn Algorithm.\nReturn `true` if `sum` is divisible by `10`, `false` otherwise.\n\n", "tags": [ "math", - "utility", "advanced" ] }, "meta": { - "hash": "ab83bac8546d02dfe4227792750f0b4c64cd2c8f8ce6063eef2a3f4357210d63" + "hash": "d7c1a6ff15bf0d8f33dddfcebe892089a7902a94fc18803fafd5fe76ebdd3ffc" } }, { @@ -3173,12 +3144,11 @@ "string", "array", "function", - "utility", "beginner" ] }, "meta": { - "hash": "c4df98d941aeadd165c6a02143d79f7a9bf013f8c221f709aa545bf83495a956" + "hash": "ef9621c9cc38b1f4ab76ed4246de33ef9125bfa44f4ecc8113e7890d99b61a01" } }, { @@ -3205,7 +3175,6 @@ "text": "Replaces all but the last `num` of characters with the specified mask character.\n\nUse `String.prototype.slice()` to grab the portion of the characters that will remain unmasked and use `String.padStart()` to fill the beginning of the string with the mask character up to the original length.\nOmit the second argument, `num`, to keep a default of `4` characters unmasked. If `num` is negative, the unmasked characters will be at the start of the string.\nOmit the third argument, `mask`, to use a default character of `'*'` for the mask.\n\n", "tags": [ "string", - "utility", "intermediate" ] }, @@ -3429,12 +3398,12 @@ "attributes": { "text": "Returns the index of the function in an array of functions which executed the fastest.\n\nUse `Array.prototype.map()` to generate an array where each value is the total time taken to execute the function after `iterations` times. Use the difference in `performance.now()` values before and after to get the total time in milliseconds to a high degree of accuracy.\nUse `Math.min()` to find the minimum execution time, and return the index of that shortest time which corresponds to the index of the most performant function.\nOmit the second argument, `iterations`, to use a default of 10,000 iterations. The more iterations, the more reliable the result but the longer it will take.\n\n", "tags": [ - "utility", - "function" + "function", + "intermediate" ] }, "meta": { - "hash": "120e31fa38796906a99beccdc457e83a8075e6ec72b5a937e03913b2e996ae26" + "hash": "2334d95a86e23b04825a6b9f696d9866749f4d69e6c6003651cc69dccc71e98d" } }, { @@ -3506,13 +3475,12 @@ "attributes": { "text": "Creates a function that gets the argument at index `n`. If `n` is negative, the nth argument from the end is returned.\n\nUse `Array.prototype.slice()` to get the desired argument at index `n`.\n\n", "tags": [ - "utility", "function", "beginner" ] }, "meta": { - "hash": "1885078f5fddc5de00844a837ab3c427f770c5325a70d5362ecab26c1c904125" + "hash": "837bf47e8e264266d22fc1d8186b6b5561a94500a1b725ce897ffbd6e0df1b98" } }, { @@ -3585,14 +3553,13 @@ "attributes": { "text": "Returns a query string generated from the key-value pairs of the given object.\n\nUse `Array.prototype.reduce()` on `Object.entries(queryParameters)` to create the query string.\nDetermine the `symbol` to be either `?` or `&` based on the `length` of `queryString` and concatenate `val` to `queryString` only if it's a string.\nReturn the `queryString` or an empty string when the `queryParameters` are falsy.\n\n", "tags": [ - "utility", "object", "function", "intermediate" ] }, "meta": { - "hash": "e8f820ce6da97eabde082ffb829c9fb700e85efc79bdebe883c67237269e3f52" + "hash": "b031c3387ef66411ab5d295788eac4247ada5b4b068dda90603d3c973890bc26" } }, { @@ -3805,13 +3772,13 @@ "attributes": { "text": "Parse an HTTP Cookie header string and return an object of all cookie name-value pairs.\n\nUse `String.prototype.split(';')` to separate key-value pairs from each other.\nUse `Array.prototype.map()` and `String.prototype.split('=')` to separate keys from values in each pair.\nUse `Array.prototype.reduce()` and `decodeURIComponent()` to create an object with all key-value pairs.\n\n", "tags": [ - "utility", + "browser", "string", "intermediate" ] }, "meta": { - "hash": "c25aef075df93042a81bd98ebd7b77aefb91df3f08b9f1d2e7859ec0d95ad55b" + "hash": "5bcee736e351fb23173369a678122d12b4278a02ab3204cfee2b3b0d3c598544" } }, { @@ -3938,7 +3905,7 @@ ] }, "meta": { - "hash": "a2b9ac4f1209c3791caa6f40f0d041acd75514e9ee8909f2e3833635f357c0bd" + "hash": "0eb844801e767edcaa6a882a6dce4b5b1dadecb53a92d6ec259d36c57b6a3dd0" } }, { @@ -3994,12 +3961,11 @@ "text": "Returns the prefixed version (if necessary) of a CSS property that the browser supports.\n\nUse `Array.prototype.findIndex()` on an array of vendor prefix strings to test if `document.body` has one of them defined in its `CSSStyleDeclaration` object, otherwise return `null`.\nUse `String.prototype.charAt()` and `String.prototype.toUpperCase()` to capitalize the property, which will be appended to the vendor prefix string.\n\n", "tags": [ "browser", - "utility", "intermediate" ] }, "meta": { - "hash": "6668f37f9f1158b2bdd292ad64defea6e33a0b2908ea1e494b191dcaa9f039d6" + "hash": "942f8061fb78b9a96dc0da7e249bb8d5c1b2902f9101d6dbdae272c95a49ab92" } }, { @@ -4009,14 +3975,13 @@ "attributes": { "text": "Converts a number in bytes to a human-readable string.\n\nUse an array dictionary of units to be accessed based on the exponent.\nUse `Number.toPrecision()` to truncate the number to a certain number of digits.\nReturn the prettified string by building it up, taking into account the supplied options and whether it is negative or not.\nOmit the second argument, `precision`, to use a default precision of `3` digits.\nOmit the third argument, `addSpace`, to add space between the number and unit by default.\n\n", "tags": [ - "utility", "string", "math", "advanced" ] }, "meta": { - "hash": "e752de4a4f2b339851e796a5289e7adde51cf7e672b8230fd97bf79cf7330758" + "hash": "7053095cc3085b11fde252bfec58b3888290d30936fe7cd7b570cd075d29225a" } }, { @@ -4132,15 +4097,15 @@ "type": "snippetListing", "title": "randomHexColorCode", "attributes": { - "text": "Generates a random hexadecimal color code.\n\nUse `Math.random` to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using `toString(16)`.\n\n", + "text": "Generates a random hexadecimal color code.\n\nUse `Math.random` to generate a random 24-bit(6x4bits) hexadecimal number.\nUse bit shifting and then convert it to an hexadecimal String using `toString(16)`.\n\n", "tags": [ - "utility", + "math", "random", "beginner" ] }, "meta": { - "hash": "42788f8392f5511db3641dbe2ab92b2c043b3b5209e95c386c73e5d96eaa63af" + "hash": "4af37a3a8c080de92657476319fc3a6d4ff7febfe34f8391b81d97336bb147d6" } }, { @@ -4151,13 +4116,12 @@ "text": "Returns an array of n random integers in the specified range.\n\nUse `Array.from()` to create an empty array of the specific length, `Math.random()` to generate a random number and map it to the desired range, using `Math.floor()` to make it an integer.\n\n", "tags": [ "math", - "utility", "random", "intermediate" ] }, "meta": { - "hash": "7bff02cd849d994da1229f3153cca71b4c054d6774ab732101a5f60a0a04ba3a" + "hash": "6887efc77e1a29d40b7194fe16a2005b8f33f15bb92ee3f0329b55be27f21225" } }, { @@ -4168,13 +4132,12 @@ "text": "Returns a random integer in the specified range.\n\nUse `Math.random()` to generate a random number and map it to the desired range, using `Math.floor()` to make it an integer.\n\n", "tags": [ "math", - "utility", "random", "beginner" ] }, "meta": { - "hash": "8d8cca3d593e677c8a4ffc17e9f97b3018f800e7c014daa3462edc152fbbeec7" + "hash": "939080b53f5ebf57e2fcb7b88cc827902a3d01c428eed9e989dd2545c3717b6f" } }, { @@ -4185,13 +4148,12 @@ "text": "Returns a random number in the specified range.\n\nUse `Math.random()` to generate a random value, map it to the desired range using multiplication.\n\n", "tags": [ "math", - "utility", "random", "beginner" ] }, "meta": { - "hash": "c86e3227e32565afb301805798da3a46756e13bff0115b880fcc3175a58d95af" + "hash": "209c6f231e06e1840d46fd6f836961f9dfc8c954e6675a230863eb0824a35c7c" } }, { @@ -4231,15 +4193,14 @@ "type": "snippetListing", "title": "recordAnimationFrames", "attributes": { - "text": "Invokes the provided callback on each animation frame.\n\nUse recursion. \nProvided that `running` is `true`, continue invoking `window.requestAnimationFrame()` which invokes the provided callback. \nReturn an object with two methods `start` and `stop` to allow manual control of the recording. \nOmit the second argument, `autoStart`, to implicitly call `start` when the function is invoked.\n\n", + "text": "Invokes the provided callback on each animation frame.\n\nUse recursion.\nProvided that `running` is `true`, continue invoking `window.requestAnimationFrame()` which invokes the provided callback.\nReturn an object with two methods `start` and `stop` to allow manual control of the recording.\nOmit the second argument, `autoStart`, to implicitly call `start` when the function is invoked.\n\n", "tags": [ "browser", - "utility", "intermediate" ] }, "meta": { - "hash": "b780a5af9c22faa9601191aff53c24d55f5e88b62ac79fd2e02517f9a724b502" + "hash": "f734a70077b4723415eae15573378f1596b6b8810831d8784e730771fdba0bfa" } }, { @@ -4332,7 +4293,7 @@ ] }, "meta": { - "hash": "ffb9c0d1d09aeb989789286efb91cc237b89ce13f44ad9510a014f9ab150df71" + "hash": "be8ec39c092128ba679a3f0421b6abc34ad891dec85354caa419dc4104687a05" } }, { @@ -4389,12 +4350,13 @@ "attributes": { "text": "Converts the values of RGB components to a color code.\n\nConvert given RGB parameters to hexadecimal string using bitwise left-shift operator (`<<`) and `toString(16)`, then `String.padStart(6,'0')` to get a 6-digit hexadecimal value.\n\n", "tags": [ - "utility", + "string", + "math", "intermediate" ] }, "meta": { - "hash": "592446fabae44d631396de3441738710626c4d274eaabe3dfdb9b822ce3a5179" + "hash": "85235b8cc5276d21a4f2659a8e04c65dd1b3cab52d1ff700750253dc11b5b5be" } }, { @@ -4501,12 +4463,11 @@ "text": "Hashes the input string into a whole number.\n\nUse `String.prototype.split('')` and `Array.prototype.reduce()` to create a hash of the input string, utilizing bit shifting.\n\n", "tags": [ "math", - "utility", "intermediate" ] }, "meta": { - "hash": "58d91b4760b4af29df95cf1b073166c02660f9af3d46c950fba64b922c999ba1" + "hash": "957622c5cf0b59acacea276978fcf66cef1bdc6f5cc16dde77eda3bc8c3686c8" } }, { @@ -4516,13 +4477,13 @@ "attributes": { "text": "Serialize a cookie name-value pair into a Set-Cookie header string.\n\nUse template literals and `encodeURIComponent()` to create the appropriate string.\n\n", "tags": [ - "utility", + "browser", "string", "intermediate" ] }, "meta": { - "hash": "defdaa306864196a4f561c37c4c7f74ffc159406c4538a0f7e1f3f153840eebe" + "hash": "740ef7d2635d22c19eca6fdce566d679ddfeb5f2a3c382665efe205c2cb1001b" } }, { @@ -4648,7 +4609,7 @@ ] }, "meta": { - "hash": "6dd4c6a51d2c80fa4768c95ae01c16a8359c4140bcad28c7fde0cecd72d7d3e2" + "hash": "24b93b68a59b49f245590930fed6fb82e286ce09f90e292466cde63c1784c347" } }, { @@ -4851,13 +4812,12 @@ "text": "Removes HTML/XML tags from string.\n\nUse a regular expression to remove HTML/XML tags from a string.\n\n", "tags": [ "string", - "utility", "regexp", "beginner" ] }, "meta": { - "hash": "a33dbe87821f5017cf4238c69d9effcfe993698f055fec5e915f4fff68c01e34" + "hash": "5d500a11b098ee757fd6803e199a191c529e4070d47e0d576a6f290d0b6c3d14" } }, { @@ -5070,12 +5030,12 @@ "attributes": { "text": "Measures the time taken by a function to execute.\n\nUse `console.time()` and `console.timeEnd()` to measure the difference between the start and end times to determine how long the callback took to execute.\n\n", "tags": [ - "utility", + "function", "beginner" ] }, "meta": { - "hash": "26246364ba1e8e3f52a51c8e1f329af721b05a5d307ed88bf31ccd2620c0deee" + "hash": "8017947366418af3f9991be27f5f622bee0b1cb97f54b46395455800fa015139" } }, { @@ -5101,12 +5061,13 @@ "attributes": { "text": "Take a number and return specified currency formatting.\n\nUse `Intl.NumberFormat` to enable country / currency sensitive formatting.\n\n", "tags": [ - "utility", + "math", + "string", "intermediate" ] }, "meta": { - "hash": "2f817f7dc3ca24a50bfaa1a59dec3ec6d8ee3392ac2d7f3ecae3a93a9c96f09c" + "hash": "41156e65825b59559469feca57214c9f802cb42fba5a16f5fb5990033a2f7059" } }, { @@ -5116,7 +5077,6 @@ "attributes": { "text": "Converts a number to a decimal mark formatted string.\n\nUse `Number.prototype.toLocaleString()` to convert the numbre to decimal mark format.\n\n", "tags": [ - "utility", "math", "beginner" ] @@ -5193,13 +5153,12 @@ "attributes": { "text": "Adds an ordinal suffix to a number.\n\nUse the modulo operator (`%`) to find values of single and tens digits.\nFind which ordinal pattern digits match.\nIf digit is found in teens pattern, use teens ordinal.\n\n", "tags": [ - "utility", "math", "intermediate" ] }, "meta": { - "hash": "0ebd3351685fd96bf678c2baa38fabc9aa18bd6a3fa6674ea0bae9663424ea5f" + "hash": "b9a61d3a7c80d3140aa3cbfea42f8af1ed15cc47bc8d224685c0d9127e74813c" } }, { @@ -5572,13 +5531,12 @@ "text": "Joins all given URL segments together, then normalizes the resulting URL.\n\nUse `String.prototype.join('/')` to combine URL segments, then a series of `String.prototype.replace()` calls with various regexps to normalize the resulting URL (remove double slashes, add proper slashes for protocol, remove slashes before parameters, combine parameters with `'&'` and normalize first parameter delimiter).\n\n", "tags": [ "string", - "utility", "regexp", "advanced" ] }, "meta": { - "hash": "6050cfa3a2a39089151bacfce1f5cedaec12f5da253dbc20a56dfaf50cb8924b" + "hash": "1de784a29009c7bf3e08cc95110316c4362125f603e862c29c07be50f54186d9" } }, { @@ -5589,13 +5547,12 @@ "text": "Generates a UUID in a browser.\n\nUse `crypto` API to generate a UUID, compliant with [RFC4122](https://www.ietf.org/rfc/rfc4122.txt) version 4.\n\n", "tags": [ "browser", - "utility", "random", "intermediate" ] }, "meta": { - "hash": "9f84a12da85558ebdb189097dbc581b338e07d52eedc5975f1001133b123aad2" + "hash": "24c28431e9eb84a8a0f8e38370c3635ea9b68482c7a894895fd8ef09c1eb02aa" } }, { @@ -5606,13 +5563,12 @@ "text": "Generates a UUID in Node.JS.\n\nUse `crypto` API to generate a UUID, compliant with [RFC4122](https://www.ietf.org/rfc/rfc4122.txt) version 4.\n\n", "tags": [ "node", - "utility", "random", "intermediate" ] }, "meta": { - "hash": "79604b0f854a91af789fea8416c7099acfb3633259ef387f52a21337d2242478" + "hash": "2322d2d42be4e3037ec6d4e707358bd114f1378cd64dee48e9a0cb8c918efa3f" } }, { @@ -5622,13 +5578,12 @@ "attributes": { "text": "Returns `true` if the given value is a number, `false` otherwise.\n\nUse `!isNaN()` in combination with `parseFloat()` to check if the argument is a number.\nUse `isFinite()` to check if the number is finite.\nUse `Number()` to check if the coercion holds.\n\n", "tags": [ - "utility", "math", "intermediate" ] }, "meta": { - "hash": "73fc55564fa0b59a71553aa442bda666cbcddbcd618f9ca53c2b55e42a7c26ca" + "hash": "dffaec8a8f2b3c66e709b2e9ee0a57082be53305f000db3d75983ae103866607" } }, { @@ -5731,13 +5686,13 @@ "attributes": { "text": "Returns `true` if the string is `y`/`yes` or `false` if the string is `n`/`no`.\n\nUse `RegExp.test()` to check if the string evaluates to `y/yes` or `n/no`.\nOmit the second argument, `def` to set the default answer as `no`.\n\n", "tags": [ - "utility", + "string", "regexp", "intermediate" ] }, "meta": { - "hash": "6365f144def8abb711b890f8689ff8c9f1f1aee092525583fa913057ba623472" + "hash": "8b858ab37c0cd7f7a09f54810b9f435037922cdbf7c4dd659899790476152479" } }, { diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json index 4782141d7..073b73ea3 100644 --- a/snippet_data/snippets.json +++ b/snippet_data/snippets.json @@ -118,15 +118,14 @@ "tags": [ "array", "string", - "utility", "intermediate" ] }, "meta": { - "hash": "aeabb3d1d2be2d44fd8a20da3b069fdd1a8ad963f27e3e1ae9f5e8b40a8908cb", + "hash": "e5c607cd29800661ad8ea0506afaa42cd3f3936f835714939ceba49a5bd95638", "firstSeen": "1530120403", - "lastUpdated": "1565681352", - "updateCount": 11, + "lastUpdated": "1587067653", + "updateCount": 12, "authorCount": 5 } }, @@ -196,15 +195,14 @@ "tags": [ "node", "string", - "utility", "beginner" ] }, "meta": { - "hash": "32988360d63d6d62251314a88d3f4482ec3a265d67154a92a86d4140bd61c54b", + "hash": "6b8f586d9f697e08949128ec6774022484444daa8575c45a28fb1f9c8ba2c2bc", "firstSeen": "1516218201", - "lastUpdated": "1565681352", - "updateCount": 4, + "lastUpdated": "1587067653", + "updateCount": 5, "authorCount": 3 } }, @@ -480,15 +478,14 @@ "tags": [ "node", "string", - "utility", "beginner" ] }, "meta": { - "hash": "1c7836009987b8b1097b54a84c38144f6cb643477f08f00b1a37e274cf0c9f78", + "hash": "afb23f750b1460a89dca8424056fa581a7befd6e4f8b369ac2e93d50c94d9749", "firstSeen": "1516218201", - "lastUpdated": "1565681352", - "updateCount": 5, + "lastUpdated": "1587067653", + "updateCount": 6, "authorCount": 3 } }, @@ -607,17 +604,16 @@ "example": "castArray('foo'); // ['foo']\ncastArray([1]); // [1]" }, "tags": [ - "utility", - "array", "type", + "array", "beginner" ] }, "meta": { - "hash": "307add91ea4d5c2a122256f799120f580ac235567523dddeeadd6500f1e81e94", + "hash": "2f0d1b37cbcc8d6646fda98864848a41cb6ecaec02f7a0ba52bb45c87a210441", "firstSeen": "1516733652", - "lastUpdated": "1565681352", - "updateCount": 5, + "lastUpdated": "1587067653", + "updateCount": 6, "authorCount": 4 } }, @@ -686,15 +682,14 @@ "tags": [ "function", "object", - "utility", "beginner" ] }, "meta": { "hash": "52eca7b91d4205abe619c672895a773fc7ed7c2e151fd37e83ceda54ee74ad71", "firstSeen": "1552787580", - "lastUpdated": "1577784150", - "updateCount": 77, + "lastUpdated": "1587067653", + "updateCount": 78, "authorCount": 7 } }, @@ -761,16 +756,17 @@ "example": "const regExp = /lorem ipsum/gi;\nconst regExp2 = cloneRegExp(regExp); // /lorem ipsum/gi" }, "tags": [ - "utility", + "type", + "string", "regexp", "intermediate" ] }, "meta": { - "hash": "3b7e9a506c229c792da093336574e3524cd1a8c794d18fc450f469f171ff83cf", + "hash": "8a748ad892a46df9ff2a5e64aba3b9a35fbd9a0d0351c21e2c2bf1d40a39c046", "firstSeen": "1514828747", - "lastUpdated": "1565681352", - "updateCount": 3, + "lastUpdated": "1587067653", + "updateCount": 4, "authorCount": 2 } }, @@ -787,15 +783,15 @@ "example": "coalesce(null, undefined, '', NaN, 'Waldo'); // ''" }, "tags": [ - "utility", + "type", "beginner" ] }, "meta": { "hash": "7c0db11447039e7d9bce2ed420ca1f69671b25928d272596587192a84aa78e31", "firstSeen": "1513498135", - "lastUpdated": "1583442418", - "updateCount": 11, + "lastUpdated": "1587067653", + "updateCount": 12, "authorCount": 6 } }, @@ -812,15 +808,15 @@ "example": "const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_));\ncustomCoalesce(undefined, null, NaN, '', 'Waldo'); // \"Waldo\"" }, "tags": [ - "utility", + "type", "intermediate" ] }, "meta": { - "hash": "b85ec57d815ff34ba3906195440fce5d2ad9f33b64d7d96159c0e1125fee283c", + "hash": "26bbe0fe97b8a037808ae4b7310e54cd3a31f6a0f0a0d9c6a2ae733046501132", "firstSeen": "1513592136", - "lastUpdated": "1565681352", - "updateCount": 6, + "lastUpdated": "1587067653", + "updateCount": 7, "authorCount": 5 } }, @@ -864,16 +860,15 @@ }, "tags": [ "node", - "utility", "string", "intermediate" ] }, "meta": { - "hash": "1ce726b8cbc9f87ff8ff6d68e0678325523b1118fa038b97f53ddad9031dbe23", + "hash": "d33a3685273eb81bf2a224330007c5425f434c2292859bdfebbe1fbafd5da48c", "firstSeen": "1515843419", - "lastUpdated": "1565681352", - "updateCount": 4, + "lastUpdated": "1587067653", + "updateCount": 5, "authorCount": 3 } }, @@ -1162,7 +1157,7 @@ "type": "snippet", "attributes": { "fileName": "createElement.md", - "text": "Creates an element from a string (without appending it to the document). \nIf the given string contains multiple elements, only the first one will be returned.\n\nUse `document.createElement()` to create a new element.\nSet its `innerHTML` to the string supplied as the argument. \nUse `ParentNode.firstElementChild` to return the element version of the string.\n\n", + "text": "Creates an element from a string (without appending it to the document).\nIf the given string contains multiple elements, only the first one will be returned.\n\nUse `document.createElement()` to create a new element.\nSet its `innerHTML` to the string supplied as the argument.\nUse `ParentNode.firstElementChild` to return the element version of the string.\n\n", "codeBlocks": { "es6": "const createElement = str => {\n const el = document.createElement('div');\n el.innerHTML = str;\n return el.firstElementChild;\n};", "es5": "var createElement = function createElement(str) {\n var el = document.createElement('div');\n el.innerHTML = str;\n return el.firstElementChild;\n};", @@ -1170,15 +1165,14 @@ }, "tags": [ "browser", - "utility", "beginner" ] }, "meta": { - "hash": "d162fbc50166f304216db6ea700e5fc7f428ea33d50b204ae921e1c58552a4e0", + "hash": "de8ab0037be4b5d74805237ea414516a1ca227fa2b693b01190bd50f01d362bb", "firstSeen": "1515169304", - "lastUpdated": "1565681352", - "updateCount": 5, + "lastUpdated": "1587067653", + "updateCount": 6, "authorCount": 3 } }, @@ -1223,15 +1217,14 @@ "tags": [ "string", "array", - "utility", "intermediate" ] }, "meta": { - "hash": "3169ab83e588063262fa6a01f7d7df7bd9521345c65a7c7f874f577478c90305", + "hash": "e53a8dfbb2ab55c1678e462164268773fbc3876ce9cd8326fb44428694fb9f72", "firstSeen": "1530122274", - "lastUpdated": "1565681352", - "updateCount": 5, + "lastUpdated": "1587067653", + "updateCount": 6, "authorCount": 4 } }, @@ -1398,7 +1391,7 @@ "fileName": "deepClone.md", "text": "Creates a deep clone of an object.\n\nUse recursion.\nCheck if the passed object is `null` and, if so, return `null`.\nUse `Object.assign()` and an empty object (`{}`) to create a shallow clone of the original.\nUse `Object.keys()` and `Array.prototype.forEach()` to determine which key-value pairs need to be deep cloned.\n\n", "codeBlocks": { - "es6": "const deepClone = obj => {\n if (obj === null) return null;\n let clone = Object.assign({}, obj);\n Object.keys(clone).forEach(\n key => (clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[key])\n );\n return Array.isArray(obj) && obj.length\n ? (clone.length = obj.length) && Array.from(clone)\n : Array.isArray(obj)\n ? Array.from(obj)\n : clone;\n};", + "es6": "const deepClone = obj => {\n if (obj === null) return null;\n let clone = Object.assign({}, obj);\n Object.keys(clone).forEach(\n key => (clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[key])\n );\n return Array.isArray(obj) && obj.length\n ? (clone.length = obj.length) && Array.from(clone)\n : Array.isArray(obj)\n ? Array.from(obj)\n : clone;\n};", "es5": "function _typeof(obj) { \"@babel/helpers - typeof\"; 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 deepClone = function deepClone(obj) {\n if (obj === null) return null;\n var clone = Object.assign({}, obj);\n Object.keys(clone).forEach(function (key) {\n return clone[key] = _typeof(obj[key]) === 'object' ? deepClone(obj[key]) : obj[key];\n });\n return Array.isArray(obj) && obj.length ? (clone.length = obj.length) && Array.from(clone) : Array.isArray(obj) ? Array.from(obj) : clone;\n};", "example": "const a = { foo: 'bar', obj: { a: 1, b: 2 } };\nconst b = deepClone(a); // a !== b, a.obj !== b.obj" }, @@ -1409,7 +1402,7 @@ ] }, "meta": { - "hash": "77a01af8797ecbe71b9c9412d21c144c03a46a49dd3d0e7d869c3df38b39b2b4", + "hash": "0a4684d6fc79bdbbac31df3af6c493ba7c881936ada5bc52824b4f26ca177459", "firstSeen": "1516733326", "lastUpdated": "1587046062", "updateCount": 87, @@ -1501,7 +1494,7 @@ "fileName": "deepMapKeys.md", "text": "Deep maps an object's keys.\n\nCreates an object with the same values as the provided object and keys generated by running the provided function for each key.\nUse `Object.keys(obj)` to iterate over the object's keys. \nUse `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.\n\n", "codeBlocks": { - "es6": "const deepMapKeys = (obj, f) =>\n Array.isArray(obj)\n ? obj.map(val => deepMapKeys(val, f))\n : typeof obj === 'object'\n ? Object.keys(obj).reduce((acc, current) => {\n const val = obj[current];\n acc[f(current)] =\n val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);\n return acc;\n }, {})\n : obj;", + "es6": "const deepMapKeys = (obj, f) =>\n Array.isArray(obj)\n ? obj.map(val => deepMapKeys(val, f))\n : typeof obj === 'object'\n ? Object.keys(obj).reduce((acc, current) => {\n const val = obj[current];\n acc[f(current)] =\n val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);\n return acc;\n }, {})\n : obj;", "es5": "function _typeof(obj) { \"@babel/helpers - typeof\"; 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 deepMapKeys = function deepMapKeys(obj, f) {\n return Array.isArray(obj) ? obj.map(function (val) {\n return deepMapKeys(val, f);\n }) : _typeof(obj) === 'object' ? Object.keys(obj).reduce(function (acc, current) {\n var val = obj[current];\n acc[f(current)] = val !== null && _typeof(val) === 'object' ? deepMapKeys(val, f) : acc[f(current)] = val;\n return acc;\n }, {}) : obj;\n};", "example": "const obj = {\n foo: '1',\n nested: {\n child: {\n withArray: [\n {\n grandChild: ['hello']\n }\n ]\n }\n }\n};\nconst upperKeysObj = deepMapKeys(obj, key => key.toUpperCase());\n/*\n{\n \"FOO\":\"1\",\n \"NESTED\":{\n \"CHILD\":{\n \"WITHARRAY\":[\n {\n \"GRANDCHILD\":[ 'hello' ]\n }\n ]\n }\n }\n}\n*/" }, @@ -1512,7 +1505,7 @@ ] }, "meta": { - "hash": "6fa14364405f7b99aa49c2157bdc08c02b4ce2f288db29a4348a6983460933c7", + "hash": "a4e1e33c0688dbf1ca231d9d8ea315ffed93b7f83f5d8cbf0714f10fdfeda8cf", "firstSeen": "1544374334", "lastUpdated": "1587046062", "updateCount": 99, @@ -1730,7 +1723,7 @@ "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.\n\n", "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) { \"@babel/helpers - typeof\"; 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" }, @@ -1741,7 +1734,7 @@ ] }, "meta": { - "hash": "bdc202436bee09f06a353d31841c6cfff33e8efead34c6c56ae1a1413284976d", + "hash": "484bd222e636e8a8409c30ddb1fe6e3fe72ab7a43f2edf089b2758d5e9bee528", "firstSeen": "1531080384", "lastUpdated": "1587046062", "updateCount": 124, @@ -1999,8 +1992,8 @@ "meta": { "hash": "ff5ed6bd1f89525d1481499cd24fcb5f1f4d5f5e268d42caef3b23076fd5fd91", "firstSeen": "1516034051", - "lastUpdated": "1587067279", - "updateCount": 9, + "lastUpdated": "1587067469", + "updateCount": 10, "authorCount": 6 } }, @@ -2095,16 +2088,15 @@ "example": "extendHex('#03f'); // '#0033ff'\nextendHex('05a'); // '#0055aa'" }, "tags": [ - "utility", "string", "intermediate" ] }, "meta": { - "hash": "34df599e00a3541dfecf1c0780514006d8d6cadfe28905ead9e782cc3903902c", + "hash": "6435af35454a85174aee2740e4a628f47b7fd5efbb73ca11044c78ac5340fc19", "firstSeen": "1513526151", - "lastUpdated": "1565681352", - "updateCount": 12, + "lastUpdated": "1587067653", + "updateCount": 13, "authorCount": 7 } }, @@ -2116,7 +2108,7 @@ "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.\n\n", "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};", "example": "factorial(6); // 720" }, @@ -2127,7 +2119,7 @@ ] }, "meta": { - "hash": "6e9710c9117f500e74e65c0ee36b39fb80bd55537fa5ff9c4b1136b2667096f2", + "hash": "0eac852db7a7add352b0d36677b22718b342ed9dc12f11780cac87e3b8260a05", "firstSeen": "1512650493", "lastUpdated": "1587046062", "updateCount": 130, @@ -2457,15 +2449,14 @@ "date", "math", "string", - "utility", "intermediate" ] }, "meta": { - "hash": "176cd07a9486286924a7393fe631e83471e7123e3b6349309a7c1cee7746d764", + "hash": "b69c2666e5ce5a98b4c91b7efcbd715209381716d9f274e42f1b8b333ae3fb3f", "firstSeen": "1515050802", - "lastUpdated": "1565681352", - "updateCount": 9, + "lastUpdated": "1587067653", + "updateCount": 10, "authorCount": 6 } }, @@ -2609,15 +2600,14 @@ }, "tags": [ "function", - "utility", "beginner" ] }, "meta": { - "hash": "9f8947652b9c2faba5f1bda82f992bdc81a71c67374fcc843e96ce2a327a28db", + "hash": "4919ad66b88f64d19d2bb661db604ccfd7544d2265ac0d8708a06204746e4439", "firstSeen": "1513526151", - "lastUpdated": "1565681352", - "updateCount": 6, + "lastUpdated": "1587067653", + "updateCount": 7, "authorCount": 4 } }, @@ -2806,7 +2796,7 @@ "fileName": "getMeridiemSuffixOfInteger.md", "text": "Converts an integer to a suffixed string, adding `am` or `pm` based on its value.\n\nUse the modulo operator (`%`) and conditional checks to transform an integer to a stringified 12-hour format with meridiem suffix.\n\n", "codeBlocks": { - "es6": "const getMeridiemSuffixOfInteger = num =>\n num === 0 || num === 24\n ? 12 + 'am'\n : num === 12\n ? 12 + 'pm'\n : num < 12\n ? (num % 12) + 'am'\n : (num % 12) + 'pm';", + "es6": "const getMeridiemSuffixOfInteger = num =>\n num === 0 || num === 24\n ? 12 + 'am'\n : num === 12\n ? 12 + 'pm'\n : num < 12\n ? (num % 12) + 'am'\n : (num % 12) + 'pm';", "es5": "var getMeridiemSuffixOfInteger = function getMeridiemSuffixOfInteger(num) {\n return num === 0 || num === 24 ? 12 + 'am' : num === 12 ? 12 + 'pm' : num < 12 ? num % 12 + 'am' : num % 12 + 'pm';\n};", "example": "getMeridiemSuffixOfInteger(0); // \"12am\"\ngetMeridiemSuffixOfInteger(11); // \"11am\"\ngetMeridiemSuffixOfInteger(13); // \"1pm\"\ngetMeridiemSuffixOfInteger(25); // \"1pm\"" }, @@ -2816,7 +2806,7 @@ ] }, "meta": { - "hash": "f9e6687cc28cd80e68f7a6776f893c7478aaa942710e0eb7144f105eba574a54", + "hash": "9e39c6a3a8ec5b51c5e16f69107fc9e90b2697b2cf2689850872071bb968723e", "firstSeen": "1515856488", "lastUpdated": "1587046062", "updateCount": 89, @@ -2894,9 +2884,9 @@ "meta": { "hash": "0a1f42c4c267fe273f3452f80ed1fbdbe45bc47793f86077c5733146a7018e44", "firstSeen": "1513526151", - "lastUpdated": "1587067279", - "updateCount": 12, - "authorCount": 6 + "lastUpdated": "1587067469", + "updateCount": 13, + "authorCount": 7 } }, { @@ -2912,7 +2902,6 @@ "example": "getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'}\ngetURLParameters('google.com'); // {}" }, "tags": [ - "utility", "browser", "string", "url", @@ -2920,10 +2909,10 @@ ] }, "meta": { - "hash": "460d0f75a526126cabbc1a0b7b727b78999332bec7876959519c187cd8db96db", + "hash": "6478f1648c76af5261784e25b95f1d344ecad8ff7886f049cd1c5c184fbf8444", "firstSeen": "1513526151", - "lastUpdated": "1565681352", - "updateCount": 11, + "lastUpdated": "1587067653", + "updateCount": 12, "authorCount": 6 } }, @@ -3044,16 +3033,15 @@ }, "tags": [ "browser", - "utility", "advanced", "promise" ] }, "meta": { - "hash": "beb6f68f5a8b63fd90a671758556aa72b5c061b681df049779cdf5631837966c", + "hash": "2a9b9f2743606d247f1074840edcabadb880c2c79f4e6deb3f2982bca2fe3307", "firstSeen": "1516190941", - "lastUpdated": "1565681352", - "updateCount": 6, + "lastUpdated": "1587067653", + "updateCount": 7, "authorCount": 3 } }, @@ -3071,16 +3059,15 @@ }, "tags": [ "node", - "utility", "promise", "intermediate" ] }, "meta": { - "hash": "e7b6164cfaacf4869f997747df3e135a1ec4342abf5a56498586513332272a96", + "hash": "66caf1183c70728fa7e9dd6256fc46cc49b3699decbaea8ec1269a2eec07992f", "firstSeen": "1516190941", - "lastUpdated": "1565681352", - "updateCount": 8, + "lastUpdated": "1587067653", + "updateCount": 9, "authorCount": 4 } }, @@ -3172,17 +3159,16 @@ "example": "hexToRGB('#27ae60ff'); // 'rgba(39, 174, 96, 255)'\nhexToRGB('27ae60'); // 'rgb(39, 174, 96)'\nhexToRGB('#fff'); // 'rgb(255, 255, 255)'" }, "tags": [ - "utility", "string", "math", "advanced" ] }, "meta": { - "hash": "f61b08541372ded95a947cc570f57f7bbc9c7908ede569d59f294c5b9ef6feb1", + "hash": "b373e046d50f40ac11b6a538668cdcba6342afe7f92701a36ffe156a6e572edd", "firstSeen": "1513526151", - "lastUpdated": "1565681352", - "updateCount": 10, + "lastUpdated": "1587067653", + "updateCount": 11, "authorCount": 8 } }, @@ -3225,17 +3211,16 @@ "example": "httpDelete('https://jsonplaceholder.typicode.com/posts/1', request => {\n console.log(request.responseText);\n}); /*\nLogs: {}\n*/" }, "tags": [ - "utility", - "url", "browser", + "url", "intermediate" ] }, "meta": { "hash": "f41090864871a22e83896f869524d3037dc552f18f37f3a77128119698a3fa4e", "firstSeen": "1587025293", - "lastUpdated": "1587025293", - "updateCount": 2, + "lastUpdated": "1587067653", + "updateCount": 3, "authorCount": 2 } }, @@ -3252,17 +3237,16 @@ "example": "httpGet(\n 'https://jsonplaceholder.typicode.com/posts/1',\n console.log\n); /*\nLogs: {\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n}\n*/" }, "tags": [ - "utility", - "url", "browser", + "url", "intermediate" ] }, "meta": { - "hash": "c138c0e5f16d48997691a98de7c0bc43b228a0b4285f0ab2b26d230e209d1530", + "hash": "4c412ce4ed5d0573b7a87c273e07aa200c0151a564d41f828e6601202ea06416", "firstSeen": "1515428512", - "lastUpdated": "1565681352", - "updateCount": 12, + "lastUpdated": "1587067653", + "updateCount": 13, "authorCount": 4 } }, @@ -3279,17 +3263,16 @@ "example": "const newPost = {\n userId: 1,\n id: 1337,\n title: 'Foo',\n body: 'bar bar bar'\n};\nconst data = JSON.stringify(newPost);\nhttpPost(\n 'https://jsonplaceholder.typicode.com/posts',\n data,\n console.log\n); /*\nLogs: {\n \"userId\": 1,\n \"id\": 1337,\n \"title\": \"Foo\",\n \"body\": \"bar bar bar\"\n}\n*/\nhttpPost(\n 'https://jsonplaceholder.typicode.com/posts',\n null, // does not send a body\n console.log\n); /*\nLogs: {\n \"id\": 101\n}\n*/" }, "tags": [ - "utility", - "url", "browser", + "url", "intermediate" ] }, "meta": { - "hash": "5b29941074f19769531b3320ec8d61e2b2bdc69735fb781bf7e880ff2080ec04", + "hash": "d842ebdfd968b1dfdd8a8aaa0d27e69608c4c02078b180c8439da72bfa558ec1", "firstSeen": "1515442022", - "lastUpdated": "1565681352", - "updateCount": 30, + "lastUpdated": "1587067653", + "updateCount": 31, "authorCount": 5 } }, @@ -3306,17 +3289,16 @@ "example": "const password = 'fooBaz';\nconst data = JSON.stringify({\n id: 1,\n title: 'foo',\n body: 'bar',\n userId: 1\n});\nhttpPut('https://jsonplaceholder.typicode.com/posts/1', data, request => {\n console.log(request.responseText);\n}); /*\nLogs: {\n id: 1,\n title: 'foo',\n body: 'bar',\n userId: 1\n}\n*/" }, "tags": [ - "utility", - "url", "browser", + "url", "intermediate" ] }, "meta": { "hash": "69d235228441b9dff3092419365e0c4a0bd293b6c3f940de4a31d1f01fb7fcba", "firstSeen": "1587025293", - "lastUpdated": "1587039270", - "updateCount": 4, + "lastUpdated": "1587067653", + "updateCount": 5, "authorCount": 3 } }, @@ -3435,15 +3417,14 @@ }, "tags": [ "string", - "utility", "beginner" ] }, "meta": { - "hash": "544ebe19f71cab5f4b4ad5a6121d4327ebf2b09f04451151e7339c90c8924789", + "hash": "e744d3d9c040feecdd17afc470078ea47047250ed521e138936d1434eba7898a", "firstSeen": "1537816467", - "lastUpdated": "1565681352", - "updateCount": 4, + "lastUpdated": "1587067653", + "updateCount": 5, "authorCount": 3 } }, @@ -3846,17 +3827,16 @@ }, "tags": [ "string", - "utility", "browser", "url", "intermediate" ] }, "meta": { - "hash": "7523c5d3ab85075efa61efc135bb1c8d85e2a2e5407ddc5768099993d46f13b5", + "hash": "71c32c111d21f3ed9c1af2c7216b6f81e8ab652b353ab3f938418738c2a00ac7", "firstSeen": "1514724165", - "lastUpdated": "1565681352", - "updateCount": 4, + "lastUpdated": "1587067653", + "updateCount": 5, "authorCount": 3 } }, @@ -3874,15 +3854,14 @@ }, "tags": [ "date", - "utility", "beginner" ] }, "meta": { - "hash": "19efe22718bca00459c41fa9df56c3574270c500bdd670873358052ccc870f5b", + "hash": "6e1abb3cac28b9ccf95e55db3daec18aeff50735be56cce96ffb326ff99f7669", "firstSeen": "1538218718", - "lastUpdated": "1565681352", - "updateCount": 3, + "lastUpdated": "1587067653", + "updateCount": 4, "authorCount": 2 } }, @@ -3952,15 +3931,14 @@ }, "tags": [ "date", - "utility", "beginner" ] }, "meta": { - "hash": "e0d70480b239a585f907c965214a037ce23ae15f5484ab80930ea9f57cbe529e", + "hash": "3c6950661df4657fc49636fc97050e5a46a9337caaae3f5dd584d3aaf436b451", "firstSeen": "1538218718", - "lastUpdated": "1565681352", - "updateCount": 3, + "lastUpdated": "1587067653", + "updateCount": 4, "authorCount": 2 } }, @@ -4002,16 +3980,15 @@ "example": "isBrowser(); // true (browser)\nisBrowser(); // false (Node)" }, "tags": [ - "utility", "browser", "intermediate" ] }, "meta": { - "hash": "6fb24837c043a0cc320a46695ef0e286a558aaf06e9354407569ae61c4a8d0bd", + "hash": "8aa110b4d9adf4e44eb0b770309dacb3b372268143223e862749519e6a896f1c", "firstSeen": "1521427855", - "lastUpdated": "1565681352", - "updateCount": 7, + "lastUpdated": "1587067653", + "updateCount": 8, "authorCount": 5 } }, @@ -4234,15 +4211,14 @@ }, "tags": [ "string", - "utility", "beginner" ] }, "meta": { - "hash": "e47bc176d868f3aab83f762997bf9d355258607594648573d2482faf7fc08826", + "hash": "a665c8ada73822926f03aa49bf65551ce20459dc4466ce5d5306690d53e04285", "firstSeen": "1515230165", - "lastUpdated": "1565681352", - "updateCount": 7, + "lastUpdated": "1587067653", + "updateCount": 8, "authorCount": 4 } }, @@ -4260,15 +4236,14 @@ }, "tags": [ "math", - "utility", "beginner" ] }, "meta": { - "hash": "ec55fd2848f1443613e33d59634ecaefc9dc82b721424b5416830a7389e1ce6e", + "hash": "c8af31822c3b74d0e3e3099ff770aa467825ecd8edc3e6fb07f84a5af9d615af", "firstSeen": "1542030336", - "lastUpdated": "1565681352", - "updateCount": 4, + "lastUpdated": "1587067653", + "updateCount": 5, "authorCount": 3 } }, @@ -4597,15 +4572,14 @@ }, "tags": [ "date", - "utility", "beginner" ] }, "meta": { - "hash": "4accb95c8fb5ac770c73c78b6236938773499c74617df09a1f73a60abd6f44d7", + "hash": "f2cef555daea23fb46e93ad5bd556840c55f343924578b26329983c0407d88d5", "firstSeen": "1538218718", - "lastUpdated": "1565681352", - "updateCount": 4, + "lastUpdated": "1587067653", + "updateCount": 5, "authorCount": 2 } }, @@ -4775,15 +4749,14 @@ }, "tags": [ "string", - "utility", "beginner" ] }, "meta": { "hash": "e9f213bd74fba0cfc5e7706967f03dee72ee516e213715dab97c5fd32ba7f4f3", "firstSeen": "1515230165", - "lastUpdated": "1567395249", - "updateCount": 8, + "lastUpdated": "1587067653", + "updateCount": 9, "authorCount": 5 } }, @@ -4897,7 +4870,7 @@ "fileName": "join.md", "text": "Joins all elements of an array into a string and returns this string.\nUses a separator and an end separator.\n\nUse `Array.prototype.reduce()` to combine elements into a string.\nOmit the second argument, `separator`, to use a default separator of `','`.\nOmit the third argument, `end`, to use the same value as `separator` by default.\n\n", "codeBlocks": { - "es6": "const join = (arr, separator = ',', end = separator) =>\n arr.reduce(\n (acc, val, i) =>\n i === arr.length - 2\n ? acc + val + end\n : i === arr.length - 1\n ? acc + val\n : acc + val + separator,\n ''\n );", + "es6": "const join = (arr, separator = ',', end = separator) =>\n arr.reduce(\n (acc, val, i) =>\n i === arr.length - 2\n ? acc + val + end\n : i === arr.length - 1\n ? acc + val\n : acc + val + separator,\n ''\n );", "es5": "var join = function join(arr) {\n var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ',';\n var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : separator;\n return arr.reduce(function (acc, val, i) {\n return i === arr.length - 2 ? acc + val + end : i === arr.length - 1 ? acc + val : acc + val + separator;\n }, '');\n};", "example": "join(['pen', 'pineapple', 'apple', 'pen'], ',', '&'); // \"pen,pineapple,apple&pen\"\njoin(['pen', 'pineapple', 'apple', 'pen'], ','); // \"pen,pineapple,apple,pen\"\njoin(['pen', 'pineapple', 'apple', 'pen']); // \"pen,pineapple,apple,pen\"" }, @@ -4907,10 +4880,10 @@ ] }, "meta": { - "hash": "3db3faac666ee61ab86c70766d2ab5d1293ffd818da87edb971bfff7a366364a", + "hash": "362fddaa6244404741e84bca6fc442a101fdb642af53b299e8b9994d0d7162d8", "firstSeen": "1514801920", - "lastUpdated": "1587046062", - "updateCount": 96, + "lastUpdated": "1587067469", + "updateCount": 97, "authorCount": 7 } }, @@ -5033,15 +5006,14 @@ "tags": [ "array", "string", - "utility", "intermediate" ] }, "meta": { - "hash": "1277ce52444adcbc3a7b62d5c9019aa3cf01293e7749b8d0e1871ae2aa6a8c88", + "hash": "bc43866db3708c27d333faa8a71f9075af24899a7785496ca28206061d4910d1", "firstSeen": "1515440027", - "lastUpdated": "1565681352", - "updateCount": 13, + "lastUpdated": "1587067653", + "updateCount": 14, "authorCount": 7 } }, @@ -5084,15 +5056,14 @@ }, "tags": [ "math", - "utility", "advanced" ] }, "meta": { - "hash": "ab83bac8546d02dfe4227792750f0b4c64cd2c8f8ce6063eef2a3f4357210d63", + "hash": "d7c1a6ff15bf0d8f33dddfcebe892089a7902a94fc18803fafd5fe76ebdd3ffc", "firstSeen": "1514970155", - "lastUpdated": "1565681352", - "updateCount": 13, + "lastUpdated": "1587067653", + "updateCount": 14, "authorCount": 6 } }, @@ -5189,15 +5160,14 @@ "string", "array", "function", - "utility", "beginner" ] }, "meta": { - "hash": "c4df98d941aeadd165c6a02143d79f7a9bf013f8c221f709aa545bf83495a956", + "hash": "ef9621c9cc38b1f4ab76ed4246de33ef9125bfa44f4ecc8113e7890d99b61a01", "firstSeen": "1531555196", - "lastUpdated": "1565681352", - "updateCount": 5, + "lastUpdated": "1587067653", + "updateCount": 6, "authorCount": 4 } }, @@ -5241,15 +5211,14 @@ }, "tags": [ "string", - "utility", "intermediate" ] }, "meta": { "hash": "d95e586ebffdfdbaa182feb6a21c41619d6bacde9b7a49ace88b2c958480f25d", "firstSeen": "1514804579", - "lastUpdated": "1579690066", - "updateCount": 17, + "lastUpdated": "1587067653", + "updateCount": 18, "authorCount": 8 } }, @@ -5605,15 +5574,15 @@ "example": "mostPerformant([\n () => {\n // Loops through the entire array before returning `false`\n [1, 2, 3, 4, 5, 6, 7, 8, 9, '10'].every(el => typeof el === 'number');\n },\n () => {\n // Only needs to reach index `1` before returning false\n [1, '2', 3, 4, 5, 6, 7, 8, 9, 10].every(el => typeof el === 'number');\n }\n]); // 1" }, "tags": [ - "utility", - "function" + "function", + "intermediate" ] }, "meta": { - "hash": "120e31fa38796906a99beccdc457e83a8075e6ec72b5a937e03913b2e996ae26", + "hash": "2334d95a86e23b04825a6b9f696d9866749f4d69e6c6003651cc69dccc71e98d", "firstSeen": "1518608325", - "lastUpdated": "1565681352", - "updateCount": 6, + "lastUpdated": "1587067653", + "updateCount": 7, "authorCount": 5 } }, @@ -5732,16 +5701,15 @@ "example": "const third = nthArg(2);\nthird(1, 2, 3); // 3\nthird(1, 2); // undefined\nconst last = nthArg(-1);\nlast(1, 2, 3, 4, 5); // 5" }, "tags": [ - "utility", "function", "beginner" ] }, "meta": { - "hash": "1885078f5fddc5de00844a837ab3c427f770c5325a70d5362ecab26c1c904125", + "hash": "837bf47e8e264266d22fc1d8186b6b5561a94500a1b725ce897ffbd6e0df1b98", "firstSeen": "1516735657", - "lastUpdated": "1565681352", - "updateCount": 5, + "lastUpdated": "1587067653", + "updateCount": 6, "authorCount": 4 } }, @@ -5856,22 +5824,21 @@ "fileName": "objectToQueryString.md", "text": "Returns a query string generated from the key-value pairs of the given object.\n\nUse `Array.prototype.reduce()` on `Object.entries(queryParameters)` to create the query string.\nDetermine the `symbol` to be either `?` or `&` based on the `length` of `queryString` and concatenate `val` to `queryString` only if it's a string.\nReturn the `queryString` or an empty string when the `queryParameters` are falsy.\n\n", "codeBlocks": { - "es6": "const objectToQueryString = queryParameters => {\n return queryParameters\n ? Object.entries(queryParameters).reduce((queryString, [key, val], index) => {\n const symbol = queryString.length === 0 ? '?' : '&';\n queryString += typeof val === 'string' ? `${symbol}${key}=${val}` : '';\n return queryString;\n }, '')\n : '';\n};", + "es6": "const objectToQueryString = queryParameters => {\n return queryParameters\n ? Object.entries(queryParameters).reduce((queryString, [key, val], index) => {\n const symbol = queryString.length === 0 ? '?' : '&';\n queryString += typeof val === 'string' ? `${symbol}${key}=${val}` : '';\n return queryString;\n }, '')\n : '';\n};", "es5": "function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); }\n\nfunction _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === \"[object Arguments]\")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\nvar objectToQueryString = function objectToQueryString(queryParameters) {\n return queryParameters ? Object.entries(queryParameters).reduce(function (queryString, _ref, index) {\n var _ref2 = _slicedToArray(_ref, 2),\n key = _ref2[0],\n val = _ref2[1];\n\n var symbol = queryString.length === 0 ? '?' : '&';\n queryString += typeof val === 'string' ? \"\".concat(symbol).concat(key, \"=\").concat(val) : '';\n return queryString;\n }, '') : '';\n};", "example": "objectToQueryString({ page: '1', size: '2kg', key: undefined }); // '?page=1&size=2kg'" }, "tags": [ - "utility", "object", "function", "intermediate" ] }, "meta": { - "hash": "e8f820ce6da97eabde082ffb829c9fb700e85efc79bdebe883c67237269e3f52", + "hash": "b031c3387ef66411ab5d295788eac4247ada5b4b068dda90603d3c973890bc26", "firstSeen": "1570824965", - "lastUpdated": "1587046062", - "updateCount": 63, + "lastUpdated": "1587067662", + "updateCount": 66, "authorCount": 4 } }, @@ -6221,16 +6188,16 @@ "example": "parseCookie('foo=bar; equation=E%3Dmc%5E2'); // { foo: 'bar', equation: 'E=mc^2' }" }, "tags": [ - "utility", + "browser", "string", "intermediate" ] }, "meta": { - "hash": "c25aef075df93042a81bd98ebd7b77aefb91df3f08b9f1d2e7859ec0d95ad55b", + "hash": "5bcee736e351fb23173369a678122d12b4278a02ab3204cfee2b3b0d3c598544", "firstSeen": "1515845961", - "lastUpdated": "1565681352", - "updateCount": 5, + "lastUpdated": "1587067653", + "updateCount": 6, "authorCount": 4 } }, @@ -6425,7 +6392,7 @@ "codeBlocks": { "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};", - "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": [ "function", @@ -6434,10 +6401,10 @@ ] }, "meta": { - "hash": "a2b9ac4f1209c3791caa6f40f0d041acd75514e9ee8909f2e3833635f357c0bd", + "hash": "0eb844801e767edcaa6a882a6dce4b5b1dadecb53a92d6ec259d36c57b6a3dd0", "firstSeen": "1517069864", - "lastUpdated": "1587046062", - "updateCount": 121, + "lastUpdated": "1587067469", + "updateCount": 122, "authorCount": 5 } }, @@ -6530,15 +6497,14 @@ }, "tags": [ "browser", - "utility", "intermediate" ] }, "meta": { - "hash": "6668f37f9f1158b2bdd292ad64defea6e33a0b2908ea1e494b191dcaa9f039d6", + "hash": "942f8061fb78b9a96dc0da7e249bb8d5c1b2902f9101d6dbdae272c95a49ab92", "firstSeen": "1520515374", - "lastUpdated": "1565681352", - "updateCount": 8, + "lastUpdated": "1587067653", + "updateCount": 9, "authorCount": 5 } }, @@ -6555,17 +6521,16 @@ "example": "prettyBytes(1000); // \"1 KB\"\nprettyBytes(-27145424323.5821, 5); // \"-27.145 GB\"\nprettyBytes(123456789, 3, false); // \"123MB\"" }, "tags": [ - "utility", "string", "math", "advanced" ] }, "meta": { - "hash": "e752de4a4f2b339851e796a5289e7adde51cf7e672b8230fd97bf79cf7330758", + "hash": "7053095cc3085b11fde252bfec58b3888290d30936fe7cd7b570cd075d29225a", "firstSeen": "1514823609", - "lastUpdated": "1565681352", - "updateCount": 14, + "lastUpdated": "1587067653", + "updateCount": 15, "authorCount": 5 } }, @@ -6753,23 +6718,23 @@ "type": "snippet", "attributes": { "fileName": "randomHexColorCode.md", - "text": "Generates a random hexadecimal color code.\n\nUse `Math.random` to generate a random 24-bit(6x4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal String using `toString(16)`.\n\n", + "text": "Generates a random hexadecimal color code.\n\nUse `Math.random` to generate a random 24-bit(6x4bits) hexadecimal number.\nUse bit shifting and then convert it to an hexadecimal String using `toString(16)`.\n\n", "codeBlocks": { "es6": "const randomHexColorCode = () => {\n let n = (Math.random() * 0xfffff * 1000000).toString(16);\n return '#' + n.slice(0, 6);\n};", "es5": "var randomHexColorCode = function randomHexColorCode() {\n var n = (Math.random() * 0xfffff * 1000000).toString(16);\n return '#' + n.slice(0, 6);\n};", "example": "randomHexColorCode(); // \"#e34155\"" }, "tags": [ - "utility", + "math", "random", "beginner" ] }, "meta": { - "hash": "42788f8392f5511db3641dbe2ab92b2c043b3b5209e95c386c73e5d96eaa63af", + "hash": "4af37a3a8c080de92657476319fc3a6d4ff7febfe34f8391b81d97336bb147d6", "firstSeen": "1514383576", - "lastUpdated": "1565681352", - "updateCount": 22, + "lastUpdated": "1587067653", + "updateCount": 23, "authorCount": 10 } }, @@ -6787,16 +6752,15 @@ }, "tags": [ "math", - "utility", "random", "intermediate" ] }, "meta": { - "hash": "7bff02cd849d994da1229f3153cca71b4c054d6774ab732101a5f60a0a04ba3a", + "hash": "6887efc77e1a29d40b7194fe16a2005b8f33f15bb92ee3f0329b55be27f21225", "firstSeen": "1516015518", - "lastUpdated": "1565681352", - "updateCount": 6, + "lastUpdated": "1587067653", + "updateCount": 7, "authorCount": 4 } }, @@ -6814,16 +6778,15 @@ }, "tags": [ "math", - "utility", "random", "beginner" ] }, "meta": { - "hash": "8d8cca3d593e677c8a4ffc17e9f97b3018f800e7c014daa3462edc152fbbeec7", + "hash": "939080b53f5ebf57e2fcb7b88cc827902a3d01c428eed9e989dd2545c3717b6f", "firstSeen": "1513526151", - "lastUpdated": "1565681352", - "updateCount": 6, + "lastUpdated": "1587067653", + "updateCount": 7, "authorCount": 4 } }, @@ -6841,16 +6804,15 @@ }, "tags": [ "math", - "utility", "random", "beginner" ] }, "meta": { - "hash": "c86e3227e32565afb301805798da3a46756e13bff0115b880fcc3175a58d95af", + "hash": "209c6f231e06e1840d46fd6f836961f9dfc8c954e6675a230863eb0824a35c7c", "firstSeen": "1513526151", - "lastUpdated": "1565681352", - "updateCount": 7, + "lastUpdated": "1587067653", + "updateCount": 8, "authorCount": 4 } }, @@ -6912,7 +6874,7 @@ "type": "snippet", "attributes": { "fileName": "recordAnimationFrames.md", - "text": "Invokes the provided callback on each animation frame.\n\nUse recursion. \nProvided that `running` is `true`, continue invoking `window.requestAnimationFrame()` which invokes the provided callback. \nReturn an object with two methods `start` and `stop` to allow manual control of the recording. \nOmit the second argument, `autoStart`, to implicitly call `start` when the function is invoked.\n\n", + "text": "Invokes the provided callback on each animation frame.\n\nUse recursion.\nProvided that `running` is `true`, continue invoking `window.requestAnimationFrame()` which invokes the provided callback.\nReturn an object with two methods `start` and `stop` to allow manual control of the recording.\nOmit the second argument, `autoStart`, to implicitly call `start` when the function is invoked.\n\n", "codeBlocks": { "es6": "const recordAnimationFrames = (callback, autoStart = true) => {\n let running = true,\n raf;\n const stop = () => {\n running = false;\n cancelAnimationFrame(raf);\n };\n const start = () => {\n running = true;\n run();\n };\n const run = () => {\n raf = requestAnimationFrame(() => {\n callback();\n if (running) run();\n });\n };\n if (autoStart) start();\n return { start, stop };\n};", "es5": "var recordAnimationFrames = function recordAnimationFrames(callback) {\n var autoStart = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;\n var running = true,\n raf;\n\n var stop = function stop() {\n running = false;\n cancelAnimationFrame(raf);\n };\n\n var start = function start() {\n running = true;\n run();\n };\n\n var run = function run() {\n raf = requestAnimationFrame(function () {\n callback();\n if (running) run();\n });\n };\n\n if (autoStart) start();\n return {\n start: start,\n stop: stop\n };\n};", @@ -6920,15 +6882,14 @@ }, "tags": [ "browser", - "utility", "intermediate" ] }, "meta": { - "hash": "b780a5af9c22faa9601191aff53c24d55f5e88b62ac79fd2e02517f9a724b502", + "hash": "f734a70077b4723415eae15573378f1596b6b8810831d8784e730771fdba0bfa", "firstSeen": "1519798747", - "lastUpdated": "1565681352", - "updateCount": 5, + "lastUpdated": "1587067653", + "updateCount": 6, "authorCount": 4 } }, @@ -7068,7 +7029,7 @@ "fileName": "remove.md", "text": "Mutates an array by removing elements for which the given function returns `false`.\n\nUse `Array.prototype.filter()` to find array elements that return truthy values and `Array.prototype.reduce()` to remove elements using `Array.prototype.splice()`.\nThe `func` is invoked with three arguments (`value, index, array`).\n\n", "codeBlocks": { - "es6": "const remove = (arr, func) =>\n Array.isArray(arr)\n ? arr.filter(func).reduce((acc, val) => {\n arr.splice(arr.indexOf(val), 1);\n return acc.concat(val);\n }, [])\n : [];", + "es6": "const remove = (arr, func) =>\n Array.isArray(arr)\n ? arr.filter(func).reduce((acc, val) => {\n arr.splice(arr.indexOf(val), 1);\n return acc.concat(val);\n }, [])\n : [];", "es5": "var remove = function remove(arr, func) {\n return Array.isArray(arr) ? arr.filter(func).reduce(function (acc, val) {\n arr.splice(arr.indexOf(val), 1);\n return acc.concat(val);\n }, []) : [];\n};", "example": "remove([1, 2, 3, 4], n => n % 2 === 0); // [2, 4]" }, @@ -7078,10 +7039,10 @@ ] }, "meta": { - "hash": "ffb9c0d1d09aeb989789286efb91cc237b89ce13f44ad9510a014f9ab150df71", + "hash": "be8ec39c092128ba679a3f0421b6abc34ad891dec85354caa419dc4104687a05", "firstSeen": "1513521691", - "lastUpdated": "1587046062", - "updateCount": 118, + "lastUpdated": "1587067469", + "updateCount": 119, "authorCount": 6 } }, @@ -7175,15 +7136,16 @@ "example": "RGBToHex(255, 165, 1); // 'ffa501'" }, "tags": [ - "utility", + "string", + "math", "intermediate" ] }, "meta": { - "hash": "592446fabae44d631396de3441738710626c4d274eaabe3dfdb9b822ce3a5179", + "hash": "85235b8cc5276d21a4f2659a8e04c65dd1b3cab52d1ff700750253dc11b5b5be", "firstSeen": "1513526151", - "lastUpdated": "1565681352", - "updateCount": 9, + "lastUpdated": "1587067653", + "updateCount": 10, "authorCount": 5 } }, @@ -7357,15 +7319,14 @@ }, "tags": [ "math", - "utility", "intermediate" ] }, "meta": { - "hash": "58d91b4760b4af29df95cf1b073166c02660f9af3d46c950fba64b922c999ba1", + "hash": "957622c5cf0b59acacea276978fcf66cef1bdc6f5cc16dde77eda3bc8c3686c8", "firstSeen": "1514387554", - "lastUpdated": "1565681352", - "updateCount": 10, + "lastUpdated": "1587067653", + "updateCount": 11, "authorCount": 6 } }, @@ -7382,16 +7343,16 @@ "example": "serializeCookie('foo', 'bar'); // 'foo=bar'" }, "tags": [ - "utility", + "browser", "string", "intermediate" ] }, "meta": { - "hash": "defdaa306864196a4f561c37c4c7f74ffc159406c4538a0f7e1f3f153840eebe", + "hash": "740ef7d2635d22c19eca6fdce566d679ddfeb5f2a3c382665efe205c2cb1001b", "firstSeen": "1515845961", - "lastUpdated": "1565681352", - "updateCount": 3, + "lastUpdated": "1587067653", + "updateCount": 4, "authorCount": 2 } }, @@ -7582,7 +7543,7 @@ "fileName": "size.md", "text": "Gets the size of an array, object or string.\n\nGet type of `val` (`array`, `object` or `string`). \nUse `length` property for arrays.\nUse `length` or `size` value if available or number of keys for objects.\nUse `size` of a [`Blob` object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) created from `val` for strings.\nSplit strings into array of characters with `split('')` and return its length.\n\n", "codeBlocks": { - "es6": "const size = val =>\n Array.isArray(val)\n ? val.length\n : val && typeof val === 'object'\n ? val.size || val.length || Object.keys(val).length\n : typeof val === 'string'\n ? new Blob([val]).size\n : 0;", + "es6": "const size = val =>\n Array.isArray(val)\n ? val.length\n : val && typeof val === 'object'\n ? val.size || val.length || Object.keys(val).length\n : typeof val === 'string'\n ? new Blob([val]).size\n : 0;", "es5": "function _typeof(obj) { \"@babel/helpers - typeof\"; 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 size = function size(val) {\n return Array.isArray(val) ? val.length : val && _typeof(val) === 'object' ? val.size || val.length || Object.keys(val).length : typeof val === 'string' ? new Blob([val]).size : 0;\n};", "example": "size([1, 2, 3, 4, 5]); // 5\nsize('size'); // 4\nsize({ one: 1, two: 2, three: 3 }); // 3" }, @@ -7594,10 +7555,10 @@ ] }, "meta": { - "hash": "6dd4c6a51d2c80fa4768c95ae01c16a8359c4140bcad28c7fde0cecd72d7d3e2", + "hash": "24b93b68a59b49f245590930fed6fb82e286ce09f90e292466cde63c1784c347", "firstSeen": "1514645161", - "lastUpdated": "1587046062", - "updateCount": 60, + "lastUpdated": "1587067469", + "updateCount": 61, "authorCount": 5 } }, @@ -7927,16 +7888,15 @@ }, "tags": [ "string", - "utility", "regexp", "beginner" ] }, "meta": { - "hash": "a33dbe87821f5017cf4238c69d9effcfe993698f055fec5e915f4fff68c01e34", + "hash": "5d500a11b098ee757fd6803e199a191c529e4070d47e0d576a6f290d0b6c3d14", "firstSeen": "1516969049", - "lastUpdated": "1565681352", - "updateCount": 3, + "lastUpdated": "1587067653", + "updateCount": 4, "authorCount": 2 } }, @@ -8286,15 +8246,15 @@ "example": "timeTaken(() => Math.pow(2, 10)); // 1024, (logged): timeTaken: 0.02099609375ms" }, "tags": [ - "utility", + "function", "beginner" ] }, "meta": { - "hash": "26246364ba1e8e3f52a51c8e1f329af721b05a5d307ed88bf31ccd2620c0deee", + "hash": "8017947366418af3f9991be27f5f622bee0b1cb97f54b46395455800fa015139", "firstSeen": "1513526151", - "lastUpdated": "1565681352", - "updateCount": 9, + "lastUpdated": "1587067653", + "updateCount": 10, "authorCount": 4 } }, @@ -8337,15 +8297,16 @@ "example": "toCurrency(123456.789, 'EUR'); // €123,456.79 | currency: Euro | currencyLangFormat: Local\ntoCurrency(123456.789, 'USD', 'en-us'); // $123,456.79 | currency: US Dollar | currencyLangFormat: English (United States)\ntoCurrency(123456.789, 'USD', 'fa'); // ۱۲۳٬۴۵۶٫۷۹ ؜$ | currency: US Dollar | currencyLangFormat: Farsi\ntoCurrency(322342436423.2435, 'JPY'); // ¥322,342,436,423 | currency: Japanese Yen | currencyLangFormat: Local\ntoCurrency(322342436423.2435, 'JPY', 'fi'); // 322 342 436 423 ¥ | currency: Japanese Yen | currencyLangFormat: Finnish" }, "tags": [ - "utility", + "math", + "string", "intermediate" ] }, "meta": { - "hash": "2f817f7dc3ca24a50bfaa1a59dec3ec6d8ee3392ac2d7f3ecae3a93a9c96f09c", + "hash": "41156e65825b59559469feca57214c9f802cb42fba5a16f5fb5990033a2f7059", "firstSeen": "1517066148", - "lastUpdated": "1565681352", - "updateCount": 7, + "lastUpdated": "1587067653", + "updateCount": 8, "authorCount": 4 } }, @@ -8362,7 +8323,6 @@ "example": "toDecimalMark(12305030388.9087); // \"12,305,030,388.909\"" }, "tags": [ - "utility", "math", "beginner" ] @@ -8370,8 +8330,8 @@ "meta": { "hash": "22c2a4835f37334d3b5fa5f83bbaaddc642feb71c1868f514928c656e250abe6", "firstSeen": "1513866591", - "lastUpdated": "1583481487", - "updateCount": 16, + "lastUpdated": "1587067653", + "updateCount": 17, "authorCount": 7 } }, @@ -8489,16 +8449,15 @@ "example": "toOrdinalSuffix('123'); // \"123rd\"" }, "tags": [ - "utility", "math", "intermediate" ] }, "meta": { - "hash": "0ebd3351685fd96bf678c2baa38fabc9aa18bd6a3fa6674ea0bae9663424ea5f", + "hash": "b9a61d3a7c80d3140aa3cbfea42f8af1ed15cc47bc8d224685c0d9127e74813c", "firstSeen": "1513526151", - "lastUpdated": "1565681352", - "updateCount": 6, + "lastUpdated": "1587067653", + "updateCount": 7, "authorCount": 4 } }, @@ -9108,16 +9067,15 @@ }, "tags": [ "string", - "utility", "regexp", "advanced" ] }, "meta": { - "hash": "6050cfa3a2a39089151bacfce1f5cedaec12f5da253dbc20a56dfaf50cb8924b", + "hash": "1de784a29009c7bf3e08cc95110316c4362125f603e862c29c07be50f54186d9", "firstSeen": "1516110783", - "lastUpdated": "1565681352", - "updateCount": 5, + "lastUpdated": "1587067653", + "updateCount": 6, "authorCount": 4 } }, @@ -9135,16 +9093,15 @@ }, "tags": [ "browser", - "utility", "random", "intermediate" ] }, "meta": { - "hash": "9f84a12da85558ebdb189097dbc581b338e07d52eedc5975f1001133b123aad2", + "hash": "24c28431e9eb84a8a0f8e38370c3635ea9b68482c7a894895fd8ef09c1eb02aa", "firstSeen": "1514533630", - "lastUpdated": "1565681352", - "updateCount": 4, + "lastUpdated": "1587067653", + "updateCount": 5, "authorCount": 3 } }, @@ -9162,16 +9119,15 @@ }, "tags": [ "node", - "utility", "random", "intermediate" ] }, "meta": { - "hash": "79604b0f854a91af789fea8416c7099acfb3633259ef387f52a21337d2242478", + "hash": "2322d2d42be4e3037ec6d4e707358bd114f1378cd64dee48e9a0cb8c918efa3f", "firstSeen": "1514533630", - "lastUpdated": "1565681352", - "updateCount": 6, + "lastUpdated": "1587067653", + "updateCount": 7, "authorCount": 4 } }, @@ -9188,16 +9144,15 @@ "example": "validateNumber('10'); // true" }, "tags": [ - "utility", "math", "intermediate" ] }, "meta": { - "hash": "73fc55564fa0b59a71553aa442bda666cbcddbcd618f9ca53c2b55e42a7c26ca", + "hash": "dffaec8a8f2b3c66e709b2e9ee0a57082be53305f000db3d75983ae103866607", "firstSeen": "1513526151", - "lastUpdated": "1565681352", - "updateCount": 7, + "lastUpdated": "1587067653", + "updateCount": 8, "authorCount": 4 } }, @@ -9367,16 +9322,16 @@ "example": "yesNo('Y'); // true\nyesNo('yes'); // true\nyesNo('No'); // false\nyesNo('Foo', true); // true" }, "tags": [ - "utility", + "string", "regexp", "intermediate" ] }, "meta": { - "hash": "6365f144def8abb711b890f8689ff8c9f1f1aee092525583fa913057ba623472", + "hash": "8b858ab37c0cd7f7a09f54810b9f435037922cdbf7c4dd659899790476152479", "firstSeen": "1514651754", - "lastUpdated": "1565681352", - "updateCount": 4, + "lastUpdated": "1587067653", + "updateCount": 5, "authorCount": 3 } }, diff --git a/snippets/deepClone.md b/snippets/deepClone.md index 583169aa7..a0da1f0a5 100644 --- a/snippets/deepClone.md +++ b/snippets/deepClone.md @@ -20,8 +20,8 @@ const deepClone = obj => { return Array.isArray(obj) && obj.length ? (clone.length = obj.length) && Array.from(clone) : Array.isArray(obj) - ? Array.from(obj) - : clone; + ? Array.from(obj) + : clone; }; ``` diff --git a/snippets/deepMapKeys.md b/snippets/deepMapKeys.md index e9561091d..e07084847 100644 --- a/snippets/deepMapKeys.md +++ b/snippets/deepMapKeys.md @@ -14,13 +14,13 @@ const deepMapKeys = (obj, f) => Array.isArray(obj) ? obj.map(val => deepMapKeys(val, f)) : typeof obj === 'object' - ? Object.keys(obj).reduce((acc, current) => { + ? Object.keys(obj).reduce((acc, current) => { const val = obj[current]; acc[f(current)] = val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val); return acc; }, {}) - : obj; + : obj; ``` ```js diff --git a/snippets/dig.md b/snippets/dig.md index 4484cdd6f..16c08bebe 100644 --- a/snippets/dig.md +++ b/snippets/dig.md @@ -13,9 +13,9 @@ const dig = (obj, target) => target in obj ? obj[target] : Object.values(obj).reduce((acc, val) => { - if (acc !== undefined) return acc; - if (typeof val === 'object') return dig(val, target); - }, undefined); + if (acc !== undefined) return acc; + if (typeof val === 'object') return dig(val, target); + }, undefined); ``` ```js diff --git a/snippets/factorial.md b/snippets/factorial.md index 461dbd4f1..0b1413c15 100644 --- a/snippets/factorial.md +++ b/snippets/factorial.md @@ -14,11 +14,11 @@ Throws an exception if `n` is a negative number. const factorial = n => n < 0 ? (() => { - throw new TypeError('Negative numbers are not allowed!'); - })() + throw new TypeError('Negative numbers are not allowed!'); + })() : n <= 1 - ? 1 - : n * factorial(n - 1); + ? 1 + : n * factorial(n - 1); ``` ```js diff --git a/snippets/getMeridiemSuffixOfInteger.md b/snippets/getMeridiemSuffixOfInteger.md index 1d9c01ee0..c460f5644 100644 --- a/snippets/getMeridiemSuffixOfInteger.md +++ b/snippets/getMeridiemSuffixOfInteger.md @@ -12,10 +12,10 @@ const getMeridiemSuffixOfInteger = num => num === 0 || num === 24 ? 12 + 'am' : num === 12 - ? 12 + 'pm' - : num < 12 - ? (num % 12) + 'am' - : (num % 12) + 'pm'; + ? 12 + 'pm' + : num < 12 + ? (num % 12) + 'am' + : (num % 12) + 'pm'; ``` ```js diff --git a/snippets/join.md b/snippets/join.md index 6df3c9145..6bf258224 100644 --- a/snippets/join.md +++ b/snippets/join.md @@ -11,14 +11,15 @@ Omit the second argument, `separator`, to use a default separator of `','`. Omit the third argument, `end`, to use the same value as `separator` by default. ```js + const join = (arr, separator = ',', end = separator) => arr.reduce( (acc, val, i) => i === arr.length - 2 ? acc + val + end : i === arr.length - 1 - ? acc + val - : acc + val + separator, + ? acc + val + : acc + val + separator, '' ); ``` diff --git a/snippets/objectToQueryString.md b/snippets/objectToQueryString.md index 66b1aa628..682987b59 100644 --- a/snippets/objectToQueryString.md +++ b/snippets/objectToQueryString.md @@ -10,13 +10,14 @@ Determine the `symbol` to be either `?` or `&` based on the `length` of `querySt Return the `queryString` or an empty string when the `queryParameters` are falsy. ```js + const objectToQueryString = queryParameters => { return queryParameters ? Object.entries(queryParameters).reduce((queryString, [key, val], index) => { - const symbol = queryString.length === 0 ? '?' : '&'; - queryString += typeof val === 'string' ? `${symbol}${key}=${val}` : ''; - return queryString; - }, '') + const symbol = queryString.length === 0 ? '?' : '&'; + queryString += typeof val === 'string' ? `${symbol}${key}=${val}` : ''; + return queryString; + }, '') : ''; }; ``` diff --git a/snippets/pipeAsyncFunctions.md b/snippets/pipeAsyncFunctions.md index 3044ba7ea..921de2bd4 100644 --- a/snippets/pipeAsyncFunctions.md +++ b/snippets/pipeAsyncFunctions.md @@ -14,13 +14,14 @@ const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Pr ``` ```js + const sum = pipeAsyncFunctions( x => x + 1, x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)), x => x + 3, async x => (await x) + 4 ); -(async () => { +(async() => { console.log(await sum(5)); // 15 (after one second) })(); ``` diff --git a/snippets/remove.md b/snippets/remove.md index 1c08d075e..1f6491ce4 100644 --- a/snippets/remove.md +++ b/snippets/remove.md @@ -9,12 +9,13 @@ Use `Array.prototype.filter()` to find array elements that return truthy values The `func` is invoked with three arguments (`value, index, array`). ```js + const remove = (arr, func) => Array.isArray(arr) ? arr.filter(func).reduce((acc, val) => { - arr.splice(arr.indexOf(val), 1); - return acc.concat(val); - }, []) + arr.splice(arr.indexOf(val), 1); + return acc.concat(val); + }, []) : []; ``` diff --git a/snippets/size.md b/snippets/size.md index b940a8ea5..c658adcb7 100644 --- a/snippets/size.md +++ b/snippets/size.md @@ -12,14 +12,15 @@ Use `size` of a [`Blob` object](https://developer.mozilla.org/en-US/docs/Web/API Split strings into array of characters with `split('')` and return its length. ```js + const size = val => Array.isArray(val) ? val.length : val && typeof val === 'object' - ? val.size || val.length || Object.keys(val).length - : typeof val === 'string' - ? new Blob([val]).size - : 0; + ? val.size || val.length || Object.keys(val).length + : typeof val === 'string' + ? new Blob([val]).size + : 0; ``` ```js