object-flatten-referencing 7.0.14 → 7.0.16
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,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.16
|
|
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 J}from"matcher";import{arrayiffy as v}from"arrayiffy-if-string";import{existy as y,isStr as m,isPlainObject as b}from"codsen-utils";import D from"rfdc";import{isStr as w,isPlainObject as I}from"codsen-utils";var T=D(),W={wrapHeadsWith:"%%_",wrapTailsWith:"_%%",dontWrapKeys:[],dontWrapPaths:[],xhtml:!0,preventDoubleWrapping:!0,preventWrappingIfContains:[],objectKeyAndValueJoinChar:".",wrapGlobalFlipSwitch:!0,ignore:[],whatToDoWhenReferenceIsMissing:0,mergeArraysWithLineBreaks:!0,mergeWithoutTrailingBrIfLineContainsBr:!0,enforceStrictKeyset:!0};function j(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]=j(i[a],c)),Array.isArray(i[a])&&(n=n.concat(i[a].map(p=>`${a}${c.objectKeyAndValueJoinChar}${p}`))),w(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(w(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(w)){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.
|
|
10
|
+
import C from"rfdc";import{strIndexesOfPlus as S}from"str-indexes-of-plus";import{isMatch as J}from"matcher";import{arrayiffy as v}from"arrayiffy-if-string";import{existy as y,isStr as m,isPlainObject as b}from"codsen-utils";import D from"rfdc";import{isStr as w,isPlainObject as I}from"codsen-utils";var T=D(),W={wrapHeadsWith:"%%_",wrapTailsWith:"_%%",dontWrapKeys:[],dontWrapPaths:[],xhtml:!0,preventDoubleWrapping:!0,preventWrappingIfContains:[],objectKeyAndValueJoinChar:".",wrapGlobalFlipSwitch:!0,ignore:[],whatToDoWhenReferenceIsMissing:0,mergeArraysWithLineBreaks:!0,mergeWithoutTrailingBrIfLineContainsBr:!0,enforceStrictKeyset:!0};function j(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]=j(i[a],c)),Array.isArray(i[a])&&(n=n.concat(i[a].map(p=>`${a}${c.objectKeyAndValueJoinChar}${p}`))),w(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(w(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(w)){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.16";var A=C(),X=x;function Y(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=A(a),o=A(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=>J(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)))),y(o[r])||!y(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($=>{Array.isArray($)&&!$.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(j(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)=>{y(t[f])&&y(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,j as flattenObject,Y as flattenReferencing,X as version};
|
|
@@ -1,13 +1,13 @@
|
|
|
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.16
|
|
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.14";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 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.16";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);})();
|
|
11
11
|
/**
|
|
12
12
|
* @name str-indexes-of-plus
|
|
13
13
|
* @fileoverview Like indexOf but returns array and counts per-grapheme
|
|
@@ -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.7
|
|
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.2
|
|
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.16",
|
|
4
4
|
"description": "Flatten complex nested objects according to a reference objects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"advanced",
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"arrayiffy-if-string": "^5.0.
|
|
74
|
-
"codsen-utils": "^1.6.
|
|
73
|
+
"arrayiffy-if-string": "^5.0.7",
|
|
74
|
+
"codsen-utils": "^1.6.2",
|
|
75
75
|
"matcher": "^5.0.0",
|
|
76
76
|
"rfdc": "^1.3.0",
|
|
77
77
|
"str-indexes-of-plus": "^5.0.6"
|