-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
14 changed files
with
6,628 additions
and
13,436 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# These are supported funding model platforms | ||
|
||
github: mesqueeb | ||
patreon: # Replace with a single Patreon username | ||
open_collective: # Replace with a single Open Collective username | ||
ko_fi: # Replace with a single Ko-fi username | ||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel | ||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | ||
liberapay: # Replace with a single Liberapay username | ||
issuehunt: # Replace with a single IssueHunt username | ||
otechie: # Replace with a single Otechie username | ||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] |
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,37 @@ | ||
name: Test | ||
on: | ||
push: | ||
branches: main | ||
paths: | ||
- src/** | ||
- test/** | ||
- '*.js' | ||
- '*.ts' | ||
- '*.json' | ||
- .github/workflows/test.yml | ||
pull_request: | ||
branches: main | ||
paths: | ||
- src/** | ||
- test/** | ||
- '*.js' | ||
- '*.ts' | ||
- '*.json' | ||
- .github/workflows/test.yml | ||
concurrency: | ||
group: test-${{ github.ref }} | ||
cancel-in-progress: true | ||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
node-version: ['18', '20'] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: npm | ||
- run: npm ci | ||
- run: npm test |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
import prettier from "@cycraft/eslint/prettier" | ||
|
||
export default prettier |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,35 +1,55 @@ | ||
import { isArray, isAnyObject, isPlainObject, isNaNValue } from 'is-what'; | ||
|
||
function findAndReplace(target, find, replaceWith, config = { onlyPlainObjects: false, checkArrayValues: false }) { | ||
const _target = target; | ||
if (config.checkArrayValues && isArray(_target) && !isAnyObject(_target)) { | ||
return _target.map((value) => findAndReplace(value, find, replaceWith, config)); | ||
} | ||
if (!config.onlyPlainObjects && !isAnyObject(_target) || config.onlyPlainObjects === true && !isPlainObject(_target)) { | ||
if (_target === find || isNaNValue(_target) && isNaNValue(find)) { | ||
return replaceWith; | ||
import { isAnyObject, isArray, isNaNValue, isPlainObject } from 'is-what'; | ||
/** | ||
* Goes through an object recursively and replaces all occurences of the `find` value with `replaceWith`. Also works no non-objects. | ||
* | ||
* @export | ||
* @param target Target can be anything | ||
* @param find val to find | ||
* @param replaceWith val to replace | ||
* @param [config={onlyPlainObjects: false, checkArrayValues: false}] | ||
* @returns the target with replaced values | ||
*/ | ||
export function findAndReplace(target, find, replaceWith, config = { onlyPlainObjects: false, checkArrayValues: false }) { | ||
const _target = target; | ||
// arrays | ||
if (config.checkArrayValues && isArray(_target) && !isAnyObject(_target)) { | ||
return _target.map((value) => findAndReplace(value, find, replaceWith, config)); | ||
} | ||
return _target; | ||
} | ||
return Object.entries(target).reduce((carry, [key, val]) => { | ||
carry[key] = findAndReplace(val, find, replaceWith, config); | ||
return carry; | ||
}, {}); | ||
// non-objects | ||
if ((!config.onlyPlainObjects && !isAnyObject(_target)) || | ||
(config.onlyPlainObjects === true && !isPlainObject(_target))) { | ||
if (_target === find || (isNaNValue(_target) && isNaNValue(find))) { | ||
return replaceWith; | ||
} | ||
return _target; | ||
} | ||
// objects | ||
return Object.entries(target).reduce((carry, [key, val]) => { | ||
carry[key] = findAndReplace(val, find, replaceWith, config); | ||
return carry; | ||
}, {}); | ||
} | ||
function _findAndReplaceIf(target, checkFn, propKey, config = { onlyPlainObjects: true, checkArrayValues: false }) { | ||
const _target = checkFn(target, propKey); | ||
if (config.checkArrayValues && isArray(_target) && !isAnyObject(_target)) { | ||
return _target.map((value) => _findAndReplaceIf(value, checkFn, void 0, config)); | ||
} | ||
if (!isPlainObject(_target)) | ||
return _target; | ||
return Object.entries(_target).reduce((carry, [key, val]) => { | ||
carry[key] = _findAndReplaceIf(val, checkFn, key, config); | ||
return carry; | ||
}, {}); | ||
export function _findAndReplaceIf(target, checkFn, propKey, config = { onlyPlainObjects: true, checkArrayValues: false }) { | ||
const _target = checkFn(target, propKey); | ||
if (config.checkArrayValues && isArray(_target) && !isAnyObject(_target)) { | ||
return _target.map((value) => _findAndReplaceIf(value, checkFn, undefined, config)); | ||
} | ||
if (!isPlainObject(_target)) | ||
return _target; | ||
return Object.entries(_target).reduce((carry, [key, val]) => { | ||
carry[key] = _findAndReplaceIf(val, checkFn, key, config); | ||
return carry; | ||
}, {}); | ||
} | ||
function findAndReplaceIf(target, checkFn, config = { onlyPlainObjects: true, checkArrayValues: false }) { | ||
return _findAndReplaceIf(target, checkFn, void 0, config); | ||
/** | ||
* Goes through an object recursively and replaces all props with what's is returned in the `checkFn`. Also works on non-objects. `checkFn` is triggered on every single level of any value/object. | ||
* | ||
* @export | ||
* @param target Target can be anything | ||
* @param checkFn a function that will receive the `foundVal` | ||
* @param [config={onlyPlainObjects: true, checkArrayValues: false}] | ||
* @returns the target with replaced values | ||
*/ | ||
export function findAndReplaceIf(target, checkFn, config = { onlyPlainObjects: true, checkArrayValues: false }) { | ||
return _findAndReplaceIf(target, checkFn, undefined, config); | ||
} | ||
|
||
export { _findAndReplaceIf, findAndReplace, findAndReplaceIf }; |
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,10 @@ | ||
import config from '@cycraft/eslint/config' | ||
|
||
export default [ | ||
...config, | ||
{ | ||
rules: { | ||
'@typescript-eslint/no-explicit-any': 'warn', | ||
}, | ||
}, | ||
] |
Oops, something went wrong.