Linted archive

This commit is contained in:
Angelos Chalaris
2018-09-15 13:52:12 +03:00
parent 3a887a67f4
commit 2ba4b95b47
11 changed files with 77 additions and 51 deletions

View File

@ -58,6 +58,6 @@ locales.forEach(locale => {
fs.writeFileSync( fs.writeFileSync(
path.join(LOCALE_PATH, locale + '_log'), path.join(LOCALE_PATH, locale + '_log'),
`${new Date()}\nHash changes: ${hashChanges.length}\n${ `${new Date()}\nHash changes: ${hashChanges.length}\n${
hashChanges.length ? hashChanges.map(v => `Snippet name: ${v.snippetName}\n Old hash: ${v.oldHash}\n New hash: ${v.newHash}\n`).join('\n'): ''}` hashChanges.length ? hashChanges.map(v => `Snippet name: ${v.snippetName}\n Old hash: ${v.oldHash}\n New hash: ${v.newHash}\n`).join('\n') : ''}`
); );
}); });

View File

@ -10,7 +10,7 @@ Omit the third argument, `err` to log the request to the console's error stream
```js ```js
const httpDelete = (url, callback, err = console.error) => { const httpDelete = (url, callback, err = console.error) => {
const request = new XMLHttpRequest(); const request = new XMLHttpRequest();
request.open("DELETE", url, true); request.open('DELETE', url, true);
request.onload = () => callback(request); request.onload = () => callback(request);
request.onerror = () => err(request); request.onerror = () => err(request);
request.send(); request.send();

View File

@ -10,12 +10,12 @@ Omit the last argument, `err` to log the request to the console's error stream b
```js ```js
const httpPut = (url, data, callback, err = console.error) => { const httpPut = (url, data, callback, err = console.error) => {
const request = new XMLHttpRequest(); const request = new XMLHttpRequest();
request.open("PUT", url, true); request.open("PUT", url, true);
request.setRequestHeader('Content-type','application/json; charset=utf-8'); request.setRequestHeader('Content-type','application/json; charset=utf-8');
request.onload = () => callback(request); request.onload = () => callback(request);
request.onerror = () => err(request); request.onerror = () => err(request);
request.send(data); request.send(data);
}; };
``` ```

View File

@ -7,9 +7,15 @@ Adapted from [here](https://github.com/forrestthewoods/lib_fts/blob/80f3f8c52db5
```js ```js
const isSimilar = (pattern, str) => const isSimilar = (pattern, str) =>
[...str].reduce( [...str].reduce(
(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0 (matchIndex, char) =>
) === pattern.length ? true : false; char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
? matchIndex + 1
: matchIndex,
0
) === pattern.length
? true
: false;
``` ```
```js ```js

View File

@ -7,21 +7,28 @@ Can also be used to compare two strings as shown in the second example.
``` js ``` js
const levenshteinDistance = (string1, string2) => { const levenshteinDistance = (string1, string2) => {
if(string1.length === 0) return string2.length; if (string1.length === 0) return string2.length;
if(string2.length === 0) return string1.length; if (string2.length === 0) return string1.length;
let matrix = Array(string2.length + 1).fill(0).map((x,i) => [i]); let matrix = Array(string2.length + 1)
matrix[0] = Array(string1.length + 1).fill(0).map((x,i) => i); .fill(0)
for(let i = 1; i <= string2.length; i++) { .map((x, i) => [i]);
for(let j = 1; j<=string1.length; j++) { matrix[0] = Array(string1.length + 1)
if(string2[i-1] === string1[j-1]) { .fill(0)
matrix[i][j] = matrix[i-1][j-1]; .map((x, i) => i);
} for (let i = 1; i <= string2.length; i++) {
else{ for (let j = 1; j <= string1.length; j++) {
matrix[i][j] = Math.min(matrix[i-1][j-1]+1, matrix[i][j-1]+1, matrix[i-1][j]+1); if (string2[i - 1] === string1[j - 1]) {
} matrix[i][j] = matrix[i - 1][j - 1];
} } else {
matrix[i][j] = Math.min(
matrix[i - 1][j - 1] + 1,
matrix[i][j - 1] + 1,
matrix[i - 1][j] + 1
);
}
} }
return matrix[string2.length][string1.length]; }
return matrix[string2.length][string1.length];
}; };
``` ```

View File

@ -6,7 +6,7 @@ Use `String.replace()` with a regexp to replace all vowels in `str`.
Omot `repl` to use a default value of `''`. Omot `repl` to use a default value of `''`.
```js ```js
const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi,repl); const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi, repl);
``` ```
```js ```js

View File

@ -1,6 +1,6 @@
const httpDelete = (url, callback, err = console.error) => { const httpDelete = (url, callback, err = console.error) => {
const request = new XMLHttpRequest(); const request = new XMLHttpRequest();
request.open("DELETE", url, true); request.open('DELETE', url, true);
request.onload = () => callback(request); request.onload = () => callback(request);
request.onerror = () => err(request); request.onerror = () => err(request);
request.send(); request.send();

View File

@ -1,9 +1,9 @@
const httpPut = (url, data, callback, err = console.error) => { const httpPut = (url, data, callback, err = console.error) => {
const request = new XMLHttpRequest(); const request = new XMLHttpRequest();
request.open("PUT", url, true); request.open('PUT', url, true);
request.setRequestHeader('Content-type','application/json; charset=utf-8'); request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
request.onload = () => callback(request); request.onload = () => callback(request);
request.onerror = () => err(request); request.onerror = () => err(request);
request.send(data); request.send(data);
}; };
module.exports = httpPut; module.exports = httpPut;

View File

@ -1,5 +1,11 @@
const isSimilar = (pattern, str) => const isSimilar = (pattern, str) =>
[...str].reduce( [...str].reduce(
(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0 (matchIndex, char) =>
) === pattern.length ? true : false; char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
? matchIndex + 1
: matchIndex,
0
) === pattern.length
? true
: false;
module.exports = isSimilar; module.exports = isSimilar;

View File

@ -1,18 +1,25 @@
const levenshteinDistance = (string1, string2) => { const levenshteinDistance = (string1, string2) => {
if(string1.length === 0) return string2.length; if (string1.length === 0) return string2.length;
if(string2.length === 0) return string1.length; if (string2.length === 0) return string1.length;
let matrix = Array(string2.length + 1).fill(0).map((x,i) => [i]); let matrix = Array(string2.length + 1)
matrix[0] = Array(string1.length + 1).fill(0).map((x,i) => i); .fill(0)
for(let i = 1; i <= string2.length; i++) { .map((x, i) => [i]);
for(let j = 1; j<=string1.length; j++) { matrix[0] = Array(string1.length + 1)
if(string2[i-1] === string1[j-1]) { .fill(0)
matrix[i][j] = matrix[i-1][j-1]; .map((x, i) => i);
} for (let i = 1; i <= string2.length; i++) {
else{ for (let j = 1; j <= string1.length; j++) {
matrix[i][j] = Math.min(matrix[i-1][j-1]+1, matrix[i][j-1]+1, matrix[i-1][j]+1); if (string2[i - 1] === string1[j - 1]) {
} matrix[i][j] = matrix[i - 1][j - 1];
} } else {
matrix[i][j] = Math.min(
matrix[i - 1][j - 1] + 1,
matrix[i][j - 1] + 1,
matrix[i - 1][j] + 1
);
}
} }
return matrix[string2.length][string1.length]; }
return matrix[string2.length][string1.length];
}; };
module.exports = levenshteinDistance; module.exports = levenshteinDistance;

View File

@ -1,2 +1,2 @@
const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi,repl); const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi, repl);
module.exports = removeVowels; module.exports = removeVowels;