diff --git a/loc.js b/loc.js new file mode 100644 index 000000000..e51395775 --- /dev/null +++ b/loc.js @@ -0,0 +1,3248 @@ + +> 30-seconds-of-code@0.0.1 localizer G:\My Files\git Repositories\30-seconds-of-code +> node ./scripts/localize.js + +module.exports = { +anagrams : { + description: `### anagrams + +⚠️ **WARNING**: This function's execution time increases exponentially with each character. Anything more than 8 to 10 characters will cause your browser to hang as it tries to solve all the different combinations. + +Generates all anagrams of a string (contains duplicates). + +Use recursion. +For each letter in the given string, create all the partial anagrams for the rest of its letters. +Use \`Array.map()\` to combine the letter with each partial anagram, then \`Array.reduce()\` to combine all anagrams in one array. +Base cases are for string \`length\` equal to \`2\` or \`1\`. + +`, + comments: [`// ['abc','acb','bac','bca','cab','cba']`], + hash: 'db57928e845bb3ddd75803bc9fb56e35682f0db49c44fc5bf49ce92ed7823ec2' +}, +arrayToHtmlList : { + description: `### arrayToHtmlList + +Converts the given array elements into \`
  • \` tags and appends them to the list of the given id. + +Use \`Array.map()\` and \`document.querySelector()\` to create a list of html tags. + +`, + comments: [], + hash: 'cd04af6fa6e404bd23fe048eaa3487cd3c6ca41510a1fa655562f1f021b6ea79' +}, +ary : { + description: `### ary + +Creates a function that accepts up to \`n\` arguments, ignoring any additional arguments. + +Call the provided function, \`fn\`, with up to \`n\` arguments, using \`Array.slice(0,n)\` and the spread operator (\`...\`). + +`, + comments: [`// [6, 8, 10]`], + hash: '4f3141d750bb65b9ea7749e1d87c56e20b175471218daad82a9d39b85c83709c' +}, +atob : { + description: `### atob + +Decodes a string of data which has been encoded using base-64 encoding. + +Create a \`Buffer\` for the given string with base-64 encoding and use \`Buffer.toString('binary')\` to return the decoded string. + +`, + comments: [`// 'foobar'`], + hash: '63d1284df5e152ae1017e1345be0afdfe537b8958955e8d48b1dc09096c0ddbb' +}, +attempt : { + description: `### attempt + +Attempts to invoke a function with the provided arguments, returning either the result or the caught error object. + +Use a \`try... catch\` block to return either the result of the function or an appropriate error. + +`, + comments: [`// elements = []`], + hash: 'af5e1ebd6ac8b69a8bb7ae4411181e693e1152460d749b00e08ebb8a0eb0738d' +}, +average : { + description: `### average + +Returns the average of two or more numbers. + +Use \`Array.reduce()\` to add each value to an accumulator, initialized with a value of \`0\`, divide by the \`length\` of the array. + +`, + comments: [`// 2`,`// 2`], + hash: '9ae903bc29b9075c9326bbceb0682c697cb73ddb632a434fe8035fd2a48e54e3' +}, +averageBy : { + description: `### averageBy + +Returns the average of an array, after mapping each element to a value using the provided function. + +Use \`Array.map()\` to map each element to the value returned by \`fn\`, \`Array.reduce()\` to add each value to an accumulator, initialized with a value of \`0\`, divide by the \`length\` of the array. + +`, + comments: [`// 5`,`// 5`], + hash: 'cc0fc4d2586eed04909cbd7912008273e04b988ee41897517cf9c39f21c16d72' +}, +bind : { + description: `### bind + +Creates a function that invokes \`fn\` with a given context, optionally adding any additional supplied parameters to the beginning of the arguments. + +Return a \`function\` that uses \`Function.apply()\` to apply the given \`context\` to \`fn\`. +Use \`Array.concat()\` to prepend any additional supplied parameters to the arguments. + +`, + comments: [`// 'hi fred!'`], + hash: '559b6272a1b9c506513617f815f128495feb27ad9b3fa807c3cdded9aae35e9d' +}, +bindAll : { + description: `### bindAll + +Use \`Array.forEach()\` to return a \`function\` that uses \`Function.apply()\` to apply the given context (\`obj\`) to \`fn\` for each function specified. + +`, + comments: [`// Logs 'clicked docs' when clicked.`], + hash: '2d8eba637f445e60525f33ebc004a70e40b06ab4bc13f8262652535008cbb40c' +}, +bindKey : { + description: `### bindKey + +Creates a function that invokes the method at a given key of an object, optionally adding any additional supplied parameters to the beginning of the arguments. + +Return a \`function\` that uses \`Function.apply()\` to bind \`context[fn]\` to \`context\`. +Use \`Array.concat()\` to prepend any additional supplied parameters to the arguments. + +`, + comments: [`// 'hi fred!'`], + hash: 'ef7847ba9292b447909df4a34aba1f9227c270e53ce93c4ef18165657f03b92a' +}, +bottomVisible : { + description: `### bottomVisible + +Returns \`true\` if the bottom of the page is visible, \`false\` otherwise. + +Use \`scrollY\`, \`scrollHeight\` and \`clientHeight\` to determine if the bottom of the page is visible. + +`, + comments: [`// true`], + hash: '50d33c2e1ebb78ca9d9f1c288848082d590aded131aea41f86164af1050204ef' +}, +btoa : { + description: `### btoa + +Creates a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data. + +Create a \`Buffer\` for the given string with binary encoding and use \`Buffer.toString('base64')\` to return the encoded string. + +`, + comments: [`// 'Zm9vYmFy'`], + hash: '6d50b12885716eddce47396bb755e6d3facf8dff786e6978b5402ead8f0e6990' +}, +byteSize : { + description: `### byteSize + +Returns the length of a string in bytes. + +Convert a given string to a [\`Blob\` Object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) and find its \`size\`. + +`, + comments: [`//developer.mozilla.org/en-US/docs/Web/API/Blob) and find its \`size\`.`,`// 4`,`// 11`], + hash: '1848a81b6d95cc66138d877364bcbb3de7b89ebc4d2031348aa95345602f4a60' +}, +call : { + description: `### call + +Given a key and a set of arguments, call them when given a context. Primarily useful in composition. + +Use a closure to call a stored key with stored arguments. + +`, + comments: [`//[ 2, 4, 6 ]`,`//[ 2, 4, 6 ]`], + hash: '732d63737f940a76c33a42ae3a1dcbf72b93149f57e14e34e301dad7ce245236' +}, +capitalize : { + description: `### capitalize + +Capitalizes the first letter of a string. + +Use array destructuring and \`String.toUpperCase()\` to capitalize first letter, \`...rest\` to get array of characters after first letter and then \`Array.join('')\` to make it a string again. +Omit the \`lowerRest\` parameter to keep the rest of the string intact, or set it to \`true\` to convert to lowercase. + +`, + comments: [`// 'FooBar'`,`// 'Foobar'`], + hash: '225acdf8e1cbce3dba7ac8591de9d6051165523bf78e1c9b37954a9c5a267252' +}, +capitalizeEveryWord : { + description: `### capitalizeEveryWord + +Capitalizes the first letter of every word in a string. + +Use \`String.replace()\` to match the first character of each word and \`String.toUpperCase()\` to capitalize it. + +`, + comments: [`// 'Hello World!'`], + hash: 'f1ce5987c4180d806c65b415f913bb0a2dcc708ad7a5249d31f9e52d8cba30e3' +}, +castArray : { + description: `### castArray + +Casts the provided value as an array if it's not one. + +Use \`Array.isArray()\` to determine if \`val\` is an array and return it as-is or encapsulated in an array accordingly. + +`, + comments: [`// ['foo']`,`// [1]`], + hash: 'a43c8982dc21f32869d600d175ddcc0b56a24da09a629f6f3be5167bb753e189' +}, +chainAsync : { + description: `### chainAsync + +Chains asynchronous functions. + +Loop through an array of functions containing asynchronous events, calling \`next\` when each asynchronous event has completed. + +`, + comments: [], + hash: '8b6d33fba612cac3b4e97a42fc7bfaa5b52fc96a47d6e580528f6aeae789606d' +}, +chunk : { + description: `### chunk + +Chunks an array into smaller arrays of a specified size. + +Use \`Array.from()\` to create a new array, that fits the number of chunks that will be produced. +Use \`Array.slice()\` to map each element of the new array to a chunk the length of \`size\`. +If the original array can't be split evenly, the final chunk will contain the remaining elements. + +`, + comments: [`// [[1,2],[3,4],[5]]`], + hash: '08ec92acf3f5d606ad2358a30d40f18b2cb78b4e48d31599bb022c749cc6c9c2' +}, +clampNumber : { + description: `### clampNumber + +Clamps \`num\` within the inclusive range specified by the boundary values \`a\` and \`b\`. + +If \`num\` falls within the range, return \`num\`. +Otherwise, return the nearest number in the range. + +`, + comments: [`// 3`,`// -1`], + hash: '09c31287b551db9961ca3f15ec3bbc53965edf318ef50c05fac8cfd52919c2e9' +}, +cloneRegExp : { + description: `### cloneRegExp + +Clones a regular expression. + +Use \`new RegExp()\`, \`RegExp.source\` and \`RegExp.flags\` to clone the given regular expression. + +`, + comments: [`// /lorem ipsum/gi`], + hash: 'ee8e6e19269907273e58f0820bdbfc57022b6673453283058aedbbfc76586658' +}, +coalesce : { + description: `### coalesce + +Returns the first non-null/undefined argument. + +Use \`Array.find()\` to return the first non \`null\`/\`undefined\` argument. + +`, + comments: [`// ""`], + hash: 'e0623f0679ae4ec6af58ad00526ba69458fce3bb442e86796d91638e45d8f509' +}, +coalesceFactory : { + description: `### coalesceFactory + +Returns a customized coalesce function that returns the first argument that returns \`true\` from the provided argument validation function. + +Use \`Array.find()\` to return the first argument that returns \`true\` from the provided argument validation function. + +`, + comments: [`// "Waldo"`], + hash: 'a7874701262b9deec699ed856a358e40fd5de71524a175efe7a9a76a9936d3ad' +}, +collectInto : { + description: `### collectInto + +Changes a function that accepts an array into a variadic function. + +Given a function, return a closure that collects all inputs into an array-accepting function. + +`, + comments: [`// [1, 2, 3] (after about 2 seconds)`], + hash: '6b57cac68ad177d8fbb30e9c586f8f9c088acf755c6c956b5387441ea3850fce' +}, +colorize : { + description: `### colorize + +Add special characters to text to print in color in the console (combined with \`console.log()\`). + +Use template literals and special characters to add the appropriate color code to the string output. +For background colors, add a special character that resets the background color at the end of the string. + +`, + comments: [`// 'foo' (red letters)`,`// 'foo bar' (blue background)`,`// 'foo bar' (first word in yellow letters, second word in green letters, white background for both)`], + hash: '4f42f00e7d675d21829a5fcd2ab2e3fa2058d1c1b1d6850ff28f2a424364593e' +}, +compact : { + description: `### compact + +Removes falsey values from an array. + +Use \`Array.filter()\` to filter out falsey values (\`false\`, \`null\`, \`0\`, \`""\`, \`undefined\`, and \`NaN\`). + +`, + comments: [`// [ 1, 2, 3, 'a', 's', 34 ]`], + hash: '9e8d5592a9de422eff555d3e3e27779d6f1a6cd06de0461c3c0799283348332c' +}, +compose : { + description: `### compose + +Performs right-to-left function composition. + +Use \`Array.reduce()\` to perform right-to-left function composition. +The last (rightmost) function can accept one or more arguments; the remaining functions must be unary. + +`, + comments: [`// 15`], + hash: 'eadb3dc774a236e7c0255a2fb1e203eaa390eb50fcff2a410284557385134f58' +}, +composeRight : { + description: `### composeRight + +Performs left-to-right function composition. + +Use \`Array.reduce()\` to perform left-to-right function composition. +The first (leftmost) function can accept one or more arguments; the remaining functions must be unary. + +`, + comments: [`// 9`], + hash: '8504d35e91465faf7d001d829b855dddb2672882699328ae8c90520c8f59eaf8' +}, +converge : { + description: `### converge + +Accepts a converging function and a list of branching functions and returns a function that applies each branching function to the arguments and the results of the branching functions are passed as arguments to the converging function. + +Use \`Array.map()\` and \`Function.apply()\` to apply each function to the given arguments. +Use the spread operator (\`...\`) to call \`coverger\` with the results of all other functions. + +`, + comments: [`// 4`], + hash: '198b90bf166c74f511a66cfcb6c2e55aab7dafd600d3c53f2b26d9f8a0aade0f' +}, +copyToClipboard : { + description: `### copyToClipboard + +Copy a string to the clipboard. Only works as a result of user action (i.e. inside a \`click\` event listener). + +Create a new \`