@visulima/object 3.0.0-alpha.14 → 3.0.0-alpha.16

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/CHANGELOG.md CHANGED
@@ -1,3 +1,39 @@
1
+ ## @visulima/object [3.0.0-alpha.16](https://github.com/visulima/visulima/compare/@visulima/object@3.0.0-alpha.15...@visulima/object@3.0.0-alpha.16) (2026-06-13)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **object:** fix broken types, array/escape paths and docs ([7c560b1](https://github.com/visulima/visulima/commit/7c560b175507231ba3d50a18faa372283f6fb13c))
6
+
7
+ ### Miscellaneous Chores
8
+
9
+ * apply safe prettier and eslint formatting ([05120af](https://github.com/visulima/visulima/commit/05120af8c898d18c495575680f01134681e29b65))
10
+
11
+ ### Code Refactoring
12
+
13
+ * **object:** apply prettier/eslint formatting cleanup ([b293527](https://github.com/visulima/visulima/commit/b293527bc95a2b260665c98f5b7206996f23ac91))
14
+
15
+ ### Tests
16
+
17
+ * **object:** add safe-assign coverage ([0dc5c7b](https://github.com/visulima/visulima/commit/0dc5c7bb14a59595b3ec2f5f37f64842eefad26e))
18
+
19
+ ### Build System
20
+
21
+ * regenerate bundled-license manifests and types ordering ([af26588](https://github.com/visulima/visulima/commit/af26588d75aaa937fd4862800560bd4070a4878c))
22
+
23
+ ## @visulima/object [3.0.0-alpha.15](https://github.com/visulima/visulima/compare/@visulima/object@3.0.0-alpha.14...@visulima/object@3.0.0-alpha.15) (2026-06-04)
24
+
25
+ ### Bug Fixes
26
+
27
+ * **object:** 1 bug fix + 1 perf ([d317d30](https://github.com/visulima/visulima/commit/d317d30cf89629f3a2cea5a1f7a6e9b3967c86d4))
28
+
29
+ ### Miscellaneous Chores
30
+
31
+ * apply eslint + prettier autofixes across packages ([c1bb784](https://github.com/visulima/visulima/commit/c1bb7848a0d93d0dfe2960c77e3cda22239c79a0))
32
+
33
+ ### Tests
34
+
35
+ * **object:** cover recursive pick/omit non-plain-object and empty-keys branches ([79c3498](https://github.com/visulima/visulima/commit/79c34986008e0633e61a4be39dc18c2b02589e3d))
36
+
1
37
  ## @visulima/object [3.0.0-alpha.14](https://github.com/visulima/visulima/compare/@visulima/object@3.0.0-alpha.13...@visulima/object@3.0.0-alpha.14) (2026-05-27)
2
38
 
3
39
  ### Bug Fixes
package/README.md CHANGED
@@ -50,56 +50,113 @@ pnpm add @visulima/object
50
50
 
51
51
  ## Usage
52
52
 
53
- ### deleteProperty
54
-
55
- ### escapePath
56
-
57
- ### getProperty
58
-
59
- ### hasProperty
60
-
61
- ### setProperty
62
-
63
- ### deepKeys
64
-
65
- ### deepKeysFromList
66
-
67
- ### isPlainObject
53
+ `@visulima/object` exposes two local helpers (`pick`, `omit`) plus a curated set
54
+ of re-exports from [`dot-prop`](https://github.com/sindresorhus/dot-prop) and
55
+ [`deeks`](https://github.com/mrodrig/deeks).
68
56
 
69
57
  ### pick
70
58
 
71
- With `pick` you pass an object and an array of keys of an object - **the props which may stay**.
59
+ With `pick` you pass an object and an array of keys - **the props which may stay**.
72
60
 
73
61
  ```js
74
62
  import { pick } from "@visulima/object";
75
63
 
76
64
  const squirtle = { id: "007", name: "Squirtle", type: "water" };
77
65
 
78
- const newObject = pick(squirtle, ["name", "type"]);
79
- // returns { name: 'Squirtle', type: 'water' }
66
+ pick(squirtle, ["name", "type"]);
67
+ // => { name: 'Squirtle', type: 'water' }
80
68
 
81
69
  const doc = { items: { keep: "📌", discard: "✂️" } };
82
70
 
83
71
  pick(doc, ["items.keep"]);
84
- // returns {items: {keep: '📌'}}
72
+ // => { items: { keep: '📌' } }
85
73
  ```
86
74
 
75
+ `pick` returns a **new object** and never shares structure with the input. An
76
+ empty key list returns `{}`.
77
+
87
78
  ### omit
88
79
 
89
- With `omit` you pass an object and an array of keys of an object - the props which should be removed.
80
+ With `omit` you pass an object and an array of keys - the props which should be removed.
90
81
 
91
82
  ```js
92
83
  import { omit } from "@visulima/object";
93
84
 
94
85
  const squirtle = { id: "007", name: "Squirtle", type: "water" };
95
86
 
96
- const withoutId = omit(squirtle, ["id"]);
97
- // returns { name: 'Squirtle', type: 'water' }
87
+ omit(squirtle, ["id"]);
88
+ // => { name: 'Squirtle', type: 'water' }
98
89
 
99
90
  const doc = { items: { keep: "📌", discard: "✂️" } };
100
91
 
101
92
  omit(doc, ["items.discard"]);
102
- // returns {items: {keep: '📌'}}
93
+ // => { items: { keep: '📌' } }
94
+ ```
95
+
96
+ `omit` always returns a **fresh deep copy** — even when the key list is empty —
97
+ so mutating the result never affects the input.
98
+
99
+ ### Path features (`pick` / `omit`)
100
+
101
+ Both helpers share the same path dialect:
102
+
103
+ - **Dot-notation** for nested props: `nested.prop`.
104
+ - **Wildcard segments** with `*` to match any single key: `items.*.secret`.
105
+ - **Array traversal** by index or wildcard: `users.0.password`, `users.*.password`.
106
+ - **Backslash-escaped dots** for keys that literally contain a `.`: `omit(obj, ["a\\.b"])`
107
+ targets the key named `"a.b"` (compatible with the re-exported `escapePath`).
108
+ - **Symbol-keyed properties** are always preserved (string paths can never name them).
109
+
110
+ ```js
111
+ omit({ users: [{ name: "a", password: "x" }] }, ["users.*.password"]);
112
+ // => { users: [{ name: "a" }] }
113
+ ```
114
+
115
+ ### isPlainObject
116
+
117
+ Returns `true` only for objects created from `{}` or `Object.create(null)`
118
+ (arrays, class instances, `Map`/`Set`, etc. return `false`).
119
+
120
+ ```js
121
+ import { isPlainObject } from "@visulima/object";
122
+
123
+ isPlainObject({}); // => true
124
+ isPlainObject([]); // => false
125
+ isPlainObject(new Map()); // => false
126
+ ```
127
+
128
+ ### getProperty / setProperty / hasProperty / deleteProperty / escapePath
129
+
130
+ Re-exported from [`dot-prop`](https://github.com/sindresorhus/dot-prop) for
131
+ get/set/has/delete on nested objects using a dot path (this uses dot-prop's own
132
+ `a.b[0].c` array syntax). `escapePath` escapes a string so dots inside it are
133
+ treated as literal characters.
134
+
135
+ ```js
136
+ import { getProperty, setProperty, hasProperty, deleteProperty, escapePath } from "@visulima/object";
137
+
138
+ getProperty({ foo: { bar: "baz" } }, "foo.bar"); // => "baz"
139
+ setProperty({}, "foo.bar", "baz"); // => { foo: { bar: "baz" } }
140
+ hasProperty({ foo: { bar: "baz" } }, "foo.bar"); // => true
141
+ deleteProperty({ foo: { bar: "baz" } }, "foo.bar"); // => true (mutates input)
142
+ escapePath("foo.bar"); // => "foo\\.bar"
143
+ ```
144
+
145
+ > Note: the `dot-prop` helpers use dot-prop's own path/array syntax, while
146
+ > `pick`/`omit` use the dialect described above. Use `escapePath` for the
147
+ > dot-prop helpers and `\\.`-escaping for `pick`/`omit`.
148
+
149
+ ### deepKeys / deepKeysFromList
150
+
151
+ Re-exported from [`deeks`](https://github.com/mrodrig/deeks) — collect every
152
+ dot-notation key path from a single object (`deepKeys`) or an array of objects
153
+ (`deepKeysFromList`). Accepts a `DeepKeysOptions` object.
154
+
155
+ ```js
156
+ import { deepKeys, deepKeysFromList } from "@visulima/object";
157
+
158
+ deepKeys({ a: { b: 1, c: 2 } }); // => ["a.b", "a.c"]
159
+ deepKeysFromList([{ a: 1 }, { b: { c: 2 } }]); // => [["a"], ["b.c"]]
103
160
  ```
104
161
 
105
162
  ## Related
package/dist/index.d.ts CHANGED
@@ -1,23 +1,49 @@
1
1
  import { Paths, OmitDeep, PickDeep, Get } from 'type-fest';
2
- export { type OmitDeep, type Paths, type PickDeep, type Split } from 'type-fest';
2
+ export type { OmitDeep, Paths, PickDeep, Split } from 'type-fest';
3
3
  /**
4
4
  * Omit returns a new object without the props you omit.
5
+ *
6
+ * Supports dot-notation for nested props (e.g. `nested.prop`), `*` wildcard
7
+ * segments (e.g. `items.*.secret`), array traversal (e.g. `users.0.password`
8
+ * or `users.*.password`), and backslash-escaped dots for keys that literally
9
+ * contain a `.` (e.g. `a\\.b`). Symbol-keyed properties are always preserved.
5
10
  * @template T
6
11
  * @template K
7
12
  * @param object the target object to omit props from
8
13
  * @param keys the prop names you want to omit
9
14
  * @returns a new object without the omitted props
15
+ * @example
16
+ * ```js
17
+ * omit({ id: "1", name: "n", secret: "x" }, ["secret"]);
18
+ * // => { id: "1", name: "n" }
19
+ *
20
+ * omit({ users: [{ name: "a", password: "p" }] }, ["users.*.password"]);
21
+ * // => { users: [{ name: "a" }] }
22
+ * ```
10
23
  */
11
- declare const omit: <T extends { [key in string]: unknown }, K extends string>(object: T, keys: Paths<T>[]) => OmitDeep<T, K>;
24
+ declare const omit: <T extends { [key in string]: unknown }, const K extends Paths<T>>(object: T, keys: ReadonlyArray<K>) => OmitDeep<T, K>;
12
25
  /**
13
26
  * Pick returns a new object with only the props you pick.
27
+ *
28
+ * Supports dot-notation for nested props (e.g. `nested.prop` keeps just
29
+ * `{ nested: { prop: 1 } }`), `*` wildcard segments (e.g. `items.*.id`), array
30
+ * traversal (e.g. `users.0.name` or `users.*.name`), and backslash-escaped
31
+ * dots for keys that literally contain a `.` (e.g. `a\\.b`).
14
32
  * @template T
15
33
  * @template K
16
34
  * @param object the target object to pick props from
17
- * @param keys an array of prop names you want to keep - allows dot-notation for nested props, eg. `nested.prop` will keep just `{ nested: { prop: 1 } }`
35
+ * @param keys an array of prop names you want to keep
18
36
  * @returns a new object with just the picked props
37
+ * @example
38
+ * ```js
39
+ * pick({ id: "1", name: "n", secret: "x" }, ["id", "name"]);
40
+ * // => { id: "1", name: "n" }
41
+ *
42
+ * pick({ users: [{ name: "a", password: "p" }] }, ["users.*.name"]);
43
+ * // => { users: [{ name: "a" }] }
44
+ * ```
19
45
  */
20
- declare const pick: <T extends { [key in string]: unknown }, K extends Paths<T>>(object: T, keys: Paths<T>[]) => PickDeep<T, K>;
46
+ declare const pick: <T extends { [key in string]: unknown }, const K extends Paths<T>>(object: T, keys: ReadonlyArray<K>) => PickDeep<T, K>;
21
47
  /**
22
48
  * Determines whether a value is a plain object (i.e. created from `{}` or `Object.create(null)`).
23
49
  * @param value Value to inspect.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var T=Object.defineProperty;var a=(t,c)=>T(t,"name",{value:c,configurable:!0});import{default as $}from"./packem_shared/omit-CFZMq4XQ.js";import{default as te}from"./packem_shared/pick-gi5xtds4.js";import{default as ne}from"./packem_shared/isPlainObject-CKRRjQp3.js";import{deleteProperty as oe,escapePath as se,getProperty as ue,hasProperty as ce,setProperty as ie}from"./packem_shared/getProperty-DPNB_aKG.js";var W=Object.defineProperty,j=a((t,c)=>W(t,"name",{value:c,configurable:!0}),"t");function B(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}a(B,"getDefaultExportFromCjs");j(B,"getDefaultExportFromCjs");function C(t){return t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}a(C,"getDefaultExportFromNamespaceIfPresent");j(C,"getDefaultExportFromNamespaceIfPresent");function U(t){return t&&Object.prototype.hasOwnProperty.call(t,"default")&&Object.keys(t).length===1?t.default:t}a(U,"getDefaultExportFromNamespaceIfNotNamed");j(U,"getDefaultExportFromNamespaceIfNotNamed");function z(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var c=t.default;if(typeof c=="function"){var u=j(a(function p(){var y=!1;try{y=this instanceof p}catch{}return y?Reflect.construct(c,arguments,this.constructor):c.apply(this,arguments)},"a"),"a");u.prototype=c.prototype}else u={};return Object.defineProperty(u,"__esModule",{value:!0}),Object.keys(t).forEach(function(p){var y=Object.getOwnPropertyDescriptor(t,p);Object.defineProperty(u,p,y.get?y:{enumerable:!0,get:j(function(){return t[p]},"get")})}),u}a(z,"getAugmentedNamespace");j(z,"getAugmentedNamespace");var l={},b={},S;function G(){if(S)return b;S=1;var t=Object.defineProperty,c=a((f,D)=>t(f,"name",{value:D,configurable:!0}),"t");Object.defineProperty(b,"__esModule",{value:!0}),b.isDocumentToRecurOn=b.flatten=b.unique=void 0;function u(f){return[...new Set(f)]}a(u,"unique"),c(u,"unique"),b.unique=u;function p(f){return[].concat(...f)}a(p,"flatten"),c(p,"flatten"),b.flatten=p;function y(f){return typeof f=="object"&&f!==null&&!Array.isArray(f)&&Object.keys(f).length}return a(y,"isDocumentToRecurOn"),c(y,"isDocumentToRecurOn"),b.isDocumentToRecurOn=y,b}a(G,"requireUtils");var E={},I;function H(){return I||(I=1,Object.defineProperty(E,"__esModule",{value:!0})),E}a(H,"requireTypes");var R;function J(){return R||(R=1,(function(t){var c=Object.defineProperty,u=a((e,r)=>c(e,"name",{value:r,configurable:!0}),"u"),p=l&&l.__createBinding||(Object.create?(function(e,r,n,o){o===void 0&&(o=n);var s=Object.getOwnPropertyDescriptor(r,n);(!s||("get"in s?!r.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:u(function(){return r[n]},"get")}),Object.defineProperty(e,o,s)}):(function(e,r,n,o){o===void 0&&(o=n),e[o]=r[n]})),y=l&&l.__setModuleDefault||(Object.create?(function(e,r){Object.defineProperty(e,"default",{enumerable:!0,value:r})}):function(e,r){e.default=r}),f=l&&l.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var n in e)n!=="default"&&Object.prototype.hasOwnProperty.call(e,n)&&p(r,e,n);return y(r,e),r},D=l&&l.__exportStar||function(e,r){for(var n in e)n!=="default"&&!Object.prototype.hasOwnProperty.call(r,n)&&p(r,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),t.deepKeysFromList=t.deepKeys=void 0;const v=f(G());D(H(),t);function q(e,r){const n=N(r);return typeof e=="object"&&e!==null?k("",e,n,new WeakSet):[]}a(q,"deepKeys"),u(q,"deepKeys"),t.deepKeys=q;function K(e,r,n){const o=N(r),s=n??new WeakSet;return e.map(d=>typeof d=="object"&&d!==null?s.has(d)?[]:k("",d,o,s):[])}a(K,"deepKeysFromList"),u(K,"deepKeysFromList"),t.deepKeysFromList=K;function k(e,r,n,o){const s=[],d=Object.keys(r);o.add(r);const m=[{obj:r,keys:d,i:0,basePath:e}];for(;m.length;){const O=m[m.length-1];if(O.i>=O.keys.length){m.pop();continue}const F=O.keys[O.i++],i=O.obj[F],P=_(O.basePath,x(F,n));if(n.expandNestedObjects&&v.isDocumentToRecurOn(i)||n.arrayIndexesAsKeys&&Array.isArray(i)&&i.length)if(n.arrayIndexesAsKeys&&Array.isArray(i)){const A=i;for(let h=A.length-1;h>=0;h--){const g=A[h],M=_(P,String(h));typeof g=="object"&&g!==null&&!Array.isArray(g)?o.has(g)||(o.add(g),m.push({obj:g,keys:Object.keys(g),i:0,basePath:M})):s.push(M)}}else o.has(i)||(o.add(i),m.push({obj:i,keys:Object.keys(i),i:0,basePath:P}));else if(n.expandArrayObjects&&Array.isArray(i)){const A=w(i,P,n,o);for(const h of A)s.push(h)}else{if(n.ignoreEmptyArrays&&Array.isArray(i)&&!i.length)continue;s.push(P)}}return v.unique(s)}a(k,"generateDeepKeysList"),u(k,"generateDeepKeysList");function w(e,r,n,o){let s=K(e,n,o);return e.length?e.length&&v.flatten(s).length===0?[r]:(s=s.map(d=>Array.isArray(d)&&d.length===0?[r]:d.map(m=>_(r,x(m,n)))),v.unique(v.flatten(s))):n.ignoreEmptyArraysWhenExpanding?[]:[r]}a(w,"processArrayKeys"),u(w,"processArrayKeys");function x(e,r){return r.escapeNestedDots?e.replace(/\./g,"\\."):e}a(x,"escapeNestedDotsIfSpecified"),u(x,"escapeNestedDotsIfSpecified");function _(e,r){return e?e+"."+r:r}a(_,"buildKeyName"),u(_,"buildKeyName");function N(e){return{arrayIndexesAsKeys:!1,expandNestedObjects:!0,expandArrayObjects:!1,ignoreEmptyArraysWhenExpanding:!1,escapeNestedDots:!1,ignoreEmptyArrays:!1,...e??{}}}a(N,"mergeOptions"),u(N,"mergeOptions")})(l)),l}a(J,"requireDeeks");var L=J();const V=L.deepKeys,X=L.deepKeysFromList;export{V as deepKeys,X as deepKeysFromList,oe as deleteProperty,se as escapePath,ue as getProperty,ce as hasProperty,ne as isPlainObject,$ as omit,te as pick,ie as setProperty};
1
+ import{default as U}from"./packem_shared/omit-DUxizCOe.js";import{default as C}from"./packem_shared/pick-L4PJlDoB.js";import{default as H}from"./packem_shared/isPlainObject-DqcjswLg.js";import{deleteProperty as Q,escapePath as V,getProperty as X,hasProperty as Y,setProperty as Z}from"./packem_shared/deleteProperty-y5ClNSkn.js";var o={},c={},x;function L(){if(x)return c;x=1,Object.defineProperty(c,"__esModule",{value:!0}),c.isDocumentToRecurOn=c.flatten=c.unique=void 0;function y(u){return[...new Set(u)]}c.unique=y;function h(u){return[].concat(...u)}c.flatten=h;function m(u){return typeof u=="object"&&u!==null&&!Array.isArray(u)&&Object.keys(u).length}return c.isDocumentToRecurOn=m,c}var _={},q;function N(){return q||(q=1,Object.defineProperty(_,"__esModule",{value:!0})),_}var S;function T(){return S||(S=1,(function(y){var h=o&&o.__createBinding||(Object.create?(function(e,t,r,n){n===void 0&&(n=r);var s=Object.getOwnPropertyDescriptor(t,r);(!s||("get"in s?!t.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,s)}):(function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]})),m=o&&o.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),u=o&&o.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)r!=="default"&&Object.prototype.hasOwnProperty.call(e,r)&&h(t,e,r);return m(t,e),t},E=o&&o.__exportStar||function(e,t){for(var r in e)r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r)&&h(t,e,r)};Object.defineProperty(y,"__esModule",{value:!0}),y.deepKeysFromList=y.deepKeys=void 0;const b=u(L());E(N(),y);function M(e,t){const r=k(t);return typeof e=="object"&&e!==null?v("",e,r,new WeakSet):[]}y.deepKeys=M;function A(e,t,r){const n=k(t),s=r??new WeakSet;return e.map(i=>typeof i=="object"&&i!==null?s.has(i)?[]:v("",i,n,s):[])}y.deepKeysFromList=A;function v(e,t,r,n){const s=[],i=Object.keys(t);n.add(t);const f=[{obj:t,keys:i,i:0,basePath:e}];for(;f.length;){const p=f[f.length-1];if(p.i>=p.keys.length){f.pop();continue}const K=p.keys[p.i++],a=p.obj[K],g=O(p.basePath,P(K,r));if(r.expandNestedObjects&&b.isDocumentToRecurOn(a)||r.arrayIndexesAsKeys&&Array.isArray(a)&&a.length)if(r.arrayIndexesAsKeys&&Array.isArray(a)){const j=a;for(let d=j.length-1;d>=0;d--){const l=j[d],D=O(g,String(d));typeof l=="object"&&l!==null&&!Array.isArray(l)?n.has(l)||(n.add(l),f.push({obj:l,keys:Object.keys(l),i:0,basePath:D})):s.push(D)}}else n.has(a)||(n.add(a),f.push({obj:a,keys:Object.keys(a),i:0,basePath:g}));else if(r.expandArrayObjects&&Array.isArray(a)){const j=R(a,g,r,n);for(const d of j)s.push(d)}else{if(r.ignoreEmptyArrays&&Array.isArray(a)&&!a.length)continue;s.push(g)}}return b.unique(s)}function R(e,t,r,n){let s=A(e,r,n);return e.length?e.length&&b.flatten(s).length===0?[t]:(s=s.map(i=>Array.isArray(i)&&i.length===0?[t]:i.map(f=>O(t,P(f,r)))),b.unique(b.flatten(s))):r.ignoreEmptyArraysWhenExpanding?[]:[t]}function P(e,t){return t.escapeNestedDots?e.replace(/\./g,"\\."):e}function O(e,t){return e?e+"."+t:t}function k(e){return{arrayIndexesAsKeys:!1,expandNestedObjects:!0,expandArrayObjects:!1,ignoreEmptyArraysWhenExpanding:!1,escapeNestedDots:!1,ignoreEmptyArrays:!1,...e??{}}}})(o)),o}var w=T();const F=w.deepKeys,I=w.deepKeysFromList;export{F as deepKeys,I as deepKeysFromList,Q as deleteProperty,V as escapePath,X as getProperty,Y as hasProperty,H as isPlainObject,U as omit,C as pick,Z as setProperty};
@@ -0,0 +1 @@
1
+ const f=e=>{const r=typeof e;return e!==null&&(r==="object"||r==="function")},g=e=>{if(!f(e))return!1;for(const r in e)if(Object.hasOwn(e,r))return!1;return!0},y=new Set(["__proto__","prototype","constructor"]),d=1e6,w=e=>e>="0"&&e<="9";function u(e){if(e==="0")return!0;if(/^[1-9]\d*$/.test(e)){const r=Number.parseInt(e,10);return r<=Number.MAX_SAFE_INTEGER&&r<=d}return!1}function c(e,r){return y.has(e)?!1:(e&&u(e)?r.push(Number.parseInt(e,10)):r.push(e),!0)}function b(e){if(typeof e!="string")throw new TypeError(`Expected a string, got ${typeof e}`);const r=[];let n="",t="start",o=!1,i=0;for(const s of e){if(i++,o){n+=s,o=!1;continue}if(s==="\\"){if(t==="index")throw new Error(`Invalid character '${s}' in an index at position ${i}`);if(t==="indexEnd")throw new Error(`Invalid character '${s}' after an index at position ${i}`);o=!0,t=t==="start"?"property":t;continue}switch(s){case".":{if(t==="index")throw new Error(`Invalid character '${s}' in an index at position ${i}`);if(t==="indexEnd"){t="property";break}if(!c(n,r))return[];n="",t="property";break}case"[":{if(t==="index")throw new Error(`Invalid character '${s}' in an index at position ${i}`);if(t==="indexEnd"){t="index";break}if(t==="property"||t==="start"){if((n||t==="property")&&!c(n,r))return[];n=""}t="index";break}case"]":{if(t==="index"){if(n==="")n=(r.pop()||"")+"[]",t="property";else{const a=Number.parseInt(n,10);!Number.isNaN(a)&&Number.isFinite(a)&&a>=0&&a<=Number.MAX_SAFE_INTEGER&&a<=d&&n===String(a)?r.push(a):r.push(n),n="",t="indexEnd"}break}if(t==="indexEnd")throw new Error(`Invalid character '${s}' after an index at position ${i}`);n+=s;break}default:{if(t==="index"&&!w(s))throw new Error(`Invalid character '${s}' in an index at position ${i}`);if(t==="indexEnd")throw new Error(`Invalid character '${s}' after an index at position ${i}`);t==="start"&&(t="property"),n+=s}}}switch(o&&(n+="\\"),t){case"property":{if(!c(n,r))return[];break}case"index":throw new Error("Index was not closed");case"start":{r.push("");break}}return r}function p(e){if(typeof e=="string")return b(e);if(Array.isArray(e)){const r=[];for(const[n,t]of e.entries()){if(typeof t!="string"&&typeof t!="number")throw new TypeError(`Expected a string or number for path segment at index ${n}, got ${typeof t}`);if(typeof t=="number"&&!Number.isFinite(t))throw new TypeError(`Path segment at index ${n} must be a finite number, got ${t}`);if(y.has(t))return[];typeof t=="string"&&u(t)?r.push(Number.parseInt(t,10)):r.push(t)}return r}return[]}function m(e,r,n){if(!f(e)||typeof r!="string"&&!Array.isArray(r))return n===void 0?e:n;const t=p(r);if(t.length===0)return n;for(let o=0;o<t.length;o++){const i=t[o];if(e=e[i],e==null){if(o!==t.length-1)return n;break}}return e===void 0?n:e}function x(e,r,n){if(!f(e)||typeof r!="string"&&!Array.isArray(r))return e;const t=e,o=p(r);if(o.length===0)return e;for(let i=0;i<o.length;i++){const s=o[i];if(i===o.length-1)e[s]=n;else if(!f(e[s])){const a=typeof o[i+1]=="number";e[s]=a?[]:{}}e=e[s]}return t}function A(e,r){if(!f(e)||typeof r!="string"&&!Array.isArray(r))return!1;const n=p(r);if(n.length===0)return!1;for(let t=0;t<n.length;t++){const o=n[t];if(t===n.length-1)return Object.hasOwn(e,o)?(delete e[o],!0):!1;if(e=e[o],!f(e))return!1}}function I(e,r){if(!f(e)||typeof r!="string"&&!Array.isArray(r))return!1;const n=p(r);if(n.length===0)return!1;for(const t of n){if(!f(e)||!(t in e))return!1;e=e[t]}return!0}function h(e){if(typeof e!="string")throw new TypeError(`Expected a string, got ${typeof e}`);return e.replaceAll(/[\\.[]/g,String.raw`\$&`)}function E(e){const r=Object.entries(e);return Array.isArray(e)?r.map(([n,t])=>[u(n)?Number.parseInt(n,10):n,t]):r}function $(e,r={}){if(!Array.isArray(e))throw new TypeError(`Expected an array, got ${typeof e}`);const{preferDotForIndices:n=!1}=r,t=[];for(const[o,i]of e.entries()){if(typeof i!="string"&&typeof i!="number")throw new TypeError(`Expected a string or number for path segment at index ${o}, got ${typeof i}`);if(typeof i=="number")if(!Number.isInteger(i)||i<0){const s=h(String(i));t.push(o===0?s:`.${s}`)}else n&&o>0?t.push(`.${i}`):t.push(`[${i}]`);else if(typeof i=="string")if(i==="")o===0||t.push(".");else if(u(i)){const s=Number.parseInt(i,10);n&&o>0?t.push(`.${s}`):t.push(`[${s}]`)}else{const s=h(i);t.push(o===0?s:`.${s}`)}}return t.join("")}function*l(e,r=[],n=new Set){if(!f(e)||g(e)){r.length>0&&(yield $(r));return}if(!n.has(e)){n.add(e);for(const[t,o]of E(e))r.push(t),yield*l(o,r,n),r.pop();n.delete(e)}}function N(e){return[...l(e)]}function k(e){const r={};if(!f(e))return r;for(const[n,t]of Object.entries(e))x(r,n,t);return r}export{N as deepKeys,A as deleteProperty,h as escapePath,m as getProperty,I as hasProperty,b as parsePath,x as setProperty,$ as stringifyPath,k as unflatten};
@@ -0,0 +1 @@
1
+ const o=t=>{if(typeof t!="object"||t===null)return!1;const e=Object.getPrototypeOf(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Symbol.toStringTag in t)&&!(Symbol.iterator in t)};export{o as default};
@@ -0,0 +1 @@
1
+ import a from"./isPlainObject-DqcjswLg.js";import{o as m,t as u,i as y}from"./safe-assign-Dy7OR5kT.js";const b=(t,o)=>{for(const r of Object.getOwnPropertySymbols(t))Object.getOwnPropertyDescriptor(t,r)?.enumerable&&(o[r]=t[r])},i=(t,o,r)=>{if(Array.isArray(t)){const s=[];for(const[f,c]of t.entries()){const n=[...r,String(f)];o.some(p=>m(n,p))||s.push(i(c,o,n))}return s}if(!a(t))return t;const e={};for(const[s,f]of Object.entries(t)){const c=[...r,s];o.some(n=>m(c,n))||u(e,s,i(f,o,c))}return b(t,e),e},O=(t,o)=>i(t,o,[]),l=(t,o)=>{const r=o.map(e=>y(e));return O(t,r)};export{l as default};
@@ -0,0 +1 @@
1
+ import m from"./isPlainObject-DqcjswLg.js";import{t as u,o as a,i as h}from"./safe-assign-Dy7OR5kT.js";const l=(o,t)=>t.some(e=>{const r=Math.min(o.length,e.length);return a(o.slice(0,r),e.slice(0,r))}),c=(o,t,e)=>{if(Array.isArray(o)){const n=[];for(const[i,s]of o.entries()){const f=[...e,String(i)];t.length>0&&!l(f,t)||n.push(c(s,t,f))}return n}if(!m(o))return o;const r={};for(const[n,i]of Object.entries(o)){const s=[...e,n];t.length>0&&!l(s,t)||u(r,n,c(i,t,s))}return r},g=(o,t)=>c(o,t,[]),A=(o,t)=>{if(t.length===0)return{};const e=t.map(r=>h(r));return g(o,e)};export{A as default};
@@ -0,0 +1 @@
1
+ const u=r=>{const t=[];let e="",n=!1;for(const o of r){if(n){e+=o==="."||o==="\\"?o:`\\${o}`,n=!1;continue}if(o==="\\"){n=!0;continue}if(o==="."){t.push(e),e="";continue}e+=o}return n&&(e+="\\"),t.push(e),t},f=(r,t)=>{if(r.length!==t.length)return!1;for(const[e,n]of t.entries())if(n!=="*"&&n!==r[e])return!1;return!0},i=(r,t,e)=>{if(t==="__proto__"){Object.defineProperty(r,t,{configurable:!0,enumerable:!0,value:e,writable:!0});return}r[t]=e};export{u as i,f as o,i as t};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/object",
3
- "version": "3.0.0-alpha.14",
3
+ "version": "3.0.0-alpha.16",
4
4
  "description": "Helper functions for working with objects and arrays.",
5
5
  "keywords": [
6
6
  "access",
@@ -57,6 +57,9 @@
57
57
  "README.md",
58
58
  "CHANGELOG.md"
59
59
  ],
60
+ "dependencies": {
61
+ "type-fest": "5.7.0"
62
+ },
60
63
  "engines": {
61
64
  "node": "^22.14.0 || >=24.10.0"
62
65
  },
@@ -1 +0,0 @@
1
- var $=Object.defineProperty;var f=(e,r)=>$(e,"name",{value:r,configurable:!0});var A=Object.defineProperty,a=f((e,r)=>A(e,"name",{value:r,configurable:!0}),"f");const p=a(e=>{const r=typeof e;return e!==null&&(r==="object"||r==="function")},"isObject"),I=a(e=>{if(!p(e))return!1;for(const r in e)if(Object.hasOwn(e,r))return!1;return!0},"isEmptyObject"),g=new Set(["__proto__","prototype","constructor"]),b=1e6,N=a(e=>e>="0"&&e<="9","isDigit");function c(e){if(e==="0")return!0;if(/^[1-9]\d*$/.test(e)){const r=Number.parseInt(e,10);return r<=Number.MAX_SAFE_INTEGER&&r<=b}return!1}f(c,"p");a(c,"shouldCoerceToNumber");function h(e,r){return g.has(e)?!1:(e&&c(e)?r.push(Number.parseInt(e,10)):r.push(e),!0)}f(h,"y");a(h,"processSegment");function w(e){if(typeof e!="string")throw new TypeError(`Expected a string, got ${typeof e}`);const r=[];let n="",t="start",o=!1,i=0;for(const s of e){if(i++,o){n+=s,o=!1;continue}if(s==="\\"){if(t==="index")throw new Error(`Invalid character '${s}' in an index at position ${i}`);if(t==="indexEnd")throw new Error(`Invalid character '${s}' after an index at position ${i}`);o=!0,t=t==="start"?"property":t;continue}switch(s){case".":{if(t==="index")throw new Error(`Invalid character '${s}' in an index at position ${i}`);if(t==="indexEnd"){t="property";break}if(!h(n,r))return[];n="",t="property";break}case"[":{if(t==="index")throw new Error(`Invalid character '${s}' in an index at position ${i}`);if(t==="indexEnd"){t="index";break}if(t==="property"||t==="start"){if((n||t==="property")&&!h(n,r))return[];n=""}t="index";break}case"]":{if(t==="index"){if(n==="")n=(r.pop()||"")+"[]",t="property";else{const u=Number.parseInt(n,10);!Number.isNaN(u)&&Number.isFinite(u)&&u>=0&&u<=Number.MAX_SAFE_INTEGER&&u<=b&&n===String(u)?r.push(u):r.push(n),n="",t="indexEnd"}break}if(t==="indexEnd")throw new Error(`Invalid character '${s}' after an index at position ${i}`);n+=s;break}default:{if(t==="index"&&!N(s))throw new Error(`Invalid character '${s}' in an index at position ${i}`);if(t==="indexEnd")throw new Error(`Invalid character '${s}' after an index at position ${i}`);t==="start"&&(t="property"),n+=s}}}switch(o&&(n+="\\"),t){case"property":{if(!h(n,r))return[];break}case"index":throw new Error("Index was not closed");case"start":{r.push("");break}}return r}f(w,"parsePath");a(w,"parsePath");function y(e){if(typeof e=="string")return w(e);if(Array.isArray(e)){const r=[];for(const[n,t]of e.entries()){if(typeof t!="string"&&typeof t!="number")throw new TypeError(`Expected a string or number for path segment at index ${n}, got ${typeof t}`);if(typeof t=="number"&&!Number.isFinite(t))throw new TypeError(`Path segment at index ${n} must be a finite number, got ${t}`);if(g.has(t))return[];typeof t=="string"&&c(t)?r.push(Number.parseInt(t,10)):r.push(t)}return r}return[]}f(y,"d");a(y,"normalizePath");function P(e,r,n){if(!p(e)||typeof r!="string"&&!Array.isArray(r))return n===void 0?e:n;const t=y(r);if(t.length===0)return n;for(let o=0;o<t.length;o++){const i=t[o];if(e=e[i],e==null){if(o!==t.length-1)return n;break}}return e===void 0?n:e}f(P,"getProperty");a(P,"getProperty");function E(e,r,n){if(!p(e)||typeof r!="string"&&!Array.isArray(r))return e;const t=e,o=y(r);if(o.length===0)return e;for(let i=0;i<o.length;i++){const s=o[i];if(i===o.length-1)e[s]=n;else if(!p(e[s])){const u=typeof o[i+1]=="number";e[s]=u?[]:{}}e=e[s]}return t}f(E,"setProperty");a(E,"setProperty");function v(e,r){if(!p(e)||typeof r!="string"&&!Array.isArray(r))return!1;const n=y(r);if(n.length===0)return!1;for(let t=0;t<n.length;t++){const o=n[t];if(t===n.length-1)return Object.hasOwn(e,o)?(delete e[o],!0):!1;if(e=e[o],!p(e))return!1}}f(v,"deleteProperty");a(v,"deleteProperty");function j(e,r){if(!p(e)||typeof r!="string"&&!Array.isArray(r))return!1;const n=y(r);if(n.length===0)return!1;for(const t of n){if(!p(e)||!(t in e))return!1;e=e[t]}return!0}f(j,"hasProperty");a(j,"hasProperty");function l(e){if(typeof e!="string")throw new TypeError(`Expected a string, got ${typeof e}`);return e.replaceAll(/[\\.[]/g,String.raw`\$&`)}f(l,"escapePath");a(l,"escapePath");function m(e){const r=Object.entries(e);return Array.isArray(e)?r.map(([n,t])=>[c(n)?Number.parseInt(n,10):n,t]):r}f(m,"m");a(m,"normalizeEntries");function x(e,r={}){if(!Array.isArray(e))throw new TypeError(`Expected an array, got ${typeof e}`);const{preferDotForIndices:n=!1}=r,t=[];for(const[o,i]of e.entries()){if(typeof i!="string"&&typeof i!="number")throw new TypeError(`Expected a string or number for path segment at index ${o}, got ${typeof i}`);if(typeof i=="number")if(!Number.isInteger(i)||i<0){const s=l(String(i));t.push(o===0?s:`.${s}`)}else n&&o>0?t.push(`.${i}`):t.push(`[${i}]`);else if(typeof i=="string")if(i==="")o===0||t.push(".");else if(c(i)){const s=Number.parseInt(i,10);n&&o>0?t.push(`.${s}`):t.push(`[${s}]`)}else{const s=l(i);t.push(o===0?s:`.${s}`)}}return t.join("")}f(x,"stringifyPath");a(x,"stringifyPath");function*d(e,r=[],n=new Set){if(!p(e)||I(e)){r.length>0&&(yield x(r));return}if(!n.has(e)){n.add(e);for(const[t,o]of m(e))r.push(t),yield*d(o,r,n),r.pop();n.delete(e)}}f(d,"x");a(d,"deepKeysIterator");function k(e){return[...d(e)]}f(k,"deepKeys");a(k,"deepKeys");function O(e){const r={};if(!p(e))return r;for(const[n,t]of Object.entries(e))E(r,n,t);return r}f(O,"unflatten");a(O,"unflatten");export{k as deepKeys,v as deleteProperty,l as escapePath,P as getProperty,j as hasProperty,w as parsePath,E as setProperty,x as stringifyPath,O as unflatten};
@@ -1 +0,0 @@
1
- var r=Object.defineProperty;var o=(e,t)=>r(e,"name",{value:t,configurable:!0});var n=Object.defineProperty,l=o((e,t)=>n(e,"name",{value:t,configurable:!0}),"n");const b=l(e=>{if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)},"isPlainObject");export{b as default};
@@ -1 +0,0 @@
1
- var f=Object.defineProperty;var i=(r,e)=>f(r,"name",{value:e,configurable:!0});import u from"./isPlainObject-CKRRjQp3.js";import{c as v}from"./paths-are-equal-BYur8Hqc.js";var b=Object.defineProperty,p=i((r,e)=>b(r,"name",{value:e,configurable:!0}),"u");const m=p((r,e,l="")=>u(r)?Object.entries(r).reduce((a,[o,n])=>{let t=l;return t&&(t+="."),t+=o,e.some(s=>v(t,s))?a:u(n)?(a[o]=m(r[o],e,t),a):(a[o]=n,a)},{}):r,"recursiveOmit");var y=Object.defineProperty,c=i((r,e)=>y(r,"name",{value:e,configurable:!0}),"r");const d=c(r=>Array.isArray(r)&&r.length>0,"isFullArray"),A=c((r,e)=>d(e)?m(r,e):r,"omit");export{A as default};
@@ -1 +0,0 @@
1
- var s=Object.defineProperty;var n=(r,e)=>s(r,"name",{value:e,configurable:!0});var p=Object.defineProperty,l=n((r,e)=>p(r,"name",{value:e,configurable:!0}),"n");const d=l((r,e)=>{const o=e.split(".");return r.split(".").reduce((t,u,a)=>{const c=o[a]==="*"?"*":u;return t.push(c),t},[]).join(".")===e},"pathsAreEqual");export{d as c};
@@ -1 +0,0 @@
1
- var d=Object.defineProperty;var a=(e,r)=>d(e,"name",{value:r,configurable:!0});import u from"./isPlainObject-CKRRjQp3.js";import{c as h}from"./paths-are-equal-BYur8Hqc.js";var j=Object.defineProperty,y=a((e,r)=>j(e,"name",{value:r,configurable:!0}),"a$1");const f=y((e,r,s="")=>u(e)?Object.entries(e).reduce((l,[i,c])=>{let t=s;if(t&&(t+="."),t+=i,r.length>0){let n=!1;if(r.forEach(o=>{const v=t.split(".").length,g=o.split(".").length,m=o.split(".").slice(0,v).join("."),b=t.split(".").slice(0,g).join(".");h(b,m)&&(n=!0)}),!n)return l}return u(c)?(l[i]=f(e[i],r,t),l):(l[i]=c,l)},{}):e,"recursivePick");var P=Object.defineProperty,p=a((e,r)=>P(e,"name",{value:r,configurable:!0}),"t");const A=p(e=>Array.isArray(e)&&e.length>0,"isFullArray"),E=p((e,r)=>A(r)?f(e,r):{},"pick");export{E as default};