UNPKG

1.94 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
9
10function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
12function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
14function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
15
16function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
17
18function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
20/**
21 * Get initial key from dot notation path
22 * @description returns first key defined in dot notation and the remaining path
23 * @param {string} value
24 * @returns {[string, string | undefined]} - returns key, remaining dot notation path and isArray,
25 */
26var getKey = function getKey(value) {
27 var _value$split$filter = value.split(getKey.regex).filter(Boolean),
28 _value$split$filter2 = _toArray(_value$split$filter),
29 current = _value$split$filter2[0],
30 remaining = _value$split$filter2.slice(1);
31
32 return [current, remaining.length ? remaining.join('.') : undefined];
33};
34
35getKey.regex = /\.|(\[[^\]]*\])|(\[[-]*\d*\])/;
36var _default = getKey;
37exports.default = _default;
\No newline at end of file