Created
June 1, 2016 14:04
-
-
Save jrencz/0390f4c0ba51a271e5db894bc7dc0234 to your computer and use it in GitHub Desktop.
Lodash: merge property paths given as strings or arrays into one
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
/** | |
* @param {...(string|Array)} paths | |
* | |
* @example | |
* > mergePaths('a.b.c', 'd'); | |
* // ['a', 'b', 'c', 'd'] | |
* | |
* > mergePaths('a.b.c', ['d']); | |
* // ['a', 'b', 'c', 'd'] | |
* | |
* > mergePaths(['a', 'b', 'c'], ['d']); | |
* // ['a', 'b', 'c', 'd'] | |
* | |
* > mergePaths(['a', 'b', 'c'], 'd'); | |
* // ['a', 'b', 'c', 'd'] | |
* | |
* @returns {Array} | |
*/ | |
const mergePaths = (...paths) => _.flatMap(paths, _.toPath); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment