object-flatten-referencing 7.0.18 → 7.0.22
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010-
|
|
3
|
+
Copyright (c) 2010-2025 Roy Revelt and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
package/README.md
CHANGED
|
@@ -66,6 +66,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
|
|
|
66
66
|
|
|
67
67
|
MIT License.
|
|
68
68
|
|
|
69
|
-
Copyright © 2010-
|
|
69
|
+
Copyright © 2010-2025 Roy Revelt and other contributors.
|
|
70
70
|
|
|
71
71
|
<p align="center"><img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center"></p>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name object-flatten-referencing
|
|
3
3
|
* @fileoverview Flatten complex nested objects according to a reference objects
|
|
4
|
-
* @version 7.0.
|
|
4
|
+
* @version 7.0.22
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/object-flatten-referencing/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import C from"rfdc";import{strIndexesOfPlus as S}from"str-indexes-of-plus";import{isMatch as
|
|
10
|
+
import C from"rfdc";import{strIndexesOfPlus as S}from"str-indexes-of-plus";import{isMatch as P}from"matcher";import{arrayiffy as v}from"arrayiffy-if-string";import{existy as w,isStr as m,isPlainObject as b}from"codsen-utils";import A from"rfdc";import{isStr as y,isPlainObject as I}from"codsen-utils";var T=A(),W={wrapHeadsWith:"%%_",wrapTailsWith:"_%%",dontWrapKeys:[],dontWrapPaths:[],xhtml:!0,preventDoubleWrapping:!0,preventWrappingIfContains:[],objectKeyAndValueJoinChar:".",wrapGlobalFlipSwitch:!0,ignore:[],whatToDoWhenReferenceIsMissing:0,mergeArraysWithLineBreaks:!0,mergeWithoutTrailingBrIfLineContainsBr:!0,enforceStrictKeyset:!0};function $(u,g){let c={...W,...g};if(arguments.length===0||Object.keys(u).length===0)return[];let i=T(u),n=[];return I(i)&&Object.keys(i).forEach(a=>{I(i[a])&&(i[a]=$(i[a],c)),Array.isArray(i[a])&&(n=n.concat(i[a].map(p=>`${a}${c.objectKeyAndValueJoinChar}${p}`))),y(i[a])&&n.push(`${a}${c.objectKeyAndValueJoinChar}${i[a]}`)}),n}function O(u,g,c=!1,i=!1){let n={...W,...g};if(arguments.length===0||u.length===0)return"";let a=T(u),p="";if(a.length)if(i){for(let e=0,s=a.length;e<s;e++)if(y(a[e])){let l;l="",n.mergeArraysWithLineBreaks&&e>0&&(!n.mergeWithoutTrailingBrIfLineContainsBr||typeof a[e-1]!="string"||n.mergeWithoutTrailingBrIfLineContainsBr&&a[e-1]!==void 0&&!a[e-1].toLowerCase().includes("<br"))&&(l=`<br${n.xhtml?" /":""}>`),p+=`${l}${c?n.wrapHeadsWith:""}${a[e]}${c?n.wrapTailsWith:""}`}else if(Array.isArray(a[e])&&a[e].length&&a[e].every(y)){let l="";n.mergeArraysWithLineBreaks&&p.length&&(l=`<br${n.xhtml?" /":""}>`),p=a[e].reduce((d,t,o,r)=>{let f="";return o!==r.length-1&&(f=" "),d+(o===0?l:"")+(c?n.wrapHeadsWith:"")+t+(c?n.wrapTailsWith:"")+f},p)}}else p=a.reduce((e,s,l,d)=>{let t="";n.mergeArraysWithLineBreaks&&l>0&&(t=`<br${n.xhtml?" /":""}>`);let o="";return l!==d.length-1&&(o=" "),`${e}${l===0?t:""}${c?n.wrapHeadsWith:""}${s}${c?n.wrapTailsWith:""}${o}`},p);return p}var x="7.0.22";var D=C(),Q=x;function X(u,g,c){if(!b(u))throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_01] the first input argument must be a plain object! It was given as ${JSON.stringify(u,null,4)} (its typeof was ${typeof u}).`);if(!b(g))throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_02] the second input argument must be a plain object! It was given as ${JSON.stringify(g,null,4)} (its typeof was ${typeof g}).`);if(c&&!b(c))throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_03] the third input argument must be a plain object! It was given as ${JSON.stringify(c,null,4)} (its typeof was ${typeof c}).`);let i={...W,...c};i.dontWrapKeys=v(i.dontWrapKeys),i.preventWrappingIfContains=v(i.preventWrappingIfContains),i.dontWrapPaths=v(i.dontWrapPaths),i.ignore=v(i.ignore),typeof i.whatToDoWhenReferenceIsMissing!="number"&&(i.whatToDoWhenReferenceIsMissing=+i.whatToDoWhenReferenceIsMissing||0);function n(a,p,e,s=!0,l=!0,d=""){let t=D(a),o=D(p);return e.wrapGlobalFlipSwitch||(s=!1),b(t)?Object.keys(t).forEach(r=>{let f=d+(d.length===0?r:`.${r}`);if(e.ignore.length===0||!e.ignore.includes(r)){if(e.wrapGlobalFlipSwitch&&(s=!0,e.dontWrapKeys.length&&(s=s&&!e.dontWrapKeys.some(h=>P(r,h,{caseSensitive:!0}))),e.dontWrapPaths.length&&(s=s&&!e.dontWrapPaths.some(h=>h===f)),e.preventWrappingIfContains.length&&typeof t[r]=="string"&&(s=s&&!e.preventWrappingIfContains.some(h=>t[r].includes(h)))),w(o[r])||!w(o[r])&&e.whatToDoWhenReferenceIsMissing===2)if(Array.isArray(t[r]))if(e.whatToDoWhenReferenceIsMissing===2||m(o[r]))t[r]=O(t[r],e,s,l);else{if(t[r].every(h=>typeof h=="string"||Array.isArray(h))){let h=!0;t[r].forEach(j=>{Array.isArray(j)&&!j.every(m)&&(h=!1)}),h&&(l=!1)}t[r]=n(t[r],o[r],e,s,l,f)}else b(t[r])?e.whatToDoWhenReferenceIsMissing===2||m(o[r])?t[r]=O($(t[r],e),e,s,l):s?t[r]=n(t[r],o[r],e,s,l,f):t[r]=n(t[r],o[r],{...e,wrapGlobalFlipSwitch:!1},s,l,f):m(t[r])&&(t[r]=n(t[r],o[r],e,s,l,f));else if(typeof t[r]!=typeof o[r]&&e.whatToDoWhenReferenceIsMissing===1)throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_06] resolvedReference object does not have the key ${r} and we need it. TIP: Turn off throwing via opts2.whatToDoWhenReferenceIsMissing.`)}}):Array.isArray(t)?Array.isArray(o)?t.forEach((r,f)=>{w(t[f])&&w(o[f])?t[f]=n(t[f],o[f],e,s,l,`${d}[${f}]`):t[f]=n(t[f],o[0],e,s,l,`${d}[${f}]`)}):m(o)&&(t=O(t,e,s,l)):m(t)&&t.length&&(e.wrapHeadsWith||e.wrapTailsWith)&&(!e.preventDoubleWrapping||(e.wrapHeadsWith===""||!S(t,e.wrapHeadsWith.trim()).length)&&(e.wrapTailsWith===""||!S(t,e.wrapTailsWith.trim()).length))&&(t=`${s?e.wrapHeadsWith:""}${t}${s?e.wrapTailsWith:""}`),t}return n(u,g,i)}export{v as arrayiffy,W as defaults,O as flattenArr,$ as flattenObject,X as flattenReferencing,Q as version};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name object-flatten-referencing
|
|
3
3
|
* @fileoverview Flatten complex nested objects according to a reference objects
|
|
4
|
-
* @version 7.0.
|
|
4
|
+
* @version 7.0.22
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/object-flatten-referencing/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
"use strict";var objectFlattenReferencing=(()=>{var Q=Object.create;var v=Object.defineProperty,q=Object.defineProperties,z=Object.getOwnPropertyDescriptor,Z=Object.getOwnPropertyDescriptors,X=Object.getOwnPropertyNames,M=Object.getOwnPropertySymbols,Y=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var E=(r,t,a)=>t in r?v(r,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):r[t]=a,m=(r,t)=>{for(var a in t||(t={}))B.call(t,a)&&E(r,a,t[a]);if(M)for(var a of M(t))U.call(t,a)&&E(r,a,t[a]);return r},P=(r,t)=>q(r,Z(t));var k=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ee=(r,t)=>{for(var a in t)v(r,a,{get:t[a],enumerable:!0})},R=(r,t,a,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of X(t))!B.call(r,n)&&n!==a&&v(r,n,{get:()=>t[n],enumerable:!(o=z(t,n))||o.enumerable});return r};var j=(r,t,a)=>(a=r!=null?Q(Y(r)):{},R(t||!r||!r.__esModule?v(a,"default",{value:r,enumerable:!0}):a,r)),re=r=>R(v({},"__esModule",{value:!0}),r);var x=k((ce,N)=>{"use strict";N.exports=te;function w(r){return r instanceof Buffer?Buffer.from(r):new r.constructor(r.buffer.slice(),r.byteOffset,r.length)}function te(r){if(r=r||{},r.circles)return ne(r);return r.proto?o:a;function t(n,l){for(var i=Object.keys(n),e=new Array(i.length),f=0;f<i.length;f++){var s=i[f],p=n[s];typeof p!="object"||p===null?e[s]=p:p instanceof Date?e[s]=new Date(p):ArrayBuffer.isView(p)?e[s]=w(p):e[s]=l(p)}return e}function a(n){if(typeof n!="object"||n===null)return n;if(n instanceof Date)return new Date(n);if(Array.isArray(n))return t(n,a);if(n instanceof Map)return new Map(t(Array.from(n),a));if(n instanceof Set)return new Set(t(Array.from(n),a));var l={};for(var i in n)if(Object.hasOwnProperty.call(n,i)!==!1){var e=n[i];typeof e!="object"||e===null?l[i]=e:e instanceof Date?l[i]=new Date(e):e instanceof Map?l[i]=new Map(t(Array.from(e),a)):e instanceof Set?l[i]=new Set(t(Array.from(e),a)):ArrayBuffer.isView(e)?l[i]=w(e):l[i]=a(e)}return l}function o(n){if(typeof n!="object"||n===null)return n;if(n instanceof Date)return new Date(n);if(Array.isArray(n))return t(n,o);if(n instanceof Map)return new Map(t(Array.from(n),o));if(n instanceof Set)return new Set(t(Array.from(n),o));var l={};for(var i in n){var e=n[i];typeof e!="object"||e===null?l[i]=e:e instanceof Date?l[i]=new Date(e):e instanceof Map?l[i]=new Map(t(Array.from(e),o)):e instanceof Set?l[i]=new Set(t(Array.from(e),o)):ArrayBuffer.isView(e)?l[i]=w(e):l[i]=o(e)}return l}}function ne(r){var t=[],a=[];return r.proto?l:n;function o(i,e){for(var f=Object.keys(i),s=new Array(f.length),p=0;p<f.length;p++){var u=f[p],h=i[u];if(typeof h!="object"||h===null)s[u]=h;else if(h instanceof Date)s[u]=new Date(h);else if(ArrayBuffer.isView(h))s[u]=w(h);else{var c=t.indexOf(h);c!==-1?s[u]=a[c]:s[u]=e(h)}}return s}function n(i){if(typeof i!="object"||i===null)return i;if(i instanceof Date)return new Date(i);if(Array.isArray(i))return o(i,n);if(i instanceof Map)return new Map(o(Array.from(i),n));if(i instanceof Set)return new Set(o(Array.from(i),n));var e={};t.push(i),a.push(e);for(var f in i)if(Object.hasOwnProperty.call(i,f)!==!1){var s=i[f];if(typeof s!="object"||s===null)e[f]=s;else if(s instanceof Date)e[f]=new Date(s);else if(s instanceof Map)e[f]=new Map(o(Array.from(s),n));else if(s instanceof Set)e[f]=new Set(o(Array.from(s),n));else if(ArrayBuffer.isView(s))e[f]=w(s);else{var p=t.indexOf(s);p!==-1?e[f]=a[p]:e[f]=n(s)}}return t.pop(),a.pop(),e}function l(i){if(typeof i!="object"||i===null)return i;if(i instanceof Date)return new Date(i);if(Array.isArray(i))return o(i,l);if(i instanceof Map)return new Map(o(Array.from(i),l));if(i instanceof Set)return new Set(o(Array.from(i),l));var e={};t.push(i),a.push(e);for(var f in i){var s=i[f];if(typeof s!="object"||s===null)e[f]=s;else if(s instanceof Date)e[f]=new Date(s);else if(s instanceof Map)e[f]=new Map(o(Array.from(s),l));else if(s instanceof Set)e[f]=new Set(o(Array.from(s),l));else if(ArrayBuffer.isView(s))e[f]=w(s);else{var p=t.indexOf(s);p!==-1?e[f]=a[p]:e[f]=l(s)}}return t.pop(),a.pop(),e}}});var le={};ee(le,{arrayiffy:()=>A,defaults:()=>S,flattenArr:()=>W,flattenObject:()=>$,flattenReferencing:()=>oe,version:()=>fe});var G=j(x(),1);function D(r,t,a=0){if(typeof r!="string")throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): first input argument must be a string! Currently it's: ${typeof r}`);if(typeof t!="string")throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): second input argument must be a string! Currently it's: ${typeof t}`);if(isNaN(+a)||typeof a=="string"&&!/^\d*$/.test(a))throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): third input argument must be a natural number! Currently it's: ${a}`);let o=Array.from(r),n=Array.from(t);if(o.length===0||n.length===0||a!=null&&+a>=o.length)return[];a||(a=0);let l=[],i=!1,e;for(let f=a,s=o.length;f<s;f++)i&&(o[f]===n[f-+e]?f-+e+1===n.length&&l.push(+e):(e=null,i=!1)),i||o[f]===n[0]&&(n.length===1?l.push(f):(i=!0,e=f));return l}function C(r){if(typeof r!="string")throw new TypeError("Expected a string");return r.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}var T=new Map,L=(r,t)=>{if(!Array.isArray(r))switch(typeof r){case"string":r=[r];break;case"undefined":r=[];break;default:throw new TypeError(`Expected '${t}' to be a string or an array, but got a type of '${typeof r}'`)}return r.filter(a=>{if(typeof a!="string"){if(typeof a>"u")return!1;throw new TypeError(`Expected '${t}' to be an array of strings, but found a type of '${typeof a}' in the array`)}return!0})},ie=(r,t)=>{t=m({caseSensitive:!1},t);let a=r+JSON.stringify(t);if(T.has(a))return T.get(a);let o=r[0]==="!";o&&(r=r.slice(1)),r=C(r).replace(/\\\*/g,"[\\s\\S]*");let n=new RegExp(`^${r}$`,t.caseSensitive?"":"i");return n.negated=o,T.set(a,n),n},ae=(r,t,a,o)=>{if(r=L(r,"inputs"),t=L(t,"patterns"),t.length===0)return[];t=t.map(i=>ie(i,a));let{allPatterns:n}=a||{},l=[];for(let i of r){let e,f=[...t].fill(!1);for(let[s,p]of t.entries())if(p.test(i)&&(f[s]=!0,e=!p.negated,!e))break;if(!(e===!1||e===void 0&&t.some(s=>!s.negated)||n&&f.some((s,p)=>!s&&!t[p].negated))&&(l.push(i),o))break}return l};function J(r,t,a){return ae(r,t,a,!0).length>0}function A(r){return typeof r!="string"?r:r.length?[r]:[]}var F=j(x(),1);var be=(0,F.default)();function b(r){if(r==null||typeof r!="object")return!1;let t=Object.getPrototypeOf(r);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null?!1:!(Symbol.iterator in r)&&!(Symbol.toStringTag in r)}function y(r){return typeof r=="string"}function O(r){return r!=null}var K=j(x(),1);var H=(0,K.default)(),S={wrapHeadsWith:"%%_",wrapTailsWith:"_%%",dontWrapKeys:[],dontWrapPaths:[],xhtml:!0,preventDoubleWrapping:!0,preventWrappingIfContains:[],objectKeyAndValueJoinChar:".",wrapGlobalFlipSwitch:!0,ignore:[],whatToDoWhenReferenceIsMissing:0,mergeArraysWithLineBreaks:!0,mergeWithoutTrailingBrIfLineContainsBr:!0,enforceStrictKeyset:!0};function $(r,t){let a=m(m({},S),t);if(arguments.length===0||Object.keys(r).length===0)return[];let o=H(r),n=[];return b(o)&&Object.keys(o).forEach(l=>{b(o[l])&&(o[l]=$(o[l],a)),Array.isArray(o[l])&&(n=n.concat(o[l].map(i=>`${l}${a.objectKeyAndValueJoinChar}${i}`))),y(o[l])&&n.push(`${l}${a.objectKeyAndValueJoinChar}${o[l]}`)}),n}function W(r,t,a=!1,o=!1){let n=m(m({},S),t);if(arguments.length===0||r.length===0)return"";let l=H(r),i="";if(l.length)if(o){for(let e=0,f=l.length;e<f;e++)if(y(l[e])){let s;s="",n.mergeArraysWithLineBreaks&&e>0&&(!n.mergeWithoutTrailingBrIfLineContainsBr||typeof l[e-1]!="string"||n.mergeWithoutTrailingBrIfLineContainsBr&&l[e-1]!==void 0&&!l[e-1].toLowerCase().includes("<br"))&&(s=`<br${n.xhtml?" /":""}>`),i+=`${s}${a?n.wrapHeadsWith:""}${l[e]}${a?n.wrapTailsWith:""}`}else if(Array.isArray(l[e])&&l[e].length&&l[e].every(y)){let s="";n.mergeArraysWithLineBreaks&&i.length&&(s=`<br${n.xhtml?" /":""}>`),i=l[e].reduce((p,u,h,c)=>{let g="";return h!==c.length-1&&(g=" "),p+(h===0?s:"")+(a?n.wrapHeadsWith:"")+u+(a?n.wrapTailsWith:"")+g},i)}}else i=l.reduce((e,f,s,p)=>{let u="";n.mergeArraysWithLineBreaks&&s>0&&(u=`<br${n.xhtml?" /":""}>`);let h="";return s!==p.length-1&&(h=" "),`${e}${s===0?u:""}${a?n.wrapHeadsWith:""}${f}${a?n.wrapTailsWith:""}${h}`},i);return i}var V="7.0.18";var _=(0,G.default)(),fe=V;function oe(r,t,a){if(!b(r))throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_01] the first input argument must be a plain object! It was given as ${JSON.stringify(r,null,4)} (its typeof was ${typeof r}).`);if(!b(t))throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_02] the second input argument must be a plain object! It was given as ${JSON.stringify(t,null,4)} (its typeof was ${typeof t}).`);if(a&&!b(a))throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_03] the third input argument must be a plain object! It was given as ${JSON.stringify(a,null,4)} (its typeof was ${typeof a}).`);let o=m(m({},S),a);o.dontWrapKeys=A(o.dontWrapKeys),o.preventWrappingIfContains=A(o.preventWrappingIfContains),o.dontWrapPaths=A(o.dontWrapPaths),o.ignore=A(o.ignore),typeof o.whatToDoWhenReferenceIsMissing!="number"&&(o.whatToDoWhenReferenceIsMissing=+o.whatToDoWhenReferenceIsMissing||0);function n(l,i,e,f=!0,s=!0,p=""){let u=_(l),h=_(i);return e.wrapGlobalFlipSwitch||(f=!1),b(u)?Object.keys(u).forEach(c=>{let g=p+(p.length===0?c:`.${c}`);if(e.ignore.length===0||!e.ignore.includes(c)){if(e.wrapGlobalFlipSwitch&&(f=!0,e.dontWrapKeys.length&&(f=f&&!e.dontWrapKeys.some(d=>J(c,d,{caseSensitive:!0}))),e.dontWrapPaths.length&&(f=f&&!e.dontWrapPaths.some(d=>d===g)),e.preventWrappingIfContains.length&&typeof u[c]=="string"&&(f=f&&!e.preventWrappingIfContains.some(d=>u[c].includes(d)))),O(h[c])||!O(h[c])&&e.whatToDoWhenReferenceIsMissing===2)if(Array.isArray(u[c]))if(e.whatToDoWhenReferenceIsMissing===2||y(h[c]))u[c]=W(u[c],e,f,s);else{if(u[c].every(d=>typeof d=="string"||Array.isArray(d))){let d=!0;u[c].forEach(I=>{Array.isArray(I)&&!I.every(y)&&(d=!1)}),d&&(s=!1)}u[c]=n(u[c],h[c],e,f,s,g)}else b(u[c])?e.whatToDoWhenReferenceIsMissing===2||y(h[c])?u[c]=W($(u[c],e),e,f,s):f?u[c]=n(u[c],h[c],e,f,s,g):u[c]=n(u[c],h[c],P(m({},e),{wrapGlobalFlipSwitch:!1}),f,s,g):y(u[c])&&(u[c]=n(u[c],h[c],e,f,s,g));else if(typeof u[c]!=typeof h[c]&&e.whatToDoWhenReferenceIsMissing===1)throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_06] resolvedReference object does not have the key ${c} and we need it. TIP: Turn off throwing via opts2.whatToDoWhenReferenceIsMissing.`)}}):Array.isArray(u)?Array.isArray(h)?u.forEach((c,g)=>{O(u[g])&&O(h[g])?u[g]=n(u[g],h[g],e,f,s,`${p}[${g}]`):u[g]=n(u[g],h[0],e,f,s,`${p}[${g}]`)}):y(h)&&(u=W(u,e,f,s)):y(u)&&u.length&&(e.wrapHeadsWith||e.wrapTailsWith)&&(!e.preventDoubleWrapping||(e.wrapHeadsWith===""||!D(u,e.wrapHeadsWith.trim()).length)&&(e.wrapTailsWith===""||!D(u,e.wrapTailsWith.trim()).length))&&(u=`${f?e.wrapHeadsWith:""}${u}${f?e.wrapTailsWith:""}`),u}return n(r,t,o)}return re(le);})();
|
|
10
|
+
"use strict";var objectFlattenReferencing=(()=>{var Q=Object.create;var O=Object.defineProperty,q=Object.defineProperties,z=Object.getOwnPropertyDescriptor,Z=Object.getOwnPropertyDescriptors,k=Object.getOwnPropertyNames,E=Object.getOwnPropertySymbols,X=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var B=(e,t,i)=>t in e?O(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,b=(e,t)=>{for(var i in t||(t={}))P.call(t,i)&&B(e,i,t[i]);if(E)for(var i of E(t))Y.call(t,i)&&B(e,i,t[i]);return e},R=(e,t)=>q(e,Z(t));var U=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ee=(e,t)=>{for(var i in t)O(e,i,{get:t[i],enumerable:!0})},M=(e,t,i,f)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of k(t))!P.call(e,o)&&o!==i&&O(e,o,{get:()=>t[o],enumerable:!(f=z(t,o))||f.enumerable});return e};var S=(e,t,i)=>(i=e!=null?Q(X(e)):{},M(t||!e||!e.__esModule?O(i,"default",{value:e,enumerable:!0}):i,e)),re=e=>M(O({},"__esModule",{value:!0}),e);var $=U((ce,L)=>{"use strict";L.exports=te;function w(e){return e instanceof Buffer?Buffer.from(e):new e.constructor(e.buffer.slice(),e.byteOffset,e.length)}function te(e){if(e=e||{},e.circles)return ne(e);let t=new Map;if(t.set(Date,l=>new Date(l)),t.set(Map,(l,n)=>new Map(f(Array.from(l),n))),t.set(Set,(l,n)=>new Set(f(Array.from(l),n))),e.constructorHandlers)for(let l of e.constructorHandlers)t.set(l[0],l[1]);let i=null;return e.proto?c:o;function f(l,n){let r=Object.keys(l),s=new Array(r.length);for(let g=0;g<r.length;g++){let a=r[g],p=l[a];typeof p!="object"||p===null?s[a]=p:p.constructor!==Object&&(i=t.get(p.constructor))?s[a]=i(p,n):ArrayBuffer.isView(p)?s[a]=w(p):s[a]=n(p)}return s}function o(l){if(typeof l!="object"||l===null)return l;if(Array.isArray(l))return f(l,o);if(l.constructor!==Object&&(i=t.get(l.constructor)))return i(l,o);let n={};for(let r in l){if(Object.hasOwnProperty.call(l,r)===!1)continue;let s=l[r];typeof s!="object"||s===null?n[r]=s:s.constructor!==Object&&(i=t.get(s.constructor))?n[r]=i(s,o):ArrayBuffer.isView(s)?n[r]=w(s):n[r]=o(s)}return n}function c(l){if(typeof l!="object"||l===null)return l;if(Array.isArray(l))return f(l,c);if(l.constructor!==Object&&(i=t.get(l.constructor)))return i(l,c);let n={};for(let r in l){let s=l[r];typeof s!="object"||s===null?n[r]=s:s.constructor!==Object&&(i=t.get(s.constructor))?n[r]=i(s,c):ArrayBuffer.isView(s)?n[r]=w(s):n[r]=c(s)}return n}}function ne(e){let t=[],i=[],f=new Map;if(f.set(Date,r=>new Date(r)),f.set(Map,(r,s)=>new Map(c(Array.from(r),s))),f.set(Set,(r,s)=>new Set(c(Array.from(r),s))),e.constructorHandlers)for(let r of e.constructorHandlers)f.set(r[0],r[1]);let o=null;return e.proto?n:l;function c(r,s){let g=Object.keys(r),a=new Array(g.length);for(let p=0;p<g.length;p++){let u=g[p],h=r[u];if(typeof h!="object"||h===null)a[u]=h;else if(h.constructor!==Object&&(o=f.get(h.constructor)))a[u]=o(h,s);else if(ArrayBuffer.isView(h))a[u]=w(h);else{let d=t.indexOf(h);d!==-1?a[u]=i[d]:a[u]=s(h)}}return a}function l(r){if(typeof r!="object"||r===null)return r;if(Array.isArray(r))return c(r,l);if(r.constructor!==Object&&(o=f.get(r.constructor)))return o(r,l);let s={};t.push(r),i.push(s);for(let g in r){if(Object.hasOwnProperty.call(r,g)===!1)continue;let a=r[g];if(typeof a!="object"||a===null)s[g]=a;else if(a.constructor!==Object&&(o=f.get(a.constructor)))s[g]=o(a,l);else if(ArrayBuffer.isView(a))s[g]=w(a);else{let p=t.indexOf(a);p!==-1?s[g]=i[p]:s[g]=l(a)}}return t.pop(),i.pop(),s}function n(r){if(typeof r!="object"||r===null)return r;if(Array.isArray(r))return c(r,n);if(r.constructor!==Object&&(o=f.get(r.constructor)))return o(r,n);let s={};t.push(r),i.push(s);for(let g in r){let a=r[g];if(typeof a!="object"||a===null)s[g]=a;else if(a.constructor!==Object&&(o=f.get(a.constructor)))s[g]=o(a,n);else if(ArrayBuffer.isView(a))s[g]=w(a);else{let p=t.indexOf(a);p!==-1?s[g]=i[p]:s[g]=n(a)}}return t.pop(),i.pop(),s}}});var fe={};ee(fe,{arrayiffy:()=>A,defaults:()=>j,flattenArr:()=>x,flattenObject:()=>v,flattenReferencing:()=>le,version:()=>oe});var G=S($(),1);function C(e,t,i=0){if(typeof e!="string")throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): first input argument must be a string! Currently it's: ${typeof e}`);if(typeof t!="string")throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): second input argument must be a string! Currently it's: ${typeof t}`);if(isNaN(+i)||typeof i=="string"&&!/^\d*$/.test(i))throw new TypeError(`str-indexes-of-plus/strIndexesOfPlus(): third input argument must be a natural number! Currently it's: ${i}`);let f=Array.from(e),o=Array.from(t);if(f.length===0||o.length===0||i!=null&&+i>=f.length)return[];i||(i=0);let c=[],l=!1,n;for(let r=i,s=f.length;r<s;r++)l&&(f[r]===o[r-+n]?r-+n+1===o.length&&c.push(+n):(n=null,l=!1)),l||f[r]===o[0]&&(o.length===1?c.push(r):(l=!0,n=r));return c}function T(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}var I=new Map,H=(e,t)=>{if(!Array.isArray(e))switch(typeof e){case"string":e=[e];break;case"undefined":e=[];break;default:throw new TypeError(`Expected '${t}' to be a string or an array, but got a type of '${typeof e}'`)}return e.filter(i=>{if(typeof i!="string"){if(typeof i>"u")return!1;throw new TypeError(`Expected '${t}' to be an array of strings, but found a type of '${typeof i}' in the array`)}return!0})},ie=(e,t)=>{t=b({caseSensitive:!1},t);let i=e+JSON.stringify(t);if(I.has(i))return I.get(i);let f=e[0]==="!";f&&(e=e.slice(1)),e=T(e).replace(/\\\*/g,"[\\s\\S]*");let o=new RegExp(`^${e}$`,t.caseSensitive?"":"i");return o.negated=f,I.set(i,o),o},se=(e,t,i,f)=>{if(e=H(e,"inputs"),t=H(t,"patterns"),t.length===0)return[];t=t.map(l=>ie(l,i));let{allPatterns:o}=i||{},c=[];for(let l of e){let n,r=[...t].fill(!1);for(let[s,g]of t.entries())if(g.test(l)&&(r[s]=!0,n=!g.negated,!n))break;if(!(n===!1||n===void 0&&t.some(s=>!s.negated)||o&&r.some((s,g)=>!s&&!t[g].negated))&&(c.push(l),f))break}return c};function N(e,t,i){return se(e,t,i,!0).length>0}function A(e){return typeof e!="string"?e:e.length?[e]:[]}var F=S($(),1);var ye=(0,F.default)();function y(e){if(e==null||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null?!1:!(Symbol.iterator in e)&&!(Symbol.toStringTag in e)}function m(e){return typeof e=="string"}function W(e){return e!=null}var J=S($(),1);var K=(0,J.default)(),j={wrapHeadsWith:"%%_",wrapTailsWith:"_%%",dontWrapKeys:[],dontWrapPaths:[],xhtml:!0,preventDoubleWrapping:!0,preventWrappingIfContains:[],objectKeyAndValueJoinChar:".",wrapGlobalFlipSwitch:!0,ignore:[],whatToDoWhenReferenceIsMissing:0,mergeArraysWithLineBreaks:!0,mergeWithoutTrailingBrIfLineContainsBr:!0,enforceStrictKeyset:!0};function v(e,t){let i=b(b({},j),t);if(arguments.length===0||Object.keys(e).length===0)return[];let f=K(e),o=[];return y(f)&&Object.keys(f).forEach(c=>{y(f[c])&&(f[c]=v(f[c],i)),Array.isArray(f[c])&&(o=o.concat(f[c].map(l=>`${c}${i.objectKeyAndValueJoinChar}${l}`))),m(f[c])&&o.push(`${c}${i.objectKeyAndValueJoinChar}${f[c]}`)}),o}function x(e,t,i=!1,f=!1){let o=b(b({},j),t);if(arguments.length===0||e.length===0)return"";let c=K(e),l="";if(c.length)if(f){for(let n=0,r=c.length;n<r;n++)if(m(c[n])){let s;s="",o.mergeArraysWithLineBreaks&&n>0&&(!o.mergeWithoutTrailingBrIfLineContainsBr||typeof c[n-1]!="string"||o.mergeWithoutTrailingBrIfLineContainsBr&&c[n-1]!==void 0&&!c[n-1].toLowerCase().includes("<br"))&&(s=`<br${o.xhtml?" /":""}>`),l+=`${s}${i?o.wrapHeadsWith:""}${c[n]}${i?o.wrapTailsWith:""}`}else if(Array.isArray(c[n])&&c[n].length&&c[n].every(m)){let s="";o.mergeArraysWithLineBreaks&&l.length&&(s=`<br${o.xhtml?" /":""}>`),l=c[n].reduce((g,a,p,u)=>{let h="";return p!==u.length-1&&(h=" "),g+(p===0?s:"")+(i?o.wrapHeadsWith:"")+a+(i?o.wrapTailsWith:"")+h},l)}}else l=c.reduce((n,r,s,g)=>{let a="";o.mergeArraysWithLineBreaks&&s>0&&(a=`<br${o.xhtml?" /":""}>`);let p="";return s!==g.length-1&&(p=" "),`${n}${s===0?a:""}${i?o.wrapHeadsWith:""}${r}${i?o.wrapTailsWith:""}${p}`},l);return l}var V="7.0.22";var _=(0,G.default)(),oe=V;function le(e,t,i){if(!y(e))throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_01] the first input argument must be a plain object! It was given as ${JSON.stringify(e,null,4)} (its typeof was ${typeof e}).`);if(!y(t))throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_02] the second input argument must be a plain object! It was given as ${JSON.stringify(t,null,4)} (its typeof was ${typeof t}).`);if(i&&!y(i))throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_03] the third input argument must be a plain object! It was given as ${JSON.stringify(i,null,4)} (its typeof was ${typeof i}).`);let f=b(b({},j),i);f.dontWrapKeys=A(f.dontWrapKeys),f.preventWrappingIfContains=A(f.preventWrappingIfContains),f.dontWrapPaths=A(f.dontWrapPaths),f.ignore=A(f.ignore),typeof f.whatToDoWhenReferenceIsMissing!="number"&&(f.whatToDoWhenReferenceIsMissing=+f.whatToDoWhenReferenceIsMissing||0);function o(c,l,n,r=!0,s=!0,g=""){let a=_(c),p=_(l);return n.wrapGlobalFlipSwitch||(r=!1),y(a)?Object.keys(a).forEach(u=>{let h=g+(g.length===0?u:`.${u}`);if(n.ignore.length===0||!n.ignore.includes(u)){if(n.wrapGlobalFlipSwitch&&(r=!0,n.dontWrapKeys.length&&(r=r&&!n.dontWrapKeys.some(d=>N(u,d,{caseSensitive:!0}))),n.dontWrapPaths.length&&(r=r&&!n.dontWrapPaths.some(d=>d===h)),n.preventWrappingIfContains.length&&typeof a[u]=="string"&&(r=r&&!n.preventWrappingIfContains.some(d=>a[u].includes(d)))),W(p[u])||!W(p[u])&&n.whatToDoWhenReferenceIsMissing===2)if(Array.isArray(a[u]))if(n.whatToDoWhenReferenceIsMissing===2||m(p[u]))a[u]=x(a[u],n,r,s);else{if(a[u].every(d=>typeof d=="string"||Array.isArray(d))){let d=!0;a[u].forEach(D=>{Array.isArray(D)&&!D.every(m)&&(d=!1)}),d&&(s=!1)}a[u]=o(a[u],p[u],n,r,s,h)}else y(a[u])?n.whatToDoWhenReferenceIsMissing===2||m(p[u])?a[u]=x(v(a[u],n),n,r,s):r?a[u]=o(a[u],p[u],n,r,s,h):a[u]=o(a[u],p[u],R(b({},n),{wrapGlobalFlipSwitch:!1}),r,s,h):m(a[u])&&(a[u]=o(a[u],p[u],n,r,s,h));else if(typeof a[u]!=typeof p[u]&&n.whatToDoWhenReferenceIsMissing===1)throw new Error(`object-flatten-referencing/ofr(): [THROW_ID_06] resolvedReference object does not have the key ${u} and we need it. TIP: Turn off throwing via opts2.whatToDoWhenReferenceIsMissing.`)}}):Array.isArray(a)?Array.isArray(p)?a.forEach((u,h)=>{W(a[h])&&W(p[h])?a[h]=o(a[h],p[h],n,r,s,`${g}[${h}]`):a[h]=o(a[h],p[0],n,r,s,`${g}[${h}]`)}):m(p)&&(a=x(a,n,r,s)):m(a)&&a.length&&(n.wrapHeadsWith||n.wrapTailsWith)&&(!n.preventDoubleWrapping||(n.wrapHeadsWith===""||!C(a,n.wrapHeadsWith.trim()).length)&&(n.wrapTailsWith===""||!C(a,n.wrapTailsWith.trim()).length))&&(a=`${r?n.wrapHeadsWith:""}${a}${r?n.wrapTailsWith:""}`),a}return o(e,t,f)}return re(fe);})();
|
|
11
11
|
/**
|
|
12
12
|
* @name str-indexes-of-plus
|
|
13
13
|
* @fileoverview Like indexOf but returns array and counts per-grapheme
|
|
14
|
-
* @version 5.0.
|
|
14
|
+
* @version 5.0.9
|
|
15
15
|
* @author Roy Revelt, Codsen Ltd
|
|
16
16
|
* @license MIT
|
|
17
17
|
* {@link https://codsen.com/os/str-indexes-of-plus/}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
/**
|
|
20
20
|
* @name arrayiffy-if-string
|
|
21
21
|
* @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
|
|
22
|
-
* @version 5.0.
|
|
22
|
+
* @version 5.0.10
|
|
23
23
|
* @author Roy Revelt, Codsen Ltd
|
|
24
24
|
* @license MIT
|
|
25
25
|
* {@link https://codsen.com/os/arrayiffy-if-string/}
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
/**
|
|
28
28
|
* @name codsen-utils
|
|
29
29
|
* @fileoverview Various utility functions
|
|
30
|
-
* @version 1.6.
|
|
30
|
+
* @version 1.6.8
|
|
31
31
|
* @author Roy Revelt, Codsen Ltd
|
|
32
32
|
* @license MIT
|
|
33
33
|
* {@link https://codsen.com/os/codsen-utils/}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "object-flatten-referencing",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.22",
|
|
4
4
|
"description": "Flatten complex nested objects according to a reference objects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"advanced",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"homepage": "https://codsen.com/os/object-flatten-referencing",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "https://github.com/codsen/codsen.git",
|
|
20
|
+
"url": "git+https://github.com/codsen/codsen.git",
|
|
21
21
|
"directory": "packages/object-flatten-referencing"
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
44
44
|
"lect": "node '../../ops/lect/lect.js' && npm run prettier -- 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
|
|
45
45
|
"letspublish": "npm publish || :",
|
|
46
|
-
"lint": "eslint . --
|
|
46
|
+
"lint": "eslint . --fix",
|
|
47
47
|
"perf": "node perf/check.js",
|
|
48
48
|
"prep": "echo 'ready'",
|
|
49
49
|
"prettier": "prettier",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"arrayiffy-if-string": "^5.0.
|
|
74
|
-
"codsen-utils": "^1.6.
|
|
73
|
+
"arrayiffy-if-string": "^5.0.10",
|
|
74
|
+
"codsen-utils": "^1.6.8",
|
|
75
75
|
"matcher": "^5.0.0",
|
|
76
|
-
"rfdc": "^1.
|
|
77
|
-
"str-indexes-of-plus": "^5.0.
|
|
76
|
+
"rfdc": "^1.4.1",
|
|
77
|
+
"str-indexes-of-plus": "^5.0.9"
|
|
78
78
|
}
|
|
79
79
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -33,11 +33,5 @@ declare function flattenReferencing(
|
|
|
33
33
|
opts?: Partial<Opts>,
|
|
34
34
|
): any;
|
|
35
35
|
|
|
36
|
-
export {
|
|
37
|
-
|
|
38
|
-
defaults,
|
|
39
|
-
flattenArr,
|
|
40
|
-
flattenObject,
|
|
41
|
-
flattenReferencing,
|
|
42
|
-
version,
|
|
43
|
-
};
|
|
36
|
+
export { defaults, flattenArr, flattenObject, flattenReferencing, version };
|
|
37
|
+
export type { Opts };
|