cascade-extend 1.0.2 → 1.0.4

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.
package/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016-present CabloyJS
package/README.md CHANGED
File without changes
@@ -0,0 +1,3 @@
1
+ export declare function cascadeExtendKeys(scope: object, source: object | undefined, prefix?: string, sep?: string): string[] | undefined;
2
+ export declare function cascadeExtend(scope: object, source: object | undefined, prefix?: string, sep?: string): object | undefined;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,MAAM,CAAC,EAAE,MAAM,EACf,GAAG,GAAE,MAAqB,GACzB,MAAM,EAAE,GAAG,SAAS,CAqBtB;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,MAAM,CAAC,EAAE,MAAM,EACf,GAAG,GAAE,MAAqB,GACzB,MAAM,GAAG,SAAS,CAapB"}
package/dist/index.js CHANGED
@@ -1,240 +1,52 @@
1
- /******/ (() => { // webpackBootstrap
2
- /******/ "use strict";
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
- /******/ }
153
- /******/
154
- /************************************************************************/
155
- /******/ /* webpack/runtime/define property getters */
156
- /******/ (() => {
157
- /******/ // define getter functions for harmony exports
158
- /******/ __webpack_require__.d = (exports, definition) => {
159
- /******/ for(var key in definition) {
160
- /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
161
- /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
162
- /******/ }
163
- /******/ }
164
- /******/ };
165
- /******/ })();
166
- /******/
167
- /******/ /* webpack/runtime/hasOwnProperty shorthand */
168
- /******/ (() => {
169
- /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
170
- /******/ })();
171
- /******/
172
- /******/ /* webpack/runtime/make namespace object */
173
- /******/ (() => {
174
- /******/ // define __esModule on exports
175
- /******/ __webpack_require__.r = (exports) => {
176
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
177
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
178
- /******/ }
179
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
180
- /******/ };
181
- /******/ })();
182
- /******/
183
- /************************************************************************/
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
- (() => {
187
- __webpack_require__.r(__webpack_exports__);
188
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
189
- /* harmony export */ "default": () => (/* binding */ cascadeExtend)
190
- /* harmony export */ });
191
- /* harmony import */ var _zhennann_extend__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(381);
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; } } }; }
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); }
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
-
196
- function cascadeExtend(_ref) {
197
- var scope = _ref.scope,
198
- source = _ref.source,
199
- name = _ref.name;
200
- if (!source || !name) return null;
201
- var keys = Object.keys(source).filter(function (key) {
202
- return key === name || key.indexOf(name + '_') === 0;
203
- });
204
- if (keys.length === 0) return null;
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
- });
209
- var result = {};
210
- var nameLength = name.length;
211
- var _iterator = _createForOfIteratorHelper(keys),
212
- _step;
213
- try {
214
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
215
- var key = _step.value;
216
- if (key === name) {
217
- _zhennann_extend__WEBPACK_IMPORTED_MODULE_0__(true, result, source[key]);
218
- } else {
219
- var parts = key.substring(nameLength + 1).split('_');
220
- var test = parts.every(function (part) {
221
- return !!scope[part];
222
- });
223
- if (test) {
224
- _zhennann_extend__WEBPACK_IMPORTED_MODULE_0__(true, result, source[key]);
225
- }
226
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cascadeExtend = exports.cascadeExtendKeys = void 0;
4
+ const extend_1 = require("@cabloy/extend");
5
+ const __SepDefault = '.';
6
+ function cascadeExtendKeys(scope, source, prefix, sep = __SepDefault) {
7
+ if (!source)
8
+ return undefined;
9
+ if (prefix === undefined)
10
+ prefix = '';
11
+ // filter
12
+ let keys = Object.keys(source).filter(key => {
13
+ return key === prefix || key.indexOf(prefix + sep) === 0;
14
+ });
15
+ if (keys.length === 0)
16
+ return undefined;
17
+ if (keys.length === 1 && keys[0] === prefix)
18
+ return keys;
19
+ // sort
20
+ keys.sort((a, b) => {
21
+ return a.split(sep).length - b.split(sep).length;
22
+ });
23
+ // filter
24
+ keys = keys.filter(key => {
25
+ if (key === prefix)
26
+ return true;
27
+ const parts = key.substring(prefix.length + 1).split(sep);
28
+ return parts.every(part => !!scope[part]);
29
+ });
30
+ // ok
31
+ return keys.length === 0 ? undefined : keys;
32
+ }
33
+ exports.cascadeExtendKeys = cascadeExtendKeys;
34
+ function cascadeExtend(scope, source, prefix, sep = __SepDefault) {
35
+ if (!source)
36
+ return undefined;
37
+ // keys
38
+ const keys = cascadeExtendKeys(scope, source, prefix, sep);
39
+ if (!keys)
40
+ return undefined;
41
+ // special
42
+ if (keys.length === 1)
43
+ return source[keys[0]];
44
+ // extend
45
+ const result = {};
46
+ for (const key of keys) {
47
+ (0, extend_1.extend)(true, result, source[key]);
227
48
  }
228
- } catch (err) {
229
- _iterator.e(err);
230
- } finally {
231
- _iterator.f();
232
- }
233
- return result;
49
+ return result;
234
50
  }
235
- })();
236
-
237
- module.exports = __webpack_exports__;
238
- /******/ })()
239
- ;
51
+ exports.cascadeExtend = cascadeExtend;
240
52
  //# sourceMappingURL=index.js.map
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;AAC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EA,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":""}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;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AAC,CAAC,CAAC;IACH,KAAK;IACL,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9C,CAAC;AA1BD,8CA0BC;AAED,SAAgB,aAAa,CAC3B,KAAa,EACb,MAA0B,EAC1B,MAAe,EACf,MAAc,YAAY;IAE1B,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,OAAO;IACP,MAAM,IAAI,GAAG,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3D,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5B,UAAU;IACV,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,SAAS;IACT,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAA,eAAM,EAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAlBD,sCAkBC"}
package/package.json CHANGED
@@ -1,15 +1,24 @@
1
1
  {
2
2
  "name": "cascade-extend",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "cascade-extend",
5
- "main": "dist/index.js",
6
5
  "publishConfig": {
7
6
  "access": "public"
8
7
  },
9
- "scripts": {
10
- "build": "node build/front/build.js",
11
- "preversion": "npm run build && git add ."
8
+ "exports": {
9
+ ".": {
10
+ "types": [
11
+ "./src/index.ts",
12
+ "./dist/index.d.ts"
13
+ ],
14
+ "import": "./src/index.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "./package.json": "./package.json"
12
18
  },
19
+ "files": [
20
+ "dist"
21
+ ],
13
22
  "repository": {
14
23
  "type": "git",
15
24
  "url": "git+https://github.com/zhennann/cascade-extend.git"
@@ -27,65 +36,10 @@
27
36
  },
28
37
  "homepage": "https://github.com/zhennann/cascade-extend#readme",
29
38
  "devDependencies": {
30
- "@babel/core": "^7.12.10",
31
- "@babel/eslint-parser": "^7.13.10",
32
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
33
- "@babel/plugin-transform-runtime": "^7.8.3",
34
- "@babel/preset-env": "^7.8.4",
35
- "@babel/register": "^7.8.3",
36
- "@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
37
- "@vue/babel-preset-jsx": "^1.1.2",
38
- "@zhennann/babel-generator": "^7.17.3",
39
- "@zhennann/babel-helper-wrap-function": "^7.16.8",
40
- "@zhennann/babel-plugin-transform-async-to-generator": "^7.16.8",
41
- "@zhennann/extend":"^3.0.2",
42
- "autoprefixer": "^9.7.4",
43
- "babel-eslint": "^10.1.0",
44
- "babel-loader": "^8.2.2",
45
- "babel-plugin-jsx-v-model": "^2.0.3",
46
- "babel-plugin-syntax-jsx": "^6.18.0",
47
- "bluebird": "^3.7.2",
48
- "chalk": "^3.0.0",
49
- "connect-history-api-fallback": "^1.6.0",
50
- "copy-webpack-plugin": "^7.0.0",
51
- "css-loader": "^5.0.1",
52
- "egg-born-mglob": "^3.0.1",
53
- "egg-born-mparse": "^2.1.5",
54
- "eslint": "^7.21.0",
55
- "eslint-config-egg-born": "^1.1.2",
56
- "eslint-config-prettier": "^8.3.0",
57
- "eslint-plugin-jsdoc": "^37.9.1",
58
- "eslint-plugin-node": "^11.1.0",
59
- "eslint-plugin-prettier": "^3.4.0",
60
- "eslint-plugin-vue": "^7.17.0",
61
- "eventsource-polyfill": "^0.9.6",
62
- "express": "^4.15.4",
63
- "extend2": "^1.0.1",
64
- "file-loader": "^6.2.0",
65
- "fs-extra": "^10.1.0",
66
- "function-bind": "^1.1.1",
67
- "globby": "^11.0.0",
68
- "html-webpack-plugin": "^5.3.1",
69
- "http-proxy-middleware": "^1.0.6",
70
- "is-type-of": "^1.2.0",
71
- "less": "^3.13.0",
72
- "less-loader": "^7.1.0",
73
- "mini-css-extract-plugin": "^1.3.3",
74
- "module-alias": "^2.2.2",
75
- "open": "^7.0.2",
76
- "ora": "^4.0.3",
77
- "prettier": "2.3.2",
78
- "rimraf": "^3.0.2",
79
- "semver": "^7.3.7",
80
- "url-loader": "^4.1.1",
81
- "vue-eslint-parser": "^7.10.0",
82
- "vue-loader": "^15.9.5",
83
- "vue-style-loader": "^4.1.2",
84
- "vue-template-compiler": "^2.6.14",
85
- "webpack": "^5.61.0",
86
- "webpack-bundle-analyzer": "^4.2.0",
87
- "webpack-dev-middleware": "^4.0.2",
88
- "webpack-hot-middleware": "^2.25.0",
89
- "webpack-merge": "^5.7.0"
90
- }
91
- }
39
+ "@cabloy/lint": "^4.0.5"
40
+ },
41
+ "dependencies": {
42
+ "@cabloy/extend": "^3.0.5"
43
+ },
44
+ "scripts": {}
45
+ }
package/babel.config.js DELETED
@@ -1,13 +0,0 @@
1
- module.exports = {
2
- presets: [
3
- [
4
- '@babel/preset-env',
5
- {
6
- modules: false,
7
- useBuiltIns: false,
8
- },
9
- ],
10
- ],
11
- plugins: ['@babel/plugin-syntax-dynamic-import'],
12
- comments: false,
13
- };
package/build/config.js DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- productionSourceMap: true,
3
- uglify: false,
4
- };
@@ -1,41 +0,0 @@
1
- process.env.NODE_ENV = 'production';
2
-
3
- const ora = require('ora');
4
- const rm = require('rimraf');
5
- const path = require('path');
6
- const chalk = require('chalk');
7
- const webpack = require('webpack');
8
- const config = require('./config.js');
9
- const webpackConfig = require('./webpack.prod.conf');
10
-
11
- const spinner = ora('building for production...');
12
- spinner.start();
13
-
14
- rm(path.join(config.build.assetsRoot, 'index.*'), err => {
15
- if (err) throw err;
16
-
17
- rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18
- if (err) throw err;
19
- webpack(webpackConfig, function (err, stats) {
20
- spinner.stop();
21
- if (err) throw err;
22
- process.stdout.write(
23
- stats.toString({
24
- colors: true,
25
- modules: false,
26
- children: false,
27
- chunks: false,
28
- chunkModules: false,
29
- }) + '\n\n'
30
- );
31
-
32
- console.log(chalk.cyan(' Build complete.\n'));
33
- console.log(
34
- chalk.yellow(
35
- ' Tip: built files are meant to be served over an HTTP server.\n' +
36
- " Opening index.html over file:// won't work.\n"
37
- )
38
- );
39
- });
40
- });
41
- });
@@ -1,19 +0,0 @@
1
- const path = require('path');
2
- const { merge } = require('webpack-merge');
3
- const config = require('../config.js');
4
-
5
- module.exports = merge(
6
- {
7
- build: {
8
- env: {
9
- NODE_ENV: '"production"',
10
- },
11
- assetsRoot: path.resolve(__dirname, '../../dist'),
12
- assetsSubDirectory: 'static',
13
- assetsPublicPath: '',
14
- productionSourceMap: true,
15
- uglify: false,
16
- },
17
- },
18
- { build: config }
19
- );
@@ -1,64 +0,0 @@
1
- const path = require('path');
2
- const config = require('./config.js');
3
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
4
-
5
- exports.assetsPath = function (_path) {
6
- return path.join(config.build.assetsSubDirectory, _path);
7
- };
8
-
9
- exports.cssLoaders = function (options) {
10
- options = options || {};
11
-
12
- const cssLoader = {
13
- loader: 'css-loader',
14
- options: {
15
- minimize: process.env.NODE_ENV === 'production',
16
- sourceMap: options.sourceMap,
17
- },
18
- };
19
-
20
- // generate loader string to be used with extract text plugin
21
- function generateLoaders(loader, loaderOptions) {
22
- const loaders = [cssLoader];
23
- if (loader) {
24
- loaders.push({
25
- loader: loader + '-loader',
26
- options: Object.assign({}, loaderOptions, {
27
- sourceMap: options.sourceMap,
28
- }),
29
- });
30
- }
31
-
32
- // Extract CSS when that option is specified
33
- // (which is the case during production build)
34
- if (options.extract) {
35
- return [MiniCssExtractPlugin.loader].concat(loaders);
36
- }
37
- return ['vue-style-loader'].concat(loaders);
38
- }
39
-
40
- // http://vuejs.github.io/vue-loader/en/configurations/extract-css.html
41
- return {
42
- css: generateLoaders(),
43
- postcss: generateLoaders(),
44
- less: generateLoaders('less'),
45
- sass: generateLoaders('sass', { indentedSyntax: true }),
46
- scss: generateLoaders('sass'),
47
- stylus: generateLoaders('stylus'),
48
- styl: generateLoaders('stylus'),
49
- };
50
- };
51
-
52
- // Generate loaders for standalone style files (outside of .vue)
53
- exports.styleLoaders = function (options) {
54
- const output = [];
55
- const loaders = exports.cssLoaders(options);
56
- for (const extension in loaders) {
57
- const loader = loaders[extension];
58
- output.push({
59
- test: new RegExp('\\.' + extension + '$'),
60
- use: loader,
61
- });
62
- }
63
- return output;
64
- };
@@ -1,74 +0,0 @@
1
- const path = require('path');
2
- const utils = require('./utils');
3
- const config = require('./config.js');
4
-
5
- function resolve(dir) {
6
- return path.join(__dirname, '../..', dir);
7
- }
8
-
9
- module.exports = {
10
- entry: {
11
- index: resolve('src/main.mjs'),
12
- },
13
- output: {
14
- path: config.build.assetsRoot,
15
- filename: '[name].js',
16
- publicPath: config.build.assetsPublicPath,
17
- libraryTarget: 'commonjs2',
18
- },
19
- externals: {
20
- vue: 'vue',
21
- },
22
- resolve: {
23
- extensions: ['.js', '.vue', '.json'],
24
- alias: {
25
- '@': resolve('src'),
26
- },
27
- },
28
- module: {
29
- rules: [
30
- {
31
- test: /\.vue$/,
32
- loader: 'vue-loader',
33
- },
34
- {
35
- test: /\.esm\.js$/,
36
- loader: 'babel-loader',
37
- },
38
- {
39
- test: /\.esm\.bundle\.js$/,
40
- loader: 'babel-loader',
41
- },
42
- {
43
- test: /\.module\.js$/,
44
- loader: 'babel-loader',
45
- },
46
- {
47
- test: /\.js$/,
48
- loader: 'babel-loader',
49
- include: [resolve('src')],
50
- },
51
- {
52
- test: /\.mjs$/,
53
- loader: 'babel-loader',
54
- include: [resolve('src')],
55
- },
56
- {
57
- test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
58
- loader: 'url-loader',
59
- options: {
60
- limit: 10000,
61
- name: utils.assetsPath('img/[name].[hash].[ext]'),
62
- },
63
- },
64
- {
65
- test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
66
- loader: 'url-loader',
67
- options: {
68
- limit: 10000,
69
- name: utils.assetsPath('fonts/[name].[hash].[ext]'),
70
- },
71
- },
72
- ],
73
- },
74
- };
@@ -1,36 +0,0 @@
1
- const utils = require('./utils');
2
- const webpack = require('webpack');
3
- const config = require('./config.js');
4
- const { merge } = require('webpack-merge');
5
- const baseWebpackConfig = require('./webpack.base.conf');
6
- const { VueLoaderPlugin } = require('vue-loader');
7
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
8
-
9
- const env = config.build.env;
10
-
11
- const plugins = [
12
- new webpack.DefinePlugin({
13
- 'process.env': env,
14
- }),
15
- new VueLoaderPlugin(),
16
- new MiniCssExtractPlugin({
17
- filename: utils.assetsPath('[name].css'),
18
- }),
19
- ];
20
-
21
- const webpackConfig = merge(baseWebpackConfig, {
22
- mode: 'production',
23
- module: {
24
- rules: utils.styleLoaders({
25
- sourceMap: config.build.productionSourceMap,
26
- extract: true,
27
- }),
28
- },
29
- devtool: config.build.productionSourceMap ? 'source-map' : false,
30
- plugins,
31
- optimization: {
32
- minimize: config.build.uglify,
33
- },
34
- });
35
-
36
- module.exports = webpackConfig;
package/src/main.mjs DELETED
@@ -1,30 +0,0 @@
1
- import extend from '@zhennann/extend';
2
-
3
- export default function cascadeExtend({ scope, source, name }) {
4
- if (!source || !name) return null;
5
- // filter
6
- const keys = Object.keys(source).filter(key => {
7
- return key === name || key.indexOf(name + '_') === 0
8
- });
9
- if (keys.length === 0) return null;
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
16
- const result = {};
17
- const nameLength = name.length;
18
- for (const key of keys) {
19
- if (key === name) {
20
- extend(true, result, source[key]);
21
- } else {
22
- const parts = key.substring(nameLength + 1).split('_');
23
- const test = parts.every(part => !!scope[part]);
24
- if (test) {
25
- extend(true, result, source[key]);
26
- }
27
- }
28
- }
29
- return result;
30
- }
package/test/test.mjs DELETED
@@ -1,28 +0,0 @@
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);