Skip to content

Commit

Permalink
feat: Support options conditions strict value
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed May 14, 2024
1 parent f8cfe8b commit d11e6c0
Show file tree
Hide file tree
Showing 11 changed files with 393 additions and 237 deletions.
9 changes: 9 additions & 0 deletions src/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@ module.exports = {
'@typescript-eslint/no-namespace': [1, {allowDeclarations: true}],
},
},
{
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
project: ['./tsconfig.transform.json', './tsconfig.json'],
tsconfigRootDir: __dirname + '/../',
},
}
],
};
21 changes: 14 additions & 7 deletions src/transform/getObject.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
export = function getObject(path: string, obj: Object) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return path.split('.').reduce((acc: any | undefined, item) => {
if (!acc || !Object.getOwnPropertyNames(acc).includes(item)) {
return undefined;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export = function getObject(path: string, obj: Record<string, any>, fallback?: any) {
const queue = path.split('.');

let box = obj;
while (queue.length) {
const step = queue.shift() as string;

if (!Object.prototype.hasOwnProperty.call(box, step)) {
return fallback || undefined;
}

return acc[item];
}, obj);
box = box[step];
}

return box;
};
Loading

0 comments on commit d11e6c0

Please sign in to comment.