diff --git a/glossary/keyword_database b/glossary/keyword_database index 69c17186b..aba50a92d 100644 --- a/glossary/keyword_database +++ b/glossary/keyword_database @@ -21,4 +21,4 @@ regular-expressions selector string template-literals -value-vs-reference \ No newline at end of file +value-vs-reference diff --git a/scripts/analyze.js b/scripts/analyze.js index 1bf3485bf..0accad74d 100644 --- a/scripts/analyze.js +++ b/scripts/analyze.js @@ -48,7 +48,7 @@ let snippetArchiveTokens = {data: snippetsArchiveData.data.map(snippet => { meta: { hash: snippet.meta.hash } - } + }; }), meta: { specification: "http://jsonapi.org/format/"}}; // Write data fs.writeFileSync(path.join(OUTPUT_PATH, 'snippetAnalytics.json'), JSON.stringify(snippetTokens, null, 2)); diff --git a/scripts/build.js b/scripts/build.js index aecfb4e81..f011cc1ba 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -15,7 +15,7 @@ if (util.isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_M console.log(`${chalk.green('NOBUILD')} README build terminated, parent commit is a Travis build!`); process.exit(0); } -if (util.isTravisCI() && (process.env['TRAVIS_EVENT_TYPE'] === 'cron' || process.env['TRAVIS_EVENT_TYPE'] === 'api')){ +if (util.isTravisCI() && (process.env['TRAVIS_EVENT_TYPE'] === 'cron' || process.env['TRAVIS_EVENT_TYPE'] === 'api')) { console.log(`${chalk.green('ARCHIVE')} Cron job or custom build, building archive README!`); console.time('Builder'); let snippets = {}; @@ -46,7 +46,7 @@ These snippets, while useful and interesting, didn\'t quite make it into the rep for(const snippet of Object.entries(snippets)) output += `* [\`${snippet[0].slice(0,-3)}\`](#${snippet[0].toLowerCase().slice(0,-3)})\n`; output += '\n---\n'; - for (const snippet of Object.entries(snippets)){ + for (const snippet of Object.entries(snippets)) { let data = snippet[1]; data = data.slice(0, data.lastIndexOf('```js')) + @@ -140,7 +140,7 @@ try { for (const taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag)) { let data = snippets[taggedSnippet[0] + '.md']; // Add advanced tag - if(taggedSnippet[1].includes('advanced')){ + if(taggedSnippet[1].includes('advanced')) { data = data.split(/\r?\n/); data[0] = data[0] +' ![advanced](/advanced.svg)'; data = data.join('\n'); diff --git a/scripts/glossary/keyword.js b/scripts/glossary/keyword.js index b9ed69613..409b9b0f1 100644 --- a/scripts/glossary/keyword.js +++ b/scripts/glossary/keyword.js @@ -13,7 +13,7 @@ try { const output = glossaryFiles.reduce( (accumulator, currentFilename) => accumulator.toLowerCase().replace(/\.[^/.]+$/, "") + "\n" + - currentFilename.toLowerCase().replace(/\.[^/.]+$/, "")); + currentFilename.toLowerCase().replace(/\.[^/.]+$/, ""))+'\n'; fs.writeFileSync('glossary/keyword_database', output); } catch (err) { console.log(`${chalk.red('ERROR!')} During glossary keyword_database generation: ${err}`); diff --git a/scripts/localize.js b/scripts/localize.js index eea88bde4..28a621800 100644 --- a/scripts/localize.js +++ b/scripts/localize.js @@ -23,7 +23,7 @@ locales.forEach(locale => { Object.keys(snippets).forEach(snippet => { const snippetName = snippet.split('.')[0]; const snippetHash = util.hashData(snippets[snippet]); - if(locData.hasOwnProperty(snippetName)){ + if(locData.hasOwnProperty(snippetName)) { if (locData[snippetName].hash !== snippetHash) { existingData = existingData.indexOf(' => '+snippetHash) !== -1 ? existingData : existingData.replace(locData[snippetName].hash, locData[snippetName].hash+' => '+snippetHash); hashChanges.push({snippetName, oldHash: locData[snippetName].hash.split(' => ')[0], newHash: snippetHash}); diff --git a/scripts/rollup.js b/scripts/rollup.js index 4fe1951a6..d684f7d68 100644 --- a/scripts/rollup.js +++ b/scripts/rollup.js @@ -16,7 +16,7 @@ if (!fs.existsSync(DIST)) fs.mkdirSync(DIST); const es5 = babel({ presets: [['env', { modules: false }]] }); const min = minify({ comments: false }); // Create the bundles -(async () => { +(async() => { const bundle = await rollup({ input: INPUT_FILE }); const bundleES5 = await rollup({ input: INPUT_FILE, plugins: [es5] }); const bundleMin = await rollup({ input: INPUT_FILE, plugins: [min] }); diff --git a/scripts/web.js b/scripts/web.js index 4db1c0cf3..441e7eaaf 100644 --- a/scripts/web.js +++ b/scripts/web.js @@ -273,32 +273,32 @@ try { }, {}); for (let snippet of Object.entries(filteredBeginnerSnippets)) - beginnerOutput += - '
' + - '
' + - '
' + - md - .render(`\n${snippets[snippet[0]]}`) - .replace(/

/g, `${snippet[1].includes('advanced') ? 'advanced' : ''}

`) - .replace(/<\/h3>/g, '
') - .replace(/
([^\0]*?)<\/code><\/pre>/gm, (match, p1) => `
${Prism.highlight(unescapeHTML(p1), Prism.languages.javascript)}
`) - .replace(/<\/pre>\s+
📋 Copy to clipboard' +
-          '
'; + beginnerOutput += + '
' + + '
' + + '
' + + md + .render(`\n${snippets[snippet[0]]}`) + .replace(/

/g, `${snippet[1].includes('advanced') ? 'advanced' : ''}

`) + .replace(/<\/h3>/g, '
') + .replace(/
([^\0]*?)<\/code><\/pre>/gm, (match, p1) => `
${Prism.highlight(unescapeHTML(p1), Prism.languages.javascript)}
`) + .replace(/<\/pre>\s+
📋 Copy to clipboard' +
+      '
'; - // Optimize punctuation nodes - beginnerOutput = util.optimizeNodes(beginnerOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); - // Optimize operator nodes - beginnerOutput = util.optimizeNodes(beginnerOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); - // Optimize keyword nodes - beginnerOutput = util.optimizeNodes(beginnerOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); + // Optimize punctuation nodes + beginnerOutput = util.optimizeNodes(beginnerOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); + // Optimize operator nodes + beginnerOutput = util.optimizeNodes(beginnerOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); + // Optimize keyword nodes + beginnerOutput = util.optimizeNodes(beginnerOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); beginnerOutput += `${beginnerEndPart}`; // Generate and minify 'beginner.html' file - const minifiedBeginnerOutput = minify(beginnerOutput, { + const minifiedBeginnerOutput = minify(beginnerOutput, { collapseBooleanAttributes: true, collapseWhitespace: true, decodeEntities: false, @@ -339,48 +339,45 @@ try { // Generate archived snippets from md files for (let snippet of Object.entries(filteredArchivedSnippets)) - archivedOutput += - '
' + - '
' + - '
' + - md - .render(`\n${filteredArchivedSnippets[snippet[0]]}`) - .replace(/

/g, '

') - .replace(/
([^\0]*?)<\/code><\/pre>/gm, (match, p1) => `
${Prism.highlight(unescapeHTML(p1), Prism.languages.javascript)}
`) - .replace(/<\/pre>\s+
📋 Copy to clipboard' +
-          '
'; - - // Optimize punctuation nodes - archivedOutput = util.optimizeNodes(archivedOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); - // Optimize operator nodes - archivedOutput = util.optimizeNodes(archivedOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); - // Optimize keyword nodes - archivedOutput = util.optimizeNodes(archivedOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); - - - archivedOutput += `${archivedEndPart}`; + archivedOutput += + '
' + + '
' + + '
' + + md + .render(`\n${filteredArchivedSnippets[snippet[0]]}`) + .replace(/

/g, '

') + .replace(/
([^\0]*?)<\/code><\/pre>/gm, (match, p1) => `
${Prism.highlight(unescapeHTML(p1), Prism.languages.javascript)}
`) + .replace(/<\/pre>\s+
📋 Copy to clipboard' +
+      '
'; + // Optimize punctuation nodes + archivedOutput = util.optimizeNodes(archivedOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); + // Optimize operator nodes + archivedOutput = util.optimizeNodes(archivedOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); + // Optimize keyword nodes + archivedOutput = util.optimizeNodes(archivedOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); + archivedOutput += `${archivedEndPart}`; // Generate and minify 'archive.html' file - const minifiedArchivedOutput = minify(archivedOutput, { - collapseBooleanAttributes: true, - collapseWhitespace: true, - decodeEntities: false, - minifyCSS: true, - minifyJS: true, - keepClosingSlash: true, - processConditionalComments: true, - removeAttributeQuotes: false, - removeComments: true, - removeEmptyAttributes: false, - removeOptionalTags: false, - removeScriptTypeAttributes: false, - removeStyleLinkTypeAttributes: false, - trimCustomFragments: true - }); + const minifiedArchivedOutput = minify(archivedOutput, { + collapseBooleanAttributes: true, + collapseWhitespace: true, + decodeEntities: false, + minifyCSS: true, + minifyJS: true, + keepClosingSlash: true, + processConditionalComments: true, + removeAttributeQuotes: false, + removeComments: true, + removeEmptyAttributes: false, + removeOptionalTags: false, + removeScriptTypeAttributes: false, + removeStyleLinkTypeAttributes: false, + trimCustomFragments: true + }); fs.writeFileSync(path.join(docsPath, 'archive.html'), minifiedArchivedOutput); console.log(`${chalk.green('SUCCESS!')} archive.html file generated!`); diff --git a/snippets_archive/levenshteinDistance.md b/snippets_archive/levenshteinDistance.md index 5100d4d30..4ab2a0d3a 100644 --- a/snippets_archive/levenshteinDistance.md +++ b/snippets_archive/levenshteinDistance.md @@ -6,14 +6,14 @@ Calculates the number of changes (substitutions, deletions or additions) require Can also be used to compare two strings as shown in the second example. ``` js -const levenshteinDistance = (string1, string2) => { +const levenshteinDistance = (string1, string2) => { if(string1.length === 0) return string2.length; if(string2.length === 0) return string1.length; let matrix = Array(string2.length + 1).fill(0).map((x,i) => [i]); matrix[0] = Array(string1.length + 1).fill(0).map((x,i) => i); - for(let i = 1; i <= string2.length; i++){ - for(let j = 1; j<=string1.length; j++){ - if(string2[i-1] === string1[j-1]){ + for(let i = 1; i <= string2.length; i++) { + for(let j = 1; j<=string1.length; j++) { + if(string2[i-1] === string1[j-1]) { matrix[i][j] = matrix[i-1][j-1]; } else{ diff --git a/test/cleanObj/cleanObj.test.js b/test/cleanObj/cleanObj.test.js index 9e221f468..b10103acb 100644 --- a/test/cleanObj/cleanObj.test.js +++ b/test/cleanObj/cleanObj.test.js @@ -6,5 +6,5 @@ test('cleanObj is a Function', () => { }); const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } }; test('Removes any properties except the ones specified from a JSON object', () => { - expect(cleanObj(testObj, ['a'], 'children')).toEqual({ a: 1, children : { a: 1}}); + expect(cleanObj(testObj, ['a'], 'children')).toEqual({ a: 1, children: { a: 1}}); }); diff --git a/test/collatz/collatz.test.js b/test/collatz/collatz.test.js index a4bfa2125..ee2d93ff1 100644 --- a/test/collatz/collatz.test.js +++ b/test/collatz/collatz.test.js @@ -12,8 +12,8 @@ test('When n is odd, times by 3 and add 1', () => { }); test('Eventually reaches 1', () => { let n = 9; - while(true){ - if (n === 1){ + while(true) { + if (n === 1) { expect(n).toBe(1); break; } diff --git a/test/collectInto/collectInto.test.js b/test/collectInto/collectInto.test.js index 78b34607f..fc262e1c5 100644 --- a/test/collectInto/collectInto.test.js +++ b/test/collectInto/collectInto.test.js @@ -9,5 +9,5 @@ let p1 = Promise.resolve(1); let p2 = Promise.resolve(2); let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3)); test('Works with multiple promises', () => { - Pall(p1, p2, p3).then(function(val){ expect(val).toBe([1,2,3]);}, function(reason){}); + Pall(p1, p2, p3).then(function(val) { expect(val).toBe([1, 2, 3]);}, function(reason){}); }); diff --git a/test/dig/dig.test.js b/test/dig/dig.test.js index 280272dce..d863e8e55 100644 --- a/test/dig/dig.test.js +++ b/test/dig/dig.test.js @@ -2,11 +2,11 @@ const expect = require("expect"); const dig = require("./dig.js"); const data = { - level1:{ - level2:{ + level1: { + level2: { level3: "some data", level3f: false, - level3a: [1,2,3,4] + level3a: [1, 2, 3, 4] } } }; diff --git a/test/elementContains/elementContains.test.js b/test/elementContains/elementContains.test.js index bb01687e8..ef9019c76 100644 --- a/test/elementContains/elementContains.test.js +++ b/test/elementContains/elementContains.test.js @@ -3,4 +3,4 @@ const elementContains = require('./elementContains.js'); test('elementContains is a Function', () => { expect(elementContains).toBeInstanceOf(Function); -}); \ No newline at end of file +}); diff --git a/test/insertAfter/insertAfter.test.js b/test/insertAfter/insertAfter.test.js index 2f2dcf68b..05f508d1a 100644 --- a/test/insertAfter/insertAfter.test.js +++ b/test/insertAfter/insertAfter.test.js @@ -3,4 +3,4 @@ const insertAfter = require('./insertAfter.js'); test('insertAfter is a Function', () => { expect(insertAfter).toBeInstanceOf(Function); -}); \ No newline at end of file +}); diff --git a/test/insertBefore/insertBefore.test.js b/test/insertBefore/insertBefore.test.js index 5b602a15f..a482fb3df 100644 --- a/test/insertBefore/insertBefore.test.js +++ b/test/insertBefore/insertBefore.test.js @@ -3,4 +3,4 @@ const insertBefore = require('./insertBefore.js'); test('insertBefore is a Function', () => { expect(insertBefore).toBeInstanceOf(Function); -}); \ No newline at end of file +}); diff --git a/test/isObject/isObject.test.js b/test/isObject/isObject.test.js index d5e58c496..134cc9693 100644 --- a/test/isObject/isObject.test.js +++ b/test/isObject/isObject.test.js @@ -11,7 +11,7 @@ test('isObject([]) is a object', () => { expect(isObject([])).toBeTruthy(); }); test('isObject({ a:1 }) is a object', () => { - expect(isObject({ a:1 })).toBeTruthy(); + expect(isObject({ a: 1 })).toBeTruthy(); }); test('isObject(true) is not a object', () => { expect(isObject(true)).toBeFalsy(); diff --git a/test/levenshteinDistance/levenshteinDistance.js b/test/levenshteinDistance/levenshteinDistance.js index a01055db7..688e14685 100644 --- a/test/levenshteinDistance/levenshteinDistance.js +++ b/test/levenshteinDistance/levenshteinDistance.js @@ -1,11 +1,11 @@ -const levenshteinDistance = (string1, string2) => { +const levenshteinDistance = (string1, string2) => { if(string1.length === 0) return string2.length; if(string2.length === 0) return string1.length; - let matrix = Array(string2.length + 1).fill(0).map((x,i) => [i]); - matrix[0] = Array(string1.length + 1).fill(0).map((x,i) => i); - for(let i = 1; i <= string2.length; i++){ - for(let j = 1; j<=string1.length; j++){ - if(string2[i-1] === string1[j-1]){ + let matrix = Array(string2.length + 1).fill(0).map((x, i) => [i]); + matrix[0] = Array(string1.length + 1).fill(0).map((x, i) => i); + for(let i = 1; i <= string2.length; i++) { + for(let j = 1; j<=string1.length; j++) { + if(string2[i-1] === string1[j-1]) { matrix[i][j] = matrix[i-1][j-1]; } else{ diff --git a/test/nodeListToArray/nodeListToArray.test.js b/test/nodeListToArray/nodeListToArray.test.js index 3ebb00c14..414565976 100644 --- a/test/nodeListToArray/nodeListToArray.test.js +++ b/test/nodeListToArray/nodeListToArray.test.js @@ -3,4 +3,4 @@ const nodeListToArray = require('./nodeListToArray.js'); test('nodeListToArray is a Function', () => { expect(nodeListToArray).toBeInstanceOf(Function); -}); \ No newline at end of file +}); diff --git a/test/partition/partition.test.js b/test/partition/partition.test.js index b90671943..4cb266592 100644 --- a/test/partition/partition.test.js +++ b/test/partition/partition.test.js @@ -6,5 +6,5 @@ test('partition is a Function', () => { }); const users = [{ user: 'barney', age: 36, active: false }, { user: 'fred', age: 40, active: true }]; test('Groups the elements into two arrays, depending on the provided function\'s truthiness for each element.', () => { - expect(partition(users, o => o.active)).toEqual([[{ 'user': 'fred', 'age': 40, 'active': true }],[{ 'user': 'barney', 'age': 36, 'active': false }]]); + expect(partition(users, o => o.active)).toEqual([[{ 'user': 'fred', 'age': 40, 'active': true }],[{ 'user': 'barney', 'age': 36, 'active': false }]]); }); diff --git a/test/pipeAsyncFunctions/pipeAsyncFunctions.test.js b/test/pipeAsyncFunctions/pipeAsyncFunctions.test.js index 53ec89173..2ca7213c8 100644 --- a/test/pipeAsyncFunctions/pipeAsyncFunctions.test.js +++ b/test/pipeAsyncFunctions/pipeAsyncFunctions.test.js @@ -9,7 +9,7 @@ test('pipeAsyncFunctions result should be 15', () => { (x) => x + 1, (x) => new Promise((resolve) => setTimeout(() => resolve(x + 2), 0)), (x) => x + 3, - async (x) => await x + 4, + async(x) => await x + 4, ) (5)).resolves.toBe(15); }); diff --git a/test/triggerEvent/triggerEvent.test.js b/test/triggerEvent/triggerEvent.test.js index 681107dcd..02f0a0e18 100644 --- a/test/triggerEvent/triggerEvent.test.js +++ b/test/triggerEvent/triggerEvent.test.js @@ -3,4 +3,4 @@ const triggerEvent = require('./triggerEvent.js'); test('triggerEvent is a Function', () => { expect(triggerEvent).toBeInstanceOf(Function); -}); \ No newline at end of file +});