cascade-extend 1.0.0 → 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
@@ -1,7 +1,155 @@
1
1
  /******/ (() => { // webpackBootstrap
2
2
  /******/ "use strict";
3
- /******/ // The require scope
4
- /******/ var __webpack_require__ = {};
3
+ /******/ var __webpack_modules__ = ({
4
+
5
+ /***/ 381:
6
+ /***/ ((module) => {
7
+
8
+
9
+
10
+ var hasOwn = Object.prototype.hasOwnProperty;
11
+ var toStr = Object.prototype.toString;
12
+ var defineProperty = Object.defineProperty;
13
+ var gOPD = Object.getOwnPropertyDescriptor;
14
+
15
+ var isArray = function isArray(arr) {
16
+ if (typeof Array.isArray === 'function') {
17
+ return Array.isArray(arr);
18
+ }
19
+
20
+ return toStr.call(arr) === '[object Array]';
21
+ };
22
+
23
+ var isPlainObject = function isPlainObject(obj) {
24
+ if (!obj || toStr.call(obj) !== '[object Object]') {
25
+ return false;
26
+ }
27
+
28
+ var hasOwnConstructor = hasOwn.call(obj, 'constructor');
29
+ var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');
30
+ // Not own constructor property must be Object
31
+ if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
32
+ return false;
33
+ }
34
+
35
+ // Own properties are enumerated firstly, so to speed up, if last one is own, then all properties are own.
36
+ var key;
37
+ for (key in obj) { /**/ }
38
+
39
+ return typeof key === 'undefined' || hasOwn.call(obj, key);
40
+ };
41
+
42
+ // If name is '__proto__', and Object.defineProperty is available, define __proto__ as an own property on target
43
+ var setProperty = function setProperty(target, options) {
44
+ if (defineProperty && options.name === '__proto__') {
45
+ defineProperty(target, options.name, {
46
+ enumerable: true,
47
+ configurable: true,
48
+ value: options.newValue,
49
+ writable: true
50
+ });
51
+ } else {
52
+ // eslint-disable-next-line no-param-reassign
53
+ target[options.name] = options.newValue;
54
+ }
55
+ };
56
+
57
+ // Return undefined instead of __proto__ if '__proto__' is not an own property
58
+ var getProperty = function getProperty(obj, name) {
59
+ if (name === '__proto__') {
60
+ if (!hasOwn.call(obj, name)) {
61
+ return void 0;
62
+ } else if (gOPD) {
63
+ // In early versions of node, obj['__proto__'] is buggy when obj has __proto__ as an own property. Object.getOwnPropertyDescriptor() works.
64
+ return gOPD(obj, name).value;
65
+ }
66
+ }
67
+
68
+ return obj[name];
69
+ };
70
+
71
+ module.exports = function extend() {
72
+ var options, name, src, copy, copyIsArray, clone;
73
+ var target = arguments[0];
74
+ var i = 1;
75
+ var length = arguments.length;
76
+ var deep = false;
77
+
78
+ // Handle a deep copy situation
79
+ if (typeof target === 'boolean') {
80
+ deep = target;
81
+ target = arguments[1] || {};
82
+ // skip the boolean and the target
83
+ i = 2;
84
+ }
85
+ if (target == null || (typeof target !== 'object' && typeof target !== 'function')) {
86
+ target = {};
87
+ }
88
+
89
+ for (; i < length; ++i) {
90
+ options = arguments[i];
91
+ // Only deal with non-null/undefined values
92
+ if (options != null) {
93
+ // Extend the base object
94
+ for (name in options) {
95
+ src = getProperty(target, name);
96
+ copy = getProperty(options, name);
97
+
98
+ // Prevent never-ending loop
99
+ if (target !== copy) {
100
+ // Recurse if we're merging plain objects or arrays
101
+ if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
102
+ if (copyIsArray) {
103
+ copyIsArray = false;
104
+ clone = []; //clone = src && isArray(src) ? src : [];
105
+ } else {
106
+ clone = src && isPlainObject(src) ? src : {};
107
+ }
108
+
109
+ // Never move original objects, clone them
110
+ setProperty(target, { name: name, newValue: extend(deep, clone, copy) });
111
+
112
+ // Don't bring in undefined values
113
+ } else if (typeof copy !== 'undefined') {
114
+ setProperty(target, { name: name, newValue: copy });
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }
120
+
121
+ // Return the modified object
122
+ return target;
123
+ };
124
+
125
+
126
+ /***/ })
127
+
128
+ /******/ });
129
+ /************************************************************************/
130
+ /******/ // The module cache
131
+ /******/ var __webpack_module_cache__ = {};
132
+ /******/
133
+ /******/ // The require function
134
+ /******/ function __webpack_require__(moduleId) {
135
+ /******/ // Check if module is in cache
136
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
137
+ /******/ if (cachedModule !== undefined) {
138
+ /******/ return cachedModule.exports;
139
+ /******/ }
140
+ /******/ // Create a new module (and put it into the cache)
141
+ /******/ var module = __webpack_module_cache__[moduleId] = {
142
+ /******/ // no module.id needed
143
+ /******/ // no module.loaded needed
144
+ /******/ exports: {}
145
+ /******/ };
146
+ /******/
147
+ /******/ // Execute the module function
148
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
149
+ /******/
150
+ /******/ // Return the exports of the module
151
+ /******/ return module.exports;
152
+ /******/ }
5
153
  /******/
6
154
  /************************************************************************/
7
155
  /******/ /* webpack/runtime/define property getters */
@@ -34,13 +182,17 @@
34
182
  /******/
35
183
  /************************************************************************/
36
184
  var __webpack_exports__ = {};
185
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
186
+ (() => {
37
187
  __webpack_require__.r(__webpack_exports__);
38
188
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
39
189
  /* harmony export */ "default": () => (/* binding */ cascadeExtend)
40
190
  /* harmony export */ });
191
+ /* harmony import */ var _zhennann_extend__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(381);
41
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; } } }; }
42
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); }
43
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; }
195
+
44
196
  function cascadeExtend(_ref) {
45
197
  var scope = _ref.scope,
46
198
  source = _ref.source,
@@ -51,6 +203,9 @@ function cascadeExtend(_ref) {
51
203
  });
52
204
  if (keys.length === 0) return null;
53
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
+ });
54
209
  var result = {};
55
210
  var nameLength = name.length;
56
211
  var _iterator = _createForOfIteratorHelper(keys),
@@ -59,14 +214,14 @@ function cascadeExtend(_ref) {
59
214
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
60
215
  var key = _step.value;
61
216
  if (key === name) {
62
- extend(true, result, source[key]);
217
+ _zhennann_extend__WEBPACK_IMPORTED_MODULE_0__(true, result, source[key]);
63
218
  } else {
64
219
  var parts = key.substring(nameLength + 1).split('_');
65
220
  var test = parts.every(function (part) {
66
221
  return !!scope[part];
67
222
  });
68
223
  if (test) {
69
- extend(true, result, source[key]);
224
+ _zhennann_extend__WEBPACK_IMPORTED_MODULE_0__(true, result, source[key]);
70
225
  }
71
226
  }
72
227
  }
@@ -77,6 +232,8 @@ function cascadeExtend(_ref) {
77
232
  }
78
233
  return result;
79
234
  }
235
+ })();
236
+
80
237
  module.exports = __webpack_exports__;
81
238
  /******/ })()
82
239
  ;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","mappings":";;UAAA;UACA;;;;;WCDA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;ACNe,SAASA,aAAaA,CAAAC,IAAA,EAA0B;EAAA,IAAvBC,KAAK,GAAAD,IAAA,CAALC,KAAK;IAAEC,MAAM,GAAAF,IAAA,CAANE,MAAM;IAAEC,IAAI,GAAAH,IAAA,CAAJG,IAAI;EACzD,IAAI,CAACD,MAAM,IAAI,CAACC,IAAI,EAAE,OAAO,IAAI;EACjC,IAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACF,MAAM,CAAC,CAACI,MAAM,CAAC,UAAAC,GAAG,EAAI;IAC7C,OAAOA,GAAG,KAAKJ,IAAI,IAAII,GAAG,CAACC,OAAO,CAACL,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC;EACtD,CAAC,CAAC;EACF,IAAIC,IAAI,CAACK,MAAM,KAAK,CAAC,EAAE,OAAO,IAAI;EAClC,IAAIL,IAAI,CAACK,MAAM,KAAK,CAAC,IAAIL,IAAI,CAAC,CAAC,CAAC,KAAKD,IAAI,EAAE,OAAOD,MAAM,CAACE,IAAI,CAAC,CAAC,CAAC,CAAC;EACjE,IAAMM,MAAM,GAAG,CAAC,CAAC;EACjB,IAAMC,UAAU,GAAGR,IAAI,CAACM,MAAM;EAAC,IAAAG,SAAA,GAAAC,0BAAA,CACbT,IAAI;IAAAU,KAAA;EAAA;IAAtB,KAAAF,SAAA,CAAAG,CAAA,MAAAD,KAAA,GAAAF,SAAA,CAAAI,CAAA,IAAAC,IAAA,GAAwB;MAAA,IAAbV,GAAG,GAAAO,KAAA,CAAAI,KAAA;MACZ,IAAIX,GAAG,KAAKJ,IAAI,EAAE;QAChBgB,MAAM,CAAC,IAAI,EAAET,MAAM,EAAER,MAAM,CAACK,GAAG,CAAC,CAAC;MACnC,CAAC,MAAM;QACL,IAAMa,KAAK,GAAGb,GAAG,CAACc,SAAS,CAACV,UAAU,GAAG,CAAC,CAAC,CAACW,KAAK,CAAC,GAAG,CAAC;QACtD,IAAMC,IAAI,GAAGH,KAAK,CAACI,KAAK,CAAC,UAAAC,IAAI;UAAA,OAAI,CAAC,CAACxB,KAAK,CAACwB,IAAI,CAAC;QAAA,EAAC;QAC/C,IAAIF,IAAI,EAAE;UACRJ,MAAM,CAAC,IAAI,EAAET,MAAM,EAAER,MAAM,CAACK,GAAG,CAAC,CAAC;QACnC;MACF;IACF;EAAC,SAAAmB,GAAA;IAAAd,SAAA,CAAAe,CAAA,CAAAD,GAAA;EAAA;IAAAd,SAAA,CAAAgB,CAAA;EAAA;EACD,OAAOlB,MAAM;AACf,C","sources":["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.js"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\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};","export 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":["cascadeExtend","_ref","scope","source","name","keys","Object","filter","key","indexOf","length","result","nameLength","_iterator","_createForOfIteratorHelper","_step","s","n","done","value","extend","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;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;;;;ACNsC;AAEvB,SAASC,aAAaA,CAAAC,IAAA,EAA0B;EAAA,IAAvBC,KAAK,GAAAD,IAAA,CAALC,KAAK;IAAEC,MAAM,GAAAF,IAAA,CAANE,MAAM;IAAEC,IAAI,GAAAH,IAAA,CAAJG,IAAI;EACzD,IAAI,CAACD,MAAM,IAAI,CAACC,IAAI,EAAE,OAAO,IAAI;EAEjC,IAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACF,MAAM,CAAC,CAACI,MAAM,CAAC,UAAAC,GAAG,EAAI;IAC7C,OAAOA,GAAG,KAAKJ,IAAI,IAAII,GAAG,CAACC,OAAO,CAACL,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC;EACtD,CAAC,CAAC;EACF,IAAIC,IAAI,CAACK,MAAM,KAAK,CAAC,EAAE,OAAO,IAAI;EAClC,IAAIL,IAAI,CAACK,MAAM,KAAK,CAAC,IAAIL,IAAI,CAAC,CAAC,CAAC,KAAKD,IAAI,EAAE,OAAOD,MAAM,CAACE,IAAI,CAAC,CAAC,CAAC,CAAC;EAEjEA,IAAI,CAACM,IAAI,CAAC,UAACC,CAAC,EAAEC,CAAC,EAAK;IAClB,OAAOD,CAAC,CAACE,KAAK,CAAC,GAAG,CAAC,CAACJ,MAAM,GAAGG,CAAC,CAACC,KAAK,CAAC,GAAG,CAAC,CAACJ,MAAM;EAClD,CAAC,CAAC;EAEF,IAAMK,MAAM,GAAG,CAAC,CAAC;EACjB,IAAMC,UAAU,GAAGZ,IAAI,CAACM,MAAM;EAAC,IAAAO,SAAA,GAAAC,0BAAA,CACbb,IAAI;IAAAc,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.0",
3
+ "version": "1.0.2",
4
4
  "description": "cascade-extend",
5
5
  "main": "dist/index.js",
6
6
  "publishConfig": {
@@ -1,10 +1,18 @@
1
+ import extend from '@zhennann/extend';
2
+
1
3
  export default function cascadeExtend({ scope, source, name }) {
2
4
  if (!source || !name) return null;
5
+ // filter
3
6
  const keys = Object.keys(source).filter(key => {
4
7
  return key === name || key.indexOf(name + '_') === 0
5
8
  });
6
9
  if (keys.length === 0) return null;
7
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
8
16
  const result = {};
9
17
  const nameLength = name.length;
10
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);