-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3233be0
commit 28320a2
Showing
19 changed files
with
501 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module.exports = parameters => { | ||
const expectedParameters = [ | ||
'array', | ||
'iteration' | ||
] | ||
|
||
const missingParameter = expectedParameters.find(parameter => { | ||
return !Object.keys(parameters).includes(parameter) | ||
}) | ||
|
||
if (missingParameter) { | ||
throw Error(`Expected a parameter called ${missingParameter} in arrayEvery()`) | ||
} | ||
|
||
const { array, iteration } = parameters | ||
|
||
if (array.length === 0) { | ||
throw Error('arrayEvery() cannot be used in empty arrays.') | ||
} | ||
|
||
const callback = (currentValue, index, array) => { | ||
return iteration({ | ||
value: currentValue, | ||
index, | ||
array | ||
}) | ||
} | ||
|
||
return array.every(callback) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module.exports = parameters => { | ||
const expectedParameters = [ | ||
'value', | ||
'default', | ||
'array' | ||
] | ||
|
||
const missingParameter = expectedParameters.find(parameter => { | ||
return !Object.keys(parameters).includes(parameter) | ||
}) | ||
|
||
if (missingParameter) { | ||
throw Error(`Expected an parameter called ${missingParameter} in arrayMatch()`) | ||
} | ||
|
||
const { array, value } = parameters | ||
const _default = parameters.default | ||
|
||
const _case = array.find(element => { | ||
const expectedParameters = [ | ||
'case', | ||
'assign' | ||
] | ||
|
||
const missingParameter = expectedParameters.find(parameter => { | ||
return !Object.keys(element).includes(parameter) | ||
}) | ||
|
||
if (missingParameter) { | ||
throw Error(`Expected a parameter called ${missingParameter} in array argument of arrayMatch()`) | ||
} | ||
|
||
return element.case === value | ||
}) | ||
|
||
if (!_case) { | ||
return _default | ||
} | ||
|
||
return _case.assign | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const arrayAdd = require('php-bundler/lib/array_add.js') | ||
|
||
module.exports = (parameters) => { | ||
const expectedParameters = [ | ||
'text', | ||
'transform' | ||
] | ||
|
||
const missingParameter = expectedParameters.find(parameter => { | ||
return !Object.keys(parameters).includes(parameter) | ||
}) | ||
|
||
if (missingParameter) { | ||
throw Error(`Expected a parameter called ${missingParameter} in ignoreText()`) | ||
} | ||
|
||
let { text, transform } = parameters | ||
const betweenBackticks = /`(?<=`).+?(?=`)`/g | ||
let matchedText = [...text.matchAll(betweenBackticks)] | ||
if (matchedText === undefined) { | ||
text = transform(text) | ||
if (typeof text !== 'string') { | ||
throw Error('transform() expected to return a value of type text') | ||
} | ||
} | ||
|
||
matchedText = matchedText.map(text => text[0]) | ||
|
||
text = text.replaceAll(betweenBackticks, '<STRING>') | ||
text = transform(text) | ||
if (typeof text !== 'string') { | ||
throw Error('transform() expected to return a value of type text') | ||
} | ||
return arrayAdd({ | ||
array: matchedText, | ||
carry: text, | ||
iteration: parameters => { | ||
const text = parameters.carry | ||
const match = parameters.value | ||
|
||
return text.replace('<STRING>', match) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module.exports = ({ lines, index, filename, multilineString }) => { | ||
if (lines[index].endsWith('<<<STRING')) { | ||
const indentation = lines[index].length - lines[index].trimStart().length | ||
multilineString = { line: lines[index], index, indentation } | ||
return multilineString | ||
} | ||
|
||
if (lines[index].trimStart().startsWith('STRING')) { | ||
multilineString = {} | ||
return multilineString | ||
} | ||
|
||
if (!lines[index].endsWith('`')) { | ||
return multilineString | ||
} | ||
|
||
if (multilineString.line && lines[index].trimStart() === '`') { | ||
const indentation = lines[index].length - lines[index].trimStart().length | ||
|
||
if (indentation !== multilineString.indentation) { | ||
return multilineString | ||
} | ||
|
||
const linesAfter = [ | ||
lines[index + 1], | ||
lines[index + 2] | ||
] | ||
|
||
if (indentation === 0 && (linesAfter[0] !== '' || linesAfter[1] === '')) { | ||
console.log(`${filename} ${index + 1}`, '- There must be one blank line after each top level multiline string') | ||
return { error: true } | ||
} | ||
|
||
lines[index] = `${' '.repeat(indentation)}STRING` | ||
multilineString = {} | ||
return multilineString | ||
} | ||
|
||
const multilineStringDeclaration = ([...lines[index].matchAll(/`/g)].length % 2) !== 0 | ||
if (!multilineString.line && multilineStringDeclaration) { | ||
const linesBefore = [ | ||
lines[index - 1], | ||
lines[index - 2] | ||
] | ||
|
||
if (linesBefore[0] !== undefined) { | ||
if (!lines[index].startsWith(' ')) { | ||
if (linesBefore[0] !== '' || linesBefore[1] === '') { | ||
console.log(`${filename} ${index + 1}`, '- There must be one blank line before each top level multiline string') | ||
return { error: true } | ||
} | ||
} | ||
} | ||
|
||
lines[index] = `${lines[index].slice(0, -1)}<<<STRING` | ||
const indentation = lines[index].length - lines[index].trimStart().length | ||
multilineString = { line: lines[index], index, indentation } | ||
} | ||
|
||
return multilineString | ||
} |
Oops, something went wrong.