UNPKG

@talend/react-components

Version:
45 lines (42 loc) 1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = formatJSONPath; exports.formatKey = formatKey; exports.readJsonKeys = readJsonKeys; /** * Format the key according to the type * @param {string} key * @param {string} type */ function formatKey(key, type) { if (type === 'array') { return `[${key}]`; } return `['${key}']`; } /** * Return a string from the keys * @param {array} keys * @param {string} type */ function readJsonKeys(keys, type) { return keys.reduce((acc, key) => { let newAcc = acc; newAcc += formatKey(key, type); return newAcc; }, ''); } /** * Return JSONPath notation * @param {array} keys array of key * @param {string} prefix current jsonpath * @param {string} type one of 'array' or 'object' * @return {string} jsonpath */ function formatJSONPath(keys, prefix, type) { const value = readJsonKeys(keys, type); return `${prefix}${value}`; } //# sourceMappingURL=jsonPath.js.map