maraj 2.2.0 → 2.3.0

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
@@ -45,7 +45,7 @@ type Remove = <T extends object>(value: T, keys: T extends any[] ? (number | `${
45
45
  */
46
46
  declare const remove: Remove;
47
47
 
48
- type Select = <T extends object, TPath extends (DotPaths<T> | '')>(state: T, path: TPath) => TPath extends PathIndexingArray<Index> ? never : TPath extends PathIndexingArray<number> ? ValueInDotPath<T, TPath> | undefined : ValueInDotPath<T, TPath>;
48
+ type Select = <T, TPath extends (DotPaths<T> | '')>(state: T, path: TPath) => TPath extends PathIndexingArray<Index> ? never : TPath extends PathIndexingArray<number> ? ValueInDotPath<T, TPath> | undefined : ValueInDotPath<T, TPath>;
49
49
  /**
50
50
  * Returns the value from a given dot path of an object/array.
51
51
  * Returns undefined if the provided path doesnt exist.
package/dist/index.d.ts CHANGED
@@ -45,7 +45,7 @@ type Remove = <T extends object>(value: T, keys: T extends any[] ? (number | `${
45
45
  */
46
46
  declare const remove: Remove;
47
47
 
48
- type Select = <T extends object, TPath extends (DotPaths<T> | '')>(state: T, path: TPath) => TPath extends PathIndexingArray<Index> ? never : TPath extends PathIndexingArray<number> ? ValueInDotPath<T, TPath> | undefined : ValueInDotPath<T, TPath>;
48
+ type Select = <T, TPath extends (DotPaths<T> | '')>(state: T, path: TPath) => TPath extends PathIndexingArray<Index> ? never : TPath extends PathIndexingArray<number> ? ValueInDotPath<T, TPath> | undefined : ValueInDotPath<T, TPath>;
49
49
  /**
50
50
  * Returns the value from a given dot path of an object/array.
51
51
  * Returns undefined if the provided path doesnt exist.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var j=(t,e)=>{for(var r in e)f(t,r,{get:e[r],enumerable:!0})},O=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of D(e))!w.call(t,o)&&o!==r&&f(t,o,{get:()=>e[o],enumerable:!(a=I(e,o))||a.enumerable});return t};var g=t=>O(f({},"__esModule",{value:!0}),t);var v={};j(v,{remove:()=>x,select:()=>T,set:()=>b,splitPathAtLastKey:()=>m,updateImmutably:()=>A});module.exports=g(v);var x=(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 o=Symbol(),y=[...t];return r.forEach(n=>{y[n]=o}),y.filter(n=>n!==o)}let a={...t};return r.forEach(o=>delete a[o]),a};var T=(t,e)=>!e||typeof e!="string"?t:e.split(".").reduce((r,a)=>{if(r?.hasOwnProperty(a))return r[a]},t);var m=t=>{if(typeof t!="string")throw new Error(`Wrong dotPath type: ${t}`);let e=t.lastIndexOf(".")+1,r=e?t.slice(0,e-1):"",a=t.slice(e);return[r,a]};var b=t=>()=>t;var A=(t,e,r)=>{if(t?.constructor!==Object&&!Array.isArray(t))throw new Error(`${t} is not an object/array`);if(!e)return t;let a=Array.isArray(t)?[...t]:{...t},o={};for(let[y,l]of Object.entries(e)){if(!y)continue;let n=y.split("."),s=n.pop(),c=o,d=a;for(let u=0;u<n.length;u++){let i=n[u],p=d[i],K=typeof p=="object"&&(p.constructor===Object||Array.isArray(p)),P=r&&p===void 0;if(!K&&!P)throw new Error(`Invalid path provided: "${i}" is not an object/array in "${y}"`);c[i]||(P?d[i]=isNaN(n[u+1]??s)?{}:[]:d[i]=Array.isArray(p)?[...p]:{...p},c[i]={}),d=d[i],c=c[i]}let h=d;if(!r){if(Array.isArray(h)&&!(s<h.length))throw new Error(`Index ${s} doesnt exist in the path ${n.join(".")} because its value is ${s}, use spread operator for adding new indexes`);if(!h.hasOwnProperty(s))throw new Error(`Property ${s} doesnt exist in the path ${n.join(".")} because its value is ${h}`)}h[s]=typeof l=="function"?l(h[s],a):l,delete c[s]}return a};0&&(module.exports={remove,select,set,splitPathAtLastKey,updateImmutably});
1
+ "use strict";var f=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var O=(t,e)=>{for(var r in e)f(t,r,{get:e[r],enumerable:!0})},j=(t,e,r,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of D(e))!w.call(t,o)&&o!==r&&f(t,o,{get:()=>e[o],enumerable:!(a=I(e,o))||a.enumerable});return t};var g=t=>j(f({},"__esModule",{value:!0}),t);var v={};O(v,{remove:()=>x,select:()=>T,set:()=>b,splitPathAtLastKey:()=>m,updateImmutably:()=>A});module.exports=g(v);var x=(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 o=Symbol(),y=[...t];return r.forEach(n=>{y[n]=o}),y.filter(n=>n!==o)}let a={...t};return r.forEach(o=>delete a[o]),a};var T=(t,e)=>!e||typeof e!="string"?t:e.split(".").reduce((r,a)=>{if(r?.hasOwnProperty(a))return r[a]},t);var m=t=>{if(typeof t!="string")throw new Error(`Wrong dotPath type: ${t}`);let e=t.lastIndexOf(".")+1,r=e?t.slice(0,e-1):"",a=t.slice(e);return[r,a]};var b=t=>()=>t;var A=(t,e,r)=>{if(t?.constructor!==Object&&!Array.isArray(t))throw new Error(`${t} is not an object/array`);if(!e)return t;let a=Array.isArray(t)?[...t]:{...t},o={};for(let[y,u]of Object.entries(e)){if(!y)continue;let n=y.split("."),s=n.pop(),l=o,h=a;for(let c=0;c<n.length;c++){let i=n[c],p=h[i],K=typeof p=="object"&&(p.constructor===Object||Array.isArray(p)),P=r&&p===void 0;if(!K&&!P)throw new Error(`Invalid path provided: "${i}" is not an object/array in "${y}"`);l[i]||(P?h[i]=isNaN(n[c+1]??s)?{}:[]:h[i]=Array.isArray(p)?[...p]:{...p},l[i]={}),h=h[i],l=l[i]}let d=h;if(!r){if(Array.isArray(d)&&!(s<d.length))throw new Error(`Index ${s} doesnt exist in the path ${n.join(".")} because its value is ${s}, use spread operator for adding new indexes`);if(!d.hasOwnProperty(s))throw new Error(`Property ${s} doesnt exist in the path ${n.join(".")} because its value is ${d}`)}d[s]=typeof u=="function"?u(d[s],a):u,delete l[s]}return a};0&&(module.exports={remove,select,set,splitPathAtLastKey,updateImmutably});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var x=(t,e)=>{if(!Array.isArray(t)&&t?.constructor!==Object)throw'Wrong type provided in "remove" function';let a=Array.isArray(e)?e:[e];if(Array.isArray(t)){let p=Symbol(),y=[...t];return a.forEach(o=>{y[o]=p}),y.filter(o=>o!==p)}let r={...t};return a.forEach(p=>delete r[p]),r};var T=(t,e)=>!e||typeof e!="string"?t:e.split(".").reduce((a,r)=>{if(a?.hasOwnProperty(r))return a[r]},t);var m=t=>{if(typeof t!="string")throw new Error(`Wrong dotPath type: ${t}`);let e=t.lastIndexOf(".")+1,a=e?t.slice(0,e-1):"",r=t.slice(e);return[a,r]};var b=t=>()=>t;var A=(t,e,a)=>{if(t?.constructor!==Object&&!Array.isArray(t))throw new Error(`${t} is not an object/array`);if(!e)return t;let r=Array.isArray(t)?[...t]:{...t},p={};for(let[y,l]of Object.entries(e)){if(!y)continue;let o=y.split("."),n=o.pop(),c=p,d=r;for(let u=0;u<o.length;u++){let s=o[u],i=d[s],P=typeof i=="object"&&(i.constructor===Object||Array.isArray(i)),f=a&&i===void 0;if(!P&&!f)throw new Error(`Invalid path provided: "${s}" is not an object/array in "${y}"`);c[s]||(f?d[s]=isNaN(o[u+1]??n)?{}:[]:d[s]=Array.isArray(i)?[...i]:{...i},c[s]={}),d=d[s],c=c[s]}let h=d;if(!a){if(Array.isArray(h)&&!(n<h.length))throw new Error(`Index ${n} doesnt exist in the path ${o.join(".")} because its value is ${n}, use spread operator for adding new indexes`);if(!h.hasOwnProperty(n))throw new Error(`Property ${n} doesnt exist in the path ${o.join(".")} because its value is ${h}`)}h[n]=typeof l=="function"?l(h[n],r):l,delete c[n]}return r};export{x as remove,T as select,b as set,m as splitPathAtLastKey,A as updateImmutably};
1
+ var x=(t,e)=>{if(!Array.isArray(t)&&t?.constructor!==Object)throw'Wrong type provided in "remove" function';let a=Array.isArray(e)?e:[e];if(Array.isArray(t)){let p=Symbol(),y=[...t];return a.forEach(o=>{y[o]=p}),y.filter(o=>o!==p)}let r={...t};return a.forEach(p=>delete r[p]),r};var T=(t,e)=>!e||typeof e!="string"?t:e.split(".").reduce((a,r)=>{if(a?.hasOwnProperty(r))return a[r]},t);var m=t=>{if(typeof t!="string")throw new Error(`Wrong dotPath type: ${t}`);let e=t.lastIndexOf(".")+1,a=e?t.slice(0,e-1):"",r=t.slice(e);return[a,r]};var b=t=>()=>t;var A=(t,e,a)=>{if(t?.constructor!==Object&&!Array.isArray(t))throw new Error(`${t} is not an object/array`);if(!e)return t;let r=Array.isArray(t)?[...t]:{...t},p={};for(let[y,u]of Object.entries(e)){if(!y)continue;let o=y.split("."),n=o.pop(),l=p,h=r;for(let c=0;c<o.length;c++){let s=o[c],i=h[s],P=typeof i=="object"&&(i.constructor===Object||Array.isArray(i)),f=a&&i===void 0;if(!P&&!f)throw new Error(`Invalid path provided: "${s}" is not an object/array in "${y}"`);l[s]||(f?h[s]=isNaN(o[c+1]??n)?{}:[]:h[s]=Array.isArray(i)?[...i]:{...i},l[s]={}),h=h[s],l=l[s]}let d=h;if(!a){if(Array.isArray(d)&&!(n<d.length))throw new Error(`Index ${n} doesnt exist in the path ${o.join(".")} because its value is ${n}, use spread operator for adding new indexes`);if(!d.hasOwnProperty(n))throw new Error(`Property ${n} doesnt exist in the path ${o.join(".")} because its value is ${d}`)}d[n]=typeof u=="function"?u(d[n],r):u,delete l[n]}return r};export{x as remove,T as select,b as set,m as splitPathAtLastKey,A as updateImmutably};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maraj",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "A lightweight 500 bytes gzipped alternative for immutable updates while dealing with objects and arrays",
5
5
  "keywords": [
6
6
  "shallow",