maraj 2.7.1 → 2.7.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 +21 -14
- package/dist/index.d.ts +21 -14
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -19,8 +19,9 @@ type OptionValues = 'error' | 'skip' | 'add';
|
|
|
19
19
|
type Options = {
|
|
20
20
|
onNewProps?: OptionValues;
|
|
21
21
|
onNewIndexes?: OptionValues;
|
|
22
|
+
onPathsIntersectedByPrimitiveValues?: OptionValues;
|
|
22
23
|
};
|
|
23
|
-
type ImmutableUpdate = <TObject
|
|
24
|
+
type ImmutableUpdate = <TObject>(state: TObject, dotPathUpdateObject: UpdateObject<TObject>, options?: Options) => TObject;
|
|
24
25
|
/**
|
|
25
26
|
* Creates a new object applying immutable updates using dot-path syntax.
|
|
26
27
|
* Can add or skip new props or indexes depending on options.
|
|
@@ -31,7 +32,7 @@ type ImmutableUpdate = <TObject extends Record<PropertyKey, any>>(state: TObject
|
|
|
31
32
|
* @returns New Updated Object.
|
|
32
33
|
*/
|
|
33
34
|
declare const update: ImmutableUpdate;
|
|
34
|
-
type ExtendableImmutableUpdate = <TObject
|
|
35
|
+
type ExtendableImmutableUpdate = <TObject, TUpdateObject extends UpdateObject<TObject>>(state: TObject, dotPathUpdateObject: TUpdateObject) => ExtendedUpdate<TObject, TUpdateObject>;
|
|
35
36
|
/**
|
|
36
37
|
* Creates a new object applying immutable updates using dot-path syntax.
|
|
37
38
|
* It will always add non-existent props or indexes if provided.
|
|
@@ -50,7 +51,7 @@ declare const extendableUpdate: ExtendableImmutableUpdate;
|
|
|
50
51
|
/** Primitives and browser native objects. */
|
|
51
52
|
type PrimitivesAndNativeObjects = null | undefined | string | number | boolean | symbol | bigint | Date | FileList | File;
|
|
52
53
|
/** Array indexes type. */
|
|
53
|
-
type ArrayIndexes = number | LiteralIndex;
|
|
54
|
+
type ArrayIndexes = number | `${number}` | LiteralIndex;
|
|
54
55
|
/** To check if a ReadonlyArray is a tuple or not. */
|
|
55
56
|
type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
|
|
56
57
|
/**
|
|
@@ -59,15 +60,21 @@ type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false
|
|
|
59
60
|
* --------------------------------------------
|
|
60
61
|
*/
|
|
61
62
|
/** Dot-paths of an array. */
|
|
62
|
-
type ArrayPaths<TInnerType, TAllowedTypes> = TInnerType extends TAllowedTypes ? TInnerType extends PrimitivesAndNativeObjects ?
|
|
63
|
+
type ArrayPaths<TInnerType, TAllowedTypes> = TInnerType extends TAllowedTypes ? TInnerType extends PrimitivesAndNativeObjects ? ArrayIndexes : ArrayIndexes | `${ArrayIndexes}.${DotPathsImplementation<TInnerType, TAllowedTypes>}` : `${ArrayIndexes}.${DotPathsImplementation<TInnerType, TAllowedTypes>}`;
|
|
63
64
|
/** Dot-paths of an object. */
|
|
64
65
|
type ObjectPaths<T, TAllowedTypes> = {
|
|
65
|
-
[Key in keyof T & (string | number)]: T[Key] extends TAllowedTypes ? T[Key] extends PrimitivesAndNativeObjects ? `${Key}` : `${Key}` | `${Key}.${
|
|
66
|
-
}[keyof T & (string | number)];
|
|
66
|
+
[Key in keyof T & (string | number)]: T[Key] extends TAllowedTypes ? T[Key] extends PrimitivesAndNativeObjects ? `${Key}` : `${Key}` | `${Key}.${DotPathsImplementation<T[Key], TAllowedTypes>}` : `${Key}.${DotPathsImplementation<T[Key], TAllowedTypes>}`;
|
|
67
|
+
}[keyof T & (string | number)] & unknown;
|
|
67
68
|
/** Dot-paths of a tuple. */
|
|
68
|
-
type TuplePaths<T, TAllowedTypes> = ObjectPaths<Omit<T, keyof any[]>, TAllowedTypes
|
|
69
|
+
type TuplePaths<T, TAllowedTypes> = ObjectPaths<Omit<T, keyof any[]>, TAllowedTypes> & unknown;
|
|
70
|
+
/** Dot-paths implementation */
|
|
71
|
+
type DotPathsImplementation<T, TAllowedTypes = any> = T extends ReadonlyArray<infer U> ? IsTuple<T> extends true ? TuplePaths<T, TAllowedTypes> : ArrayPaths<U, TAllowedTypes> : T extends PrimitivesAndNativeObjects ? never : ObjectPaths<T, TAllowedTypes>;
|
|
72
|
+
/** Extract Keys from any kind of type, including objects, arrays, tuples. */
|
|
73
|
+
type KeyOf<T, TAllowedTypes = any> = T extends ReadonlyArray<infer U> ? U extends TAllowedTypes ? IsTuple<T> extends true ? keyof Omit<T, keyof any[]> : ArrayIndexes : never : T extends PrimitivesAndNativeObjects ? never : {
|
|
74
|
+
[Key in keyof T]: T[Key] extends TAllowedTypes ? Key : never;
|
|
75
|
+
}[keyof T];
|
|
69
76
|
/** Literal union of all posible dot-paths which satisfy provided types as second argument (default: any). */
|
|
70
|
-
type DotPaths<T, TAllowedTypes = any> =
|
|
77
|
+
type DotPaths<T, TAllowedTypes = any> = KeyOf<T, TAllowedTypes> | DotPathsImplementation<T, TAllowedTypes>;
|
|
71
78
|
/**
|
|
72
79
|
* --------------------------------------------
|
|
73
80
|
* VALUE OF A NESTED PROPERTY PROVIDING A DOT PATH
|
|
@@ -88,10 +95,10 @@ type ReturnedValueInPath<TObject, TPath> = TPath extends '' ? TObject : TPath ex
|
|
|
88
95
|
* --------------------------------------------
|
|
89
96
|
*/
|
|
90
97
|
/** Value of a dot-path update object, can be the value or a function. */
|
|
91
|
-
type UpdateValue<TObject, TPath> = ValueInPath<TObject, TPath> | ((fieldValue: ValueInPath<TObject, TPath>) => ValueInPath<TObject, TPath>);
|
|
98
|
+
type UpdateValue<TObject, TPath> = ValueInPath<TObject, TPath> extends never ? never : ValueInPath<TObject, TPath> | ((fieldValue: ValueInPath<TObject, TPath>) => ValueInPath<TObject, TPath>);
|
|
92
99
|
/** Dot-path update object, used to give updates to the updateImmutably function. */
|
|
93
100
|
type UpdateObject<TObject, TPaths extends PropertyKey = DotPaths<TObject>> = {
|
|
94
|
-
[
|
|
101
|
+
[Path in TPaths]?: UpdateValue<TObject, Path>;
|
|
95
102
|
};
|
|
96
103
|
/**
|
|
97
104
|
* --------------------------------------------
|
|
@@ -118,7 +125,7 @@ type NestedPathKeys<T, K extends string | number> = {
|
|
|
118
125
|
/** Extract value if its a function */
|
|
119
126
|
type Value<T> = T extends (...args: any) => any ? ReturnType<T> : T;
|
|
120
127
|
/** To check if an empty object is provided */
|
|
121
|
-
type EmptyObject = Record<
|
|
128
|
+
type EmptyObject = Record<PropertyKey, never>;
|
|
122
129
|
/** Used to extract the type from a dot-path update object. */
|
|
123
130
|
type ExtractTypeFromDotPathUpdateObject<T extends Record<string, any>> = T extends EmptyObject ? {} : keyof T extends LiteralIndex | number | `${number}` | `${number}.${infer U}` ? Value<T[KeyPathsStartingWithAnIndex<T>]> extends never ? Array<Value<T[KeysRepresentingAnIndex<T>]>> : Array<Value<T[KeysRepresentingAnIndex<T>]> | {
|
|
124
131
|
[Key2 in U]: Value<T[KeyPathsStartingWithAnIndex<T>]>;
|
|
@@ -132,7 +139,7 @@ type ExtractTypeFromDotPathUpdateObject<T extends Record<string, any>> = T exten
|
|
|
132
139
|
}>;
|
|
133
140
|
} & unknown;
|
|
134
141
|
/** New expanded value after aplying updates including new properties */
|
|
135
|
-
type ExtendedUpdate<TObject
|
|
142
|
+
type ExtendedUpdate<TObject, TDotPathUpdateObject extends Record<PropertyKey, any>> = TObject extends Array<infer U> ? ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject> extends Array<infer W> ? Array<U | W> : TObject & ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject> : TObject & ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject>;
|
|
136
143
|
|
|
137
144
|
type Select = {
|
|
138
145
|
<T, TPath extends DotPaths<T>>(state: T, path: TPath): ReturnedValueInPath<T, TPath>;
|
|
@@ -156,7 +163,7 @@ type SplitDotPathAtLastKey = <T extends string>(dotPath: T) => [PathWithoutLastK
|
|
|
156
163
|
*/
|
|
157
164
|
declare const splitPathAtLastKey: SplitDotPathAtLastKey;
|
|
158
165
|
|
|
159
|
-
type Set = <T>(newValue: T) => (
|
|
166
|
+
type Set = <T>(newValue: T) => (v: unknown) => T;
|
|
160
167
|
/**
|
|
161
168
|
* Allows to set strongly typed values (removing inacurate "undefined" inference) in nested values inside arrays.
|
|
162
169
|
* @param newValue New value.
|
|
@@ -170,4 +177,4 @@ declare const isObjectLiteral: (valueToTest: any) => boolean;
|
|
|
170
177
|
declare const parseStringIndex: (v: string) => number | null;
|
|
171
178
|
declare const isStringIndex: (v: string) => boolean;
|
|
172
179
|
|
|
173
|
-
export { type DotPaths, type LiteralIndex, type ReturnedValueInPath, type UpdateObject, type UpdateValue, type ValueInPath, extendableUpdate, isObjectLiteral, isStringIndex, parseStringIndex, remove, select, set, splitPathAtLastKey, update };
|
|
180
|
+
export { type DotPaths, type KeyOf, type LiteralIndex, type ReturnedValueInPath, type UpdateObject, type UpdateValue, type ValueInPath, extendableUpdate, isObjectLiteral, isStringIndex, parseStringIndex, remove, select, set, splitPathAtLastKey, update };
|
package/dist/index.d.ts
CHANGED
|
@@ -19,8 +19,9 @@ type OptionValues = 'error' | 'skip' | 'add';
|
|
|
19
19
|
type Options = {
|
|
20
20
|
onNewProps?: OptionValues;
|
|
21
21
|
onNewIndexes?: OptionValues;
|
|
22
|
+
onPathsIntersectedByPrimitiveValues?: OptionValues;
|
|
22
23
|
};
|
|
23
|
-
type ImmutableUpdate = <TObject
|
|
24
|
+
type ImmutableUpdate = <TObject>(state: TObject, dotPathUpdateObject: UpdateObject<TObject>, options?: Options) => TObject;
|
|
24
25
|
/**
|
|
25
26
|
* Creates a new object applying immutable updates using dot-path syntax.
|
|
26
27
|
* Can add or skip new props or indexes depending on options.
|
|
@@ -31,7 +32,7 @@ type ImmutableUpdate = <TObject extends Record<PropertyKey, any>>(state: TObject
|
|
|
31
32
|
* @returns New Updated Object.
|
|
32
33
|
*/
|
|
33
34
|
declare const update: ImmutableUpdate;
|
|
34
|
-
type ExtendableImmutableUpdate = <TObject
|
|
35
|
+
type ExtendableImmutableUpdate = <TObject, TUpdateObject extends UpdateObject<TObject>>(state: TObject, dotPathUpdateObject: TUpdateObject) => ExtendedUpdate<TObject, TUpdateObject>;
|
|
35
36
|
/**
|
|
36
37
|
* Creates a new object applying immutable updates using dot-path syntax.
|
|
37
38
|
* It will always add non-existent props or indexes if provided.
|
|
@@ -50,7 +51,7 @@ declare const extendableUpdate: ExtendableImmutableUpdate;
|
|
|
50
51
|
/** Primitives and browser native objects. */
|
|
51
52
|
type PrimitivesAndNativeObjects = null | undefined | string | number | boolean | symbol | bigint | Date | FileList | File;
|
|
52
53
|
/** Array indexes type. */
|
|
53
|
-
type ArrayIndexes = number | LiteralIndex;
|
|
54
|
+
type ArrayIndexes = number | `${number}` | LiteralIndex;
|
|
54
55
|
/** To check if a ReadonlyArray is a tuple or not. */
|
|
55
56
|
type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
|
|
56
57
|
/**
|
|
@@ -59,15 +60,21 @@ type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false
|
|
|
59
60
|
* --------------------------------------------
|
|
60
61
|
*/
|
|
61
62
|
/** Dot-paths of an array. */
|
|
62
|
-
type ArrayPaths<TInnerType, TAllowedTypes> = TInnerType extends TAllowedTypes ? TInnerType extends PrimitivesAndNativeObjects ?
|
|
63
|
+
type ArrayPaths<TInnerType, TAllowedTypes> = TInnerType extends TAllowedTypes ? TInnerType extends PrimitivesAndNativeObjects ? ArrayIndexes : ArrayIndexes | `${ArrayIndexes}.${DotPathsImplementation<TInnerType, TAllowedTypes>}` : `${ArrayIndexes}.${DotPathsImplementation<TInnerType, TAllowedTypes>}`;
|
|
63
64
|
/** Dot-paths of an object. */
|
|
64
65
|
type ObjectPaths<T, TAllowedTypes> = {
|
|
65
|
-
[Key in keyof T & (string | number)]: T[Key] extends TAllowedTypes ? T[Key] extends PrimitivesAndNativeObjects ? `${Key}` : `${Key}` | `${Key}.${
|
|
66
|
-
}[keyof T & (string | number)];
|
|
66
|
+
[Key in keyof T & (string | number)]: T[Key] extends TAllowedTypes ? T[Key] extends PrimitivesAndNativeObjects ? `${Key}` : `${Key}` | `${Key}.${DotPathsImplementation<T[Key], TAllowedTypes>}` : `${Key}.${DotPathsImplementation<T[Key], TAllowedTypes>}`;
|
|
67
|
+
}[keyof T & (string | number)] & unknown;
|
|
67
68
|
/** Dot-paths of a tuple. */
|
|
68
|
-
type TuplePaths<T, TAllowedTypes> = ObjectPaths<Omit<T, keyof any[]>, TAllowedTypes
|
|
69
|
+
type TuplePaths<T, TAllowedTypes> = ObjectPaths<Omit<T, keyof any[]>, TAllowedTypes> & unknown;
|
|
70
|
+
/** Dot-paths implementation */
|
|
71
|
+
type DotPathsImplementation<T, TAllowedTypes = any> = T extends ReadonlyArray<infer U> ? IsTuple<T> extends true ? TuplePaths<T, TAllowedTypes> : ArrayPaths<U, TAllowedTypes> : T extends PrimitivesAndNativeObjects ? never : ObjectPaths<T, TAllowedTypes>;
|
|
72
|
+
/** Extract Keys from any kind of type, including objects, arrays, tuples. */
|
|
73
|
+
type KeyOf<T, TAllowedTypes = any> = T extends ReadonlyArray<infer U> ? U extends TAllowedTypes ? IsTuple<T> extends true ? keyof Omit<T, keyof any[]> : ArrayIndexes : never : T extends PrimitivesAndNativeObjects ? never : {
|
|
74
|
+
[Key in keyof T]: T[Key] extends TAllowedTypes ? Key : never;
|
|
75
|
+
}[keyof T];
|
|
69
76
|
/** Literal union of all posible dot-paths which satisfy provided types as second argument (default: any). */
|
|
70
|
-
type DotPaths<T, TAllowedTypes = any> =
|
|
77
|
+
type DotPaths<T, TAllowedTypes = any> = KeyOf<T, TAllowedTypes> | DotPathsImplementation<T, TAllowedTypes>;
|
|
71
78
|
/**
|
|
72
79
|
* --------------------------------------------
|
|
73
80
|
* VALUE OF A NESTED PROPERTY PROVIDING A DOT PATH
|
|
@@ -88,10 +95,10 @@ type ReturnedValueInPath<TObject, TPath> = TPath extends '' ? TObject : TPath ex
|
|
|
88
95
|
* --------------------------------------------
|
|
89
96
|
*/
|
|
90
97
|
/** Value of a dot-path update object, can be the value or a function. */
|
|
91
|
-
type UpdateValue<TObject, TPath> = ValueInPath<TObject, TPath> | ((fieldValue: ValueInPath<TObject, TPath>) => ValueInPath<TObject, TPath>);
|
|
98
|
+
type UpdateValue<TObject, TPath> = ValueInPath<TObject, TPath> extends never ? never : ValueInPath<TObject, TPath> | ((fieldValue: ValueInPath<TObject, TPath>) => ValueInPath<TObject, TPath>);
|
|
92
99
|
/** Dot-path update object, used to give updates to the updateImmutably function. */
|
|
93
100
|
type UpdateObject<TObject, TPaths extends PropertyKey = DotPaths<TObject>> = {
|
|
94
|
-
[
|
|
101
|
+
[Path in TPaths]?: UpdateValue<TObject, Path>;
|
|
95
102
|
};
|
|
96
103
|
/**
|
|
97
104
|
* --------------------------------------------
|
|
@@ -118,7 +125,7 @@ type NestedPathKeys<T, K extends string | number> = {
|
|
|
118
125
|
/** Extract value if its a function */
|
|
119
126
|
type Value<T> = T extends (...args: any) => any ? ReturnType<T> : T;
|
|
120
127
|
/** To check if an empty object is provided */
|
|
121
|
-
type EmptyObject = Record<
|
|
128
|
+
type EmptyObject = Record<PropertyKey, never>;
|
|
122
129
|
/** Used to extract the type from a dot-path update object. */
|
|
123
130
|
type ExtractTypeFromDotPathUpdateObject<T extends Record<string, any>> = T extends EmptyObject ? {} : keyof T extends LiteralIndex | number | `${number}` | `${number}.${infer U}` ? Value<T[KeyPathsStartingWithAnIndex<T>]> extends never ? Array<Value<T[KeysRepresentingAnIndex<T>]>> : Array<Value<T[KeysRepresentingAnIndex<T>]> | {
|
|
124
131
|
[Key2 in U]: Value<T[KeyPathsStartingWithAnIndex<T>]>;
|
|
@@ -132,7 +139,7 @@ type ExtractTypeFromDotPathUpdateObject<T extends Record<string, any>> = T exten
|
|
|
132
139
|
}>;
|
|
133
140
|
} & unknown;
|
|
134
141
|
/** New expanded value after aplying updates including new properties */
|
|
135
|
-
type ExtendedUpdate<TObject
|
|
142
|
+
type ExtendedUpdate<TObject, TDotPathUpdateObject extends Record<PropertyKey, any>> = TObject extends Array<infer U> ? ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject> extends Array<infer W> ? Array<U | W> : TObject & ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject> : TObject & ExtractTypeFromDotPathUpdateObject<TDotPathUpdateObject>;
|
|
136
143
|
|
|
137
144
|
type Select = {
|
|
138
145
|
<T, TPath extends DotPaths<T>>(state: T, path: TPath): ReturnedValueInPath<T, TPath>;
|
|
@@ -156,7 +163,7 @@ type SplitDotPathAtLastKey = <T extends string>(dotPath: T) => [PathWithoutLastK
|
|
|
156
163
|
*/
|
|
157
164
|
declare const splitPathAtLastKey: SplitDotPathAtLastKey;
|
|
158
165
|
|
|
159
|
-
type Set = <T>(newValue: T) => (
|
|
166
|
+
type Set = <T>(newValue: T) => (v: unknown) => T;
|
|
160
167
|
/**
|
|
161
168
|
* Allows to set strongly typed values (removing inacurate "undefined" inference) in nested values inside arrays.
|
|
162
169
|
* @param newValue New value.
|
|
@@ -170,4 +177,4 @@ declare const isObjectLiteral: (valueToTest: any) => boolean;
|
|
|
170
177
|
declare const parseStringIndex: (v: string) => number | null;
|
|
171
178
|
declare const isStringIndex: (v: string) => boolean;
|
|
172
179
|
|
|
173
|
-
export { type DotPaths, type LiteralIndex, type ReturnedValueInPath, type UpdateObject, type UpdateValue, type ValueInPath, extendableUpdate, isObjectLiteral, isStringIndex, parseStringIndex, remove, select, set, splitPathAtLastKey, update };
|
|
180
|
+
export { type DotPaths, type KeyOf, type LiteralIndex, type ReturnedValueInPath, type UpdateObject, type UpdateValue, type ValueInPath, extendableUpdate, isObjectLiteral, isStringIndex, parseStringIndex, remove, select, set, splitPathAtLastKey, update };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var T=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var $=(e,t)=>{for(var r in t)T(e,r,{get:t[r],enumerable:!0})},C=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of v(t))!D.call(e,o)&&o!==r&&T(e,o,{get:()=>t[o],enumerable:!(n=k(t,o))||n.enumerable});return e};var N=e=>C(T({},"__esModule",{value:!0}),e);var R={};$(R,{extendableUpdate:()=>L,isObjectLiteral:()=>d,isStringIndex:()=>y,parseStringIndex:()=>U,remove:()=>I,select:()=>j,set:()=>K,splitPathAtLastKey:()=>w,update:()=>E});module.exports=N(R);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 o=Symbol(),i=[...e];return r.forEach(s=>{i[s]=o}),i.filter(s=>s!==o)}let n={...e};return r.forEach(o=>delete n[o]),n};var j=(e,t)=>{if(typeof t!="string")throw new Error("path is not a string");if(!t)return e;let r=t.split("."),n=e;for(;r.length;){let o=r.join(".");if(n?.hasOwnProperty(o))return n[o];if(!n?.hasOwnProperty(r[0]))return;n=n[r[0]],r.shift()}return n};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):"",n=e.slice(t);return[r,n]};var K=e=>()=>e;var d=e=>!!e&&Object.getPrototypeOf(e)===Object.prototype;var U=e=>{let t=parseInt(e);return t.toString()===e?t:null},y=e=>parseInt(e).toString()===e;var A=e=>JSON.stringify(e),m=e=>Array.isArray(e),g=(e,t,r={})=>{if(!d(e)&&!m(e))throw new Error(`"${A(e)}" is not an literalObject/array`);if(!d(t))throw new Error('wrong "updateObject" type provided');let n=Array.isArray(e)?[...e]:{...e},o={};for(let[i,h]of Object.entries(t)){if(i==="")continue;let s=i.split("."),l=o,p=n;for(;s.length>1;){let x=s.join(".");if(Object.hasOwn(p,x)){s=[x];break}let a=s[0],f=p[a],O=d(f),b=m(f);if(!O&&!b&&!(f===void 0)){if(r.onPathsIntersectedByPrimitiveValues==="error")throw new Error(`Property "${a}" in "${i}" is a primitive`);if(r.onPathsIntersectedByPrimitiveValues==="skip")continue}if(!l[a]){if(!O&&!b){let V=m(p)&&y(a),S=y(s[1]),P=V?r.onNewIndexes:r.onNewProps;if(P==="error")throw new Error(`${a} doesn't exist in "${i}"`);if(P==="skip")continue;p[a]=S?[]:{}}else p[a]=b?[...f]:{...f};l[a]={}}p=p[a],l=l[a],s.shift()}let c=s[0],u=p;if(!Object.hasOwn(u,c)){let a=m(u)&&y(c)?r.onNewIndexes:r.onNewProps;if(a==="error")throw new Error(`Property/Index "${c}" doesnt exist in the path "${i}". Its value is: "${A(u)}"`);if(a==="skip")continue}u[c]=typeof h=="function"?h(u[c]):h,delete l[c]}return n},E=(e,t,r)=>g(e,t,r),L=(e,t)=>g(e,t);0&&(module.exports={extendableUpdate,isObjectLiteral,isStringIndex,parseStringIndex,remove,select,set,splitPathAtLastKey,update});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var K=(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 s=Symbol(),i=[...e];return r.forEach(a=>{i[a]=s}),i.filter(a=>a!==s)}let n={...e};return r.forEach(s=>delete n[s]),n};var U=(e,t)=>{if(typeof t!="string")throw new Error("path is not a string");if(!t)return e;let r=t.split("."),n=e;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 A=e=>{if(typeof e!="string")throw new Error(`Wrong dotPath type: ${e}`);let t=e.lastIndexOf(".")+1,r=t?e.slice(0,t-1):"",n=e.slice(t);return[r,n]};var g=e=>()=>e;var u=e=>!!e&&Object.getPrototypeOf(e)===Object.prototype;var E=e=>{let t=parseInt(e);return t.toString()===e?t:null},f=e=>parseInt(e).toString()===e;var P=e=>JSON.stringify(e),m=e=>Array.isArray(e),I=(e,t,r={})=>{if(!u(e)&&!m(e))throw new Error(`"${P(e)}" is not an literalObject/array`);if(!u(t))throw new Error('wrong "updateObject" type provided');let n=Array.isArray(e)?[...e]:{...e},s={};for(let[i,h]of Object.entries(t)){if(i==="")continue;let a=i.split("."),d=s,p=n;for(;a.length>1;){let x=a.join(".");if(Object.hasOwn(p,x)){a=[x];break}let o=a[0],l=p[o],T=u(l),b=m(l);if(!T&&!b&&!(l===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(!T&&!b){let j=m(p)&&f(o),w=f(a[1]),O=j?r.onNewIndexes:r.onNewProps;if(O==="error")throw new Error(`${o} doesn't exist in "${i}"`);if(O==="skip")continue;p[o]=w?[]:{}}else p[o]=b?[...l]:{...l};d[o]={}}p=p[o],d=d[o],a.shift()}let c=a[0],y=p;if(!Object.hasOwn(y,c)){let o=m(y)&&f(c)?r.onNewIndexes:r.onNewProps;if(o==="error")throw new Error(`Property/Index "${c}" doesnt exist in the path "${i}". Its value is: "${P(y)}"`);if(o==="skip")continue}y[c]=typeof h=="function"?h(y[c]):h,delete d[c]}return n},L=(e,t,r)=>I(e,t,r),V=(e,t)=>I(e,t);export{V as extendableUpdate,u as isObjectLiteral,f as isStringIndex,E as parseStringIndex,K as remove,U as select,g as set,A as splitPathAtLastKey,L as update};
|