maraj 2.8.3 → 2.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -3,7 +3,7 @@ type OptionalKeys<T> = {
3
3
  [K in keyof T]-?: {} extends Pick<T, K> ? K : never;
4
4
  }[keyof T];
5
5
  /** Removes properties or indexes, order doesn't matter. */
6
- type Remove = <T extends object>(value: T, keys: T extends any[] ? (number | `${number}` | (number | `${number}`)[]) : OptionalKeys<T> | (OptionalKeys<T>)[]) => T;
6
+ type Remove = <T extends Record<PropertyKey, any>>(value: T, keys: T extends any[] ? (number | `${number}` | (number | `${number}`)[]) : OptionalKeys<T> | (OptionalKeys<T>)[]) => T;
7
7
  /**
8
8
  * Removes properties or indexes, order doesn't matter.
9
9
  * @param value Object/array from where to remove keys/indexes shallowly.
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ type OptionalKeys<T> = {
3
3
  [K in keyof T]-?: {} extends Pick<T, K> ? K : never;
4
4
  }[keyof T];
5
5
  /** Removes properties or indexes, order doesn't matter. */
6
- type Remove = <T extends object>(value: T, keys: T extends any[] ? (number | `${number}` | (number | `${number}`)[]) : OptionalKeys<T> | (OptionalKeys<T>)[]) => T;
6
+ type Remove = <T extends Record<PropertyKey, any>>(value: T, keys: T extends any[] ? (number | `${number}` | (number | `${number}`)[]) : OptionalKeys<T> | (OptionalKeys<T>)[]) => T;
7
7
  /**
8
8
  * Removes properties or indexes, order doesn't matter.
9
9
  * @param value Object/array from where to remove keys/indexes shallowly.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var j=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var r in t)j(e,r,{get:t[r],enumerable:!0})},N=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of v(t))!V.call(e,n)&&n!==r&&j(e,n,{get:()=>t[n],enumerable:!(a=R(t,n))||a.enumerable});return e};var $=e=>N(j({},"__esModule",{value:!0}),e);var F={};D(F,{experimental_extendableUpdate:()=>k,isObjectLiteral:()=>c,isStringIndex:()=>y,parseStringIndex:()=>K,remove:()=>h,select:()=>P,set:()=>S,splitPathAtLastKey:()=>L,unsealStrictCallback:()=>A,update:()=>g});module.exports=$(F);var h=(e,t)=>{if(!Array.isArray(e)&&e?.constructor!==Object)throw'Wrong type provided in "remove" function';let r=Array.isArray(t)?t:[t];if(Array.isArray(e)){let n=Symbol(),i=[...e];return r.forEach(o=>{i[o]=n}),i.filter(o=>o!==n)}let a={...e};return r.forEach(n=>delete a[n]),a};var P=(e,t)=>{if(typeof t!="string")throw new Error("path is not a string");if(!t)return e;let r=t.split("."),a=e;for(;r.length;){let n=r.join(".");if(a?.hasOwnProperty(n))return a[n];if(!a?.hasOwnProperty(r[0]))return;a=a[r[0]],r.shift()}return a};var L=e=>{if(typeof e!="string")throw new Error(`Wrong dotPath type: ${e}`);let t=e.lastIndexOf(".")+1,r=t?e.slice(0,t-1):"",a=e.slice(t);return[r,a]};var S=e=>()=>e;var c=e=>!!e&&Object.getPrototypeOf(e)===Object.prototype,B=Symbol();var X={[B]:[""]};var K=e=>{let t=parseInt(e);return t.toString()===e?t:null},y=e=>parseInt(e).toString()===e;var w=e=>JSON.stringify(e),x=e=>Array.isArray(e),E=(e,t,r={})=>{if(!c(e)&&!x(e))throw new Error(`"${w(e)}" is not an literalObject/array`);if(!c(t))throw new Error('wrong "updateObject" type provided');let a=Array.isArray(e)?[...e]:{...e},n={};for(let[i,f]of Object.entries(t)){if(i==="")continue;let o=i.split("."),d=n,l=a;for(;o.length>1;){let m=o.join(".");if(Object.hasOwn(l,m)){o=[m];break}let s=o[0],u=l[s],T=c(u),O=x(u);if(!T&&!O&&!(u===void 0)){if(r.onPathsIntersectedByPrimitiveValues==="error")throw new Error(`Property "${s}" in "${i}" is a primitive`);if(r.onPathsIntersectedByPrimitiveValues==="skip")continue}if(!d[s]){if(!T&&!O){let U=x(l)&&y(s),C=y(o[1]),I=U?r.onNewIndexes:r.onNewProps;if(I==="error")throw new Error(`${s} doesn't exist in "${i}"`);if(I==="skip")continue;l[s]=C?[]:{}}else l[s]=O?[...u]:{...u};d[s]={}}l=l[s],d=d[s],o.shift()}let p=o[0],b=l;if(!Object.hasOwn(b,p)){let s=x(b)&&y(p)?r.onNewIndexes:r.onNewProps;if(s==="error")throw new Error(`Property/Index "${p}" doesnt exist in the path "${i}". Its value is: "${w(b)}"`);if(s==="skip")continue}b[p]=typeof f=="function"?f(b[p]):f,delete d[p]}return a},g=(e,t,r)=>E(e,t,r),k=(e,t)=>E(e,t);var A=e=>(...t)=>e(r=>r,...t);0&&(module.exports={experimental_extendableUpdate,isObjectLiteral,isStringIndex,parseStringIndex,remove,select,set,splitPathAtLastKey,unsealStrictCallback,update});
1
+ "use strict";var j=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var r in t)j(e,r,{get:t[r],enumerable:!0})},N=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of v(t))!V.call(e,n)&&n!==r&&j(e,n,{get:()=>t[n],enumerable:!(a=R(t,n))||a.enumerable});return e};var $=e=>N(j({},"__esModule",{value:!0}),e);var F={};D(F,{experimental_extendableUpdate:()=>k,isObjectLiteral:()=>p,isStringIndex:()=>y,parseStringIndex:()=>K,remove:()=>h,select:()=>P,set:()=>S,splitPathAtLastKey:()=>L,unsealStrictCallback:()=>A,update:()=>g});module.exports=$(F);var p=e=>!!e&&Object.getPrototypeOf(e)===Object.prototype,B=Symbol();var M={[B]:[""]};var h=(e,t)=>{if(!Array.isArray(e)&&!p(e))throw'Wrong type provided in "remove" function';let r=Array.isArray(t)?t:[t];if(Array.isArray(e)){let n=Symbol(),i=[...e];return r.forEach(o=>{i[o]=n}),i.filter(o=>o!==n)}let a={...e};return r.forEach(n=>delete a[n]),a};var P=(e,t)=>{if(typeof t!="string")throw new Error("path is not a string");if(!t)return e;let r=t.split("."),a=e;for(;r.length;){let n=r.join(".");if(a?.hasOwnProperty(n))return a[n];if(!a?.hasOwnProperty(r[0]))return;a=a[r[0]],r.shift()}return a};var L=e=>{if(typeof e!="string")throw new Error(`Wrong dotPath type: ${e}`);let t=e.lastIndexOf(".")+1,r=t?e.slice(0,t-1):"",a=e.slice(t);return[r,a]};var S=e=>()=>e;var K=e=>{let t=parseInt(e);return t.toString()===e?t:null},y=e=>parseInt(e).toString()===e;var w=e=>JSON.stringify(e),x=e=>Array.isArray(e),E=(e,t,r={})=>{if(!p(e)&&!x(e))throw new Error(`"${w(e)}" is not an literalObject/array`);if(!p(t))throw new Error('wrong "updateObject" type provided');let a=Array.isArray(e)?[...e]:{...e},n={};for(let[i,f]of Object.entries(t)){if(i==="")continue;let o=i.split("."),d=n,l=a;for(;o.length>1;){let m=o.join(".");if(Object.hasOwn(l,m)){o=[m];break}let s=o[0],u=l[s],T=p(u),O=x(u);if(!T&&!O&&!(u===void 0)){if(r.onPathsIntersectedByPrimitiveValues==="error")throw new Error(`Property "${s}" in "${i}" is a primitive`);if(r.onPathsIntersectedByPrimitiveValues==="skip")continue}if(!d[s]){if(!T&&!O){let U=x(l)&&y(s),C=y(o[1]),I=U?r.onNewIndexes:r.onNewProps;if(I==="error")throw new Error(`${s} doesn't exist in "${i}"`);if(I==="skip")continue;l[s]=C?[]:{}}else l[s]=O?[...u]:{...u};d[s]={}}l=l[s],d=d[s],o.shift()}let c=o[0],b=l;if(!Object.hasOwn(b,c)){let s=x(b)&&y(c)?r.onNewIndexes:r.onNewProps;if(s==="error")throw new Error(`Property/Index "${c}" doesnt exist in the path "${i}". Its value is: "${w(b)}"`);if(s==="skip")continue}b[c]=typeof f=="function"?f(b[c]):f,delete d[c]}return a},g=(e,t,r)=>E(e,t,r),k=(e,t)=>E(e,t);var A=e=>(...t)=>e(r=>r,...t);0&&(module.exports={experimental_extendableUpdate,isObjectLiteral,isStringIndex,parseStringIndex,remove,select,set,splitPathAtLastKey,unsealStrictCallback,update});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var S=(e,t)=>{if(!Array.isArray(e)&&e?.constructor!==Object)throw'Wrong type provided in "remove" function';let r=Array.isArray(t)?t:[t];if(Array.isArray(e)){let o=Symbol(),i=[...e];return r.forEach(s=>{i[s]=o}),i.filter(s=>s!==o)}let a={...e};return r.forEach(o=>delete a[o]),a};var K=(e,t)=>{if(typeof t!="string")throw new Error("path is not a string");if(!t)return e;let r=t.split("."),a=e;for(;r.length;){let o=r.join(".");if(a?.hasOwnProperty(o))return a[o];if(!a?.hasOwnProperty(r[0]))return;a=a[r[0]],r.shift()}return a};var w=e=>{if(typeof e!="string")throw new Error(`Wrong dotPath type: ${e}`);let t=e.lastIndexOf(".")+1,r=t?e.slice(0,t-1):"",a=e.slice(t);return[r,a]};var E=e=>()=>e;var b=e=>!!e&&Object.getPrototypeOf(e)===Object.prototype,g=Symbol();var $={[g]:[""]};var k=e=>{let t=parseInt(e);return t.toString()===e?t:null},u=e=>parseInt(e).toString()===e;var I=e=>JSON.stringify(e),x=e=>Array.isArray(e),h=(e,t,r={})=>{if(!b(e)&&!x(e))throw new Error(`"${I(e)}" is not an literalObject/array`);if(!b(t))throw new Error('wrong "updateObject" type provided');let a=Array.isArray(e)?[...e]:{...e},o={};for(let[i,f]of Object.entries(t)){if(i==="")continue;let s=i.split("."),c=o,l=a;for(;s.length>1;){let m=s.join(".");if(Object.hasOwn(l,m)){s=[m];break}let n=s[0],d=l[n],j=b(d),O=x(d);if(!j&&!O&&!(d===void 0)){if(r.onPathsIntersectedByPrimitiveValues==="error")throw new Error(`Property "${n}" in "${i}" is a primitive`);if(r.onPathsIntersectedByPrimitiveValues==="skip")continue}if(!c[n]){if(!j&&!O){let P=x(l)&&u(n),L=u(s[1]),T=P?r.onNewIndexes:r.onNewProps;if(T==="error")throw new Error(`${n} doesn't exist in "${i}"`);if(T==="skip")continue;l[n]=L?[]:{}}else l[n]=O?[...d]:{...d};c[n]={}}l=l[n],c=c[n],s.shift()}let p=s[0],y=l;if(!Object.hasOwn(y,p)){let n=x(y)&&u(p)?r.onNewIndexes:r.onNewProps;if(n==="error")throw new Error(`Property/Index "${p}" doesnt exist in the path "${i}". Its value is: "${I(y)}"`);if(n==="skip")continue}y[p]=typeof f=="function"?f(y[p]):f,delete c[p]}return a},A=(e,t,r)=>h(e,t,r),U=(e,t)=>h(e,t);var C=e=>(...t)=>e(r=>r,...t);export{U as experimental_extendableUpdate,b as isObjectLiteral,u as isStringIndex,k as parseStringIndex,S as remove,K as select,E as set,w as splitPathAtLastKey,C as unsealStrictCallback,A as update};
1
+ var p=e=>!!e&&Object.getPrototypeOf(e)===Object.prototype,S=Symbol();var v={[S]:[""]};var K=(e,t)=>{if(!Array.isArray(e)&&!p(e))throw'Wrong type provided in "remove" function';let r=Array.isArray(t)?t:[t];if(Array.isArray(e)){let o=Symbol(),i=[...e];return r.forEach(s=>{i[s]=o}),i.filter(s=>s!==o)}let a={...e};return r.forEach(o=>delete a[o]),a};var w=(e,t)=>{if(typeof t!="string")throw new Error("path is not a string");if(!t)return e;let r=t.split("."),a=e;for(;r.length;){let o=r.join(".");if(a?.hasOwnProperty(o))return a[o];if(!a?.hasOwnProperty(r[0]))return;a=a[r[0]],r.shift()}return a};var E=e=>{if(typeof e!="string")throw new Error(`Wrong dotPath type: ${e}`);let t=e.lastIndexOf(".")+1,r=t?e.slice(0,t-1):"",a=e.slice(t);return[r,a]};var g=e=>()=>e;var k=e=>{let t=parseInt(e);return t.toString()===e?t:null},u=e=>parseInt(e).toString()===e;var I=e=>JSON.stringify(e),x=e=>Array.isArray(e),h=(e,t,r={})=>{if(!p(e)&&!x(e))throw new Error(`"${I(e)}" is not an literalObject/array`);if(!p(t))throw new Error('wrong "updateObject" type provided');let a=Array.isArray(e)?[...e]:{...e},o={};for(let[i,f]of Object.entries(t)){if(i==="")continue;let s=i.split("."),y=o,l=a;for(;s.length>1;){let m=s.join(".");if(Object.hasOwn(l,m)){s=[m];break}let n=s[0],b=l[n],j=p(b),O=x(b);if(!j&&!O&&!(b===void 0)){if(r.onPathsIntersectedByPrimitiveValues==="error")throw new Error(`Property "${n}" in "${i}" is a primitive`);if(r.onPathsIntersectedByPrimitiveValues==="skip")continue}if(!y[n]){if(!j&&!O){let P=x(l)&&u(n),L=u(s[1]),T=P?r.onNewIndexes:r.onNewProps;if(T==="error")throw new Error(`${n} doesn't exist in "${i}"`);if(T==="skip")continue;l[n]=L?[]:{}}else l[n]=O?[...b]:{...b};y[n]={}}l=l[n],y=y[n],s.shift()}let c=s[0],d=l;if(!Object.hasOwn(d,c)){let n=x(d)&&u(c)?r.onNewIndexes:r.onNewProps;if(n==="error")throw new Error(`Property/Index "${c}" doesnt exist in the path "${i}". Its value is: "${I(d)}"`);if(n==="skip")continue}d[c]=typeof f=="function"?f(d[c]):f,delete y[c]}return a},A=(e,t,r)=>h(e,t,r),U=(e,t)=>h(e,t);var C=e=>(...t)=>e(r=>r,...t);export{U as experimental_extendableUpdate,p as isObjectLiteral,u as isStringIndex,k as parseStringIndex,K as remove,w as select,g as set,E as splitPathAtLastKey,C as unsealStrictCallback,A as update};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maraj",
3
- "version": "2.8.3",
3
+ "version": "2.8.4",
4
4
  "description": "A lightweight 600 bytes gzipped alternative for immutable updates while dealing with objects and arrays",
5
5
  "keywords": [
6
6
  "shallow",