diff --git a/src/core/path-translator.js b/src/core/path-translator.js deleted file mode 100644 index 4d1ed27b..00000000 --- a/src/core/path-translator.js +++ /dev/null @@ -1,67 +0,0 @@ -import get from "lodash/get" - -export function transformPathToArray(property, jsSpec) { - if(property.slice(0,9) === "instance.") { - var str = property.slice(9) - } else { // eslint-disable-next-line no-redeclare - var str = property - } - - var pathArr = [] - - str - .split(".") - .map(item => { - // "key[0]" becomes ["key", "0"] - if(item.includes("[")) { - let index = parseInt(item.match(/\[(.*)\]/)[1]) - let keyName = item.slice(0, item.indexOf("[")) - return [keyName, index.toString()] - } else { - return item - } - }) - .reduce(function(a, b) { - // flatten! - return a.concat(b) - }, []) - .concat([""]) // add an empty item into the array, so we don't get stuck with something in our buffer below - .reduce((buffer, curr) => { - let obj = pathArr.length ? get(jsSpec, pathArr) : jsSpec - - if(get(obj, makeAccessArray(buffer, curr))) { - if(buffer.length) { - pathArr.push(buffer) - } - if(curr.length) { - pathArr.push(curr) - } - return "" - } else { - // attach key to buffer - return `${buffer}${buffer.length ? "." : ""}${curr}` - } - }, "") - - if(typeof get(jsSpec, pathArr) !== "undefined") { - return pathArr - } else { - // if our path is not correct (there is no value at the path), - // return null - return null - } -} - -function makeAccessArray(buffer, curr) { - let arr = [] - - if(buffer.length) { - arr.push(buffer) - } - - if(curr.length) { - arr.push(curr) - } - - return arr -} diff --git a/src/core/plugins/util/index.js b/src/core/plugins/util/index.js index 57e163f4..033288a6 100644 --- a/src/core/plugins/util/index.js +++ b/src/core/plugins/util/index.js @@ -1,8 +1,7 @@ import { shallowEqualKeys } from "core/utils" -import { transformPathToArray } from "core/path-translator" export default function() { return { - fn: { shallowEqualKeys, transformPathToArray } + fn: { shallowEqualKeys } } }