You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-13Lines changed: 18 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,10 +29,10 @@ bun add @ublitzjs/niche-json-stringify
29
29
30
30
## Quick start
31
31
32
-
Generate a specialized serializer from a JSON Schema (or a TypeBox schema). The generated function **does not validate** its input—it assumes the data already matches the schema.
32
+
Generate a specialized serializer from a JSON Schema (or a TypeBox schema). The generated function **does not validate** its input - it assumes the data already matches the schema.
For hot paths, the package also exports highly optimized serializers for common array types.
127
+
Internally they are used when array has certain size and replaced with `JSON.stringify` when fed a huge one.
129
128
130
129
```ts
131
130
import {
132
-
int_arr,
133
-
bool_arr,
131
+
num_arr_node,
132
+
num_arr_bun,
133
+
bool_arr_bun,
134
+
bool_arr_node,
134
135
str_arr_node,
135
136
str_arr_bun,
136
137
} from"@ublitzjs/niche-json-stringify";
137
138
138
-
int_arr([1, 2, 3]);
139
+
int_arr_node([1, 2, 3]);
140
+
int_arr_bun([1, 2, 3]);
139
141
// "[1,2,3]"
140
142
141
-
bool_arr([true, false]);
143
+
// look for use cases
144
+
bool_arr_node([true, false]);
145
+
bool_arr_bun([true, false]);
142
146
// "[true,false]"
143
147
144
148
// optimised non-escaping serialisers
145
149
str_arr_node(["a", "b"]);
146
150
str_arr_bun(["a", "b"]);
151
+
// "[\"a\",\"b\"]"
147
152
```
148
153
149
154
> **Note:** Generated serializers prioritize speed over safety. They do **not** validate input, so invalid data may produce invalid JSON or incorrect output. Validate your data before serialization if necessary.
0 commit comments