object-flatten-referencing 6.0.5 → 6.0.6

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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @name object-flatten-referencing
3
3
  * @fileoverview Flatten complex nested objects according to a reference objects
4
- * @version 6.0.5
4
+ * @version 6.0.6
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/object-flatten-referencing/}
@@ -13,222 +13,264 @@ import { isMatch } from 'matcher';
13
13
  import isObj from 'lodash.isplainobject';
14
14
 
15
15
  const defaults = {
16
- wrapHeadsWith: "%%_",
17
- wrapTailsWith: "_%%",
18
- dontWrapKeys: [],
19
- dontWrapPaths: [],
20
- xhtml: true,
21
- preventDoubleWrapping: true,
22
- preventWrappingIfContains: [],
23
- objectKeyAndValueJoinChar: ".",
24
- wrapGlobalFlipSwitch: true,
25
- ignore: [],
26
- whatToDoWhenReferenceIsMissing: 0,
27
- mergeArraysWithLineBreaks: true,
28
- mergeWithoutTrailingBrIfLineContainsBr: true,
29
- enforceStrictKeyset: true
16
+ wrapHeadsWith: "%%_",
17
+ wrapTailsWith: "_%%",
18
+ dontWrapKeys: [],
19
+ dontWrapPaths: [],
20
+ xhtml: true,
21
+ preventDoubleWrapping: true,
22
+ preventWrappingIfContains: [],
23
+ objectKeyAndValueJoinChar: ".",
24
+ wrapGlobalFlipSwitch: true,
25
+ ignore: [],
26
+ whatToDoWhenReferenceIsMissing: 0,
27
+ mergeArraysWithLineBreaks: true,
28
+ mergeWithoutTrailingBrIfLineContainsBr: true,
29
+ enforceStrictKeyset: true,
30
30
  };
31
31
  function isStr$1(something) {
32
- return typeof something === "string";
32
+ return typeof something === "string";
33
33
  }
34
34
  function flattenObject(objOrig, originalOpts) {
35
- const opts = { ...defaults,
36
- ...originalOpts
37
- };
38
- if (arguments.length === 0 || Object.keys(objOrig).length === 0) {
39
- return [];
40
- }
41
- const obj = clone(objOrig);
42
- let res = [];
43
- if (isObj(obj)) {
44
- Object.keys(obj).forEach(key => {
45
- if (isObj(obj[key])) {
46
- obj[key] = flattenObject(obj[key], opts);
47
- }
48
- if (Array.isArray(obj[key])) {
49
- res = res.concat(obj[key].map(el => key + opts.objectKeyAndValueJoinChar + el));
50
- }
51
- if (isStr$1(obj[key])) {
52
- res.push(key + opts.objectKeyAndValueJoinChar + obj[key]);
53
- }
54
- });
55
- }
56
- return res;
35
+ const opts = { ...defaults, ...originalOpts };
36
+ if (arguments.length === 0 || Object.keys(objOrig).length === 0) {
37
+ return [];
38
+ }
39
+ const obj = clone(objOrig);
40
+ let res = [];
41
+ if (isObj(obj)) {
42
+ Object.keys(obj).forEach((key) => {
43
+ if (isObj(obj[key])) {
44
+ obj[key] = flattenObject(obj[key], opts);
45
+ }
46
+ if (Array.isArray(obj[key])) {
47
+ res = res.concat(obj[key].map((el) => key + opts.objectKeyAndValueJoinChar + el));
48
+ }
49
+ if (isStr$1(obj[key])) {
50
+ res.push(key + opts.objectKeyAndValueJoinChar + obj[key]);
51
+ }
52
+ });
53
+ }
54
+ return res;
57
55
  }
58
56
  function flattenArr(arrOrig, originalOpts, wrap = false, joinArraysUsingBrs = false) {
59
- const opts = { ...defaults,
60
- ...originalOpts
61
- };
62
- if (arguments.length === 0 || arrOrig.length === 0) {
63
- return "";
64
- }
65
- const arr = clone(arrOrig);
66
- let res = "";
67
- if (arr.length > 0) {
68
- if (joinArraysUsingBrs) {
69
- for (let i = 0, len = arr.length; i < len; i++) {
70
- if (isStr$1(arr[i])) {
71
- let lineBreak;
72
- lineBreak = "";
73
- if (opts.mergeArraysWithLineBreaks && i > 0 && (!opts.mergeWithoutTrailingBrIfLineContainsBr || typeof arr[i - 1] !== "string" || opts.mergeWithoutTrailingBrIfLineContainsBr && arr[i - 1] !== undefined && !arr[i - 1].toLowerCase().includes("<br"))) {
74
- lineBreak = `<br${opts.xhtml ? " /" : ""}>`;
75
- }
76
- res += lineBreak + (wrap ? opts.wrapHeadsWith : "") + arr[i] + (wrap ? opts.wrapTailsWith : "");
77
- } else if (Array.isArray(arr[i])) {
78
- if (arr[i].length > 0 && arr[i].every(isStr$1)) {
79
- let lineBreak = "";
80
- if (opts.mergeArraysWithLineBreaks && res.length > 0) {
81
- lineBreak = `<br${opts.xhtml ? " /" : ""}>`;
57
+ const opts = { ...defaults, ...originalOpts };
58
+ if (arguments.length === 0 || arrOrig.length === 0) {
59
+ return "";
60
+ }
61
+ const arr = clone(arrOrig);
62
+ let res = "";
63
+ if (arr.length > 0) {
64
+ if (joinArraysUsingBrs) {
65
+ for (let i = 0, len = arr.length; i < len; i++) {
66
+ if (isStr$1(arr[i])) {
67
+ let lineBreak;
68
+ lineBreak = "";
69
+ if (opts.mergeArraysWithLineBreaks &&
70
+ i > 0 &&
71
+ (!opts.mergeWithoutTrailingBrIfLineContainsBr ||
72
+ typeof arr[i - 1] !== "string" ||
73
+ (opts.mergeWithoutTrailingBrIfLineContainsBr &&
74
+ arr[i - 1] !== undefined &&
75
+ !arr[i - 1].toLowerCase().includes("<br")))) {
76
+ lineBreak = `<br${opts.xhtml ? " /" : ""}>`;
77
+ }
78
+ res +=
79
+ lineBreak +
80
+ (wrap ? opts.wrapHeadsWith : "") +
81
+ arr[i] +
82
+ (wrap ? opts.wrapTailsWith : "");
83
+ }
84
+ else if (Array.isArray(arr[i])) {
85
+ if (arr[i].length > 0 && arr[i].every(isStr$1)) {
86
+ let lineBreak = "";
87
+ if (opts.mergeArraysWithLineBreaks && res.length > 0) {
88
+ lineBreak = `<br${opts.xhtml ? " /" : ""}>`;
89
+ }
90
+ res = arr[i].reduce((acc, val, i2, arr2) => {
91
+ let trailingSpace = "";
92
+ if (i2 !== arr2.length - 1) {
93
+ trailingSpace = " ";
94
+ }
95
+ return (acc +
96
+ (i2 === 0 ? lineBreak : "") +
97
+ (wrap ? opts.wrapHeadsWith : "") +
98
+ val +
99
+ (wrap ? opts.wrapTailsWith : "") +
100
+ trailingSpace);
101
+ }, res);
102
+ }
103
+ }
82
104
  }
83
- res = arr[i].reduce((acc, val, i2, arr2) => {
84
- let trailingSpace = "";
85
- if (i2 !== arr2.length - 1) {
86
- trailingSpace = " ";
87
- }
88
- return acc + (i2 === 0 ? lineBreak : "") + (wrap ? opts.wrapHeadsWith : "") + val + (wrap ? opts.wrapTailsWith : "") + trailingSpace;
89
- }, res);
90
- }
91
105
  }
92
- }
93
- } else {
94
- res = arr.reduce((acc, val, i, arr2) => {
95
- let lineBreak = "";
96
- if (opts.mergeArraysWithLineBreaks && i > 0) {
97
- lineBreak = `<br${opts.xhtml ? " /" : ""}>`;
98
- }
99
- let trailingSpace = "";
100
- if (i !== arr2.length - 1) {
101
- trailingSpace = " ";
106
+ else {
107
+ res = arr.reduce((acc, val, i, arr2) => {
108
+ let lineBreak = "";
109
+ if (opts.mergeArraysWithLineBreaks && i > 0) {
110
+ lineBreak = `<br${opts.xhtml ? " /" : ""}>`;
111
+ }
112
+ let trailingSpace = "";
113
+ if (i !== arr2.length - 1) {
114
+ trailingSpace = " ";
115
+ }
116
+ return (acc +
117
+ (i === 0 ? lineBreak : "") +
118
+ (wrap ? opts.wrapHeadsWith : "") +
119
+ val +
120
+ (wrap ? opts.wrapTailsWith : "") +
121
+ trailingSpace);
122
+ }, res);
102
123
  }
103
- return acc + (i === 0 ? lineBreak : "") + (wrap ? opts.wrapHeadsWith : "") + val + (wrap ? opts.wrapTailsWith : "") + trailingSpace;
104
- }, res);
105
124
  }
106
- }
107
- return res;
125
+ return res;
108
126
  }
109
127
  function arrayiffyString(something) {
110
- if (isStr$1(something)) {
111
- if (something.length > 0) {
112
- return [something];
128
+ if (isStr$1(something)) {
129
+ if (something.length > 0) {
130
+ return [something];
131
+ }
132
+ return [];
113
133
  }
114
- return [];
115
- }
116
- return something;
134
+ return something;
117
135
  }
118
136
 
119
- var version$1 = "6.0.5";
137
+ var version$1 = "6.0.6";
120
138
 
121
139
  const version = version$1;
122
140
  function existy(x) {
123
- return x != null;
141
+ return x != null;
124
142
  }
125
143
  function isStr(something) {
126
- return typeof something === "string";
144
+ return typeof something === "string";
127
145
  }
128
146
  function flattenReferencing(originalInput1, originalReference1, opts1) {
129
- if (arguments.length === 0) {
130
- throw new Error("object-flatten-referencing/ofr(): [THROW_ID_01] all inputs missing!");
131
- }
132
- if (arguments.length === 1) {
133
- throw new Error("object-flatten-referencing/ofr(): [THROW_ID_02] reference object missing!");
134
- }
135
- if (existy(opts1) && !isObj(opts1)) {
136
- throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_03] third input, options object must be a plain object. Currently it's: ${typeof opts1}`);
137
- }
138
- const originalOpts = { ...defaults,
139
- ...opts1
140
- };
141
- originalOpts.dontWrapKeys = arrayiffyString(originalOpts.dontWrapKeys);
142
- originalOpts.preventWrappingIfContains = arrayiffyString(originalOpts.preventWrappingIfContains);
143
- originalOpts.dontWrapPaths = arrayiffyString(originalOpts.dontWrapPaths);
144
- originalOpts.ignore = arrayiffyString(originalOpts.ignore);
145
- if (typeof originalOpts.whatToDoWhenReferenceIsMissing !== "number") {
146
- originalOpts.whatToDoWhenReferenceIsMissing = +originalOpts.whatToDoWhenReferenceIsMissing || 0;
147
- }
148
- function ofr(originalInput, originalReference, opts, wrap = true, joinArraysUsingBrs = true, currentRoot = "") {
149
- let input = clone(originalInput);
150
- const reference = clone(originalReference);
151
- if (!opts.wrapGlobalFlipSwitch) {
152
- wrap = false;
147
+ if (arguments.length === 0) {
148
+ throw new Error("object-flatten-referencing/ofr(): [THROW_ID_01] all inputs missing!");
153
149
  }
154
- if (isObj(input)) {
155
- Object.keys(input).forEach(key => {
156
- const currentPath = currentRoot + (currentRoot.length === 0 ? key : `.${key}`);
157
- if (opts.ignore.length === 0 || !opts.ignore.includes(key)) {
158
- if (opts.wrapGlobalFlipSwitch) {
159
- wrap = true;
160
- if (opts.dontWrapKeys.length > 0) {
161
- wrap = wrap && !opts.dontWrapKeys.some(elem => isMatch(key, elem, {
162
- caseSensitive: true
163
- }));
164
- }
165
- if (opts.dontWrapPaths.length > 0) {
166
- wrap = wrap && !opts.dontWrapPaths.some(elem => elem === currentPath);
167
- }
168
- if (opts.preventWrappingIfContains.length > 0 && typeof input[key] === "string") {
169
- wrap = wrap && !opts.preventWrappingIfContains.some(elem => input[key].includes(elem));
170
- }
171
- }
172
- if (existy(reference[key]) || !existy(reference[key]) && opts.whatToDoWhenReferenceIsMissing === 2) {
173
- if (Array.isArray(input[key])) {
174
- if (opts.whatToDoWhenReferenceIsMissing === 2 || isStr(reference[key])) {
175
- input[key] = flattenArr(input[key], opts, wrap, joinArraysUsingBrs);
176
- } else {
177
- if (input[key].every(el => typeof el === "string" || Array.isArray(el))) {
178
- let allOK = true;
179
- input[key].forEach(oneOfElements => {
180
- if (Array.isArray(oneOfElements) && !oneOfElements.every(isStr)) {
181
- allOK = false;
150
+ if (arguments.length === 1) {
151
+ throw new Error("object-flatten-referencing/ofr(): [THROW_ID_02] reference object missing!");
152
+ }
153
+ if (existy(opts1) && !isObj(opts1)) {
154
+ throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_03] third input, options object must be a plain object. Currently it's: ${typeof opts1}`);
155
+ }
156
+ const originalOpts = { ...defaults, ...opts1 };
157
+ originalOpts.dontWrapKeys = arrayiffyString(originalOpts.dontWrapKeys);
158
+ originalOpts.preventWrappingIfContains = arrayiffyString(originalOpts.preventWrappingIfContains);
159
+ originalOpts.dontWrapPaths = arrayiffyString(originalOpts.dontWrapPaths);
160
+ originalOpts.ignore = arrayiffyString(originalOpts.ignore);
161
+ if (typeof originalOpts.whatToDoWhenReferenceIsMissing !== "number") {
162
+ originalOpts.whatToDoWhenReferenceIsMissing =
163
+ +originalOpts.whatToDoWhenReferenceIsMissing || 0;
164
+ }
165
+ function ofr(originalInput, originalReference, opts, wrap = true, joinArraysUsingBrs = true, currentRoot = "") {
166
+ let input = clone(originalInput);
167
+ const reference = clone(originalReference);
168
+ if (!opts.wrapGlobalFlipSwitch) {
169
+ wrap = false;
170
+ }
171
+ if (isObj(input)) {
172
+ Object.keys(input).forEach((key) => {
173
+ const currentPath = currentRoot + (currentRoot.length === 0 ? key : `.${key}`);
174
+ if (opts.ignore.length === 0 || !opts.ignore.includes(key)) {
175
+ if (opts.wrapGlobalFlipSwitch) {
176
+ wrap = true;
177
+ if (opts.dontWrapKeys.length > 0) {
178
+ wrap =
179
+ wrap &&
180
+ !opts.dontWrapKeys.some((elem) => isMatch(key, elem, { caseSensitive: true }));
181
+ }
182
+ if (opts.dontWrapPaths.length > 0) {
183
+ wrap =
184
+ wrap &&
185
+ !opts.dontWrapPaths.some((elem) => elem === currentPath);
186
+ }
187
+ if (opts.preventWrappingIfContains.length > 0 &&
188
+ typeof input[key] === "string") {
189
+ wrap =
190
+ wrap &&
191
+ !opts.preventWrappingIfContains.some((elem) => input[key].includes(elem));
192
+ }
193
+ }
194
+ if (existy(reference[key]) ||
195
+ (!existy(reference[key]) &&
196
+ opts.whatToDoWhenReferenceIsMissing === 2)) {
197
+ if (Array.isArray(input[key])) {
198
+ if (opts.whatToDoWhenReferenceIsMissing === 2 ||
199
+ isStr(reference[key])) {
200
+ input[key] = flattenArr(input[key], opts, wrap, joinArraysUsingBrs);
201
+ }
202
+ else {
203
+ if (input[key].every((el) => typeof el === "string" || Array.isArray(el))) {
204
+ let allOK = true;
205
+ input[key].forEach((oneOfElements) => {
206
+ if (Array.isArray(oneOfElements) &&
207
+ !oneOfElements.every(isStr)) {
208
+ allOK = false;
209
+ }
210
+ });
211
+ if (allOK) {
212
+ joinArraysUsingBrs = false;
213
+ }
214
+ }
215
+ input[key] = ofr(input[key], reference[key], opts, wrap, joinArraysUsingBrs, currentPath);
216
+ }
217
+ }
218
+ else if (isObj(input[key])) {
219
+ if (opts.whatToDoWhenReferenceIsMissing === 2 ||
220
+ isStr(reference[key])) {
221
+ input[key] = flattenArr(flattenObject(input[key], opts), opts, wrap, joinArraysUsingBrs);
222
+ }
223
+ else if (!wrap) {
224
+ input[key] = ofr(input[key], reference[key], { ...opts, wrapGlobalFlipSwitch: false }, wrap, joinArraysUsingBrs, currentPath);
225
+ }
226
+ else {
227
+ input[key] = ofr(input[key], reference[key], opts, wrap, joinArraysUsingBrs, currentPath);
228
+ }
229
+ }
230
+ else if (isStr(input[key])) {
231
+ input[key] = ofr(input[key], reference[key], opts, wrap, joinArraysUsingBrs, currentPath);
232
+ }
233
+ }
234
+ else if (typeof input[key] !== typeof reference[key]) {
235
+ if (opts.whatToDoWhenReferenceIsMissing === 1) {
236
+ throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_06] reference object does not have the key ${key} and we need it. TIP: Turn off throwing via opts.whatToDoWhenReferenceIsMissing.`);
237
+ }
182
238
  }
183
- });
184
- if (allOK) {
185
- joinArraysUsingBrs = false;
186
- }
187
239
  }
188
- input[key] = ofr(input[key], reference[key], opts, wrap, joinArraysUsingBrs, currentPath);
189
- }
190
- } else if (isObj(input[key])) {
191
- if (opts.whatToDoWhenReferenceIsMissing === 2 || isStr(reference[key])) {
192
- input[key] = flattenArr(flattenObject(input[key], opts), opts, wrap, joinArraysUsingBrs);
193
- } else if (!wrap) {
194
- input[key] = ofr(input[key], reference[key], { ...opts,
195
- wrapGlobalFlipSwitch: false
196
- }, wrap, joinArraysUsingBrs, currentPath);
197
- } else {
198
- input[key] = ofr(input[key], reference[key], opts, wrap, joinArraysUsingBrs, currentPath);
199
- }
200
- } else if (isStr(input[key])) {
201
- input[key] = ofr(input[key], reference[key], opts, wrap, joinArraysUsingBrs, currentPath);
240
+ });
241
+ }
242
+ else if (Array.isArray(input)) {
243
+ if (Array.isArray(reference)) {
244
+ input.forEach((_el, i) => {
245
+ if (existy(input[i]) && existy(reference[i])) {
246
+ input[i] = ofr(input[i], reference[i], opts, wrap, joinArraysUsingBrs, `${currentRoot}[${i}]`);
247
+ }
248
+ else {
249
+ input[i] = ofr(input[i], reference[0], opts, wrap, joinArraysUsingBrs, `${currentRoot}[${i}]`);
250
+ }
251
+ });
202
252
  }
203
- } else if (typeof input[key] !== typeof reference[key]) {
204
- if (opts.whatToDoWhenReferenceIsMissing === 1) {
205
- throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_06] reference object does not have the key ${key} and we need it. TIP: Turn off throwing via opts.whatToDoWhenReferenceIsMissing.`);
253
+ else if (isStr(reference)) {
254
+ input = flattenArr(input, opts, wrap, joinArraysUsingBrs);
206
255
  }
207
- }
208
256
  }
209
- });
210
- } else if (Array.isArray(input)) {
211
- if (Array.isArray(reference)) {
212
- input.forEach((_el, i) => {
213
- if (existy(input[i]) && existy(reference[i])) {
214
- input[i] = ofr(input[i], reference[i], opts, wrap, joinArraysUsingBrs, `${currentRoot}[${i}]`);
215
- } else {
216
- input[i] = ofr(input[i], reference[0], opts, wrap, joinArraysUsingBrs, `${currentRoot}[${i}]`);
217
- }
218
- });
219
- } else if (isStr(reference)) {
220
- input = flattenArr(input, opts, wrap, joinArraysUsingBrs);
221
- }
222
- } else if (isStr(input)) {
223
- if (input.length > 0 && (opts.wrapHeadsWith || opts.wrapTailsWith)) {
224
- if (!opts.preventDoubleWrapping || (opts.wrapHeadsWith === "" || !strIndexesOfPlus(input, opts.wrapHeadsWith.trim()).length) && (opts.wrapTailsWith === "" || !strIndexesOfPlus(input, opts.wrapTailsWith.trim()).length)) {
225
- input = (wrap ? opts.wrapHeadsWith : "") + input + (wrap ? opts.wrapTailsWith : "");
257
+ else if (isStr(input)) {
258
+ if (input.length > 0 && (opts.wrapHeadsWith || opts.wrapTailsWith)) {
259
+ if (!opts.preventDoubleWrapping ||
260
+ ((opts.wrapHeadsWith === "" ||
261
+ !strIndexesOfPlus(input, opts.wrapHeadsWith.trim()).length) &&
262
+ (opts.wrapTailsWith === "" ||
263
+ !strIndexesOfPlus(input, opts.wrapTailsWith.trim()).length))) {
264
+ input =
265
+ (wrap ? opts.wrapHeadsWith : "") +
266
+ input +
267
+ (wrap ? opts.wrapTailsWith : "");
268
+ }
269
+ }
226
270
  }
227
- }
271
+ return input;
228
272
  }
229
- return input;
230
- }
231
- return ofr(originalInput1, originalReference1, originalOpts);
273
+ return ofr(originalInput1, originalReference1, originalOpts);
232
274
  }
233
275
 
234
276
  export { arrayiffyString, defaults, flattenArr, flattenObject, flattenReferencing, version };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @name object-flatten-referencing
3
3
  * @fileoverview Flatten complex nested objects according to a reference objects
4
- * @version 6.0.5
4
+ * @version 6.0.6
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/object-flatten-referencing/}
@@ -11,8 +11,8 @@
11
11
  /**
12
12
  * @name str-indexes-of-plus
13
13
  * @fileoverview Like indexOf but returns array and counts per-grapheme
14
- * @version 4.0.5
14
+ * @version 4.0.6
15
15
  * @author Roy Revelt, Codsen Ltd
16
16
  * @license MIT
17
17
  * {@link https://codsen.com/os/str-indexes-of-plus/}
18
- */function o(t,e,r=0){if("string"!=typeof t)throw new TypeError("str-indexes-of-plus/strIndexesOfPlus(): first input argument must be a string! Currently it's: "+typeof t);if("string"!=typeof e)throw new TypeError("str-indexes-of-plus/strIndexesOfPlus(): second input argument must be a string! Currently it's: "+typeof e);if(isNaN(+r)||"string"==typeof r&&!/^\d*$/.test(r))throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): third input argument must be a natural number! Currently it's: ${r}`);const n=Array.from(t),o=Array.from(e);if(0===n.length||0===o.length||null!=r&&+r>=n.length)return[];r||(r=0);const i=[];let a,c=!1;for(let t=r,e=n.length;t<e;t++)c&&(n[t]===o[t-+a]?t-+a+1===o.length&&i.push(+a):(a=null,c=!1)),c||n[t]===o[0]&&(1===o.length?i.push(t):(c=!0,a=t));return i}const i=new Map,a=(t,e)=>{if(!Array.isArray(t))switch(typeof t){case"string":t=[t];break;case"undefined":t=[];break;default:throw new TypeError(`Expected '${e}' to be a string or an array, but got a type of '${typeof t}'`)}return t.filter((t=>{if("string"!=typeof t){if(void 0===t)return!1;throw new TypeError(`Expected '${e}' to be an array of strings, but found a type of '${typeof t}' in the array`)}return!0}))},c=(t,e)=>{e={caseSensitive:!1,...e};const r=t+JSON.stringify(e);if(i.has(r))return i.get(r);const n="!"===t[0];n&&(t=t.slice(1)),t=function(t){if("string"!=typeof t)throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}(t).replace(/\\\*/g,"[\\s\\S]*");const o=new RegExp(`^${t}$`,e.caseSensitive?"":"i");return o.negated=n,i.set(r,o),o};function s(t,e,r){return((t,e,r,n)=>{if(t=a(t,"inputs"),0===(e=a(e,"patterns")).length)return[];e=e.map((t=>c(t,r)));const{allPatterns:o}=r||{},i=[];for(const r of t){let t;const a=[...e].fill(!1);for(const[n,o]of e.entries())if(o.test(r)&&(a[n]=!0,t=!o.negated,!t))break;if(!(!1===t||void 0===t&&e.some((t=>!t.negated))||o&&a.some(((t,r)=>!t&&!e[r].negated)))&&(i.push(r),n))break}return i})(t,e,r,!0).length>0}var u,f,l=Object.prototype,p=Function.prototype.toString,h=l.hasOwnProperty,y=p.call(Object),g=l.toString,d=(u=Object.getPrototypeOf,f=Object,function(t){return u(f(t))});var b=function(t){if(!function(t){return!!t&&"object"==typeof t}(t)||"[object Object]"!=g.call(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t))return!1;var e=d(t);if(null===e)return!0;var r=h.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&p.call(r)==y};const _={wrapHeadsWith:"%%_",wrapTailsWith:"_%%",dontWrapKeys:[],dontWrapPaths:[],xhtml:!0,preventDoubleWrapping:!0,preventWrappingIfContains:[],objectKeyAndValueJoinChar:".",wrapGlobalFlipSwitch:!0,ignore:[],whatToDoWhenReferenceIsMissing:0,mergeArraysWithLineBreaks:!0,mergeWithoutTrailingBrIfLineContainsBr:!0,enforceStrictKeyset:!0};function v(t){return"string"==typeof t}function w(t,e){const r={..._,...e};if(0===arguments.length||0===Object.keys(t).length)return[];const o=n(t);let i=[];return b(o)&&Object.keys(o).forEach((t=>{b(o[t])&&(o[t]=w(o[t],r)),Array.isArray(o[t])&&(i=i.concat(o[t].map((e=>t+r.objectKeyAndValueJoinChar+e)))),v(o[t])&&i.push(t+r.objectKeyAndValueJoinChar+o[t])})),i}function j(t,e,r=!1,o=!1){const i={..._,...e};if(0===arguments.length||0===t.length)return"";const a=n(t);let c="";if(a.length>0)if(o){for(let t=0,e=a.length;t<e;t++)if(v(a[t])){let e;e="",i.mergeArraysWithLineBreaks&&t>0&&(!i.mergeWithoutTrailingBrIfLineContainsBr||"string"!=typeof a[t-1]||i.mergeWithoutTrailingBrIfLineContainsBr&&void 0!==a[t-1]&&!a[t-1].toLowerCase().includes("<br"))&&(e=`<br${i.xhtml?" /":""}>`),c+=e+(r?i.wrapHeadsWith:"")+a[t]+(r?i.wrapTailsWith:"")}else if(Array.isArray(a[t])&&a[t].length>0&&a[t].every(v)){let e="";i.mergeArraysWithLineBreaks&&c.length>0&&(e=`<br${i.xhtml?" /":""}>`),c=a[t].reduce(((t,n,o,a)=>{let c="";return o!==a.length-1&&(c=" "),t+(0===o?e:"")+(r?i.wrapHeadsWith:"")+n+(r?i.wrapTailsWith:"")+c}),c)}}else c=a.reduce(((t,e,n,o)=>{let a="";i.mergeArraysWithLineBreaks&&n>0&&(a=`<br${i.xhtml?" /":""}>`);let c="";return n!==o.length-1&&(c=" "),t+(0===n?a:"")+(r?i.wrapHeadsWith:"")+e+(r?i.wrapTailsWith:"")+c}),c);return c}function W(t){return v(t)?t.length>0?[t]:[]:t}function m(t){return null!=t}function A(t){return"string"==typeof t}t.arrayiffyString=W,t.defaults=_,t.flattenArr=j,t.flattenObject=w,t.flattenReferencing=function(t,e,r){if(0===arguments.length)throw new Error("object-flatten-referencing/ofr(): [THROW_ID_01] all inputs missing!");if(1===arguments.length)throw new Error("object-flatten-referencing/ofr(): [THROW_ID_02] reference object missing!");if(m(r)&&!b(r))throw new Error("object-flatten-referencing/ofr(): [THROW_ID_03] third input, options object must be a plain object. Currently it's: "+typeof r);const i={..._,...r};function a(t,e,r,i=!0,c=!0,u=""){let f=n(t);const l=n(e);return r.wrapGlobalFlipSwitch||(i=!1),b(f)?Object.keys(f).forEach((t=>{const e=u+(0===u.length?t:`.${t}`);if(0===r.ignore.length||!r.ignore.includes(t))if(r.wrapGlobalFlipSwitch&&(i=!0,r.dontWrapKeys.length>0&&(i=i&&!r.dontWrapKeys.some((e=>s(t,e,{caseSensitive:!0})))),r.dontWrapPaths.length>0&&(i=i&&!r.dontWrapPaths.some((t=>t===e))),r.preventWrappingIfContains.length>0&&"string"==typeof f[t]&&(i=i&&!r.preventWrappingIfContains.some((e=>f[t].includes(e))))),m(l[t])||!m(l[t])&&2===r.whatToDoWhenReferenceIsMissing)if(Array.isArray(f[t]))if(2===r.whatToDoWhenReferenceIsMissing||A(l[t]))f[t]=j(f[t],r,i,c);else{if(f[t].every((t=>"string"==typeof t||Array.isArray(t)))){let e=!0;f[t].forEach((t=>{Array.isArray(t)&&!t.every(A)&&(e=!1)})),e&&(c=!1)}f[t]=a(f[t],l[t],r,i,c,e)}else b(f[t])?f[t]=2===r.whatToDoWhenReferenceIsMissing||A(l[t])?j(w(f[t],r),r,i,c):a(f[t],l[t],i?r:{...r,wrapGlobalFlipSwitch:!1},i,c,e):A(f[t])&&(f[t]=a(f[t],l[t],r,i,c,e));else if(typeof f[t]!=typeof l[t]&&1===r.whatToDoWhenReferenceIsMissing)throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_06] reference object does not have the key ${t} and we need it. TIP: Turn off throwing via opts.whatToDoWhenReferenceIsMissing.`)})):Array.isArray(f)?Array.isArray(l)?f.forEach(((t,e)=>{f[e]=m(f[e])&&m(l[e])?a(f[e],l[e],r,i,c,`${u}[${e}]`):a(f[e],l[0],r,i,c,`${u}[${e}]`)})):A(l)&&(f=j(f,r,i,c)):A(f)&&f.length>0&&(r.wrapHeadsWith||r.wrapTailsWith)&&(r.preventDoubleWrapping&&(""!==r.wrapHeadsWith&&o(f,r.wrapHeadsWith.trim()).length||""!==r.wrapTailsWith&&o(f,r.wrapTailsWith.trim()).length)||(f=(i?r.wrapHeadsWith:"")+f+(i?r.wrapTailsWith:""))),f}return i.dontWrapKeys=W(i.dontWrapKeys),i.preventWrappingIfContains=W(i.preventWrappingIfContains),i.dontWrapPaths=W(i.dontWrapPaths),i.ignore=W(i.ignore),"number"!=typeof i.whatToDoWhenReferenceIsMissing&&(i.whatToDoWhenReferenceIsMissing=+i.whatToDoWhenReferenceIsMissing||0),a(t,e,i)},t.version="6.0.5",Object.defineProperty(t,"__esModule",{value:!0})}));
18
+ */function o(t,e,r=0){if("string"!=typeof t)throw new TypeError("str-indexes-of-plus/strIndexesOfPlus(): first input argument must be a string! Currently it's: "+typeof t);if("string"!=typeof e)throw new TypeError("str-indexes-of-plus/strIndexesOfPlus(): second input argument must be a string! Currently it's: "+typeof e);if(isNaN(+r)||"string"==typeof r&&!/^\d*$/.test(r))throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): third input argument must be a natural number! Currently it's: ${r}`);const n=Array.from(t),o=Array.from(e);if(0===n.length||0===o.length||null!=r&&+r>=n.length)return[];r||(r=0);const i=[];let a,c=!1;for(let t=r,e=n.length;t<e;t++)c&&(n[t]===o[t-+a]?t-+a+1===o.length&&i.push(+a):(a=null,c=!1)),c||n[t]===o[0]&&(1===o.length?i.push(t):(c=!0,a=t));return i}const i=new Map,a=(t,e)=>{if(!Array.isArray(t))switch(typeof t){case"string":t=[t];break;case"undefined":t=[];break;default:throw new TypeError(`Expected '${e}' to be a string or an array, but got a type of '${typeof t}'`)}return t.filter((t=>{if("string"!=typeof t){if(void 0===t)return!1;throw new TypeError(`Expected '${e}' to be an array of strings, but found a type of '${typeof t}' in the array`)}return!0}))},c=(t,e)=>{e={caseSensitive:!1,...e};const r=t+JSON.stringify(e);if(i.has(r))return i.get(r);const n="!"===t[0];n&&(t=t.slice(1)),t=function(t){if("string"!=typeof t)throw new TypeError("Expected a string");return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}(t).replace(/\\\*/g,"[\\s\\S]*");const o=new RegExp(`^${t}$`,e.caseSensitive?"":"i");return o.negated=n,i.set(r,o),o};function s(t,e,r){return((t,e,r,n)=>{if(t=a(t,"inputs"),0===(e=a(e,"patterns")).length)return[];e=e.map((t=>c(t,r)));const{allPatterns:o}=r||{},i=[];for(const r of t){let t;const a=[...e].fill(!1);for(const[n,o]of e.entries())if(o.test(r)&&(a[n]=!0,t=!o.negated,!t))break;if(!(!1===t||void 0===t&&e.some((t=>!t.negated))||o&&a.some(((t,r)=>!t&&!e[r].negated)))&&(i.push(r),n))break}return i})(t,e,r,!0).length>0}var u,f,l=Object.prototype,p=Function.prototype.toString,h=l.hasOwnProperty,y=p.call(Object),g=l.toString,d=(u=Object.getPrototypeOf,f=Object,function(t){return u(f(t))});var b=function(t){if(!function(t){return!!t&&"object"==typeof t}(t)||"[object Object]"!=g.call(t)||function(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}(t))return!1;var e=d(t);if(null===e)return!0;var r=h.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&p.call(r)==y};const _={wrapHeadsWith:"%%_",wrapTailsWith:"_%%",dontWrapKeys:[],dontWrapPaths:[],xhtml:!0,preventDoubleWrapping:!0,preventWrappingIfContains:[],objectKeyAndValueJoinChar:".",wrapGlobalFlipSwitch:!0,ignore:[],whatToDoWhenReferenceIsMissing:0,mergeArraysWithLineBreaks:!0,mergeWithoutTrailingBrIfLineContainsBr:!0,enforceStrictKeyset:!0};function v(t){return"string"==typeof t}function w(t,e){const r={..._,...e};if(0===arguments.length||0===Object.keys(t).length)return[];const o=n(t);let i=[];return b(o)&&Object.keys(o).forEach((t=>{b(o[t])&&(o[t]=w(o[t],r)),Array.isArray(o[t])&&(i=i.concat(o[t].map((e=>t+r.objectKeyAndValueJoinChar+e)))),v(o[t])&&i.push(t+r.objectKeyAndValueJoinChar+o[t])})),i}function j(t,e,r=!1,o=!1){const i={..._,...e};if(0===arguments.length||0===t.length)return"";const a=n(t);let c="";if(a.length>0)if(o){for(let t=0,e=a.length;t<e;t++)if(v(a[t])){let e;e="",i.mergeArraysWithLineBreaks&&t>0&&(!i.mergeWithoutTrailingBrIfLineContainsBr||"string"!=typeof a[t-1]||i.mergeWithoutTrailingBrIfLineContainsBr&&void 0!==a[t-1]&&!a[t-1].toLowerCase().includes("<br"))&&(e=`<br${i.xhtml?" /":""}>`),c+=e+(r?i.wrapHeadsWith:"")+a[t]+(r?i.wrapTailsWith:"")}else if(Array.isArray(a[t])&&a[t].length>0&&a[t].every(v)){let e="";i.mergeArraysWithLineBreaks&&c.length>0&&(e=`<br${i.xhtml?" /":""}>`),c=a[t].reduce(((t,n,o,a)=>{let c="";return o!==a.length-1&&(c=" "),t+(0===o?e:"")+(r?i.wrapHeadsWith:"")+n+(r?i.wrapTailsWith:"")+c}),c)}}else c=a.reduce(((t,e,n,o)=>{let a="";i.mergeArraysWithLineBreaks&&n>0&&(a=`<br${i.xhtml?" /":""}>`);let c="";return n!==o.length-1&&(c=" "),t+(0===n?a:"")+(r?i.wrapHeadsWith:"")+e+(r?i.wrapTailsWith:"")+c}),c);return c}function W(t){return v(t)?t.length>0?[t]:[]:t}function m(t){return null!=t}function A(t){return"string"==typeof t}t.arrayiffyString=W,t.defaults=_,t.flattenArr=j,t.flattenObject=w,t.flattenReferencing=function(t,e,r){if(0===arguments.length)throw new Error("object-flatten-referencing/ofr(): [THROW_ID_01] all inputs missing!");if(1===arguments.length)throw new Error("object-flatten-referencing/ofr(): [THROW_ID_02] reference object missing!");if(m(r)&&!b(r))throw new Error("object-flatten-referencing/ofr(): [THROW_ID_03] third input, options object must be a plain object. Currently it's: "+typeof r);const i={..._,...r};function a(t,e,r,i=!0,c=!0,u=""){let f=n(t);const l=n(e);return r.wrapGlobalFlipSwitch||(i=!1),b(f)?Object.keys(f).forEach((t=>{const e=u+(0===u.length?t:`.${t}`);if(0===r.ignore.length||!r.ignore.includes(t))if(r.wrapGlobalFlipSwitch&&(i=!0,r.dontWrapKeys.length>0&&(i=i&&!r.dontWrapKeys.some((e=>s(t,e,{caseSensitive:!0})))),r.dontWrapPaths.length>0&&(i=i&&!r.dontWrapPaths.some((t=>t===e))),r.preventWrappingIfContains.length>0&&"string"==typeof f[t]&&(i=i&&!r.preventWrappingIfContains.some((e=>f[t].includes(e))))),m(l[t])||!m(l[t])&&2===r.whatToDoWhenReferenceIsMissing)if(Array.isArray(f[t]))if(2===r.whatToDoWhenReferenceIsMissing||A(l[t]))f[t]=j(f[t],r,i,c);else{if(f[t].every((t=>"string"==typeof t||Array.isArray(t)))){let e=!0;f[t].forEach((t=>{Array.isArray(t)&&!t.every(A)&&(e=!1)})),e&&(c=!1)}f[t]=a(f[t],l[t],r,i,c,e)}else b(f[t])?f[t]=2===r.whatToDoWhenReferenceIsMissing||A(l[t])?j(w(f[t],r),r,i,c):a(f[t],l[t],i?r:{...r,wrapGlobalFlipSwitch:!1},i,c,e):A(f[t])&&(f[t]=a(f[t],l[t],r,i,c,e));else if(typeof f[t]!=typeof l[t]&&1===r.whatToDoWhenReferenceIsMissing)throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_06] reference object does not have the key ${t} and we need it. TIP: Turn off throwing via opts.whatToDoWhenReferenceIsMissing.`)})):Array.isArray(f)?Array.isArray(l)?f.forEach(((t,e)=>{f[e]=m(f[e])&&m(l[e])?a(f[e],l[e],r,i,c,`${u}[${e}]`):a(f[e],l[0],r,i,c,`${u}[${e}]`)})):A(l)&&(f=j(f,r,i,c)):A(f)&&f.length>0&&(r.wrapHeadsWith||r.wrapTailsWith)&&(r.preventDoubleWrapping&&(""!==r.wrapHeadsWith&&o(f,r.wrapHeadsWith.trim()).length||""!==r.wrapTailsWith&&o(f,r.wrapTailsWith.trim()).length)||(f=(i?r.wrapHeadsWith:"")+f+(i?r.wrapTailsWith:""))),f}return i.dontWrapKeys=W(i.dontWrapKeys),i.preventWrappingIfContains=W(i.preventWrappingIfContains),i.dontWrapPaths=W(i.dontWrapPaths),i.ignore=W(i.ignore),"number"!=typeof i.whatToDoWhenReferenceIsMissing&&(i.whatToDoWhenReferenceIsMissing=+i.whatToDoWhenReferenceIsMissing||0),a(t,e,i)},t.version="6.0.6",Object.defineProperty(t,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "object-flatten-referencing",
3
- "version": "6.0.5",
3
+ "version": "6.0.6",
4
4
  "description": "Flatten complex nested objects according to a reference objects",
5
5
  "keywords": [
6
6
  "advanced",
@@ -34,13 +34,12 @@
34
34
  "types": "types/index.d.ts",
35
35
  "scripts": {
36
36
  "build": "rollup -c",
37
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
38
- "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
37
+ "build:esbuild": "node '../../scripts/esbuild.js'",
38
+ "build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
39
+ "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
39
40
  "clean_types": "../../scripts/cleanTypes.js",
40
41
  "dev": "rollup -c --dev",
41
42
  "devunittest": "npm run dev && tap --only -R 'base'",
42
- "esbuild": "node '../../scripts/esbuild.js'",
43
- "esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
44
43
  "format": "npm run lect && npm run prettier && npm run lint",
45
44
  "lect": "lect",
46
45
  "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
@@ -49,17 +48,14 @@
49
48
  "republish": "npm publish || :",
50
49
  "tap": "tap",
51
50
  "pretest": "npm run build",
52
- "test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
51
+ "test": "npm run test:ci && npm run perf",
52
+ "test:ci": "npm run unittest && npm run test:examples && npm run format",
53
53
  "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
54
54
  "tsc": "tsc",
55
- "unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
55
+ "unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
56
56
  },
57
57
  "tap": {
58
58
  "check-coverage": false,
59
- "coverage-report": [
60
- "json-summary",
61
- "text"
62
- ],
63
59
  "node-arg": [
64
60
  "--no-warnings",
65
61
  "--experimental-loader",
@@ -82,11 +78,11 @@
82
78
  }
83
79
  },
84
80
  "dependencies": {
85
- "@babel/runtime": "^7.16.0",
81
+ "@babel/runtime": "^7.16.3",
86
82
  "lodash.clonedeep": "^4.5.0",
87
83
  "lodash.isplainobject": "^4.0.6",
88
84
  "matcher": "^5.0.0",
89
- "str-indexes-of-plus": "^4.0.5"
85
+ "str-indexes-of-plus": "^4.0.6"
90
86
  },
91
87
  "devDependencies": {
92
88
  "@babel/cli": "^7.16.0",
@@ -97,8 +93,8 @@
97
93
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
98
94
  "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
99
95
  "@babel/plugin-proposal-optional-chaining": "^7.16.0",
100
- "@babel/plugin-transform-runtime": "^7.16.0",
101
- "@babel/preset-env": "^7.16.0",
96
+ "@babel/plugin-transform-runtime": "^7.16.4",
97
+ "@babel/preset-env": "^7.16.4",
102
98
  "@babel/preset-typescript": "^7.16.0",
103
99
  "@babel/register": "^7.16.0",
104
100
  "@istanbuljs/esm-loader-hook": "^0.1.2",
@@ -110,25 +106,25 @@
110
106
  "@rollup/plugin-typescript": "^8.3.0",
111
107
  "@types/lodash.clonedeep": "^4.5.6",
112
108
  "@types/lodash.isplainobject": "^4.0.6",
113
- "@types/node": "^16.11.6",
109
+ "@types/node": "^16.11.9",
114
110
  "@types/tap": "^15.0.5",
115
- "@typescript-eslint/eslint-plugin": "^5.3.0",
116
- "@typescript-eslint/parser": "^5.3.0",
111
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
112
+ "@typescript-eslint/parser": "^5.4.0",
117
113
  "core-js": "^3.19.1",
118
114
  "cross-env": "^7.0.3",
119
- "eslint": "^8.2.0",
120
- "lect": "^0.18.5",
121
- "rollup": "^2.59.0",
115
+ "eslint": "^8.3.0",
116
+ "lect": "^0.18.6",
117
+ "rollup": "^2.60.0",
122
118
  "rollup-plugin-ascii": "^0.0.3",
123
119
  "rollup-plugin-banner": "^0.2.1",
124
120
  "rollup-plugin-cleanup": "^3.2.1",
125
121
  "rollup-plugin-dts": "^4.0.1",
126
122
  "rollup-plugin-terser": "^7.0.2",
127
- "tap": "^15.0.10",
123
+ "tap": "^15.1.2",
128
124
  "tslib": "^2.3.1",
129
- "typescript": "^4.4.4"
125
+ "typescript": "^4.5.2"
130
126
  },
131
127
  "engines": {
132
- "node": ">=12"
128
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
133
129
  }
134
130
  }