Linted archive
This commit is contained in:
@ -58,6 +58,6 @@ locales.forEach(locale => {
|
||||
fs.writeFileSync(
|
||||
path.join(LOCALE_PATH, locale + '_log'),
|
||||
`${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') : ''}`
|
||||
);
|
||||
});
|
||||
|
||||
@ -10,7 +10,7 @@ Omit the third argument, `err` to log the request to the console's error stream
|
||||
```js
|
||||
const httpDelete = (url, callback, err = console.error) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("DELETE", url, true);
|
||||
request.open('DELETE', url, true);
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send();
|
||||
|
||||
@ -10,12 +10,12 @@ Omit the last argument, `err` to log the request to the console's error stream b
|
||||
|
||||
```js
|
||||
const httpPut = (url, data, callback, err = console.error) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("PUT", url, true);
|
||||
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send(data);
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("PUT", url, true);
|
||||
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send(data);
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
@ -7,9 +7,15 @@ Adapted from [here](https://github.com/forrestthewoods/lib_fts/blob/80f3f8c52db5
|
||||
|
||||
```js
|
||||
const isSimilar = (pattern, str) =>
|
||||
[...str].reduce(
|
||||
(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0
|
||||
) === pattern.length ? true : false;
|
||||
[...str].reduce(
|
||||
(matchIndex, char) =>
|
||||
char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
|
||||
? matchIndex + 1
|
||||
: matchIndex,
|
||||
0
|
||||
) === pattern.length
|
||||
? true
|
||||
: false;
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
@ -7,21 +7,28 @@ Can also be used to compare two strings as shown in the second example.
|
||||
|
||||
``` js
|
||||
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]) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
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]) {
|
||||
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];
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ Use `String.replace()` with a regexp to replace all vowels in `str`.
|
||||
Omot `repl` to use a default value of `''`.
|
||||
|
||||
```js
|
||||
const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi,repl);
|
||||
const removeVowels = (str, repl = '') => str.replace(/[aeiou]/gi, repl);
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
const httpDelete = (url, callback, err = console.error) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("DELETE", url, true);
|
||||
request.open('DELETE', url, true);
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send();
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
const httpPut = (url, data, callback, err = console.error) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("PUT", url, true);
|
||||
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send(data);
|
||||
const request = new XMLHttpRequest();
|
||||
request.open('PUT', url, true);
|
||||
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send(data);
|
||||
};
|
||||
module.exports = httpPut;
|
||||
|
||||
@ -1,5 +1,11 @@
|
||||
const isSimilar = (pattern, str) =>
|
||||
[...str].reduce(
|
||||
(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0
|
||||
) === pattern.length ? true : false;
|
||||
[...str].reduce(
|
||||
(matchIndex, char) =>
|
||||
char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
|
||||
? matchIndex + 1
|
||||
: matchIndex,
|
||||
0
|
||||
) === pattern.length
|
||||
? true
|
||||
: false;
|
||||
module.exports = isSimilar;
|
||||
|
||||
@ -1,18 +1,25 @@
|
||||
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]) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
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]) {
|
||||
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;
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user