maraj 2.8.1 → 2.8.3

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
@@ -21,7 +21,7 @@ type Options = {
21
21
  onNewIndexes?: OptionValues;
22
22
  onPathsIntersectedByPrimitiveValues?: OptionValues;
23
23
  };
24
- type ImmutableUpdate = <TObject, TAllowedDotPathKeys extends PropertyKey = DotPaths<TObject>>(state: TObject, dotPathUpdateObject: UpdateObject<TObject, TAllowedDotPathKeys>, options?: Options) => TObject;
24
+ type ImmutableUpdate = <TObject, TAllowedDotPathKeys extends DotPaths<TObject> = DotPaths<TObject>>(state: TObject, dotPathUpdateObject: UpdateObject<TObject, TAllowedDotPathKeys>, options?: Options) => TObject;
25
25
  /**
26
26
  * Creates a new object applying immutable updates using dot-path syntax.
27
27
  * Can add or skip new props or indexes depending on options.
@@ -32,7 +32,7 @@ type ImmutableUpdate = <TObject, TAllowedDotPathKeys extends PropertyKey = DotPa
32
32
  * @returns New Updated Object.
33
33
  */
34
34
  declare const update: ImmutableUpdate;
35
- type ExtendableImmutableUpdate = <TObject, TUpdateObject extends UpdateObject<TObject>>(state: TObject, dotPathUpdateObject: TUpdateObject) => ExtendedUpdate<TObject, TUpdateObject>;
35
+ type ExtendableImmutableUpdate = <TObject, TUpdateObject extends UpdateObject<TObject> = UpdateObject<TObject>>(state: TObject, dotPathUpdateObject: TUpdateObject) => ExtendedUpdate<TObject, TUpdateObject>;
36
36
  /**
37
37
  * Creates a new object applying immutable updates using dot-path syntax.
38
38
  * It will always add non-existent props or indexes if provided.
@@ -171,11 +171,20 @@ type Set = <T>(newValue: T) => (v: unknown) => T;
171
171
  */
172
172
  declare const set: Set;
173
173
 
174
+ type Iterator = typeof Symbol.iterator;
175
+ type HasInstance = typeof Symbol.hasInstance;
176
+ type ToPrimitive = typeof Symbol.toPrimitive;
177
+ type Unscopables = typeof Symbol.unscopables;
178
+ type MatchAll = typeof Symbol.matchAll;
179
+ type NonObjectLiteralKeys = Unscopables | HasInstance | ToPrimitive | MatchAll | Iterator;
180
+ type ObjectLiteral = Record<PropertyKey, any> & {
181
+ [K in NonObjectLiteralKeys]?: never;
182
+ };
174
183
  /** Checks if any provided value is an object literal or not */
175
- declare const isObjectLiteral: (valueToTest: any) => boolean;
184
+ declare const isObjectLiteral: (valueToTest: unknown) => valueToTest is ObjectLiteral;
176
185
 
177
186
  declare const parseStringIndex: (v: string) => number | null;
178
- declare const isStringIndex: (v: string) => boolean;
187
+ declare const isStringIndex: (v: string) => v is `${number}`;
179
188
 
180
189
  type StrictCallbackError = "CALLBACK STRICTNESS RETURN ERROR: return the value using the first parameter";
181
190
  type StrictCallbackValue<T> = [StrictCallbackError, T];
@@ -186,4 +195,4 @@ type UnsealStrictCallback = <TCallback extends (r: StrictCallbackFunction<any>,
186
195
  /** Extract the callback from */
187
196
  declare const unsealStrictCallback: UnsealStrictCallback;
188
197
 
189
- export { type DotPaths, type KeyOf, type LiteralIndex, type ReturnedValueInPath, type StrictCallback, type UpdateObject, type UpdateValue, type ValueInPath, experimental_extendableUpdate, isObjectLiteral, isStringIndex, parseStringIndex, remove, select, set, splitPathAtLastKey, unsealStrictCallback, update };
198
+ export { type DotPaths, type KeyOf, type LiteralIndex, type ObjectLiteral, type ReturnedValueInPath, type StrictCallback, type UpdateObject, type UpdateValue, type ValueInPath, experimental_extendableUpdate, isObjectLiteral, isStringIndex, parseStringIndex, remove, select, set, splitPathAtLastKey, unsealStrictCallback, update };
package/dist/index.d.ts CHANGED
@@ -21,7 +21,7 @@ type Options = {
21
21
  onNewIndexes?: OptionValues;
22
22
  onPathsIntersectedByPrimitiveValues?: OptionValues;
23
23
  };
24
- type ImmutableUpdate = <TObject, TAllowedDotPathKeys extends PropertyKey = DotPaths<TObject>>(state: TObject, dotPathUpdateObject: UpdateObject<TObject, TAllowedDotPathKeys>, options?: Options) => TObject;
24
+ type ImmutableUpdate = <TObject, TAllowedDotPathKeys extends DotPaths<TObject> = DotPaths<TObject>>(state: TObject, dotPathUpdateObject: UpdateObject<TObject, TAllowedDotPathKeys>, options?: Options) => TObject;
25
25
  /**
26
26
  * Creates a new object applying immutable updates using dot-path syntax.
27
27
  * Can add or skip new props or indexes depending on options.
@@ -32,7 +32,7 @@ type ImmutableUpdate = <TObject, TAllowedDotPathKeys extends PropertyKey = DotPa
32
32
  * @returns New Updated Object.
33
33
  */
34
34
  declare const update: ImmutableUpdate;
35
- type ExtendableImmutableUpdate = <TObject, TUpdateObject extends UpdateObject<TObject>>(state: TObject, dotPathUpdateObject: TUpdateObject) => ExtendedUpdate<TObject, TUpdateObject>;
35
+ type ExtendableImmutableUpdate = <TObject, TUpdateObject extends UpdateObject<TObject> = UpdateObject<TObject>>(state: TObject, dotPathUpdateObject: TUpdateObject) => ExtendedUpdate<TObject, TUpdateObject>;
36
36
  /**
37
37
  * Creates a new object applying immutable updates using dot-path syntax.
38
38
  * It will always add non-existent props or indexes if provided.
@@ -171,11 +171,20 @@ type Set = <T>(newValue: T) => (v: unknown) => T;
171
171
  */
172
172
  declare const set: Set;
173
173
 
174
+ type Iterator = typeof Symbol.iterator;
175
+ type HasInstance = typeof Symbol.hasInstance;
176
+ type ToPrimitive = typeof Symbol.toPrimitive;
177
+ type Unscopables = typeof Symbol.unscopables;
178
+ type MatchAll = typeof Symbol.matchAll;
179
+ type NonObjectLiteralKeys = Unscopables | HasInstance | ToPrimitive | MatchAll | Iterator;
180
+ type ObjectLiteral = Record<PropertyKey, any> & {
181
+ [K in NonObjectLiteralKeys]?: never;
182
+ };
174
183
  /** Checks if any provided value is an object literal or not */
175
- declare const isObjectLiteral: (valueToTest: any) => boolean;
184
+ declare const isObjectLiteral: (valueToTest: unknown) => valueToTest is ObjectLiteral;
176
185
 
177
186
  declare const parseStringIndex: (v: string) => number | null;
178
- declare const isStringIndex: (v: string) => boolean;
187
+ declare const isStringIndex: (v: string) => v is `${number}`;
179
188
 
180
189
  type StrictCallbackError = "CALLBACK STRICTNESS RETURN ERROR: return the value using the first parameter";
181
190
  type StrictCallbackValue<T> = [StrictCallbackError, T];
@@ -186,4 +195,4 @@ type UnsealStrictCallback = <TCallback extends (r: StrictCallbackFunction<any>,
186
195
  /** Extract the callback from */
187
196
  declare const unsealStrictCallback: UnsealStrictCallback;
188
197
 
189
- export { type DotPaths, type KeyOf, type LiteralIndex, type ReturnedValueInPath, type StrictCallback, type UpdateObject, type UpdateValue, type ValueInPath, experimental_extendableUpdate, isObjectLiteral, isStringIndex, parseStringIndex, remove, select, set, splitPathAtLastKey, unsealStrictCallback, update };
198
+ export { type DotPaths, type KeyOf, type LiteralIndex, type ObjectLiteral, type ReturnedValueInPath, type StrictCallback, type UpdateObject, type UpdateValue, type ValueInPath, experimental_extendableUpdate, isObjectLiteral, isStringIndex, parseStringIndex, remove, select, set, splitPathAtLastKey, unsealStrictCallback, update };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var x=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var r in e)x(t,r,{get:e[r],enumerable:!0})},N=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of R(e))!v.call(t,a)&&a!==r&&x(t,a,{get:()=>e[a],enumerable:!(n=V(e,a))||n.enumerable});return t};var $=t=>N(x({},"__esModule",{value:!0}),t);var B={};D(B,{experimental_extendableUpdate:()=>A,isObjectLiteral:()=>c,isStringIndex:()=>y,parseStringIndex:()=>K,remove:()=>I,select:()=>j,set:()=>S,splitPathAtLastKey:()=>w,unsealStrictCallback:()=>g,update:()=>U});module.exports=$(B);var I=(t,e)=>{if(!Array.isArray(t)&&t?.constructor!==Object)throw'Wrong type provided in "remove" function';let r=Array.isArray(e)?e:[e];if(Array.isArray(t)){let a=Symbol(),i=[...t];return r.forEach(s=>{i[s]=a}),i.filter(s=>s!==a)}let n={...t};return r.forEach(a=>delete n[a]),n};var j=(t,e)=>{if(typeof e!="string")throw new Error("path is not a string");if(!e)return t;let r=e.split("."),n=t;for(;r.length;){let a=r.join(".");if(n?.hasOwnProperty(a))return n[a];if(!n?.hasOwnProperty(r[0]))return;n=n[r[0]],r.shift()}return n};var w=t=>{if(typeof t!="string")throw new Error(`Wrong dotPath type: ${t}`);let e=t.lastIndexOf(".")+1,r=e?t.slice(0,e-1):"",n=t.slice(e);return[r,n]};var S=t=>()=>t;var c=t=>!!t&&Object.getPrototypeOf(t)===Object.prototype;var K=t=>{let e=parseInt(t);return e.toString()===t?e:null},y=t=>parseInt(t).toString()===t;var k=t=>JSON.stringify(t),f=t=>Array.isArray(t),C=(t,e,r={})=>{if(!c(t)&&!f(t))throw new Error(`"${k(t)}" is not an literalObject/array`);if(!c(e))throw new Error('wrong "updateObject" type provided');let n=Array.isArray(t)?[...t]:{...t},a={};for(let[i,T]of Object.entries(e)){if(i==="")continue;let s=i.split("."),d=a,p=n;for(;s.length>1;){let h=s.join(".");if(Object.hasOwn(p,h)){s=[h];break}let o=s[0],b=p[o],O=c(b),m=f(b);if(!O&&!m&&!(b===void 0)){if(r.onPathsIntersectedByPrimitiveValues==="error")throw new Error(`Property "${o}" in "${i}" is a primitive`);if(r.onPathsIntersectedByPrimitiveValues==="skip")continue}if(!d[o]){if(!O&&!m){let E=f(p)&&y(o),L=y(s[1]),P=E?r.onNewIndexes:r.onNewProps;if(P==="error")throw new Error(`${o} doesn't exist in "${i}"`);if(P==="skip")continue;p[o]=L?[]:{}}else p[o]=m?[...b]:{...b};d[o]={}}p=p[o],d=d[o],s.shift()}let l=s[0],u=p;if(!Object.hasOwn(u,l)){let o=f(u)&&y(l)?r.onNewIndexes:r.onNewProps;if(o==="error")throw new Error(`Property/Index "${l}" doesnt exist in the path "${i}". Its value is: "${k(u)}"`);if(o==="skip")continue}u[l]=typeof T=="function"?T(u[l]):T,delete d[l]}return n},U=(t,e,r)=>C(t,e,r),A=(t,e)=>C(t,e);var g=t=>(...e)=>t(r=>r,...e);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:()=>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});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var S=(t,e)=>{if(!Array.isArray(t)&&t?.constructor!==Object)throw'Wrong type provided in "remove" function';let r=Array.isArray(e)?e:[e];if(Array.isArray(t)){let s=Symbol(),i=[...t];return r.forEach(o=>{i[o]=s}),i.filter(o=>o!==s)}let n={...t};return r.forEach(s=>delete n[s]),n};var K=(t,e)=>{if(typeof e!="string")throw new Error("path is not a string");if(!e)return t;let r=e.split("."),n=t;for(;r.length;){let s=r.join(".");if(n?.hasOwnProperty(s))return n[s];if(!n?.hasOwnProperty(r[0]))return;n=n[r[0]],r.shift()}return n};var k=t=>{if(typeof t!="string")throw new Error(`Wrong dotPath type: ${t}`);let e=t.lastIndexOf(".")+1,r=e?t.slice(0,e-1):"",n=t.slice(e);return[r,n]};var C=t=>()=>t;var u=t=>!!t&&Object.getPrototypeOf(t)===Object.prototype;var U=t=>{let e=parseInt(t);return e.toString()===t?e:null},b=t=>parseInt(t).toString()===t;var P=t=>JSON.stringify(t),f=t=>Array.isArray(t),I=(t,e,r={})=>{if(!u(t)&&!f(t))throw new Error(`"${P(t)}" is not an literalObject/array`);if(!u(e))throw new Error('wrong "updateObject" type provided');let n=Array.isArray(t)?[...t]:{...t},s={};for(let[i,T]of Object.entries(e)){if(i==="")continue;let o=i.split("."),c=s,p=n;for(;o.length>1;){let h=o.join(".");if(Object.hasOwn(p,h)){o=[h];break}let a=o[0],d=p[a],x=u(d),m=f(d);if(!x&&!m&&!(d===void 0)){if(r.onPathsIntersectedByPrimitiveValues==="error")throw new Error(`Property "${a}" in "${i}" is a primitive`);if(r.onPathsIntersectedByPrimitiveValues==="skip")continue}if(!c[a]){if(!x&&!m){let j=f(p)&&b(a),w=b(o[1]),O=j?r.onNewIndexes:r.onNewProps;if(O==="error")throw new Error(`${a} doesn't exist in "${i}"`);if(O==="skip")continue;p[a]=w?[]:{}}else p[a]=m?[...d]:{...d};c[a]={}}p=p[a],c=c[a],o.shift()}let l=o[0],y=p;if(!Object.hasOwn(y,l)){let a=f(y)&&b(l)?r.onNewIndexes:r.onNewProps;if(a==="error")throw new Error(`Property/Index "${l}" doesnt exist in the path "${i}". Its value is: "${P(y)}"`);if(a==="skip")continue}y[l]=typeof T=="function"?T(y[l]):T,delete c[l]}return n},A=(t,e,r)=>I(t,e,r),g=(t,e)=>I(t,e);var E=t=>(...e)=>t(r=>r,...e);export{g as experimental_extendableUpdate,u as isObjectLiteral,b as isStringIndex,U as parseStringIndex,S as remove,K as select,C as set,k as splitPathAtLastKey,E as unsealStrictCallback,A as update};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maraj",
3
- "version": "2.8.1",
3
+ "version": "2.8.3",
4
4
  "description": "A lightweight 600 bytes gzipped alternative for immutable updates while dealing with objects and arrays",
5
5
  "keywords": [
6
6
  "shallow",