cascade-extend 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ function resolve(dir) {
8
8
 
9
9
  module.exports = {
10
10
  entry: {
11
- index: resolve('src/main.js'),
11
+ index: resolve('src/main.mjs'),
12
12
  },
13
13
  output: {
14
14
  path: config.build.assetsRoot,
@@ -48,6 +48,11 @@ module.exports = {
48
48
  loader: 'babel-loader',
49
49
  include: [resolve('src')],
50
50
  },
51
+ {
52
+ test: /\.mjs$/,
53
+ loader: 'babel-loader',
54
+ include: [resolve('src')],
55
+ },
51
56
  {
52
57
  test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
53
58
  loader: 'url-loader',
package/dist/index.js CHANGED
@@ -152,18 +152,6 @@ module.exports = function extend() {
152
152
  /******/ }
153
153
  /******/
154
154
  /************************************************************************/
155
- /******/ /* webpack/runtime/compat get default export */
156
- /******/ (() => {
157
- /******/ // getDefaultExport function for compatibility with non-harmony modules
158
- /******/ __webpack_require__.n = (module) => {
159
- /******/ var getter = module && module.__esModule ?
160
- /******/ () => (module['default']) :
161
- /******/ () => (module);
162
- /******/ __webpack_require__.d(getter, { a: getter });
163
- /******/ return getter;
164
- /******/ };
165
- /******/ })();
166
- /******/
167
155
  /******/ /* webpack/runtime/define property getters */
168
156
  /******/ (() => {
169
157
  /******/ // define getter functions for harmony exports
@@ -201,7 +189,6 @@ __webpack_require__.r(__webpack_exports__);
201
189
  /* harmony export */ "default": () => (/* binding */ cascadeExtend)
202
190
  /* harmony export */ });
203
191
  /* harmony import */ var _zhennann_extend__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(381);
204
- /* harmony import */ var _zhennann_extend__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_zhennann_extend__WEBPACK_IMPORTED_MODULE_0__);
205
192
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
206
193
  function _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); }
207
194
  function _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; }
@@ -216,6 +203,9 @@ function cascadeExtend(_ref) {
216
203
  });
217
204
  if (keys.length === 0) return null;
218
205
  if (keys.length === 1 && keys[0] === name) return source[keys[0]];
206
+ keys.sort(function (a, b) {
207
+ return a.split('_').length - b.split('_').length;
208
+ });
219
209
  var result = {};
220
210
  var nameLength = name.length;
221
211
  var _iterator = _createForOfIteratorHelper(keys),
@@ -224,14 +214,14 @@ function cascadeExtend(_ref) {
224
214
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
225
215
  var key = _step.value;
226
216
  if (key === name) {
227
- _zhennann_extend__WEBPACK_IMPORTED_MODULE_0___default()(true, result, source[key]);
217
+ _zhennann_extend__WEBPACK_IMPORTED_MODULE_0__(true, result, source[key]);
228
218
  } else {
229
219
  var parts = key.substring(nameLength + 1).split('_');
230
220
  var test = parts.every(function (part) {
231
221
  return !!scope[part];
232
222
  });
233
223
  if (test) {
234
- _zhennann_extend__WEBPACK_IMPORTED_MODULE_0___default()(true, result, source[key]);
224
+ _zhennann_extend__WEBPACK_IMPORTED_MODULE_0__(true, result, source[key]);
235
225
  }
236
226
  }
237
227
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","mappings":";;;;;;;AAAa;;AAEb;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,oBAAoB;;AAEpB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH,GAAG;AACH;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,QAAQ,YAAY;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB;AACnB,QAAQ;AACR;AACA;;AAEA;AACA,4BAA4B,iDAAiD;;AAE7E;AACA,OAAO;AACP,4BAA4B,4BAA4B;AACxD;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;;;;;;UCnHA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAu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G,CAAC;QACtD,IAAMC,IAAI,GAAGH,KAAK,CAACI,KAAK,CAAC,UAAAC,IAAI;UAAA,OAAI,CAAC,CAACvB,KAAK,CAACuB,IAAI,CAAC;QAAA,EAAC;QAC/C,IAAIF,IAAI,EAAE;UACRxB,uDAAM,CAAC,IAAI,EAAEY,MAAM,EAAER,MAAM,CAACK,GAAG,CAAC,CAAC;QACnC;MACF;IACF;EAAC,SAAAkB,GAAA;IAAAb,SAAA,CAAAc,CAAA,CAAAD,GAAA;EAAA;IAAAb,SAAA,CAAAe,CAAA;EAAA;EACD,OAAOjB,MAAM;AACf,C","sources":["webpack://cascade-extend/./node_modules/@zhennann/extend/index.js","webpack://cascade-extend/webpack/bootstrap","webpack://cascade-extend/webpack/runtime/compat get default export","webpack://cascade-extend/webpack/runtime/define property getters","webpack://cascade-extend/webpack/runtime/hasOwnProperty shorthand","webpack://cascade-extend/webpack/runtime/make namespace object","webpack://cascade-extend/./src/main.js"],"sourcesContent":["'use strict';\n\nvar hasOwn = Object.prototype.hasOwnProperty;\nvar toStr = Object.prototype.toString;\nvar defineProperty = Object.defineProperty;\nvar gOPD = Object.getOwnPropertyDescriptor;\n\nvar isArray = function isArray(arr) {\n\tif (typeof Array.isArray === 'function') {\n\t\treturn Array.isArray(arr);\n\t}\n\n\treturn toStr.call(arr) === '[object Array]';\n};\n\nvar isPlainObject = function isPlainObject(obj) {\n\tif (!obj || toStr.call(obj) !== '[object Object]') {\n\t\treturn false;\n\t}\n\n\tvar hasOwnConstructor = hasOwn.call(obj, 'constructor');\n\tvar hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');\n\t// Not own constructor property must be Object\n\tif (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {\n\t\treturn false;\n\t}\n\n\t// Own properties are enumerated firstly, so to speed up, if last one is own, then all properties are own.\n\tvar key;\n\tfor (key in obj) { /**/ }\n\n\treturn typeof key === 'undefined' || hasOwn.call(obj, key);\n};\n\n// If name is '__proto__', and Object.defineProperty is available, define __proto__ as an own property on target\nvar setProperty = function setProperty(target, options) {\n\tif (defineProperty && options.name === '__proto__') {\n\t\tdefineProperty(target, options.name, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t\tvalue: options.newValue,\n\t\t\twritable: true\n\t\t});\n\t} else {\n\t\t// eslint-disable-next-line no-param-reassign\n\t\ttarget[options.name] = options.newValue;\n\t}\n};\n\n// Return undefined instead of __proto__ if '__proto__' is not an own property\nvar getProperty = function getProperty(obj, name) {\n\tif (name === '__proto__') {\n\t\tif (!hasOwn.call(obj, name)) {\n\t\t\treturn void 0;\n\t\t} else if (gOPD) {\n\t\t\t// In early versions of node, obj['__proto__'] is buggy when obj has __proto__ as an own property. Object.getOwnPropertyDescriptor() works.\n\t\t\treturn gOPD(obj, name).value;\n\t\t}\n\t}\n\n\treturn obj[name];\n};\n\nmodule.exports = function extend() {\n\tvar options, name, src, copy, copyIsArray, clone;\n\tvar target = arguments[0];\n\tvar i = 1;\n\tvar length = arguments.length;\n\tvar deep = false;\n\n\t// Handle a deep copy situation\n\tif (typeof target === 'boolean') {\n\t\tdeep = target;\n\t\ttarget = arguments[1] || {};\n\t\t// skip the boolean and the target\n\t\ti = 2;\n\t}\n\tif (target == null || (typeof target !== 'object' && typeof target !== 'function')) {\n\t\ttarget = {};\n\t}\n\n\tfor (; i < length; ++i) {\n\t\toptions = arguments[i];\n\t\t// Only deal with non-null/undefined values\n\t\tif (options != null) {\n\t\t\t// Extend the base object\n\t\t\tfor (name in options) {\n\t\t\t\tsrc = getProperty(target, name);\n\t\t\t\tcopy = getProperty(options, name);\n\n\t\t\t\t// Prevent never-ending loop\n\t\t\t\tif (target !== copy) {\n\t\t\t\t\t// Recurse if we're merging plain objects or arrays\n\t\t\t\t\tif (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {\n\t\t\t\t\t\tif (copyIsArray) {\n\t\t\t\t\t\t\tcopyIsArray = false;\n\t\t\t\t\t\t\tclone = []; //clone = src && isArray(src) ? src : [];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tclone = src && isPlainObject(src) ? src : {};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Never move original objects, clone them\n\t\t\t\t\t\tsetProperty(target, { name: name, newValue: extend(deep, clone, copy) });\n\n\t\t\t\t\t// Don't bring in undefined values\n\t\t\t\t\t} else if (typeof copy !== 'undefined') {\n\t\t\t\t\t\tsetProperty(target, { name: name, newValue: copy });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Return the modified object\n\treturn target;\n};\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import extend from '@zhennann/extend';\n\nexport default function cascadeExtend({ scope, source, name }) {\n if (!source || !name) return null;\n const keys = Object.keys(source).filter(key => {\n return key === name || key.indexOf(name + '_') === 0\n });\n if (keys.length === 0) return null;\n if (keys.length === 1 && keys[0] === name) return source[keys[0]];\n const result = {};\n const nameLength = name.length;\n for (const key of keys) {\n if (key === name) {\n extend(true, result, source[key]);\n } else {\n const parts = key.substring(nameLength + 1).split('_');\n const test = parts.every(part => !!scope[part]);\n if (test) {\n extend(true, result, source[key]);\n }\n }\n }\n return result;\n}"],"names":["extend","cascadeExtend","_ref","scope","source","name","keys","Object","filter","key","indexOf","length","result","nameLength","_iterator","_createForOfIteratorHelper","_step","s","n","done","value","parts","substring","split","test","every","part","err","e","f"],"sourceRoot":""}
1
+ {"version":3,"file":"index.js","mappings":";;;;;;;AAAa;;AAEb;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,oBAAoB;;AAEpB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH,GAAG;AACH;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,QAAQ,YAAY;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB;AACnB,QAAQ;AACR;AACA;;AAEA;AACA,4BAA4B,iDAAiD;;AAE7E;AACA,OAAO;AACP,4BAA4B,4BAA4B;AACxD;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;;;;;;UCnHA;UACA;;UAEA;UACA;UAC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AAAc,KAAA;EAAA;IAAtB,KAAAF,SAAA,CAAAG,CAAA,MAAAD,KAAA,GAAAF,SAAA,CAAAI,CAAA,IAAAC,IAAA,GAAwB;MAAA,IAAbd,GAAG,GAAAW,KAAA,CAAAI,KAAA;MACZ,IAAIf,GAAG,KAAKJ,IAAI,EAAE;QAChBL,6CAAM,CAAC,IAAI,EAAEgB,MAAM,EAAEZ,MAAM,CAACK,GAAG,CAAC,CAAC;MACnC,CAAC,MAAM;QACL,IAAMgB,KAAK,GAAGhB,GAAG,CAACiB,SAAS,CAACT,UAAU,GAAG,CAAC,CAAC,CAACF,KAAK,CAAC,GAAG,CAAC;QACtD,IAAMY,IAAI,GAAGF,KAAK,CAACG,KAAK,CAAC,UAAAC,IAAI;UAAA,OAAI,CAAC,CAAC1B,KAAK,CAAC0B,IAAI,CAAC;QAAA,EAAC;QAC/C,IAAIF,IAAI,EAAE;UACR3B,6CAAM,CAAC,IAAI,EAAEgB,MAAM,EAAEZ,MAAM,CAACK,GAAG,CAAC,CAAC;QACnC;MACF;IACF;EAAC,SAAAqB,GAAA;IAAAZ,SAAA,CAAAa,CAAA,CAAAD,GAAA;EAAA;IAAAZ,SAAA,CAAAc,CAAA;EAAA;EACD,OAAOhB,MAAM;AACf,C","sources":["webpack://cascade-extend/./node_modules/@zhennann/extend/index.js","webpack://cascade-extend/webpack/bootstrap","webpack://cascade-extend/webpack/runtime/define property getters","webpack://cascade-extend/webpack/runtime/hasOwnProperty shorthand","webpack://cascade-extend/webpack/runtime/make namespace object","webpack://cascade-extend/./src/main.mjs"],"sourcesContent":["'use strict';\n\nvar hasOwn = Object.prototype.hasOwnProperty;\nvar toStr = Object.prototype.toString;\nvar defineProperty = Object.defineProperty;\nvar gOPD = Object.getOwnPropertyDescriptor;\n\nvar isArray = function isArray(arr) {\n\tif (typeof Array.isArray === 'function') {\n\t\treturn Array.isArray(arr);\n\t}\n\n\treturn toStr.call(arr) === '[object Array]';\n};\n\nvar isPlainObject = function isPlainObject(obj) {\n\tif (!obj || toStr.call(obj) !== '[object Object]') {\n\t\treturn false;\n\t}\n\n\tvar hasOwnConstructor = hasOwn.call(obj, 'constructor');\n\tvar hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');\n\t// Not own constructor property must be Object\n\tif (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {\n\t\treturn false;\n\t}\n\n\t// Own properties are enumerated firstly, so to speed up, if last one is own, then all properties are own.\n\tvar key;\n\tfor (key in obj) { /**/ }\n\n\treturn typeof key === 'undefined' || hasOwn.call(obj, key);\n};\n\n// If name is '__proto__', and Object.defineProperty is available, define __proto__ as an own property on target\nvar setProperty = function setProperty(target, options) {\n\tif (defineProperty && options.name === '__proto__') {\n\t\tdefineProperty(target, options.name, {\n\t\t\tenumerable: true,\n\t\t\tconfigurable: true,\n\t\t\tvalue: options.newValue,\n\t\t\twritable: true\n\t\t});\n\t} else {\n\t\t// eslint-disable-next-line no-param-reassign\n\t\ttarget[options.name] = options.newValue;\n\t}\n};\n\n// Return undefined instead of __proto__ if '__proto__' is not an own property\nvar getProperty = function getProperty(obj, name) {\n\tif (name === '__proto__') {\n\t\tif (!hasOwn.call(obj, name)) {\n\t\t\treturn void 0;\n\t\t} else if (gOPD) {\n\t\t\t// In early versions of node, obj['__proto__'] is buggy when obj has __proto__ as an own property. Object.getOwnPropertyDescriptor() works.\n\t\t\treturn gOPD(obj, name).value;\n\t\t}\n\t}\n\n\treturn obj[name];\n};\n\nmodule.exports = function extend() {\n\tvar options, name, src, copy, copyIsArray, clone;\n\tvar target = arguments[0];\n\tvar i = 1;\n\tvar length = arguments.length;\n\tvar deep = false;\n\n\t// Handle a deep copy situation\n\tif (typeof target === 'boolean') {\n\t\tdeep = target;\n\t\ttarget = arguments[1] || {};\n\t\t// skip the boolean and the target\n\t\ti = 2;\n\t}\n\tif (target == null || (typeof target !== 'object' && typeof target !== 'function')) {\n\t\ttarget = {};\n\t}\n\n\tfor (; i < length; ++i) {\n\t\toptions = arguments[i];\n\t\t// Only deal with non-null/undefined values\n\t\tif (options != null) {\n\t\t\t// Extend the base object\n\t\t\tfor (name in options) {\n\t\t\t\tsrc = getProperty(target, name);\n\t\t\t\tcopy = getProperty(options, name);\n\n\t\t\t\t// Prevent never-ending loop\n\t\t\t\tif (target !== copy) {\n\t\t\t\t\t// Recurse if we're merging plain objects or arrays\n\t\t\t\t\tif (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {\n\t\t\t\t\t\tif (copyIsArray) {\n\t\t\t\t\t\t\tcopyIsArray = false;\n\t\t\t\t\t\t\tclone = []; //clone = src && isArray(src) ? src : [];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tclone = src && isPlainObject(src) ? src : {};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Never move original objects, clone them\n\t\t\t\t\t\tsetProperty(target, { name: name, newValue: extend(deep, clone, copy) });\n\n\t\t\t\t\t// Don't bring in undefined values\n\t\t\t\t\t} else if (typeof copy !== 'undefined') {\n\t\t\t\t\t\tsetProperty(target, { name: name, newValue: copy });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Return the modified object\n\treturn target;\n};\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import extend from '@zhennann/extend';\n\nexport default function cascadeExtend({ scope, source, name }) {\n if (!source || !name) return null;\n // filter\n const keys = Object.keys(source).filter(key => {\n return key === name || key.indexOf(name + '_') === 0\n });\n if (keys.length === 0) return null;\n if (keys.length === 1 && keys[0] === name) return source[keys[0]];\n // sort\n keys.sort((a, b) => {\n return a.split('_').length - b.split('_').length;\n })\n // extend\n const result = {};\n const nameLength = name.length;\n for (const key of keys) {\n if (key === name) {\n extend(true, result, source[key]);\n } else {\n const parts = key.substring(nameLength + 1).split('_');\n const test = parts.every(part => !!scope[part]);\n if (test) {\n extend(true, result, source[key]);\n }\n }\n }\n return result;\n}"],"names":["extend","cascadeExtend","_ref","scope","source","name","keys","Object","filter","key","indexOf","length","sort","a","b","split","result","nameLength","_iterator","_createForOfIteratorHelper","_step","s","n","done","value","parts","substring","test","every","part","err","e","f"],"sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cascade-extend",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "cascade-extend",
5
5
  "main": "dist/index.js",
6
6
  "publishConfig": {
@@ -2,11 +2,17 @@ import extend from '@zhennann/extend';
2
2
 
3
3
  export default function cascadeExtend({ scope, source, name }) {
4
4
  if (!source || !name) return null;
5
+ // filter
5
6
  const keys = Object.keys(source).filter(key => {
6
7
  return key === name || key.indexOf(name + '_') === 0
7
8
  });
8
9
  if (keys.length === 0) return null;
9
10
  if (keys.length === 1 && keys[0] === name) return source[keys[0]];
11
+ // sort
12
+ keys.sort((a, b) => {
13
+ return a.split('_').length - b.split('_').length;
14
+ })
15
+ // extend
10
16
  const result = {};
11
17
  const nameLength = name.length;
12
18
  for (const key of keys) {
package/test/test.mjs ADDED
@@ -0,0 +1,28 @@
1
+ import cascadeExtend from '../src/main.mjs';
2
+
3
+ const scope = {
4
+ group: true,
5
+ mobile: true,
6
+ small: true,
7
+ view: true,
8
+ }
9
+ const source = {
10
+ ebParams_mobile: {
11
+ size: 'small',
12
+ scene: 'mobile',
13
+ group: true,
14
+ },
15
+ ebParams: {
16
+ size: 'large',
17
+ scene: 'pc',
18
+ name: 'yang',
19
+ },
20
+ ebParams_pc: {
21
+ size: 'large',
22
+ scene: 'pc',
23
+ name: 'kevin',
24
+ group: true,
25
+ },
26
+ }
27
+ const res = cascadeExtend({ scope, source, name: 'ebParams' });
28
+ console.log(res);