@symbo.ls/utils 3.14.11 → 3.14.12
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/CHANGELOG.md +6 -0
- package/dist/cjs/object.js +6 -6
- package/dist/esm/object.js +6 -6
- package/object.js +24 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/cjs/object.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";var g=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var L=(e,t)=>{for(var o in t)g(e,o,{get:t[o],enumerable:!0})},B=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of M(t))!F.call(e,n)&&n!==o&&g(e,n,{get:()=>t[n],enumerable:!(r=R(t,n))||r.enumerable});return e};var H=e=>B(g({},"__esModule",{value:!0}),e);var
|
|
2
|
-
`;for(const s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;const c=e[s];let f=!1;for(let l=0;l<s.length;l++)if(
|
|
1
|
+
"use strict";var g=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var L=(e,t)=>{for(var o in t)g(e,o,{get:t[o],enumerable:!0})},B=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of M(t))!F.call(e,n)&&n!==o&&g(e,n,{get:()=>t[n],enumerable:!(r=R(t,n))||r.enumerable});return e};var H=e=>B(g({},"__esModule",{value:!0}),e);var pe={};L(pe,{clone:()=>z,createNestedObject:()=>se,createObjectWithoutPrototype:()=>I,deepClone:()=>D,deepContains:()=>re,deepDestringifyFunctions:()=>x,deepMerge:()=>q,deepStringifyFunctions:()=>S,destringifyGlobalScope:()=>X,detectInfiniteLoop:()=>le,excludeKeysFromObject:()=>ae,exec:()=>_,getInObjectByPath:()=>fe,hasFunction:()=>d,hasOwnProperty:()=>m,isCyclic:()=>ue,isEmpty:()=>C,isEmptyObject:()=>b,isEqualDeep:()=>W,makeObjectWithoutPrototype:()=>j,map:()=>J,merge:()=>V,objectToString:()=>P,overwrite:()=>ee,overwriteDeep:()=>T,overwriteShallow:()=>te,removeFromObject:()=>oe,removeNestedKeyByPath:()=>ce,setInObjectByPath:()=>ie,stringToObject:()=>Y});module.exports=H(pe);var O=require("./globals.js"),i=require("./types.js"),E=require("./array.js"),v=require("./string.js"),h=require("./node.js"),N=require("./keys.js");const $="production",w=e=>e.charCodeAt(0)===95&&e.charCodeAt(1)===95,_=(e,t,o,r)=>{if((0,i.isFunction)(e))return t?typeof e.call!="function"?e:e.call(t,t,o||t.state,r||t.context):void 0;if(e!=null&&t?.context?.plugins&&((0,i.isArray)(e)||(0,i.isObject)(e)&&!(0,h.isDOMNode)(e))){const n=t.context.plugins;for(const s of n)if(s.resolveHandler){const c=s.resolveHandler(e,t);if(typeof c=="function")return _(c,t,o,r)}}return e},J=(e,t,o)=>{for(const r in t)e[r]=_(t[r],o)},V=(e,t,o=[])=>{const r=o instanceof Set;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(w(n)||(r?o.has(n):o.includes(n))||e[n]===void 0&&(e[n]=t[n]));return e},q=(e,t,o=N.METHODS_EXL)=>A(e,t,o,null),A=(e,t,o,r)=>{if(e===t)return e;if(r){for(let s=0;s<r.length;s+=2)if(r[s]===e&&r[s+1]===t)return e}const n=o instanceof Set;for(const s in t){if(!Object.prototype.hasOwnProperty.call(t,s)||w(s)||s==="constructor"||s==="prototype"||(n?o.has(s):o.includes(s)))continue;const c=e[s],f=t[s];if((0,i.isObjectLike)(c)&&(0,i.isObjectLike)(f)){const u=r||[];u.push(e,t),A(c,f,o,u),u.length-=2}else c===void 0&&(e[s]=f)}return e},z=(e,t=[])=>{const o=t instanceof Set,r={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(w(n)||(o?t.has(n):t.includes(n))||(r[n]=e[n]));return r},D=(e,t={})=>{const{exclude:o=[],cleanUndefined:r=!1,cleanNull:n=!1,window:s,visited:c=new WeakMap,handleExtends:f=!1}=t,u=s||O.window||globalThis;if(!(0,i.isObjectLike)(e)||(0,h.isDOMNode)(e))return e;if(c.has(e))return c.get(e);const a=(0,i.isArray)(e)?[]:{};c.set(e,a);const k=o instanceof Set?o:o.length>3?new Set(o):null;for(const p in e){if(!Object.prototype.hasOwnProperty.call(e,p)||w(p)||p==="__proto__"||(k?k.has(p):o.includes(p)))continue;const y=e[p];if(!(r&&y===void 0)&&!(n&&y===null)){if((0,h.isDOMNode)(y)){a[p]=y;continue}if(f&&p==="extends"&&(0,i.isArray)(y)){a[p]=(0,E.unstackArrayOfObjects)(y,o);continue}if((0,i.isFunction)(y)){a[p]=y;continue}(0,i.isObjectLike)(y)?a[p]=D(y,{...t,visited:c}):a[p]=y}}return a},S=(e,t={})=>{(e.node||e.__ref||e.parent||e.__element||e.parse)&&((e.__element||e.parent?.__element).warn("Trying to clone element or state at",e),e=e.parse?.());for(const o in e){const r=e[o];if((0,i.isFunction)(r))t[o]=r.toString();else if((0,i.isObject)(r))t[o]={},S(r,t[o]);else if((0,i.isArray)(r)){const n=t[o]=[];for(let s=0;s<r.length;s++){const c=r[s];(0,i.isObject)(c)?(n[s]={},S(c,n[s])):(0,i.isFunction)(c)?n[s]=c.toString():n[s]=c}}else t[o]=r}return t},G=new Set(["&","*","-",":","%","{","}",">","<","@",".","/","!"," "]),P=(e={},t=0)=>{if(e===null||typeof e!="object")return String(e);let o=!1;for(const s in e){o=!0;break}if(!o)return"{}";const r=" ".repeat(t);let n=`{
|
|
2
|
+
`;for(const s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;const c=e[s];let f=!1;for(let l=0;l<s.length;l++)if(G.has(s[l])){f=!0;break}const u=f?`'${s}'`:s;if(n+=`${r} ${u}: `,(0,i.isArray)(c)){n+=`[
|
|
3
3
|
`;for(const l of c)(0,i.isObjectLike)(l)&&l!==null?n+=`${r} ${P(l,t+2)},
|
|
4
4
|
`:(0,i.isString)(l)?n+=`${r} '${l}',
|
|
5
5
|
`:n+=`${r} ${l},
|
|
6
|
-
`;n+=`${r} ]`}else(0,i.isObjectLike)(c)?n+=P(c,t+1):(0,i.isString)(c)?n+=(0,
|
|
6
|
+
`;n+=`${r} ]`}else(0,i.isObjectLike)(c)?n+=P(c,t+1):(0,i.isString)(c)?n+=(0,v.stringIncludesAny)(c,[`
|
|
7
7
|
`,"'"])?`\`${c}\``:`'${c}'`:n+=c;n+=`,
|
|
8
|
-
`}return n+=`${r}}`,n},
|
|
8
|
+
`}return n+=`${r}}`,n},K=[/^\(\s*\{[^}]*\}\s*\)\s*=>/,/^(\([^)]*\)|[^=]*)\s*=>/,/^function[\s(]/,/^async\s+/,/^\(\s*function/,/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/],U=/^["[{]/,d=e=>{if(!e)return!1;const t=e.trim().replace(/\n\s*/g," ").trim();if(t===""||t==="{}"||t==="[]"||!K.some(s=>s.test(t)))return!1;const r=t.charCodeAt(0),n=t.includes("=>");return!(r===123&&!n||r===91||U.test(t)&&!n)},Z=e=>(0,eval)(e),x=(e,t={},o={window:{eval:Z}})=>{for(const r in e){if(!Object.prototype.hasOwnProperty.call(e,r))continue;const n=e[r];if((0,i.isString)(n))if(d(n))try{t[r]=o.window.eval(`(${n})`)}catch(s){typeof console<"u"&&console.warn&&console.warn('[smbls] deepDestringifyFunctions: eval failed on "'+r+'" \u2014 function will be left as a string and el.call("'+r+'") will silently no-op. Reason: '+(s&&s.message?s.message:String(s))+`.
|
|
9
9
|
First 200 chars of source: `+String(n).slice(0,200)),t[r]=n}else t[r]=n;else if((0,i.isArray)(n)){const s=t[r]=[];for(let c=0;c<n.length;c++){const f=n[c];if((0,i.isString)(f))if(d(f))try{s.push(o.window.eval(`(${f})`))}catch(u){typeof console<"u"&&console.warn&&console.warn(`[smbls] deepDestringifyFunctions: eval failed in array at index ${c} (prop "${r}"). Reason: ${u&&u.message?u.message:String(u)}.
|
|
10
|
-
First 200 chars: ${String(f).slice(0,200)}`),s.push(f)}else s.push(f);else(0,i.isObject)(f)?s.push(x(f)):s.push(f)}}else(0,i.isObject)(n)?t[r]=x(n,t[r]):t[r]=n}return t},Q=e=>{if(!e||typeof e!="object")return e;const t={},o=[];for(const r of Object.keys(e)){const n=e[r];(0,i.isString)(n)&&d(n)?o.push([r,n]):t[r]=n}for(const[r,n]of o)try{const s=Object.keys(t).map(c=>`var ${c} = __gs__[${JSON.stringify(c)}];`).join(`
|
|
10
|
+
First 200 chars: ${String(f).slice(0,200)}`),s.push(f)}else s.push(f);else(0,i.isObject)(f)?s.push(x(f)):s.push(f)}}else(0,i.isObject)(n)?t[r]=x(n,t[r]):t[r]=n}return t},Q=e=>!e||typeof e!="object"?e:e.__type==="Set"&&Array.isArray(e.values)?new Set(e.values):e.__type==="Map"&&Array.isArray(e.entries)?new Map(e.entries):e,X=e=>{if(!e||typeof e!="object")return e;const t={},o=[];for(const r of Object.keys(e)){const n=e[r];(0,i.isString)(n)&&d(n)?o.push([r,n]):t[r]=Q(n)}for(const[r,n]of o)try{const s=Object.keys(t).map(c=>`var ${c} = __gs__[${JSON.stringify(c)}];`).join(`
|
|
11
11
|
`);t[r]=O.window.eval(`(function(__gs__) { ${s}
|
|
12
|
-
return (${n}); })`)(t)}catch{try{t[r]=O.window.eval(`(${n})`)}catch{t[r]=n}}return t},
|
|
12
|
+
return (${n}); })`)(t)}catch{try{t[r]=O.window.eval(`(${n})`)}catch{t[r]=n}}return t},Y=(e,t={verbose:!0})=>{try{return e?O.window.eval("("+e+")"):{}}catch(o){t.verbose&&console.warn(o)}},m=(e,...t)=>Object.prototype.hasOwnProperty.call(e,...t),C=e=>{for(const t in e)return!1;return!0},b=e=>(0,i.isObject)(e)&&C(e),j=()=>Object.create(null),ee=(e,t,o={})=>{const r=o.exclude||[],n=o.preventUnderscore;for(const s in t)r.includes(s)||!n&&w(s)||s==="constructor"||s==="prototype"||t[s]!==void 0&&(e[s]=t[s]);return e},te=(e,t,o=[])=>{const r=o instanceof Set;for(const n in t)w(n)||n==="constructor"||n==="prototype"||(r?o.has(n):o.includes(n))||(e[n]=t[n]);return e},T=(e,t,o={},r=new WeakMap)=>{if(!(0,i.isObjectLike)(e)||!(0,i.isObjectLike)(t)||(0,h.isDOMNode)(e)||(0,h.isDOMNode)(t))return t;if(r.has(e))return r.get(e);r.set(e,e);const n=o.exclude,s=n?n instanceof Set?n:new Set(n):null,c=!o.preventForce;for(const f in t){if(!Object.prototype.hasOwnProperty.call(t,f)||s&&s.has(f)||c&&w(f)||f==="constructor"||f==="prototype")continue;const u=e[f],l=t[f];(0,h.isDOMNode)(l)?e[f]=l:(0,i.isObjectLike)(u)&&(0,i.isObjectLike)(l)?e[f]=T(u,l,o,r):l!==void 0&&(e[f]=l)}return e},W=(e,t,o=new Set)=>{if(typeof e!="object"||typeof t!="object"||e===null||t===null)return e===t;if(o.has(e)||o.has(t))return!0;o.add(e),o.add(t);const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(let s=0;s<r.length;s++){const c=r[s];if(!Object.prototype.hasOwnProperty.call(t,c)||!W(e[c],t[c],o))return!1}return!0},ne=new Set(["node","__ref"]),re=(e,t,o=ne)=>{if(e===t)return!0;if(!(0,i.isObjectLike)(e)||!(0,i.isObjectLike)(t)||(0,h.isDOMNode)(e)||(0,h.isDOMNode)(t))return e===t;const r=o instanceof Set?o:new Set(o),n=new WeakSet;function s(c,f){if(n.has(f))return!0;n.add(f);for(const u in f){if(!Object.prototype.hasOwnProperty.call(f,u)||r.has(u))continue;if(!Object.prototype.hasOwnProperty.call(c,u))return!1;const l=f[u],a=c[u];if((0,h.isDOMNode)(l)||(0,h.isDOMNode)(a)){if(l!==a)return!1}else if((0,i.isObjectLike)(l)&&(0,i.isObjectLike)(a)){if(!s(a,l))return!1}else if(l!==a)return!1}return!0}return s(e,t)},oe=(e,t)=>{if(t==null)return e;if((0,i.is)(t)("string","number"))delete e[t];else if((0,i.isArray)(t))for(let o=0;o<t.length;o++)delete e[t[o]];else throw new Error("Invalid input: props must be a string or an array of strings");return e},I=e=>{if(e===null||typeof e!="object")return e;const t=Object.create(null);for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=I(e[o]));return t},se=(e,t)=>{if(e.length===0)return t;const o={};let r=o;for(let n=0;n<e.length;n++)n===e.length-1&&t?r[e[n]]=t:(r[e[n]]={},r=r[e[n]]);return o},ce=(e,t)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let o=e;for(let n=0;n<t.length-1;n++){if(o[t[n]]===void 0)return;o=o[t[n]]}const r=t[t.length-1];o&&Object.prototype.hasOwnProperty.call(o,r)&&delete o[r]},ie=(e,t,o)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let r=e;for(let n=0;n<t.length-1;n++)(!r[t[n]]||typeof r[t[n]]!="object")&&(r[t[n]]={}),r=r[t[n]];return r[t[t.length-1]]=o,e},fe=(e,t)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let o=e;for(let r=0;r<t.length;r++){if(o==null)return;o=o[t[r]]}return o},le=e=>{let o=[],r=0;for(let n=0;n<e.length;n++)if(o.length<2)o.push(e[n]);else if(e[n]===o[n%2]?r++:(o=[e[n-1],e[n]],r=1),r>=20)return($==="test"||$==="development")&&console.warn("Warning: Potential infinite loop detected due to repeated sequence:",o),!0},ue=e=>{const t=new WeakSet;function o(r){if(r&&typeof r=="object"){if(t.has(r))return!0;t.add(r);for(const n in r)if(Object.prototype.hasOwnProperty.call(r,n)&&o(r[n]))return console.log(r,"cycle at "+n),!0}return!1}return o(e)},ae=(e,t)=>{const o=t instanceof Set?t:new Set(t),r={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&!o.has(n)&&(r[n]=e[n]);return r};
|
package/dist/esm/object.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import{window as
|
|
1
|
+
import{window as _}from"./globals.js";import{isFunction as S,isObjectLike as u,isObject as d,isArray as w,isString as g,is as D}from"./types.js";import{unstackArrayOfObjects as C}from"./array.js";import{stringIncludesAny as T}from"./string.js";import{isDOMNode as h}from"./node.js";import{METHODS_EXL as W}from"./keys.js";const k="production",O=e=>e.charCodeAt(0)===95&&e.charCodeAt(1)===95,$=(e,t,o,r)=>{if(S(e))return t?typeof e.call!="function"?e:e.call(t,t,o||t.state,r||t.context):void 0;if(e!=null&&t?.context?.plugins&&(w(e)||d(e)&&!h(e))){const n=t.context.plugins;for(const s of n)if(s.resolveHandler){const c=s.resolveHandler(e,t);if(typeof c=="function")return $(c,t,o,r)}}return e},Y=(e,t,o)=>{for(const r in t)e[r]=$(t[r],o)},m=(e,t,o=[])=>{const r=o instanceof Set;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(O(n)||(r?o.has(n):o.includes(n))||e[n]===void 0&&(e[n]=t[n]));return e},b=(e,t,o=W)=>A(e,t,o,null),A=(e,t,o,r)=>{if(e===t)return e;if(r){for(let s=0;s<r.length;s+=2)if(r[s]===e&&r[s+1]===t)return e}const n=o instanceof Set;for(const s in t){if(!Object.prototype.hasOwnProperty.call(t,s)||O(s)||s==="constructor"||s==="prototype"||(n?o.has(s):o.includes(s)))continue;const c=e[s],i=t[s];if(u(c)&&u(i)){const l=r||[];l.push(e,t),A(c,i,o,l),l.length-=2}else c===void 0&&(e[s]=i)}return e},j=(e,t=[])=>{const o=t instanceof Set,r={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(O(n)||(o?t.has(n):t.includes(n))||(r[n]=e[n]));return r},I=(e,t={})=>{const{exclude:o=[],cleanUndefined:r=!1,cleanNull:n=!1,window:s,visited:c=new WeakMap,handleExtends:i=!1}=t,l=s||_||globalThis;if(!u(e)||h(e))return e;if(c.has(e))return c.get(e);const a=w(e)?[]:{};c.set(e,a);const x=o instanceof Set?o:o.length>3?new Set(o):null;for(const p in e){if(!Object.prototype.hasOwnProperty.call(e,p)||O(p)||p==="__proto__"||(x?x.has(p):o.includes(p)))continue;const y=e[p];if(!(r&&y===void 0)&&!(n&&y===null)){if(h(y)){a[p]=y;continue}if(i&&p==="extends"&&w(y)){a[p]=C(y,o);continue}if(S(y)){a[p]=y;continue}u(y)?a[p]=I(y,{...t,visited:c}):a[p]=y}}return a},E=(e,t={})=>{(e.node||e.__ref||e.parent||e.__element||e.parse)&&((e.__element||e.parent?.__element).warn("Trying to clone element or state at",e),e=e.parse?.());for(const o in e){const r=e[o];if(S(r))t[o]=r.toString();else if(d(r))t[o]={},E(r,t[o]);else if(w(r)){const n=t[o]=[];for(let s=0;s<r.length;s++){const c=r[s];d(c)?(n[s]={},E(c,n[s])):S(c)?n[s]=c.toString():n[s]=c}}else t[o]=r}return t},R=new Set(["&","*","-",":","%","{","}",">","<","@",".","/","!"," "]),v=(e={},t=0)=>{if(e===null||typeof e!="object")return String(e);let o=!1;for(const s in e){o=!0;break}if(!o)return"{}";const r=" ".repeat(t);let n=`{
|
|
2
2
|
`;for(const s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;const c=e[s];let i=!1;for(let f=0;f<s.length;f++)if(R.has(s[f])){i=!0;break}const l=i?`'${s}'`:s;if(n+=`${r} ${l}: `,w(c)){n+=`[
|
|
3
|
-
`;for(const f of c)u(f)&&f!==null?n+=`${r} ${
|
|
3
|
+
`;for(const f of c)u(f)&&f!==null?n+=`${r} ${v(f,t+2)},
|
|
4
4
|
`:g(f)?n+=`${r} '${f}',
|
|
5
5
|
`:n+=`${r} ${f},
|
|
6
|
-
`;n+=`${r} ]`}else u(c)?n+=
|
|
6
|
+
`;n+=`${r} ]`}else u(c)?n+=v(c,t+1):g(c)?n+=T(c,[`
|
|
7
7
|
`,"'"])?`\`${c}\``:`'${c}'`:n+=c;n+=`,
|
|
8
8
|
`}return n+=`${r}}`,n},M=[/^\(\s*\{[^}]*\}\s*\)\s*=>/,/^(\([^)]*\)|[^=]*)\s*=>/,/^function[\s(]/,/^async\s+/,/^\(\s*function/,/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/],F=/^["[{]/,P=e=>{if(!e)return!1;const t=e.trim().replace(/\n\s*/g," ").trim();if(t===""||t==="{}"||t==="[]"||!M.some(s=>s.test(t)))return!1;const r=t.charCodeAt(0),n=t.includes("=>");return!(r===123&&!n||r===91||F.test(t)&&!n)},L=e=>(0,eval)(e),N=(e,t={},o={window:{eval:L}})=>{for(const r in e){if(!Object.prototype.hasOwnProperty.call(e,r))continue;const n=e[r];if(g(n))if(P(n))try{t[r]=o.window.eval(`(${n})`)}catch(s){typeof console<"u"&&console.warn&&console.warn('[smbls] deepDestringifyFunctions: eval failed on "'+r+'" \u2014 function will be left as a string and el.call("'+r+'") will silently no-op. Reason: '+(s&&s.message?s.message:String(s))+`.
|
|
9
9
|
First 200 chars of source: `+String(n).slice(0,200)),t[r]=n}else t[r]=n;else if(w(n)){const s=t[r]=[];for(let c=0;c<n.length;c++){const i=n[c];if(g(i))if(P(i))try{s.push(o.window.eval(`(${i})`))}catch(l){typeof console<"u"&&console.warn&&console.warn(`[smbls] deepDestringifyFunctions: eval failed in array at index ${c} (prop "${r}"). Reason: ${l&&l.message?l.message:String(l)}.
|
|
10
|
-
First 200 chars: ${String(i).slice(0,200)}`),s.push(i)}else s.push(i);else d(i)?s.push(N(i)):s.push(i)}}else d(n)?t[r]=N(n,t[r]):t[r]=n}return t},
|
|
11
|
-
`);t[r]=
|
|
12
|
-
return (${n}); })`)(t)}catch{try{t[r]=
|
|
10
|
+
First 200 chars: ${String(i).slice(0,200)}`),s.push(i)}else s.push(i);else d(i)?s.push(N(i)):s.push(i)}}else d(n)?t[r]=N(n,t[r]):t[r]=n}return t},B=e=>!e||typeof e!="object"?e:e.__type==="Set"&&Array.isArray(e.values)?new Set(e.values):e.__type==="Map"&&Array.isArray(e.entries)?new Map(e.entries):e,ee=e=>{if(!e||typeof e!="object")return e;const t={},o=[];for(const r of Object.keys(e)){const n=e[r];g(n)&&P(n)?o.push([r,n]):t[r]=B(n)}for(const[r,n]of o)try{const s=Object.keys(t).map(c=>`var ${c} = __gs__[${JSON.stringify(c)}];`).join(`
|
|
11
|
+
`);t[r]=_.eval(`(function(__gs__) { ${s}
|
|
12
|
+
return (${n}); })`)(t)}catch{try{t[r]=_.eval(`(${n})`)}catch{t[r]=n}}return t},te=(e,t={verbose:!0})=>{try{return e?_.eval("("+e+")"):{}}catch(o){t.verbose&&console.warn(o)}},ne=(e,...t)=>Object.prototype.hasOwnProperty.call(e,...t),H=e=>{for(const t in e)return!1;return!0},re=e=>d(e)&&H(e),oe=()=>Object.create(null),se=(e,t,o={})=>{const r=o.exclude||[],n=o.preventUnderscore;for(const s in t)r.includes(s)||!n&&O(s)||s==="constructor"||s==="prototype"||t[s]!==void 0&&(e[s]=t[s]);return e},ce=(e,t,o=[])=>{const r=o instanceof Set;for(const n in t)O(n)||n==="constructor"||n==="prototype"||(r?o.has(n):o.includes(n))||(e[n]=t[n]);return e},J=(e,t,o={},r=new WeakMap)=>{if(!u(e)||!u(t)||h(e)||h(t))return t;if(r.has(e))return r.get(e);r.set(e,e);const n=o.exclude,s=n?n instanceof Set?n:new Set(n):null,c=!o.preventForce;for(const i in t){if(!Object.prototype.hasOwnProperty.call(t,i)||s&&s.has(i)||c&&O(i)||i==="constructor"||i==="prototype")continue;const l=e[i],f=t[i];h(f)?e[i]=f:u(l)&&u(f)?e[i]=J(l,f,o,r):f!==void 0&&(e[i]=f)}return e},V=(e,t,o=new Set)=>{if(typeof e!="object"||typeof t!="object"||e===null||t===null)return e===t;if(o.has(e)||o.has(t))return!0;o.add(e),o.add(t);const r=Object.keys(e),n=Object.keys(t);if(r.length!==n.length)return!1;for(let s=0;s<r.length;s++){const c=r[s];if(!Object.prototype.hasOwnProperty.call(t,c)||!V(e[c],t[c],o))return!1}return!0},q=new Set(["node","__ref"]),ie=(e,t,o=q)=>{if(e===t)return!0;if(!u(e)||!u(t)||h(e)||h(t))return e===t;const r=o instanceof Set?o:new Set(o),n=new WeakSet;function s(c,i){if(n.has(i))return!0;n.add(i);for(const l in i){if(!Object.prototype.hasOwnProperty.call(i,l)||r.has(l))continue;if(!Object.prototype.hasOwnProperty.call(c,l))return!1;const f=i[l],a=c[l];if(h(f)||h(a)){if(f!==a)return!1}else if(u(f)&&u(a)){if(!s(a,f))return!1}else if(f!==a)return!1}return!0}return s(e,t)},fe=(e,t)=>{if(t==null)return e;if(D(t)("string","number"))delete e[t];else if(w(t))for(let o=0;o<t.length;o++)delete e[t[o]];else throw new Error("Invalid input: props must be a string or an array of strings");return e},z=e=>{if(e===null||typeof e!="object")return e;const t=Object.create(null);for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=z(e[o]));return t},le=(e,t)=>{if(e.length===0)return t;const o={};let r=o;for(let n=0;n<e.length;n++)n===e.length-1&&t?r[e[n]]=t:(r[e[n]]={},r=r[e[n]]);return o},ue=(e,t)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let o=e;for(let n=0;n<t.length-1;n++){if(o[t[n]]===void 0)return;o=o[t[n]]}const r=t[t.length-1];o&&Object.prototype.hasOwnProperty.call(o,r)&&delete o[r]},ae=(e,t,o)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let r=e;for(let n=0;n<t.length-1;n++)(!r[t[n]]||typeof r[t[n]]!="object")&&(r[t[n]]={}),r=r[t[n]];return r[t[t.length-1]]=o,e},pe=(e,t)=>{if(!Array.isArray(t))throw new Error("Path must be an array.");let o=e;for(let r=0;r<t.length;r++){if(o==null)return;o=o[t[r]]}return o},ye=e=>{let o=[],r=0;for(let n=0;n<e.length;n++)if(o.length<2)o.push(e[n]);else if(e[n]===o[n%2]?r++:(o=[e[n-1],e[n]],r=1),r>=20)return(k==="test"||k==="development")&&console.warn("Warning: Potential infinite loop detected due to repeated sequence:",o),!0},he=e=>{const t=new WeakSet;function o(r){if(r&&typeof r=="object"){if(t.has(r))return!0;t.add(r);for(const n in r)if(Object.prototype.hasOwnProperty.call(r,n)&&o(r[n]))return console.log(r,"cycle at "+n),!0}return!1}return o(e)},we=(e,t)=>{const o=t instanceof Set?t:new Set(t),r={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&!o.has(n)&&(r[n]=e[n]);return r};export{j as clone,le as createNestedObject,z as createObjectWithoutPrototype,I as deepClone,ie as deepContains,N as deepDestringifyFunctions,b as deepMerge,E as deepStringifyFunctions,ee as destringifyGlobalScope,ye as detectInfiniteLoop,we as excludeKeysFromObject,$ as exec,pe as getInObjectByPath,P as hasFunction,ne as hasOwnProperty,he as isCyclic,H as isEmpty,re as isEmptyObject,V as isEqualDeep,oe as makeObjectWithoutPrototype,Y as map,m as merge,v as objectToString,se as overwrite,J as overwriteDeep,ce as overwriteShallow,fe as removeFromObject,ue as removeNestedKeyByPath,ae as setInObjectByPath,te as stringToObject};
|
package/object.js
CHANGED
|
@@ -449,15 +449,37 @@ export const deepDestringifyFunctions = (
|
|
|
449
449
|
return destringified
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
+
/**
|
|
453
|
+
* Rehydrate Set / Map tagged forms (`{ __type: 'Set', values: […] }`,
|
|
454
|
+
* `{ __type: 'Map', entries: [[k,v],…] }`) into real Set / Map
|
|
455
|
+
* instances. frank's serializer emits these for live Set/Map values on
|
|
456
|
+
* globalScope so consumers' `.has()` / `.get()` calls still work after
|
|
457
|
+
* the JSON round-trip (FT-FRANK-1).
|
|
458
|
+
*
|
|
459
|
+
* Pass-through for any other value. Cheap shape check by `__type` so
|
|
460
|
+
* normal user objects aren't perturbed.
|
|
461
|
+
*/
|
|
462
|
+
const _rehydrateTaggedValue = (val) => {
|
|
463
|
+
if (!val || typeof val !== 'object') return val
|
|
464
|
+
if (val.__type === 'Set' && Array.isArray(val.values)) return new Set(val.values)
|
|
465
|
+
if (val.__type === 'Map' && Array.isArray(val.entries)) return new Map(val.entries)
|
|
466
|
+
return val
|
|
467
|
+
}
|
|
468
|
+
|
|
452
469
|
/**
|
|
453
470
|
* Destringify a globalScope object so that function strings become real functions.
|
|
454
471
|
* All globalScope values are made available as local variables when eval'ing each
|
|
455
472
|
* function, so helpers can reference constants and other helpers naturally.
|
|
473
|
+
*
|
|
474
|
+
* Also rehydrates Set/Map tagged forms (FT-FRANK-1) so `globalScope.X.has(y)`
|
|
475
|
+
* works for the original Set/Map constructors authors put on globalScope.js.
|
|
456
476
|
*/
|
|
457
477
|
export const destringifyGlobalScope = (gs) => {
|
|
458
478
|
if (!gs || typeof gs !== 'object') return gs
|
|
459
479
|
|
|
460
|
-
// First pass: collect non-function values (constants, arrays, objects)
|
|
480
|
+
// First pass: collect non-function values (constants, arrays, objects).
|
|
481
|
+
// Set/Map tagged forms get rehydrated here so they're available as
|
|
482
|
+
// live instances in the closure that wraps function destringify below.
|
|
461
483
|
const result = {}
|
|
462
484
|
const fnEntries = []
|
|
463
485
|
for (const key of Object.keys(gs)) {
|
|
@@ -465,7 +487,7 @@ export const destringifyGlobalScope = (gs) => {
|
|
|
465
487
|
if (isString(val) && hasFunction(val)) {
|
|
466
488
|
fnEntries.push([key, val])
|
|
467
489
|
} else {
|
|
468
|
-
result[key] = val
|
|
490
|
+
result[key] = _rehydrateTaggedValue(val)
|
|
469
491
|
}
|
|
470
492
|
}
|
|
471
493
|
|