Snippet format update

To match the starter (for the migration)
This commit is contained in:
Angelos Chalaris
2019-08-13 10:29:12 +03:00
parent a5164f392a
commit 611729214a
381 changed files with 1951 additions and 1989 deletions

24
migrator.js Normal file
View File

@ -0,0 +1,24 @@
const snippets = require('./snippet_data/snippets.json');
const fs = require('fs-extra');
const path = require('path');
snippets.data.forEach(snippet => {
fs.writeFileSync(
path.join(
snippet.meta.archived ? './snippets_archive' : './snippets',
`${snippet.attributes.fileName}`),
`---
title: ${snippet.id}
tags: ${snippet.attributes.tags.join(',')}
---
${snippet.attributes.text}
\`\`\`js
${snippet.attributes.codeBlocks.es6}
\`\`\`
\`\`\`js
${snippet.attributes.codeBlocks.example}
\`\`\``);
});

45
package-lock.json generated
View File

@ -3488,7 +3488,7 @@
"version": "1.2.5",
"bundled": true,
"requires": {
"minipass": "2.2.4"
"minipass": "^2.2.1"
}
},
"fs.realpath": {
@ -3606,17 +3606,16 @@
"minipass": {
"version": "2.2.4",
"bundled": true,
"optional": true,
"requires": {
"safe-buffer": "5.1.1",
"yallist": "3.0.2"
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
}
},
"minizlib": {
"version": "1.1.0",
"bundled": true,
"requires": {
"minipass": "2.2.4"
"minipass": "^2.2.1"
}
},
"mkdirp": {
@ -3651,16 +3650,16 @@
"dev": true,
"optional": true,
"requires": {
"detect-libc": "1.0.3",
"mkdirp": "0.5.1",
"needle": "2.2.0",
"nopt": "4.0.1",
"npm-packlist": "1.1.10",
"npmlog": "4.1.2",
"rc": "1.2.7",
"rimraf": "2.6.2",
"semver": "5.5.0",
"tar": "4.4.1"
"detect-libc": "^1.0.2",
"mkdirp": "^0.5.1",
"needle": "^2.2.0",
"nopt": "^4.0.1",
"npm-packlist": "^1.1.6",
"npmlog": "^4.0.2",
"rc": "^1.1.7",
"rimraf": "^2.6.1",
"semver": "^5.3.0",
"tar": "^4"
}
},
"nopt": {
@ -3802,8 +3801,7 @@
},
"safe-buffer": {
"version": "5.1.1",
"bundled": true,
"optional": true
"bundled": true
},
"safer-buffer": {
"version": "2.1.2",
@ -3893,8 +3891,7 @@
},
"yallist": {
"version": "3.0.2",
"bundled": true,
"optional": true
"bundled": true
}
}
},
@ -6049,11 +6046,11 @@
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
"dev": true,
"requires": {
"ansi-styles": "2.2.1",
"escape-string-regexp": "1.0.5",
"has-ansi": "2.0.0",
"strip-ansi": "3.0.1",
"supports-color": "2.0.0"
"ansi-styles": "^2.2.1",
"escape-string-regexp": "^1.0.2",
"has-ansi": "^2.0.0",
"strip-ansi": "^3.0.0",
"supports-color": "^2.0.0"
}
},
"cross-spawn": {

View File

@ -10,13 +10,11 @@
"glossary:keymaker": "node ./scripts/glossary/keyword.js",
"builder": "node ./scripts/build.js",
"linter": "node ./scripts/lint.js",
"tagger": "node ./scripts/tag.js",
"webber": "node ./scripts/web.js",
"tester": "node ./scripts/tdd.js",
"extractor": "node ./scripts/extract.js",
"vscoder": "node ./scripts/vscodegen.js",
"packager": "node ./scripts/module.js",
"localizer": "node ./scripts/localize.js",
"test": "jest --verbose --coverage"
},
"repository": {

View File

@ -1,66 +0,0 @@
/*
This is the tagger script that updates the tag_databse file and logs stats for snippet tags.
Run using `npm run tagger`.
*/
// Load modules
const fs = require('fs-extra'),
{ black, blue, green, yellow, red, bgWhite } = require('kleur');
const util = require('./util');
if (util.isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) {
console.log(`${green('NOBUILD')} Tagging terminated, parent commit is a Travis build!`);
process.exit(0);
}
// Set variables for paths
const snippetsPath = './snippets';
// Set variables for script
let snippets = {},
output = '',
tagDbData = {},
missingTags = 0,
tagDbStats = {};
// Start the timer of the script
console.time('Tagger');
// Synchronously read all snippets and sort them as necessary (case-insensitive)
snippets = util.readSnippets(snippetsPath);
// Load tag data from the database
tagDbData = util.readTags();
tagDbStats = Object.entries(tagDbData).reduce((acc, val) => {
val[1].forEach(v => (acc.hasOwnProperty(v) ? acc[v]++ : (acc[v] = 1)));
return acc;
}, {});
// Update the listing of snippets in tag_database and log the statistics, along with missing scripts
try {
for (let snippet of Object.entries(snippets)) {
if (
tagDbData.hasOwnProperty(snippet[0].slice(0, -3)) &&
tagDbData[snippet[0].slice(0, -3)].join(',').trim()
) {
output += `${snippet[0].slice(0, -3)}:${tagDbData[snippet[0].slice(0, -3)]
.join(',')
.trim()}\n`;
} else {
output += `${snippet[0].slice(0, -3)}:uncategorized\n`;
missingTags++;
console.log(`${yellow('Tagged uncategorized:')} ${snippet[0].slice(0, -3)}`);
}
}
// Write to tag_database
fs.writeFileSync('tag_database', output);
} catch (err) {
// Handle errors (hopefully not!)
console.log(`${red('ERROR!')} During tag_database generation: ${err}`);
process.exit(1);
}
// Log statistics for the tag_database file
console.log(`\n${bgWhite(black('=== TAG STATS ==='))}`);
for (let tagData of Object.entries(tagDbStats)
.filter(v => v[0] !== 'undefined')
.sort((a, b) => a[0].localeCompare(b[0])))
console.log(`${green(tagData[0])}: ${tagData[1]} snippets`);
console.log(
`${blue("New untagged snippets (will be tagged as 'uncategorized'):")} ${missingTags}\n`
);
// Log a success message
console.log(`${green('SUCCESS!')} tag_database file updated!`);
// Log the time taken
console.timeEnd('Tagger');

View File

@ -1,4 +1,7 @@
### CSVToArray
---
title: CSVToArray
tags: string,array,utility,intermediate
---
Converts a comma-separated values (CSV) string to a 2D array.

View File

@ -1,4 +1,7 @@
### CSVToJSON
---
title: CSVToJSON
tags: string,array,object,advanced
---
Converts a comma-separated values (CSV) string to a 2D array of objects.
The first row of the string is used as the title row.

View File

@ -1,4 +1,7 @@
### JSONToFile
---
title: JSONToFile
tags: node,json,intermediate
---
Writes a JSON object to a file.

View File

@ -1,4 +1,7 @@
### JSONtoCSV
---
title: JSONtoCSV
tags: array,string,object,advanced
---
Converts an array of objects to a comma-separated values (CSV) string that contains only the `columns` specified.

View File

@ -1,4 +1,7 @@
### RGBToHex
---
title: RGBToHex
tags: utility,intermediate
---
Converts the values of RGB components to a color code.

View File

@ -1,4 +1,7 @@
### URLJoin
---
title: URLJoin
tags: string,utility,regexp,advanced
---
Joins all given URL segments together, then normalizes the resulting URL.

View File

@ -1,4 +1,7 @@
### UUIDGeneratorBrowser
---
title: UUIDGeneratorBrowser
tags: browser,utility,random,intermediate
---
Generates a UUID in a browser.

View File

@ -1,4 +1,7 @@
### UUIDGeneratorNode
---
title: UUIDGeneratorNode
tags: node,utility,random,intermediate
---
Generates a UUID in Node.JS.

View File

@ -1,4 +1,7 @@
### all
---
title: all
tags: array,function,beginner
---
Returns `true` if the provided predicate function returns `true` for all elements in a collection, `false` otherwise.

View File

@ -1,4 +1,7 @@
### allEqual
---
title: allEqual
tags: array,function,beginner
---
Check if all elements in an array are equal.

View File

@ -1,4 +1,7 @@
### any
---
title: any
tags: array,function,beginner
---
Returns `true` if the provided predicate function returns `true` for at least one element in a collection, `false` otherwise.

View File

@ -1,4 +1,7 @@
### approximatelyEqual
---
title: approximatelyEqual
tags: math,beginner
---
Checks if two numbers are approximately equal to each other.

View File

@ -1,4 +1,7 @@
### arrayToCSV
---
title: arrayToCSV
tags: array,string,utility,intermediate
---
Converts a 2D array to a comma-separated values (CSV) string.

View File

@ -1,4 +1,7 @@
### arrayToHtmlList
---
title: arrayToHtmlList
tags: browser,array,intermediate
---
Converts the given array elements into `<li>` tags and appends them to the list of the given id.

View File

@ -1,4 +1,7 @@
### ary
---
title: ary
tags: adapter,function,intermediate
---
Creates a function that accepts up to `n` arguments, ignoring any additional arguments.

View File

@ -1,4 +1,7 @@
### atob
---
title: atob
tags: node,string,utility,beginner
---
Decodes a string of data which has been encoded using base-64 encoding.

View File

@ -1,4 +1,7 @@
### attempt
---
title: attempt
tags: function,intermediate
---
Attempts to invoke a function with the provided arguments, returning either the result or the caught error object.

View File

@ -1,4 +1,7 @@
### average
---
title: average
tags: math,array,beginner
---
Returns the average of two or more numbers.

View File

@ -1,4 +1,7 @@
### averageBy
---
title: averageBy
tags: math,array,function,intermediate
---
Returns the average of an array, after mapping each element to a value using the provided function.

View File

@ -1,4 +1,7 @@
### bifurcate
---
title: bifurcate
tags: array,intermediate
---
Splits values into two groups. If an element in `filter` is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.

View File

@ -1,4 +1,7 @@
### bifurcateBy
---
title: bifurcateBy
tags: array,function,intermediate
---
Splits values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise, it belongs to the second group.

View File

@ -1,4 +1,7 @@
### bind
---
title: bind
tags: function,object,intermediate
---
Creates a function that invokes `fn` with a given context, optionally adding any additional supplied parameters to the beginning of the arguments.

View File

@ -1,4 +1,7 @@
### bindAll
---
title: bindAll
tags: object,function,intermediate
---
Binds methods of an object to the object itself, overwriting the existing method.

View File

@ -1,4 +1,7 @@
### bindKey
---
title: bindKey
tags: function,object,intermediate
---
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.

View File

@ -1,4 +1,7 @@
### binomialCoefficient
---
title: binomialCoefficient
tags: math,intermediate
---
Evaluates the binomial coefficient of two integers `n` and `k`.

View File

@ -1,4 +1,7 @@
### bottomVisible
---
title: bottomVisible
tags: browser,intermediate
---
Returns `true` if the bottom of the page is visible, `false` otherwise.

View File

@ -1,4 +1,7 @@
### btoa
---
title: btoa
tags: node,string,utility,beginner
---
Creates a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data.

View File

@ -1,4 +1,7 @@
### byteSize
---
title: byteSize
tags: string,beginner
---
Returns the length of a string in bytes.

View File

@ -1,4 +1,7 @@
### call
---
title: call
tags: adapter,function,intermediate
---
Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

View File

@ -1,4 +1,7 @@
### capitalize
---
title: capitalize
tags: string,array,intermediate
---
Capitalizes the first letter of a string.

View File

@ -1,4 +1,7 @@
### capitalizeEveryWord
---
title: capitalizeEveryWord
tags: string,regexp,intermediate
---
Capitalizes the first letter of every word in a string.

View File

@ -1,4 +1,7 @@
### castArray
---
title: castArray
tags: utility,array,type,beginner
---
Casts the provided value as an array if it's not one.

View File

@ -1,4 +1,7 @@
### chainAsync
---
title: chainAsync
tags: function,intermediate
---
Chains asynchronous functions.

View File

@ -1,4 +1,7 @@
### checkProp
---
title: checkProp
tags: function,object,utility,beginner
---
Given a `predicate` function and a `prop` string, this curried function will then take an `object` to inspect by calling the property and passing it to the predicate.
@ -9,22 +12,6 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
```
```js
const lengthIs4 = checkProp(l => l === 4, 'length');
lengthIs4([]); // false
lengthIs4([1,2,3,4]); // true

View File

@ -1,4 +1,7 @@
### chunk
---
title: chunk
tags: array,intermediate
---
Chunks an array into smaller arrays of a specified size.

View File

@ -1,4 +1,7 @@
### clampNumber
---
title: clampNumber
tags: math,beginner
---
Clamps `num` within the inclusive range specified by the boundary values `a` and `b`.

View File

@ -1,4 +1,7 @@
### cloneRegExp
---
title: cloneRegExp
tags: utility,regexp,intermediate
---
Clones a regular expression.

View File

@ -1,4 +1,7 @@
### coalesce
---
title: coalesce
tags: utility,beginner
---
Returns the first non-null/undefined argument.

View File

@ -1,4 +1,7 @@
### coalesceFactory
---
title: coalesceFactory
tags: utility,intermediate
---
Returns a customized coalesce function that returns the first argument that returns `true` from the provided argument validation function.

View File

@ -1,4 +1,7 @@
### collectInto
---
title: collectInto
tags: adapter,function,array,intermediate
---
Changes a function that accepts an array into a variadic function.

View File

@ -1,4 +1,7 @@
### colorize
---
title: colorize
tags: node,utility,string,intermediate
---
Add special characters to text to print in color in the console (combined with `console.log()`).

View File

@ -1,4 +1,7 @@
### compact
---
title: compact
tags: array,beginner
---
Removes falsy values from an array.

View File

@ -1,4 +1,7 @@
### compactWhitespace
---
title: compactWhitespace
tags: string,regexp,beginner
---
Returns a string with whitespaces compacted.

View File

@ -1,4 +1,7 @@
### compose
---
title: compose
tags: function,intermediate
---
Performs right-to-left function composition.

View File

@ -1,4 +1,7 @@
### composeRight
---
title: composeRight
tags: function,intermediate
---
Performs left-to-right function composition.

View File

@ -1,4 +1,7 @@
### converge
---
title: converge
tags: function,intermediate
---
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.

View File

@ -1,4 +1,7 @@
### copyToClipboard
---
title: copyToClipboard
tags: browser,string,advanced
---
⚠️ **NOTICE:** The same functionality can be easily implemented by using the new asynchronous Clipboard API, which is still experimental but should be used in the future instead of this snippet. Find out more about it [here](https://github.com/w3c/clipboard-apis/blob/master/explainer.adoc#writing-to-the-clipboard).

View File

@ -1,4 +1,7 @@
### countBy
---
title: countBy
tags: array,object,intermediate
---
Groups the elements of an array based on the given function and returns the count of elements in each group.

View File

@ -1,4 +1,7 @@
### countOccurrences
---
title: countOccurrences
tags: array,intermediate
---
Counts the occurrences of a value in an array.

View File

@ -1,4 +1,7 @@
### counter
---
title: counter
tags: browser,advanced
---
Creates a counter with the specified range, step and duration for the specified selector.

View File

@ -1,4 +1,7 @@
### createDirIfNotExists
---
title: createDirIfNotExists
tags: node,beginner
---
Creates a directory, if it does not exist.

View File

@ -1,4 +1,7 @@
### createElement
---
title: createElement
tags: browser,utility,beginner
---
Creates an element from a string (without appending it to the document).
If the given string contains multiple elements, only the first one will be returned.

View File

@ -1,4 +1,7 @@
### createEventHub
---
title: createEventHub
tags: browser,event,advanced
---
Creates a pub/sub ([publishsubscribe](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)) event hub with `emit`, `on`, and `off` methods.

View File

@ -1,4 +1,7 @@
### currentURL
---
title: currentURL
tags: browser,url,beginner
---
Returns the current URL.

View File

@ -1,4 +1,7 @@
### curry
---
title: curry
tags: function,recursion,intermediate
---
Curries a function.

View File

@ -1,4 +1,7 @@
### dayOfYear
---
title: dayOfYear
tags: date,beginner
---
Gets the day of the year from a `Date` object.

View File

@ -1,4 +1,7 @@
### debounce
---
title: debounce
tags: function,intermediate
---
Creates a debounced function that delays invoking the provided function until at least `ms` milliseconds have elapsed since the last time it was invoked.

View File

@ -1,4 +1,7 @@
### decapitalize
---
title: decapitalize
tags: string,array,intermediate
---
Decapitalizes the first letter of a string.

View File

@ -1,4 +1,7 @@
### deepClone
---
title: deepClone
tags: object,recursion,intermediate
---
Creates a deep clone of an object.

View File

@ -1,4 +1,7 @@
### deepFlatten
---
title: deepFlatten
tags: array,recursion,intermediate
---
Deep flattens an array.

View File

@ -1,4 +1,7 @@
### deepFreeze
---
title: deepFreeze
tags: object,recursion,intermediate
---
Deep freezes an object.

View File

@ -1,4 +1,7 @@
### deepGet
---
title: deepGet
tags: object,intermediate
---
Returns the target value in a nested JSON object, based on the `keys` array.

View File

@ -1,4 +1,7 @@
### deepMapKeys
---
title: deepMapKeys
tags: object,recursion,advanced
---
Deep maps an object keys.

View File

@ -1,4 +1,7 @@
### defaults
---
title: defaults
tags: object,intermediate
---
Assigns default values for all properties in an object that are `undefined`.

View File

@ -1,4 +1,7 @@
### defer
---
title: defer
tags: function,intermediate
---
Defers invoking a function until the current call stack has cleared.

View File

@ -1,4 +1,7 @@
### degreesToRads
---
title: degreesToRads
tags: math,beginner
---
Converts an angle from degrees to radians.

View File

@ -1,4 +1,7 @@
### delay
---
title: delay
tags: function,intermediate
---
Invokes the provided function after `wait` milliseconds.

View File

@ -1,4 +1,7 @@
### detectDeviceType
---
title: detectDeviceType
tags: browser,intermediate
---
Detects whether the website is being opened in a mobile device or a desktop/laptop.

View File

@ -1,4 +1,7 @@
### difference
---
title: difference
tags: array,math,beginner
---
Returns the difference between two arrays.

View File

@ -1,4 +1,7 @@
### differenceBy
---
title: differenceBy
tags: array,function,intermediate
---
Returns the difference between two arrays, after applying the provided function to each array element of both.

View File

@ -1,4 +1,7 @@
### differenceWith
---
title: differenceWith
tags: array,function,intermediate
---
Filters out all values from an array for which the comparator function does not return `true`.

View File

@ -1,4 +1,7 @@
### dig
---
title: dig
tags: object,recursion,intermediate
---
Returns the target value in a nested JSON object, based on the given key.

View File

@ -1,4 +1,7 @@
### digitize
---
title: digitize
tags: math,array,beginner
---
Converts a number to an array of digits.

View File

@ -1,4 +1,7 @@
### distance
---
title: distance
tags: math,beginner
---
Returns the distance between two points.

View File

@ -1,4 +1,7 @@
### drop
---
title: drop
tags: array,beginner
---
Returns a new array with `n` elements removed from the left.

View File

@ -1,4 +1,7 @@
### dropRight
---
title: dropRight
tags: array,beginner
---
Returns a new array with `n` elements removed from the right.

View File

@ -1,4 +1,7 @@
### dropRightWhile
---
title: dropRightWhile
tags: array,function,intermediate
---
Removes elements from the end of an array until the passed function returns `true`. Returns the remaining elements in the array.

View File

@ -1,4 +1,7 @@
### dropWhile
---
title: dropWhile
tags: array,function,intermediate
---
Removes elements in an array until the passed function returns `true`. Returns the remaining elements in the array.

View File

@ -1,4 +1,7 @@
### elementContains
---
title: elementContains
tags: browser,intermediate
---
Returns `true` if the `parent` element contains the `child` element, `false` otherwise.

View File

@ -1,4 +1,7 @@
### elementIsVisibleInViewport
---
title: elementIsVisibleInViewport
tags: browser,advanced
---
Returns `true` if the element specified is visible in the viewport, `false` otherwise.

View File

@ -1,4 +1,7 @@
### elo
---
title: elo
tags: math,array,advanced
---
Computes the new ratings between two or more opponents using the [Elo rating system](https://en.wikipedia.org/wiki/Elo_rating_system). It takes an array
of pre-ratings and returns an array containing post-ratings.

View File

@ -1,4 +1,7 @@
### equals
---
title: equals
tags: object,array,type,advanced
---
Performs a deep comparison between two values to determine if they are equivalent.

View File

@ -1,4 +1,7 @@
### escapeHTML
---
title: escapeHTML
tags: string,browser,regexp,intermediate
---
Escapes a string for use in HTML.

View File

@ -1,4 +1,7 @@
### escapeRegExp
---
title: escapeRegExp
tags: string,regexp,intermediate
---
Escapes a string to use in a regular expression.

View File

@ -1,4 +1,7 @@
### everyNth
---
title: everyNth
tags: array,beginner
---
Returns every nth element in an array.

View File

@ -1,4 +1,7 @@
### extendHex
---
title: extendHex
tags: utility,string,intermediate
---
Extends a 3-digit color code to a 6-digit color code.

View File

@ -1,4 +1,7 @@
### factorial
---
title: factorial
tags: math,recursion,beginner
---
Calculates the factorial of a number.

View File

@ -1,4 +1,7 @@
### fibonacci
---
title: fibonacci
tags: math,array,beginner
---
Generates an array, containing the Fibonacci sequence, up until the nth term.

View File

@ -1,4 +1,7 @@
### filterFalsy
---
title: filterFalsy
tags: array,beginner
---
Filters out the falsy values in an array.

View File

@ -1,4 +1,7 @@
### filterNonUnique
---
title: filterNonUnique
tags: array,beginner
---
Filters out the non-unique values in an array.

View File

@ -1,4 +1,7 @@
### filterNonUniqueBy
---
title: filterNonUniqueBy
tags: array,function,intermediate
---
Filters out the non-unique values in an array, based on a provided comparator function.

View File

@ -1,4 +1,7 @@
### findKey
---
title: findKey
tags: object,function,intermediate
---
Returns the first key that satisfies the provided testing function. Otherwise `undefined` is returned.

View File

@ -1,4 +1,7 @@
### findLast
---
title: findLast
tags: array,beginner
---
Returns the last element for which the provided function returns a truthy value.

View File

@ -1,4 +1,7 @@
### findLastIndex
---
title: findLastIndex
tags: array,function,intermediate
---
Returns the index of the last element for which the provided function returns a truthy value.

View File

@ -1,4 +1,7 @@
### findLastKey
---
title: findLastKey
tags: object,function,intermediate
---
Returns the last key that satisfies the provided testing function.
Otherwise `undefined` is returned.

View File

@ -1,4 +1,7 @@
### flatten
---
title: flatten
tags: array,intermediate
---
Flattens an array up to the specified depth.

Some files were not shown because too many files have changed in this diff Show More