@visulima/object 1.0.12 → 2.0.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/CHANGELOG.md +22 -0
- package/LICENSE.md +1 -130
- package/dist/index.d.ts +216 -7
- package/dist/index.js +1 -0
- package/dist/packem_shared/getProperty-DPNB_aKG.js +1 -0
- package/dist/packem_shared/isPlainObject-CLTs8VdF.js +1 -0
- package/dist/packem_shared/omit-BfV-sPAM.js +1 -0
- package/dist/packem_shared/paths-are-equal-BYur8Hqc.js +1 -0
- package/dist/packem_shared/pick-CT4qE7de.js +1 -0
- package/package.json +7 -21
- package/dist/index.cjs +0 -187
- package/dist/index.d.cts +0 -7
- package/dist/index.d.mts +0 -7
- package/dist/index.mjs +0 -176
- package/dist/omit.d.cts +0 -20
- package/dist/omit.d.mts +0 -20
- package/dist/omit.d.ts +0 -20
- package/dist/packem_shared/getProperty-W4y1P_8H.cjs +0 -278
- package/dist/packem_shared/getProperty-uiEqCe4m.mjs +0 -269
- package/dist/packem_shared/isPlainObject-BEp1xndO.mjs +0 -12
- package/dist/packem_shared/isPlainObject-D2hOGcuW.cjs +0 -14
- package/dist/packem_shared/omit-Bz46-jv-.mjs +0 -38
- package/dist/packem_shared/omit-DSwyUtN2.cjs +0 -40
- package/dist/packem_shared/paths-are-equal-BvHTDEDJ.cjs +0 -15
- package/dist/packem_shared/paths-are-equal-DY1QWTwZ.mjs +0 -13
- package/dist/packem_shared/pick-BX11mP2m.cjs +0 -52
- package/dist/packem_shared/pick-C9-E3eDJ.mjs +0 -50
- package/dist/pick.d.cts +0 -20
- package/dist/pick.d.mts +0 -20
- package/dist/pick.d.ts +0 -20
- package/dist/utils/paths-are-equal.d.cts +0 -9
- package/dist/utils/paths-are-equal.d.mts +0 -9
- package/dist/utils/paths-are-equal.d.ts +0 -9
- package/dist/utils/recursive-omit.d.cts +0 -3
- package/dist/utils/recursive-omit.d.mts +0 -3
- package/dist/utils/recursive-omit.d.ts +0 -3
- package/dist/utils/recursive-pick.d.cts +0 -3
- package/dist/utils/recursive-pick.d.mts +0 -3
- package/dist/utils/recursive-pick.d.ts +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## @visulima/object [2.0.0](https://github.com/visulima/visulima/compare/@visulima/object@1.0.12...@visulima/object@2.0.0) (2025-10-15)
|
|
2
|
+
|
|
3
|
+
### ⚠ BREAKING CHANGES
|
|
4
|
+
|
|
5
|
+
* Adjusted the node engine requirement to support versions 20.19 and above.
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* Adjusted the node engine requirement to support versions 20.19 and above ([6773ae4](https://github.com/visulima/visulima/commit/6773ae42e12453389298dea329016a8b30e8cfe8))
|
|
10
|
+
* update @visulima/packem to 2.0.0-alpha.30 across multiple packages for improved compatibility ([27b346e](https://github.com/visulima/visulima/commit/27b346eaa1c0fb0e420d9a9824482028307f4249))
|
|
11
|
+
|
|
12
|
+
### Miscellaneous Chores
|
|
13
|
+
|
|
14
|
+
* add type-fest dependency to package.json ([45aee19](https://github.com/visulima/visulima/commit/45aee196a7991a22631ba258f65551c9d9dcdef7))
|
|
15
|
+
* **deps:** update build scripts and remove cross-env dependency ([7510e82](https://github.com/visulima/visulima/commit/7510e826b9235a0013fe61c82a7eb333bc4cbb78))
|
|
16
|
+
* update @visulima/packem dependency to version 2.0.0-alpha.29 ([f768d6d](https://github.com/visulima/visulima/commit/f768d6d26ebd825fd8685b6845bd33969d2f9dce))
|
|
17
|
+
* update dependencies and fix linting issues ([0e802fe](https://github.com/visulima/visulima/commit/0e802fe02bb9ed791659cb5f3c77605ae5b42ec8))
|
|
18
|
+
* update ESLint and Prettier configurations for improved consistency and performance ([1584130](https://github.com/visulima/visulima/commit/1584130ff5184a6b86ceb79e4bca51c9bf67dfeb))
|
|
19
|
+
* update LICENSE.md and packem configuration ([79a0378](https://github.com/visulima/visulima/commit/79a0378af00d06b136111d7b2079238639fdeba1))
|
|
20
|
+
* update package dependencies across multiple packages for improved compatibility and performance ([9567591](https://github.com/visulima/visulima/commit/9567591c415da3002f3a4fe08f8caf7ce01ca5f7))
|
|
21
|
+
* update package.json and pnpm-lock.yaml to include publint@0.3.12 and adjust build/test commands to exclude shared-utils ([1f7b3c0](https://github.com/visulima/visulima/commit/1f7b3c0381d77edfeec80ea1bf57b3469e929414))
|
|
22
|
+
|
|
1
23
|
## @visulima/object [1.0.12](https://github.com/visulima/visulima/compare/@visulima/object@1.0.11...@visulima/object@1.0.12) (2025-09-10)
|
|
2
24
|
|
|
3
25
|
### Bug Fixes
|
package/LICENSE.md
CHANGED
|
@@ -72,7 +72,7 @@ Repository: sindresorhus/is-plain-obj
|
|
|
72
72
|
|
|
73
73
|
# Licenses of bundled types
|
|
74
74
|
The published @visulima/object artifact additionally contains code with the following licenses:
|
|
75
|
-
MIT
|
|
75
|
+
MIT
|
|
76
76
|
|
|
77
77
|
# Bundled types:
|
|
78
78
|
## deeks
|
|
@@ -114,133 +114,4 @@ Repository: sindresorhus/is-plain-obj
|
|
|
114
114
|
>
|
|
115
115
|
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
116
116
|
|
|
117
|
-
---------------------------------------
|
|
118
|
-
|
|
119
|
-
## type-fest
|
|
120
|
-
License: (MIT OR CC0-1.0)
|
|
121
|
-
By: Sindre Sorhus
|
|
122
|
-
Repository: sindresorhus/type-fest
|
|
123
|
-
|
|
124
|
-
> Creative Commons Legal Code
|
|
125
|
-
>
|
|
126
|
-
> CC0 1.0 Universal
|
|
127
|
-
>
|
|
128
|
-
> CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
129
|
-
> LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
130
|
-
> ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
131
|
-
> INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
132
|
-
> REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
133
|
-
> PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
134
|
-
> THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
135
|
-
> HEREUNDER.
|
|
136
|
-
>
|
|
137
|
-
> Statement of Purpose
|
|
138
|
-
>
|
|
139
|
-
> The laws of most jurisdictions throughout the world automatically confer
|
|
140
|
-
> exclusive Copyright and Related Rights (defined below) upon the creator
|
|
141
|
-
> and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
142
|
-
> authorship and/or a database (each, a "Work").
|
|
143
|
-
>
|
|
144
|
-
> Certain owners wish to permanently relinquish those rights to a Work for
|
|
145
|
-
> the purpose of contributing to a commons of creative, cultural and
|
|
146
|
-
> scientific works ("Commons") that the public can reliably and without fear
|
|
147
|
-
> of later claims of infringement build upon, modify, incorporate in other
|
|
148
|
-
> works, reuse and redistribute as freely as possible in any form whatsoever
|
|
149
|
-
> and for any purposes, including without limitation commercial purposes.
|
|
150
|
-
> These owners may contribute to the Commons to promote the ideal of a free
|
|
151
|
-
> culture and the further production of creative, cultural and scientific
|
|
152
|
-
> works, or to gain reputation or greater distribution for their Work in
|
|
153
|
-
> part through the use and efforts of others.
|
|
154
|
-
>
|
|
155
|
-
> For these and/or other purposes and motivations, and without any
|
|
156
|
-
> expectation of additional consideration or compensation, the person
|
|
157
|
-
> associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
158
|
-
> is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
159
|
-
> elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
160
|
-
> terms, with knowledge of his or her Copyright and Related Rights in the
|
|
161
|
-
> Work and the meaning and intended legal effect of CC0 on those rights.
|
|
162
|
-
>
|
|
163
|
-
> 1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
164
|
-
> protected by copyright and related or neighboring rights ("Copyright and
|
|
165
|
-
> Related Rights"). Copyright and Related Rights include, but are not
|
|
166
|
-
> limited to, the following:
|
|
167
|
-
>
|
|
168
|
-
> i. the right to reproduce, adapt, distribute, perform, display,
|
|
169
|
-
> communicate, and translate a Work;
|
|
170
|
-
> ii. moral rights retained by the original author(s) and/or performer(s);
|
|
171
|
-
> iii. publicity and privacy rights pertaining to a person's image or
|
|
172
|
-
> likeness depicted in a Work;
|
|
173
|
-
> iv. rights protecting against unfair competition in regards to a Work,
|
|
174
|
-
> subject to the limitations in paragraph 4(a), below;
|
|
175
|
-
> v. rights protecting the extraction, dissemination, use and reuse of data
|
|
176
|
-
> in a Work;
|
|
177
|
-
> vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
178
|
-
> European Parliament and of the Council of 11 March 1996 on the legal
|
|
179
|
-
> protection of databases, and under any national implementation
|
|
180
|
-
> thereof, including any amended or successor version of such
|
|
181
|
-
> directive); and
|
|
182
|
-
> vii. other similar, equivalent or corresponding rights throughout the
|
|
183
|
-
> world based on applicable law or treaty, and any national
|
|
184
|
-
> implementations thereof.
|
|
185
|
-
>
|
|
186
|
-
> 2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
187
|
-
> of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
188
|
-
> irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
189
|
-
> Affirmer's Copyright and Related Rights and associated claims and causes
|
|
190
|
-
> of action, whether now known or unknown (including existing as well as
|
|
191
|
-
> future claims and causes of action), in the Work (i) in all territories
|
|
192
|
-
> worldwide, (ii) for the maximum duration provided by applicable law or
|
|
193
|
-
> treaty (including future time extensions), (iii) in any current or future
|
|
194
|
-
> medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
195
|
-
> including without limitation commercial, advertising or promotional
|
|
196
|
-
> purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
197
|
-
> member of the public at large and to the detriment of Affirmer's heirs and
|
|
198
|
-
> successors, fully intending that such Waiver shall not be subject to
|
|
199
|
-
> revocation, rescission, cancellation, termination, or any other legal or
|
|
200
|
-
> equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
201
|
-
> as contemplated by Affirmer's express Statement of Purpose.
|
|
202
|
-
>
|
|
203
|
-
> 3. Public License Fallback. Should any part of the Waiver for any reason
|
|
204
|
-
> be judged legally invalid or ineffective under applicable law, then the
|
|
205
|
-
> Waiver shall be preserved to the maximum extent permitted taking into
|
|
206
|
-
> account Affirmer's express Statement of Purpose. In addition, to the
|
|
207
|
-
> extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
208
|
-
> person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
209
|
-
> irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
210
|
-
> Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
211
|
-
> maximum duration provided by applicable law or treaty (including future
|
|
212
|
-
> time extensions), (iii) in any current or future medium and for any number
|
|
213
|
-
> of copies, and (iv) for any purpose whatsoever, including without
|
|
214
|
-
> limitation commercial, advertising or promotional purposes (the
|
|
215
|
-
> "License"). The License shall be deemed effective as of the date CC0 was
|
|
216
|
-
> applied by Affirmer to the Work. Should any part of the License for any
|
|
217
|
-
> reason be judged legally invalid or ineffective under applicable law, such
|
|
218
|
-
> partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
219
|
-
> of the License, and in such case Affirmer hereby affirms that he or she
|
|
220
|
-
> will not (i) exercise any of his or her remaining Copyright and Related
|
|
221
|
-
> Rights in the Work or (ii) assert any associated claims and causes of
|
|
222
|
-
> action with respect to the Work, in either case contrary to Affirmer's
|
|
223
|
-
> express Statement of Purpose.
|
|
224
|
-
>
|
|
225
|
-
> 4. Limitations and Disclaimers.
|
|
226
|
-
>
|
|
227
|
-
> a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
228
|
-
> surrendered, licensed or otherwise affected by this document.
|
|
229
|
-
> b. Affirmer offers the Work as-is and makes no representations or
|
|
230
|
-
> warranties of any kind concerning the Work, express, implied,
|
|
231
|
-
> statutory or otherwise, including without limitation warranties of
|
|
232
|
-
> title, merchantability, fitness for a particular purpose, non
|
|
233
|
-
> infringement, or the absence of latent or other defects, accuracy, or
|
|
234
|
-
> the present or absence of errors, whether or not discoverable, all to
|
|
235
|
-
> the greatest extent permissible under applicable law.
|
|
236
|
-
> c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
237
|
-
> that may apply to the Work or any use thereof, including without
|
|
238
|
-
> limitation any person's Copyright and Related Rights in the Work.
|
|
239
|
-
> Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
240
|
-
> consents, permissions or other rights required for any use of the
|
|
241
|
-
> Work.
|
|
242
|
-
> d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
243
|
-
> party to this document and has no duty or obligation with respect to
|
|
244
|
-
> this CC0 or use of the Work.
|
|
245
|
-
|
|
246
117
|
<!-- /TYPE_DEPENDENCIES -->
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,216 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { Paths, OmitDeep, PickDeep, Get } from 'type-fest';
|
|
2
|
+
export { OmitDeep, Paths, PickDeep, Split } from 'type-fest';
|
|
3
|
+
|
|
4
|
+
declare const omit: <T extends { [key in string]: unknown; }, K extends string>(object: T, keys: Paths<T>[]) => OmitDeep<T, K>;
|
|
5
|
+
|
|
6
|
+
declare const pick: <T extends { [key in string]: unknown; }, K extends Paths<T>>(object: T, keys: Paths<T>[]) => PickDeep<T, K>;
|
|
7
|
+
|
|
8
|
+
interface DeeksOptions {
|
|
9
|
+
/** @default false */
|
|
10
|
+
arrayIndexesAsKeys?: boolean;
|
|
11
|
+
/** @default true */
|
|
12
|
+
expandNestedObjects?: boolean;
|
|
13
|
+
/** @default false */
|
|
14
|
+
expandArrayObjects?: boolean;
|
|
15
|
+
/** @default false */
|
|
16
|
+
ignoreEmptyArraysWhenExpanding?: boolean;
|
|
17
|
+
/** @default false */
|
|
18
|
+
escapeNestedDots?: boolean;
|
|
19
|
+
/** @default false */
|
|
20
|
+
ignoreEmptyArrays?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Return the deep keys list for a single document
|
|
25
|
+
* @param object
|
|
26
|
+
* @param options
|
|
27
|
+
* @returns {Array}
|
|
28
|
+
*/
|
|
29
|
+
declare function deepKeys(object: object, options?: DeeksOptions): string[];
|
|
30
|
+
/**
|
|
31
|
+
* Return the deep keys list for all documents in the provided list
|
|
32
|
+
* @param list
|
|
33
|
+
* @param options
|
|
34
|
+
* @returns Array[Array[String]]
|
|
35
|
+
*/
|
|
36
|
+
declare function deepKeysFromList(list: object[], options?: DeeksOptions): string[][];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
Get the value of the property at the given path.
|
|
40
|
+
|
|
41
|
+
@param object - Object or array to get the `path` value.
|
|
42
|
+
@param path - Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key. Array indices can be accessed using bracket notation (`'users[0].name'`) or dot notation (`'users.0.name'`). Both syntaxes are equivalent and will create arrays when setting values. Numeric strings in dot notation (like `'users.0.name'`) are automatically coerced to numbers. When using array paths, numeric strings are normalized to numbers for simplicity (treating `['users', '0']` the same as `['users', 0]`).
|
|
43
|
+
@param defaultValue - Default value.
|
|
44
|
+
|
|
45
|
+
@example
|
|
46
|
+
```
|
|
47
|
+
import {getProperty} from 'dot-prop';
|
|
48
|
+
|
|
49
|
+
getProperty({foo: {bar: 'unicorn'}}, 'foo.bar');
|
|
50
|
+
//=> 'unicorn'
|
|
51
|
+
|
|
52
|
+
getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep');
|
|
53
|
+
//=> undefined
|
|
54
|
+
|
|
55
|
+
getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value');
|
|
56
|
+
//=> 'default value'
|
|
57
|
+
|
|
58
|
+
getProperty({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot');
|
|
59
|
+
//=> 'unicorn'
|
|
60
|
+
|
|
61
|
+
getProperty({foo: [{bar: 'unicorn'}]}, 'foo[0].bar');
|
|
62
|
+
//=> 'unicorn'
|
|
63
|
+
|
|
64
|
+
getProperty({foo: [{bar: 'unicorn'}]}, 'foo.0.bar');
|
|
65
|
+
//=> 'unicorn'
|
|
66
|
+
```
|
|
67
|
+
*/
|
|
68
|
+
declare function getProperty<ObjectType, PathType extends string, DefaultValue = undefined>(
|
|
69
|
+
object: ObjectType,
|
|
70
|
+
path: PathType | ReadonlyArray<string | number>,
|
|
71
|
+
defaultValue?: DefaultValue
|
|
72
|
+
): ObjectType extends Record<string, unknown> | unknown[]
|
|
73
|
+
? (unknown extends Get<ObjectType, PathType> ? DefaultValue : Get<ObjectType, PathType>)
|
|
74
|
+
: DefaultValue extends undefined ? unknown : DefaultValue;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
Set the property at the given path to the given value.
|
|
78
|
+
|
|
79
|
+
@param object - Object or array to set the `path` value.
|
|
80
|
+
@param path - Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key. Array indices can be accessed using bracket notation (`'users[0].name'`) or dot notation (`'users.0.name'`). Both syntaxes are equivalent and will create arrays when setting values. Numeric strings in dot notation (like `'users.0.name'`) are automatically coerced to numbers. When using array paths, numeric strings are normalized to numbers for simplicity (treating `['users', '0']` the same as `['users', 0]`).
|
|
81
|
+
@param value - Value to set at `path`.
|
|
82
|
+
@returns The object.
|
|
83
|
+
|
|
84
|
+
@example
|
|
85
|
+
```
|
|
86
|
+
import {setProperty} from 'dot-prop';
|
|
87
|
+
|
|
88
|
+
const object = {foo: {bar: 'a'}};
|
|
89
|
+
setProperty(object, 'foo.bar', 'b');
|
|
90
|
+
console.log(object);
|
|
91
|
+
//=> {foo: {bar: 'b'}}
|
|
92
|
+
|
|
93
|
+
const foo = setProperty({}, 'foo.bar', 'c');
|
|
94
|
+
console.log(foo);
|
|
95
|
+
//=> {foo: {bar: 'c'}}
|
|
96
|
+
|
|
97
|
+
setProperty(object, 'foo.baz', 'x');
|
|
98
|
+
console.log(object);
|
|
99
|
+
//=> {foo: {bar: 'b', baz: 'x'}}
|
|
100
|
+
|
|
101
|
+
setProperty(object, 'foo.biz[0]', 'a');
|
|
102
|
+
console.log(object);
|
|
103
|
+
//=> {foo: {bar: 'b', baz: 'x', biz: ['a']}}
|
|
104
|
+
|
|
105
|
+
setProperty(object, 'foo.items.0', 'first');
|
|
106
|
+
console.log(object);
|
|
107
|
+
//=> {foo: {bar: 'b', baz: 'x', biz: ['a'], items: ['first']}}
|
|
108
|
+
```
|
|
109
|
+
*/
|
|
110
|
+
declare function setProperty<ObjectType extends (Record<string, any> | unknown[])>(
|
|
111
|
+
object: ObjectType,
|
|
112
|
+
path: string | ReadonlyArray<string | number>,
|
|
113
|
+
value: unknown
|
|
114
|
+
): ObjectType;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
Check whether the property at the given path exists.
|
|
118
|
+
|
|
119
|
+
@param object - Object or array to test the `path` value.
|
|
120
|
+
@param path - Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key. Array indices can be accessed using bracket notation (`'users[0].name'`) or dot notation (`'users.0.name'`). Both syntaxes are equivalent and will create arrays when setting values. Numeric strings in dot notation (like `'users.0.name'`) are automatically coerced to numbers. When using array paths, numeric strings are normalized to numbers for simplicity (treating `['users', '0']` the same as `['users', 0]`).
|
|
121
|
+
|
|
122
|
+
@example
|
|
123
|
+
```
|
|
124
|
+
import {hasProperty} from 'dot-prop';
|
|
125
|
+
|
|
126
|
+
hasProperty({foo: {bar: 'unicorn'}}, 'foo.bar');
|
|
127
|
+
//=> true
|
|
128
|
+
```
|
|
129
|
+
*/
|
|
130
|
+
declare function hasProperty(object: Record<string, any> | unknown[] | undefined, path: string | ReadonlyArray<string | number>): boolean;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
Delete the property at the given path.
|
|
134
|
+
|
|
135
|
+
@param object - Object or array to delete the `path` value.
|
|
136
|
+
@param path - Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key. Array indices can be accessed using bracket notation (`'users[0].name'`) or dot notation (`'users.0.name'`). Both syntaxes are equivalent and will create arrays when setting values. Numeric strings in dot notation (like `'users.0.name'`) are automatically coerced to numbers. When using array paths, numeric strings are normalized to numbers for simplicity (treating `['users', '0']` the same as `['users', 0]`).
|
|
137
|
+
@returns A boolean of whether the property existed before being deleted.
|
|
138
|
+
|
|
139
|
+
@example
|
|
140
|
+
```
|
|
141
|
+
import {deleteProperty} from 'dot-prop';
|
|
142
|
+
|
|
143
|
+
const object = {foo: {bar: 'a'}};
|
|
144
|
+
deleteProperty(object, 'foo.bar');
|
|
145
|
+
console.log(object);
|
|
146
|
+
//=> {foo: {}}
|
|
147
|
+
|
|
148
|
+
object.foo.bar = {x: 'y', y: 'x'};
|
|
149
|
+
deleteProperty(object, 'foo.bar.x');
|
|
150
|
+
console.log(object);
|
|
151
|
+
//=> {foo: {bar: {y: 'x'}}}
|
|
152
|
+
```
|
|
153
|
+
*/
|
|
154
|
+
declare function deleteProperty(object: Record<string, any> | unknown[], path: string | ReadonlyArray<string | number>): boolean;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
Escape special characters in a path. Useful for sanitizing user input.
|
|
158
|
+
|
|
159
|
+
@param path - The dot path to sanitize.
|
|
160
|
+
|
|
161
|
+
@example
|
|
162
|
+
```
|
|
163
|
+
import {getProperty, escapePath} from 'dot-prop';
|
|
164
|
+
|
|
165
|
+
const object = {
|
|
166
|
+
foo: {
|
|
167
|
+
bar: '👸🏻 You found me Mario!',
|
|
168
|
+
},
|
|
169
|
+
'foo.bar' : '🍄 The princess is in another castle!',
|
|
170
|
+
};
|
|
171
|
+
const escapedPath = escapePath('foo.bar');
|
|
172
|
+
|
|
173
|
+
console.log(getProperty(object, escapedPath));
|
|
174
|
+
//=> '🍄 The princess is in another castle!'
|
|
175
|
+
```
|
|
176
|
+
*/
|
|
177
|
+
declare function escapePath(path: string): string;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
Check if a value is a plain object.
|
|
181
|
+
|
|
182
|
+
An object is plain if it's created by either `{}`, `new Object()`, or `Object.create(null)`.
|
|
183
|
+
|
|
184
|
+
@example
|
|
185
|
+
```
|
|
186
|
+
import isPlainObject from 'is-plain-obj';
|
|
187
|
+
import {runInNewContext} from 'node:vm';
|
|
188
|
+
|
|
189
|
+
isPlainObject({foo: 'bar'});
|
|
190
|
+
//=> true
|
|
191
|
+
|
|
192
|
+
isPlainObject(new Object());
|
|
193
|
+
//=> true
|
|
194
|
+
|
|
195
|
+
isPlainObject(Object.create(null));
|
|
196
|
+
//=> true
|
|
197
|
+
|
|
198
|
+
// This works across realms
|
|
199
|
+
isPlainObject(runInNewContext('({})'));
|
|
200
|
+
//=> true
|
|
201
|
+
|
|
202
|
+
isPlainObject([1, 2, 3]);
|
|
203
|
+
//=> false
|
|
204
|
+
|
|
205
|
+
class Unicorn {}
|
|
206
|
+
isPlainObject(new Unicorn());
|
|
207
|
+
//=> false
|
|
208
|
+
|
|
209
|
+
isPlainObject(Math);
|
|
210
|
+
//=> false
|
|
211
|
+
```
|
|
212
|
+
*/
|
|
213
|
+
declare function isPlainObject<Value>(value: unknown): value is Record<PropertyKey, Value>;
|
|
214
|
+
|
|
215
|
+
export { deepKeys, deepKeysFromList, deleteProperty, escapePath, getProperty, hasProperty, isPlainObject, omit, pick, setProperty };
|
|
216
|
+
export type { DeeksOptions as DeepKeysOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var L=Object.defineProperty;var u=(c,p)=>L(c,"name",{value:p,configurable:!0});import{default as w}from"./packem_shared/omit-BfV-sPAM.js";import{default as B}from"./packem_shared/pick-CT4qE7de.js";import{deleteProperty as W,escapePath as z,getProperty as C,hasProperty as G,setProperty as H}from"./packem_shared/getProperty-DPNB_aKG.js";import{default as Q}from"./packem_shared/isPlainObject-CLTs8VdF.js";var i={},f={},D;function N(){if(D)return f;D=1;var c=Object.defineProperty,p=u((o,b)=>c(o,"name",{value:b,configurable:!0}),"t");Object.defineProperty(f,"__esModule",{value:!0}),f.isDocumentToRecurOn=f.flatten=f.unique=void 0;function s(o){return[...new Set(o)]}u(s,"unique"),p(s,"unique"),f.unique=s;function l(o){return[].concat(...o)}u(l,"flatten"),p(l,"flatten"),f.flatten=l;function m(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)&&Object.keys(o).length}return u(m,"isDocumentToRecurOn"),p(m,"isDocumentToRecurOn"),f.isDocumentToRecurOn=m,f}u(N,"requireUtils");var K={},P;function R(){return P||(P=1,Object.defineProperty(K,"__esModule",{value:!0})),K}u(R,"requireTypes");var q;function k(){return q||(q=1,(function(c){var p=Object.defineProperty,s=u((t,e)=>p(t,"name",{value:e,configurable:!0}),"i"),l=i&&i.__createBinding||(Object.create?(function(t,e,r,a){a===void 0&&(a=r);var n=Object.getOwnPropertyDescriptor(e,r);(!n||("get"in n?!e.__esModule:n.writable||n.configurable))&&(n={enumerable:!0,get:s(function(){return e[r]},"get")}),Object.defineProperty(t,a,n)}):(function(t,e,r,a){a===void 0&&(a=r),t[a]=e[r]})),m=i&&i.__setModuleDefault||(Object.create?(function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}):function(t,e){t.default=e}),o=i&&i.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&l(e,t,r);return m(e,t),e},b=i&&i.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&l(e,t,r)};Object.defineProperty(c,"__esModule",{value:!0}),c.deepKeysFromList=c.deepKeys=void 0;const y=o(N());b(R(),c);function O(t,e){const r=A(e);return typeof t=="object"&&t!==null?v("",t,r):[]}u(O,"deepKeys"),s(O,"deepKeys"),c.deepKeys=O;function g(t,e){const r=A(e);return t.map(a=>typeof a=="object"&&a!==null?O(a,r):[])}u(g,"deepKeysFromList"),s(g,"deepKeysFromList"),c.deepKeysFromList=g;function v(t,e,r){const a=Object.keys(e).map(n=>{const d=j(t,_(n,r));return r.expandNestedObjects&&y.isDocumentToRecurOn(e[n])||r.arrayIndexesAsKeys&&Array.isArray(e[n])&&e[n].length?v(d,e[n],r):r.expandArrayObjects&&Array.isArray(e[n])?h(e[n],d,r):r.ignoreEmptyArrays&&Array.isArray(e[n])&&!e[n].length?[]:d});return y.flatten(a)}u(v,"generateDeepKeysList"),s(v,"generateDeepKeysList");function h(t,e,r){let a=g(t,r);return t.length?t.length&&y.flatten(a).length===0?[e]:(a=a.map(n=>Array.isArray(n)&&n.length===0?[e]:n.map(d=>j(e,_(d,r)))),y.unique(y.flatten(a))):r.ignoreEmptyArraysWhenExpanding?[]:[e]}u(h,"processArrayKeys"),s(h,"processArrayKeys");function _(t,e){return e.escapeNestedDots?t.replace(/\./g,"\\."):t}u(_,"escapeNestedDotsIfSpecified"),s(_,"escapeNestedDotsIfSpecified");function j(t,e){return t?t+"."+e:e}u(j,"buildKeyName"),s(j,"buildKeyName");function A(t){return{arrayIndexesAsKeys:!1,expandNestedObjects:!0,expandArrayObjects:!1,ignoreEmptyArraysWhenExpanding:!1,escapeNestedDots:!1,ignoreEmptyArrays:!1,...t??{}}}u(A,"mergeOptions"),s(A,"mergeOptions")})(i)),i}u(k,"requireDeeks");var x=k();const M=x.deepKeys,S=x.deepKeysFromList;export{M as deepKeys,S as deepKeysFromList,W as deleteProperty,z as escapePath,C as getProperty,G as hasProperty,Q as isPlainObject,w as omit,B as pick,H as setProperty};
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
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}),"e");function a(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)}o(a,"r");l(a,"isPlainObject");export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var v=Object.defineProperty;var i=(r,e)=>v(r,"name",{value:e,configurable:!0});import m from"./isPlainObject-CLTs8VdF.js";import{c as s}from"./paths-are-equal-BYur8Hqc.js";var b=Object.defineProperty,p=i((r,e)=>b(r,"name",{value:e,configurable:!0}),"m$1");const u=p((r,e,l="")=>m(r)?Object.entries(r).reduce((a,[o,n])=>{let t=l;return t&&(t+="."),t+=o,e.some(f=>s(t,f))?a:m(n)?(a[o]=u(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)?u(r,e):r,"omit");export{A as default};
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var b=Object.defineProperty;var a=(e,r)=>b(e,"name",{value:r,configurable:!0});import u from"./isPlainObject-CLTs8VdF.js";import{c as d}from"./paths-are-equal-BYur8Hqc.js";var j=Object.defineProperty,y=a((e,r)=>j(e,"name",{value:r,configurable:!0}),"h");const s=y((e,r,p="")=>u(e)?Object.entries(e).reduce((i,[l,c])=>{let t=p;if(t&&(t+="."),t+=l,r.length>0){let n=!1;if(r.forEach(o=>{const v=t.split(".").length,g=o.split(".").length,h=o.split(".").slice(0,v).join("."),m=t.split(".").slice(0,g).join(".");d(m,h)&&(n=!0)}),!n)return i}return u(c)?(i[l]=s(e[l],r,t),i):(i[l]=c,i)},{}):e,"recursivePick");var P=Object.defineProperty,f=a((e,r)=>P(e,"name",{value:r,configurable:!0}),"t");const A=f(e=>Array.isArray(e)&&e.length>0,"isFullArray"),E=f((e,r)=>A(r)?s(e,r):{},"pick");export{E as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/object",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Helper functions for working with objects and arrays.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"visulima",
|
|
@@ -49,35 +49,21 @@
|
|
|
49
49
|
"type": "module",
|
|
50
50
|
"exports": {
|
|
51
51
|
".": {
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
"default": "./dist/index.mjs"
|
|
55
|
-
},
|
|
56
|
-
"require": {
|
|
57
|
-
"types": "./dist/index.d.cts",
|
|
58
|
-
"default": "./dist/index.cjs"
|
|
59
|
-
}
|
|
52
|
+
"types": "./dist/index.d.ts",
|
|
53
|
+
"default": "./dist/index.js"
|
|
60
54
|
},
|
|
61
55
|
"./package.json": "./package.json"
|
|
62
56
|
},
|
|
63
|
-
"main": "dist/index.cjs",
|
|
64
|
-
"module": "dist/index.mjs",
|
|
65
|
-
"browser": "dist/index.mjs",
|
|
66
|
-
"types": "dist/index.d.ts",
|
|
67
|
-
"typesVersions": {
|
|
68
|
-
">=5.0": {
|
|
69
|
-
".": [
|
|
70
|
-
"./dist/index.d.ts"
|
|
71
|
-
]
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
57
|
"files": [
|
|
75
58
|
"dist",
|
|
76
59
|
"README.md",
|
|
77
60
|
"CHANGELOG.md"
|
|
78
61
|
],
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"type-fest": "^5.1.0"
|
|
64
|
+
},
|
|
79
65
|
"engines": {
|
|
80
|
-
"node": ">=
|
|
66
|
+
"node": ">=20.19 <=24.x"
|
|
81
67
|
},
|
|
82
68
|
"publishConfig": {
|
|
83
69
|
"access": "public",
|