flattify 1.0.2 → 2.0.1

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Fernando Machado Bernardino
3
+ Copyright (c) 2016-2026 Fernando Machado Bernardino
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,135 +1,347 @@
1
1
  # [Flattify](https://github.com/NandoMB/flattify)
2
2
 
3
- Convert JSON to "Flat JSON".
4
- <br>
5
- <br>
6
- ## Getting Started
7
- #### Installation
3
+ [![npm version](https://img.shields.io/npm/v/flattify.svg)](https://www.npmjs.com/package/flattify)
4
+ [![JSR](https://jsr.io/badges/@nandomb/flattify)](https://jsr.io/@nandomb/flattify)
5
+ [![JSR Score](https://jsr.io/badges/@nandomb/flattify/score)](https://jsr.io/@nandomb/flattify)
6
+ [![CI](https://github.com/NandoMB/flattify/actions/workflows/main.yml/badge.svg)](https://github.com/NandoMB/flattify/actions/workflows/main.yml)
7
+ [![npm downloads](https://img.shields.io/npm/dm/flattify.svg)](https://www.npmjs.com/package/flattify)
8
+ [![license](https://img.shields.io/npm/l/flattify.svg)](./LICENSE)
9
+ [![Socket Badge](https://badge.socket.dev/npm/package/flattify)](https://socket.dev/npm/package/flattify)
10
+
11
+ Turn nested objects into flat `path → value` pairs **and back, without losing anything on the way**, with every path and value **inferred by TypeScript**.
12
+
13
+ - **Your data comes back exactly as it went:** dates, class instances, `null`, empty objects, keys with dots in them, key order. [Nothing is dropped or changed](#data-integrity)
14
+ - **Safe on untrusted input:** no prototype pollution, no stack overflow on deep or circular objects, no huge arrays from hostile indices
15
+ - **Typed end to end:** hover the result to see every path; `get` and `set` autocomplete paths and check values
16
+ - **Three notations:** `a.b.0`, `a.b[0]` (as in HTML forms) and `/a/b/0` (JSON Pointer)
17
+ - **Checked, not claimed:** 100% test coverage, thousands of random round trips per run, and every [comparison](#why-flattify) with other libraries verified in CI
18
+ - Zero dependencies, ESM and CommonJS, on [npm](https://www.npmjs.com/package/flattify) and [JSR](https://jsr.io/@nandomb/flattify). Runs on Node.js, Bun, Deno, browsers and Cloudflare Workers
19
+
20
+ > Upgrading from Flattify 1.x? See [Migrating](#migrating).
21
+
22
+ ## Contents
23
+
24
+ - [Installation](#installation)
25
+ - [Quick start](#quick-start)
26
+ - [Data integrity](#data-integrity)
27
+ - [Why Flattify?](#why-flattify)
28
+ - [Use cases](#use-cases)
29
+ - [API](#api): [`flatten`](#flatteninput-options), [`unflatten`](#unflatteninput-options), [notations](#notations), [`flattify/path`](#flattifypath)
30
+ - [Types](#types)
31
+ - [Limitations](#limitations)
32
+ - [Compatibility](#compatibility)
33
+ - [Migrating](#migrating)
34
+ - [Security](#security)
35
+
36
+ ## Installation
37
+
8
38
  ```sh
9
- $ npm install flattify --save
39
+ npm add flattify # or: pnpm add flattify / yarn add flattify
10
40
  ```
11
- <br>
12
- #### How to use...
13
- ```js
14
- var flattify = require('./flattify');
41
+ ###### Deno, Bun and Node.js from JSR
42
+ ```sh
43
+ deno add jsr:@nandomb/flattify
44
+ npx jsr add @nandomb/flattify # or: bunx jsr add @nandomb/flattify
15
45
  ```
16
- <br>
17
- <br>
18
- ##### flattify(json);
19
- Using with only the first parameter, only objects will be converted.
20
- Arrays will be transformed to string.
21
- <br />
22
- ```js
23
- var flattify = require('./flattify');
24
-
25
- var json = {
26
- "id": 1,
27
- "gender": "Male",
28
- "first": "Joshua",
29
- "last": "Williams",
30
- "emails": [
31
- "jwilliams1@vkontakte.ru",
32
- "phowell1@ezinearticles.com",
33
- "aferguson2@pen.io"
46
+
47
+ ## Quick start
48
+
49
+ ```ts
50
+ import { flatten, unflatten } from 'flattify';
51
+ // CommonJS: const { flatten, unflatten } = require('flattify');
52
+
53
+ const order = {
54
+ id: 1042,
55
+ customer: { name: 'Ada Lovelace' },
56
+ items: [
57
+ { sku: 'BOOK-1', qty: 2 },
58
+ { sku: 'PEN-7', qty: 1 },
34
59
  ],
35
- "addresses": [
36
- {
37
- "street": "Anzinger Court",
38
- "number": 73902
39
- },
40
- {
41
- "street": "Anthes Parkway",
42
- "number": 106
43
- }
44
- ]
60
+ shipping: { method: null },
61
+ 'utm.source': 'newsletter',
45
62
  };
46
63
 
47
- var flattenJson = flattify(json);
48
- console.log(flattenJson);
64
+ const flat = flatten(order);
65
+ // {
66
+ // 'id': 1042,
67
+ // 'customer.name': 'Ada Lovelace',
68
+ // 'items.0.sku': 'BOOK-1',
69
+ // 'items.0.qty': 2,
70
+ // 'items.1.sku': 'PEN-7',
71
+ // 'items.1.qty': 1,
72
+ // 'shipping.method': null,
73
+ // 'utm\\.source': 'newsletter', // escaped, so the dot survives the way back
74
+ // }
75
+
76
+ const back = unflatten(flat); // equals `order` again
49
77
  ```
50
- <br>
51
- Result:
52
- ```js
53
- {
54
- "id": 1,
55
- "gender": "Male",
56
- "first": "Joshua",
57
- "last": "Williams",
58
- "emails": "[\"jwilliams1@vkontakte.ru\",\"phowell1@ezinearticles.com\",\"aferguson2@pen.io\"]",
59
- "addresses": "[{\"street\":\"Anzinger Court\",\"number\":73902},{\"street\":\"Anthes Parkway\",\"number\":106}]"
60
- }
78
+
79
+ Both results are typed, so the editor knows every path:
80
+
81
+ ```ts
82
+ flat['items.0.sku']; // string
83
+ flat['customer.phone']; // ❌ Property 'customer.phone' does not exist
84
+ back.items[0].sku; // string
61
85
  ```
62
- <br>
63
- <br>
64
- #### flattify(json, true);
65
- Using with the first and second parameter, all objects and arrays will be converted.
66
- <br />
67
- ```js
68
- var flattify = require('./flattify');
69
-
70
- var json = {
71
- "id": 1,
72
- "gender": "Male",
73
- "first": "Joshua",
74
- "last": "Williams",
75
- "emails": [
76
- "jwilliams1@vkontakte.ru",
77
- "phowell1@ezinearticles.com",
78
- "aferguson2@pen.io"
79
- ],
80
- "addresses": [
81
- {
82
- "street": "Anzinger Court",
83
- "number": 73902
84
- },
85
- {
86
- "street": "Anthes Parkway",
87
- "number": 106
88
- }
89
- ]
86
+
87
+ `flatten` and `unflatten` are a round trip, like serializing and deserializing, except that both sides stay JavaScript objects: only the shape changes. A lot of data already arrives flat, too: form fields, query strings, environment variables, CSV columns. `unflatten` turns it into the object your code wants, safely.
88
+
89
+ ## Data integrity
90
+
91
+ Most libraries lose something on the way: a `Date` becomes `{}`, `null` disappears, an empty list vanishes, `'utm.source'` is split in two. Flattify keeps all of it:
92
+
93
+ ```ts
94
+ const input = {
95
+ createdAt: new Date(),
96
+ price: new Money(1990), // a class instance
97
+ discount: null,
98
+ coupon: undefined,
99
+ items: [],
100
+ meta: {},
101
+ 'utm.source': 'newsletter',
102
+ sizes: ['S', , 'L'], // an array with a hole
90
103
  };
91
104
 
92
- var flattenJson = flattify(json, true);
93
- console.log(flattenJson);
105
+ const back = unflatten(flatten(input));
106
+
107
+ back.createdAt === input.createdAt; // true: the same Date, not {} or a copy
108
+ back.price instanceof Money; // true
109
+ back.discount; // null
110
+ 'coupon' in back; // true
111
+ back.items; // []
112
+ back['utm.source']; // 'newsletter', still one key
113
+ 1 in back.sizes; // false: the hole is still a hole
114
+ ```
115
+
116
+ - **Values are never converted:** only plain objects and arrays are walked. `Date`, `Map`, `Set`, `RegExp`, typed arrays, functions and class instances are kept as they are, by reference
117
+ - **Nothing is dropped:** `null`, `undefined`, empty objects and empty arrays are kept
118
+ - **Keys stay whole:** a key that contains the delimiter is escaped (`'utm\\.source'`); keys without it are never changed
119
+ - **Order is kept:** keys come out depth first, in the order of the input, and come back in the same order
120
+ - **Your input is never modified:** `unflatten` copies the objects it finds in its input before adding keys to them
121
+ - **No surprise arrays:** only indices such as `0` or `42` build arrays, up to [`arrayLimit`](#unflatteninput-options); `'01'` or `'1e3'` stay object keys
122
+ - **Circular data is reported** with its path, instead of freezing or crashing the process; **any depth** is handled, even 100,000 levels
123
+
124
+ Each guarantee is covered by the test suite, and the round trip is checked on thousands of random objects on every run ([fast-check](https://fast-check.dev)), for every notation.
125
+
126
+ ## Why Flattify?
127
+
128
+ Every row is checked by [`bench/claims.spec.ts`](./bench/claims.spec.ts) against flat 6.0.1, flattie 1.1.1, nestie 1.0.3, es-toolkit 1.52.0 and radashi 12.9.6, on every change in CI (`pnpm claims`).
129
+
130
+ | | Flattify | [flat](https://www.npmjs.com/package/flat) | [flattie](https://www.npmjs.com/package/flattie) / [nestie](https://www.npmjs.com/package/nestie) | [es-toolkit](https://www.npmjs.com/package/es-toolkit) | [radashi](https://www.npmjs.com/package/radashi) |
131
+ | --- | --- | --- | --- | --- | --- |
132
+ | Keys with the delimiter survive the round trip | ✅ | ❌ | ❌ | – | ❌ |
133
+ | Keeps `Date` and `Map` as values | ✅ | ✅ | ❌ dropped | ✅ | ✅ |
134
+ | Keeps class instances as values | ✅ | ❌ | ❌ | ✅ | ❌ |
135
+ | Keeps `null` values | ✅ | ✅ | ❌ dropped | ✅ | ✅ |
136
+ | Keeps empty objects and arrays | ✅ | ✅ | ❌ dropped | ✅ | ❌ dropped |
137
+ | Circular references | ✅ clear error | ❌ stack overflow | ❌ stack overflow | ❌ stack overflow | ❌ stack overflow |
138
+ | Deeply nested input (100k levels) | ✅ | ❌ stack overflow | ❌ stack overflow | ❌ stack overflow | ❌ stack overflow |
139
+ | Limit on array indices when unflattening | ✅ | ❌ | ❌ | – | ❌ |
140
+ | Paths and values inferred by TypeScript | ✅ | ❌ you pass the type | ❌ | ❌ `Record<string, any>` | ❌ `Record<string, …>` |
141
+ | `unflatten` | ✅ | ✅ | ✅ | ❌ | ✅ |
142
+ | Bracket notation and JSON Pointer | ✅ | ❌ | ❌ | ❌ | ❌ |
143
+ | `get` / `set` with autocompleted paths | ✅ | ❌ | ❌ | ❌ | ❌ |
144
+ | ESM and CommonJS | ✅ | ❌ v6 is ESM only | ✅ | ✅ | ✅ |
145
+ | Size (min + gzip) | 2.3 kB | 0.7 kB | 0.35 kB | 0.34 kB | 0.8 kB |
146
+
147
+ Flattify is bigger because it does more: the checks above, three notations, escaping and clear error messages. `flattify/path` is a separate import, so it only counts when you use it.
148
+
149
+ ## Use cases
150
+
151
+ **HTML forms:** field names such as `address[city]` or `items[0][qty]` become a nested object. Keys like `__proto__[isAdmin]` sent by a malicious client are ignored.
152
+
153
+ ```ts
154
+ const body = unflatten(Object.fromEntries(new FormData(form)), { notation: 'bracket' });
155
+ // { name: 'Ada', address: { city: 'London' }, items: [{ sku: 'BOOK-1', qty: '2' }] }
156
+ ```
157
+
158
+ **Query strings**, both ways:
159
+
160
+ ```ts
161
+ const flat = flatten({ status: 'open', tags: ['a', 'b'] }, { notation: 'bracket' });
162
+ const query = new URLSearchParams(Object.entries(flat).map(([k, v]) => [k, String(v)]));
163
+ // status=open&tags[0]=a&tags[1]=b (with the brackets percent-encoded)
164
+
165
+ unflatten(Object.fromEntries(new URLSearchParams(location.search)), { notation: 'bracket' });
166
+ // { status: 'open', tags: ['a', 'b'] }
167
+ ```
168
+
169
+ **Environment variables:** with `'__'` as delimiter, `APP__DB__MAX_CONN` is `app.db.max_conn`.
170
+
171
+ ```ts
172
+ const env = unflatten(process.env, { delimiter: '__', transformKey: (key) => key.toLowerCase() });
173
+ env.app; // { db: { host: 'localhost', max_conn: '10' } }
174
+ ```
175
+
176
+ **API lists → CSV or spreadsheets:** one row per record, and the keys are the headers.
177
+
178
+ ```ts
179
+ const rows = users.map((user) => flatten(user));
180
+ // [{ id: 1, name: 'Ada', 'address.city': 'London' }, ...]
181
+
182
+ // Or flatten the whole list into one object, and get the list back:
183
+ const same = unflatten(flatten(users), { asArray: true });
184
+ ```
185
+
186
+ **Partial updates in MongoDB:** `$set` with flat paths changes only the given fields.
187
+
188
+ ```ts
189
+ await users.updateOne({ _id }, { $set: flatten({ profile: { name: 'Ada' } }) });
190
+ // $set: { 'profile.name': 'Ada' }: the other profile fields are kept
191
+ ```
192
+
193
+ **JSON Schema errors:** validators such as Ajv point to errors with JSON Pointers, which `get` reads directly.
194
+
195
+ ```ts
196
+ get(data, error.instancePath, { notation: 'pointer' }); // e.g. '/items/0/qty'
94
197
  ```
95
- <br>
96
- Result:
97
- ```js
98
- {
99
- "id": 1,
100
- "gender": "Male",
101
- "first": "Joshua",
102
- "last": "Williams",
103
- "emails.0": "jwilliams1@vkontakte.ru",
104
- "emails.1": "phowell1@ezinearticles.com",
105
- "emails.2": "aferguson2@pen.io",
106
- "addresses.0.street": "Anzinger Court",
107
- "addresses.0.number": 73902,
108
- "addresses.1.street": "Anthes Parkway",
109
- "addresses.1.number": 106
110
- }
198
+
199
+ Also: translation files (`messages['home.title']`, typed), structured logs for Datadog or Elasticsearch, and finding what changed between two objects by comparing their flat forms.
200
+
201
+ ## API
202
+
203
+ ### `flatten(input, options?)`
204
+
205
+ Takes a plain object or an array, and returns a new flat object. Values are not cloned.
206
+
207
+ | Option | Default | |
208
+ | --- | --- | --- |
209
+ | `delimiter` | `'.'` | Joins the keys: `{ delimiter: '__' }` → `db__host` |
210
+ | `notation` | `'dot'` | `'dot'`, `'bracket'` or `'pointer'`, see [notations](#notations) |
211
+ | `maxDepth` | `Infinity` | Levels to walk into; deeper objects are kept as values. `1` keeps the top-level keys only |
212
+ | `safe` | `false` | Keeps arrays as values: `{ 'user.tags': ['a', 'b'] }` instead of `user.tags.0`, `user.tags.1` |
213
+ | `keepEmpty` | `true` | Keeps empty objects and arrays; `false` drops them |
214
+ | `escape` | `true` | Escapes keys that contain the delimiter (`'utm\\.source'`); `false` leaves them as they are |
215
+ | `circular` | `'throw'` | On a circular reference, throws a `TypeError` with its path, or `'skip'` leaves the key out |
216
+ | `transformKey` | | Renames each object key: `(key) => key.toUpperCase()`. Keys are then typed as `string` |
217
+ | `preserve` | | `(path, value) => boolean`: `true` keeps that object or array as a value |
218
+
219
+ With a longer delimiter, only keys that would really be ambiguous are escaped: with `'__'`, `MAX_CONN` stays as it is, but `MAX_` (which would merge with the delimiter) is escaped.
220
+
221
+ ### `unflatten(input, options?)`
222
+
223
+ Takes a flat object, and returns a new nested object. Keys that are array indices build arrays, whatever their order; the top level is always an object, unless `asArray` is set.
224
+
225
+ | Option | Default | |
226
+ | --- | --- | --- |
227
+ | `delimiter` | `'.'` | Splits the keys into paths |
228
+ | `notation` | `'dot'` | `'dot'`, `'bracket'` or `'pointer'`, see [notations](#notations) |
229
+ | `asArray` | `false` | Returns an array: `{ '0.id': 1, '1.id': 2 }` → `[{ id: 1 }, { id: 2 }]`. A top-level key that is not an index throws |
230
+ | `object` | `false` | Never builds arrays: `{ 'list.0': 'a' }` → `{ list: { 0: 'a' } }` |
231
+ | `overwrite` | `false` | When a path goes through a value (`{ a: 1, 'a.b': 2 }`), replaces it (`{ a: { b: 2 } }`) instead of skipping the path |
232
+ | `arrayLimit` | `1000` | Larger indices build object keys, so `'a.4294967294'` can't allocate a huge array |
233
+ | `escape` | `true` | Reads `\` as an escape, as `flatten` writes it |
234
+ | `transformKey` | | Renames each key of the path (not array indices) |
235
+
236
+ ### Notations
237
+
238
+ Every function takes `notation`, and the inferred types follow it:
239
+
240
+ | `notation` | Path | Useful for |
241
+ | --- | --- | --- |
242
+ | `'dot'` (default) | `items.0.sku` | Config, translations, MongoDB, logs |
243
+ | `'bracket'` | `items[0].sku` | HTML forms and query strings. `unflatten` also reads `items[0][sku]` |
244
+ | `'pointer'` | `/items/0/sku` | [JSON Pointer](https://www.rfc-editor.org/rfc/rfc6901): JSON Patch, JSON Schema errors. `~` and `/` are written `~0` and `~1` |
245
+
246
+ ### `flattify/path`
247
+
248
+ Read and write one value by path, with the path autocompleted and the value typed:
249
+
250
+ ```ts
251
+ import { get, set, has, del, paths } from 'flattify/path';
252
+
253
+ get(order, 'items.0.sku'); // 'BOOK-1', typed string | undefined
254
+
255
+ set(config, 'db.port', 6543); // ✅
256
+ set(config, 'db.port', '6543'); // ❌ type error: string is not number
257
+ set(config, 'db.prot', 6543); // ❌ type error: no such path
258
+ ```
259
+
260
+ | Function | |
261
+ | --- | --- |
262
+ | `get(obj, path)` | The value at `path`, or `undefined` when a key is missing |
263
+ | `set(obj, path, value)` | Sets the value, creating missing objects and arrays; returns `obj` |
264
+ | `has(obj, path)` | `true` when every key of the path exists |
265
+ | `del(obj, path)` | Deletes the key; `true` when it existed |
266
+ | `paths(obj)` | The paths `flatten` produces |
267
+ | `parsePath(path)` / `stringifyPath(keys)` | `'a\\.b.c'` ↔ `['a.b', 'c']` |
268
+ | `escapeKey(key)` | Escapes one key: `` `user.${escapeKey(field)}` `` |
269
+
270
+ All of them take `delimiter`, `notation` and `escape` as a last argument, and are safe with untrusted paths.
271
+
272
+ ## Types
273
+
274
+ Paths and values are computed at the type level, for every option that changes them:
275
+
276
+ ```ts
277
+ flatten({ user: { tags: ['admin'] } });
278
+ // { [x: `user.tags.${number}`]: string; 'user.tags'?: [] }
279
+
280
+ flatten({ a: { b: 1 } }, { notation: 'pointer' });
281
+ // { '/a/b': number }
111
282
  ```
112
- <br>
283
+
284
+ Arrays give `` `${number}` `` keys and tuples exact indices; optional or nullable objects give optional paths; unions are merged; `Date`, `Map` and other built-ins stay as values. `Unflatten<Flatten<T>>` gives back `T` for plain data. When an option is only known at runtime (a `string` delimiter, `transformKey`, `preserve`), keys are typed as `string` rather than guessed.
285
+
286
+ Exported types: `Flatten<T, Options>`, `Unflatten<T, Options>`, and from `flattify/path`, `Path<T>`, `Get<T, Path>` and `SetValue<T, Path>`.
287
+
288
+ ## Limitations
289
+
290
+ - **Some round trips can't be exact:** an object with only index keys (`{ '0': 'a' }`) comes back as an array; an array given to `flatten` comes back as an object unless `unflatten` gets `{ asArray: true }`; `transformKey` needs its reverse on the way back.
291
+ - **Symbol keys are ignored**, as by `JSON.stringify`.
292
+ - **Types:** TypeScript can't tell a class instance from a plain object, so class instances are typed as if they were flattened. Paths are typed down to 10 levels, and as `unknown` below.
293
+ - **Bracket notation:** an empty top-level key holding an array (`{ '': [1] }`) can't be told apart from the array itself.
294
+
295
+ ## Compatibility
296
+
297
+ | | |
298
+ | --- | --- |
299
+ | Runtimes | Node.js, Bun, Deno, browsers (ES2015), Cloudflare Workers |
300
+ | Modules | ESM and CommonJS |
301
+ | TypeScript | 5.0+, any `moduleResolution` |
302
+
303
+ CI runs the tests on Node.js 22, 24 and 26, Bun, Deno, Chromium, Firefox, WebKit and workerd (the Cloudflare Workers runtime), and checks the package with [publint](https://publint.dev) and [Are the Types Wrong?](https://arethetypeswrong.github.io).
304
+
305
+ ## Migrating
306
+
307
+ ### From `flat`
308
+
309
+ Same option names (`delimiter`, `maxDepth`, `safe`, `object`, `overwrite`, `transformKey`), with safer defaults:
310
+
311
+ | | `flat` | Flattify |
312
+ | --- | --- | --- |
313
+ | Result type | you pass it: `flatten<T, R>()` | inferred |
314
+ | Keys with the delimiter | split in two on the way back | escaped; `{ escape: false }` for the old behavior |
315
+ | `maxDepth: 0` | no limit | `RangeError`: leave it out for no limit |
316
+ | `unflatten({ a: { 'b.c': 1 } })` | `{ a: { b: { c: 1 } } }` | values are kept as they are |
317
+ | `unflatten` of a non-object | returned as it is | `TypeError` |
318
+ | Class instances | flattened | kept as values |
319
+ | Circular references | stack overflow | `TypeError`, or `circular: 'skip'` |
320
+
321
+ ### From Flattify 1.x
322
+
323
+ 2.0 is a rewrite with named exports:
324
+
325
+ | 1.x | 2.x |
326
+ | --- | --- |
327
+ | `flattify(obj, true)` | `flatten(obj)` |
328
+ | `flattify(obj)` (arrays turned into JSON strings) | `flatten(obj, { safe: true })` (arrays kept as arrays) |
329
+ | `flattify(array)` (each item flattened) | `array.map((item) => flatten(item))` |
330
+ | `flattify(jsonString)` | `flatten(JSON.parse(jsonString))` |
331
+
332
+ It also fixes nested arrays losing their path: `{ a: { tags: [1] } }` gave `{ tags: '[1]' }`, and now gives `{ 'a.tags.0': 1 }`.
333
+
334
+ ## Security
335
+
336
+ - **No prototype pollution:** `unflatten` and `set` only create own properties; paths through `__proto__` are skipped, in every notation. (`flat` had this flaw as [CVE-2020-36632](https://nvd.nist.gov/vuln/detail/CVE-2020-36632), fixed in 5.0.1.)
337
+ - **No stack overflow:** objects are walked with an explicit stack instead of recursion, so any depth is handled, and circular references throw a clear error.
338
+ - **No huge arrays:** `arrayLimit` bounds the indices `unflatten` turns into arrays.
339
+ - **No slowdown on hostile paths:** the bracket parser stays linear on input like `a[[[[...`.
340
+
341
+ All of this is tested, and `unflatten` is fuzzed with random paths made of `__proto__`, `constructor` and `prototype`. Releases are published from GitHub Actions with [npm provenance](https://docs.npmjs.com/generating-provenance-statements) and [staged](https://docs.npmjs.com/staged-publishing/) for approval with 2FA.
342
+
343
+ Found a vulnerability? Please report it privately, see [SECURITY.md](./SECURITY.md).
344
+
113
345
  ## License
114
- The MIT License (MIT)
115
-
116
- Copyright (c) 2016 Fernando Machado Bernardino
117
- [NandoMB](https://github.com/NandoMB). https://github.com/NandoMB/flattify
118
-
119
- Permission is hereby granted, free of charge, to any person obtaining a copy
120
- of this software and associated documentation files (the "Software"), to deal
121
- in the Software without restriction, including without limitation the rights
122
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
123
- copies of the Software, and to permit persons to whom the Software is
124
- furnished to do so, subject to the following conditions:
125
-
126
- The above copyright notice and this permission notice shall be included in all
127
- copies or substantial portions of the Software.
128
-
129
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
130
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
131
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
132
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
133
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
134
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
135
- SOFTWARE.
346
+
347
+ [MIT](./LICENSE) © 2016 Fernando Machado Bernardino