@cookbook/dot-notation
Version:
Object readings and complex transformations using dot notation syntax.
11 lines • 509 B
JavaScript
import getArrayIndex from './utils/get-array-index';
import getKey from './utils/get-key';
import shallowCopy from './utils/shallow-copy';
const parseKey = (path, value) => {
const [key, remainingPath] = getKey(path);
const hasArrayNotation = getArrayIndex(key);
const compiledValue = (remainingPath ? parseKey(remainingPath, value) : shallowCopy(value));
return (hasArrayNotation ? [compiledValue] : { [key]: compiledValue });
};
export default parseKey;
//# sourceMappingURL=parse-key.js.map