-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from jy95/support_custom_separator
Support custom separator
- Loading branch information
Showing
28 changed files
with
544 additions
and
42 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,13 @@ | ||
const KEYSEPARATOR_CHECK = async (argv: any) => { | ||
let keySeparator = argv.keySeparator as any; | ||
let check = [ | ||
() => keySeparator.length !== 1, | ||
() => keySeparator === true, | ||
].some((pred) => pred()); | ||
if (check) { | ||
return new Error(`Option keySeparator should be a not-empty char or false`); | ||
} else { | ||
return true; | ||
} | ||
}; | ||
export default KEYSEPARATOR_CHECK; |
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
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
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
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
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,18 @@ | ||
// lodash methods | ||
import get from 'lodash/get'; | ||
|
||
// "Enhance" Lodash get, to deal with custom separator | ||
export default function enhancedGet( | ||
obj: any, | ||
key: string, | ||
keySeparator: string | false | ||
) { | ||
// compute path that use dot (or custom) separator + square brack notation | ||
let path = keySeparator | ||
? key | ||
// handle square brack notation - eg: a[10] should be translated as a.10 | ||
.replace(/\[(\d+)\]/g, `${keySeparator}$1`) | ||
.split(keySeparator) | ||
: [key]; | ||
return get(obj, path); | ||
} |
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,19 @@ | ||
// lodash methods | ||
import set from 'lodash/set'; | ||
|
||
// "Enhance" Lodash set, to deal with custom separator | ||
export default function enhancedSet( | ||
obj: any, | ||
key: string, | ||
val: any, | ||
keySeparator: string | false | ||
) { | ||
// compute path that use dot (or custom) separator + square brack notation | ||
let path = keySeparator | ||
? key | ||
// handle square brack notation - eg: a[10] should be translated as a.10 | ||
.replace(/\[(\d+)\]/g, `${keySeparator}$1`) | ||
.split(keySeparator) | ||
: [key]; | ||
return set(obj, path, val); | ||
} |
Oops, something went wrong.