maraj 2.8.0 → 2.8.2
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 +20 -9
- package/dist/index.d.ts +20 -9
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
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
|
|
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,15 +171,26 @@ type Set = <T>(newValue: T) => (v: unknown) => T;
|
|
|
171
171
|
*/
|
|
172
172
|
declare const set: Set;
|
|
173
173
|
|
|
174
|
+
type HasInstance = typeof Symbol.hasInstance;
|
|
175
|
+
type ToPrimitive = typeof Symbol.toPrimitive;
|
|
176
|
+
type Unscopables = typeof Symbol.unscopables;
|
|
177
|
+
type NonObjectLiteralKeys = Unscopables | HasInstance | ToPrimitive;
|
|
178
|
+
type ObjectLiteral = Record<PropertyKey, any> & {
|
|
179
|
+
[K in NonObjectLiteralKeys]?: never;
|
|
180
|
+
};
|
|
174
181
|
/** Checks if any provided value is an object literal or not */
|
|
175
|
-
declare const isObjectLiteral: (valueToTest:
|
|
182
|
+
declare const isObjectLiteral: (valueToTest: unknown) => valueToTest is ObjectLiteral;
|
|
176
183
|
|
|
177
184
|
declare const parseStringIndex: (v: string) => number | null;
|
|
178
|
-
declare const isStringIndex: (v: string) =>
|
|
185
|
+
declare const isStringIndex: (v: string) => v is `${number}`;
|
|
179
186
|
|
|
180
|
-
type
|
|
181
|
-
type
|
|
182
|
-
|
|
183
|
-
|
|
187
|
+
type StrictCallbackError = "CALLBACK STRICTNESS RETURN ERROR: return the value using the first parameter";
|
|
188
|
+
type StrictCallbackValue<T> = [StrictCallbackError, T];
|
|
189
|
+
type StrictCallbackFunction<T> = (v: T) => StrictCallbackValue<T>;
|
|
190
|
+
/** Apply strictness to a callback function */
|
|
191
|
+
type StrictCallback<T extends (...args: any[]) => any> = (r: StrictCallbackFunction<ReturnType<T>>, ...args: Parameters<T>) => [StrictCallbackError, ReturnType<T>];
|
|
192
|
+
type UnsealStrictCallback = <TCallback extends (r: StrictCallbackFunction<any>, ...args: any[]) => any>(callback: TCallback) => (...args: Parameters<TCallback> extends [infer _, ...infer RestParams] ? RestParams : never) => ReturnType<TCallback>['1'];
|
|
193
|
+
/** Extract the callback from */
|
|
194
|
+
declare const unsealStrictCallback: UnsealStrictCallback;
|
|
184
195
|
|
|
185
|
-
export { type DotPaths, type KeyOf, type LiteralIndex, type ReturnedValueInPath, type StrictCallback, type
|
|
196
|
+
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 };
|
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
|
|
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,15 +171,26 @@ type Set = <T>(newValue: T) => (v: unknown) => T;
|
|
|
171
171
|
*/
|
|
172
172
|
declare const set: Set;
|
|
173
173
|
|
|
174
|
+
type HasInstance = typeof Symbol.hasInstance;
|
|
175
|
+
type ToPrimitive = typeof Symbol.toPrimitive;
|
|
176
|
+
type Unscopables = typeof Symbol.unscopables;
|
|
177
|
+
type NonObjectLiteralKeys = Unscopables | HasInstance | ToPrimitive;
|
|
178
|
+
type ObjectLiteral = Record<PropertyKey, any> & {
|
|
179
|
+
[K in NonObjectLiteralKeys]?: never;
|
|
180
|
+
};
|
|
174
181
|
/** Checks if any provided value is an object literal or not */
|
|
175
|
-
declare const isObjectLiteral: (valueToTest:
|
|
182
|
+
declare const isObjectLiteral: (valueToTest: unknown) => valueToTest is ObjectLiteral;
|
|
176
183
|
|
|
177
184
|
declare const parseStringIndex: (v: string) => number | null;
|
|
178
|
-
declare const isStringIndex: (v: string) =>
|
|
185
|
+
declare const isStringIndex: (v: string) => v is `${number}`;
|
|
179
186
|
|
|
180
|
-
type
|
|
181
|
-
type
|
|
182
|
-
|
|
183
|
-
|
|
187
|
+
type StrictCallbackError = "CALLBACK STRICTNESS RETURN ERROR: return the value using the first parameter";
|
|
188
|
+
type StrictCallbackValue<T> = [StrictCallbackError, T];
|
|
189
|
+
type StrictCallbackFunction<T> = (v: T) => StrictCallbackValue<T>;
|
|
190
|
+
/** Apply strictness to a callback function */
|
|
191
|
+
type StrictCallback<T extends (...args: any[]) => any> = (r: StrictCallbackFunction<ReturnType<T>>, ...args: Parameters<T>) => [StrictCallbackError, ReturnType<T>];
|
|
192
|
+
type UnsealStrictCallback = <TCallback extends (r: StrictCallbackFunction<any>, ...args: any[]) => any>(callback: TCallback) => (...args: Parameters<TCallback> extends [infer _, ...infer RestParams] ? RestParams : never) => ReturnType<TCallback>['1'];
|
|
193
|
+
/** Extract the callback from */
|
|
194
|
+
declare const unsealStrictCallback: UnsealStrictCallback;
|
|
184
195
|
|
|
185
|
-
export { type DotPaths, type KeyOf, type LiteralIndex, type ReturnedValueInPath, type StrictCallback, type
|
|
196
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var O=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var r in t)O(e,r,{get:t[r],enumerable:!0})},N=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of R(t))!V.call(e,n)&&n!==r&&O(e,n,{get:()=>t[n],enumerable:!(a=v(t,n))||a.enumerable});return e};var $=e=>N(O({},"__esModule",{value:!0}),e);var F={};D(F,{experimental_extendableUpdate:()=>U,isObjectLiteral:()=>c,isStringIndex:()=>y,parseStringIndex:()=>K,remove:()=>I,select:()=>P,set:()=>S,splitPathAtLastKey:()=>L,unsealStrictCallback:()=>g,update:()=>k});module.exports=$(F);var I=(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 z={[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],b=l[s],h=c(b),T=x(b);if(!h&&!T&&!(b===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(!h&&!T){let C=x(l)&&y(s),A=y(o[1]),j=C?r.onNewIndexes:r.onNewProps;if(j==="error")throw new Error(`${s} doesn't exist in "${i}"`);if(j==="skip")continue;l[s]=A?[]:{}}else l[s]=T?[...b]:{...b};d[s]={}}l=l[s],d=d[s],o.shift()}let p=o[0],u=l;if(!Object.hasOwn(u,p)){let s=x(u)&&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(u)}"`);if(s==="skip")continue}u[p]=typeof f=="function"?f(u[p]):f,delete d[p]}return a},k=(e,t,r)=>E(e,t,r),U=(e,t)=>E(e,t);var g=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
|
|
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 u=e=>!!e&&Object.getPrototypeOf(e)===Object.prototype,k=Symbol();var $={[k]:[""]};var U=e=>{let t=parseInt(e);return t.toString()===e?t:null},b=e=>parseInt(e).toString()===e;var j=e=>JSON.stringify(e),x=e=>Array.isArray(e),I=(e,t,r={})=>{if(!u(e)&&!x(e))throw new Error(`"${j(e)}" is not an literalObject/array`);if(!u(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],O=u(d),T=x(d);if(!O&&!T&&!(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(!O&&!T){let P=x(l)&&b(n),L=b(s[1]),h=P?r.onNewIndexes:r.onNewProps;if(h==="error")throw new Error(`${n} doesn't exist in "${i}"`);if(h==="skip")continue;l[n]=L?[]:{}}else l[n]=T?[...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)&&b(p)?r.onNewIndexes:r.onNewProps;if(n==="error")throw new Error(`Property/Index "${p}" doesnt exist in the path "${i}". Its value is: "${j(y)}"`);if(n==="skip")continue}y[p]=typeof f=="function"?f(y[p]):f,delete c[p]}return a},g=(e,t,r)=>I(e,t,r),C=(e,t)=>I(e,t);var A=e=>(...t)=>e(r=>r,...t);export{C as experimental_extendableUpdate,u as isObjectLiteral,b as isStringIndex,U as parseStringIndex,S as remove,K as select,E as set,w as splitPathAtLastKey,A as unsealStrictCallback,g as update};
|