Skip to content

Commit 88fcfb4

Browse files
chore(release): release v2.0.0 [skip ci]
1 parent af9e51f commit 88fcfb4

File tree

11 files changed

+791
-1
lines changed

11 files changed

+791
-1
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
## [2.0.0](https://github.com/Kit-p/json-kit/compare/v1.1.1...v2.0.0) (2023-07-30)
2+
3+
4+
### ⚠ BREAKING CHANGES
5+
6+
* **signature:** CHANGES
7+
8+
### Features
9+
10+
* **serialize:** add generic type and typeGuard parameter to serialize and deserialize ([6542bf6](https://github.com/Kit-p/json-kit/commit/6542bf6afee31b8066cc8ff66320a7986e2e482d))
11+
* **serialize:** serialize and deserialize ([#42](https://github.com/Kit-p/json-kit/issues/42)) ([0c008fe](https://github.com/Kit-p/json-kit/commit/0c008fefcea5fb49b93c2e1aae45fab2e674abd7))
12+
* **signature:** provide overloads for stringify and parse ([95ef4b8](https://github.com/Kit-p/json-kit/commit/95ef4b86b74195c5651784e54d471dfe12ce7a93))
13+
14+
15+
### Bug Fixes
16+
17+
* **serialize:** add missing return type ([04577d3](https://github.com/Kit-p/json-kit/commit/04577d35dcbe2a68b22b4c86897bd8e14d3e7525))
18+
* **types:** use namespace export for better consumption ([759eaa7](https://github.com/Kit-p/json-kit/commit/759eaa7024a0d4d91f7d4682f78626a7878d92e9))
19+
120
## [1.1.1](https://github.com/Kit-p/json-kit/compare/v1.1.0...v1.1.1) (2023-03-25)
221

322
### Bug Fixes

docs/.gitkeep

Whitespace-only changes.

docs/.nojekyll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.

docs/README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
@kit-p/json-kit / [Exports](modules.md)
2+
3+
<h1 align="center">json-kit</h1>
4+
5+
<div align="center">
6+
<a href="https://www.npmjs.com/package/@kit-p/json-kit">
7+
<img
8+
src="https://img.shields.io/npm/v/%40kit-p/json-kit"
9+
alt="npm: @kit-p/json-kit"
10+
/>
11+
</a>
12+
<a>
13+
<img
14+
src="https://img.shields.io/github/languages/top/Kit-p/json-kit"
15+
alt="languages: github.com/Kit-p/json-kit"
16+
/>
17+
</a>
18+
<a href="https://github.com/semantic-release/semantic-release">
19+
<img
20+
src="https://img.shields.io/badge/semantic--release-conventionalcommits-e10079?logo=semantic-release"
21+
alt="semantic-release: conventionalcommits"
22+
/>
23+
</a>
24+
<a href="https://gitpod.io/#https://github.com/Kit-p/json-kit">
25+
<img
26+
src="https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod"
27+
alt="Contribute with Gitpod"
28+
/>
29+
</a>
30+
</div>
31+
32+
<h3 align="center">JSON Toolkit for (de)serialization | (un)minification | (de)compression</h3>
33+
34+
---
35+
36+
## Project State
37+
38+
> This project is in **maintenance** state. The APIs are stable.
39+
40+
## Installation
41+
42+
### For Node.js:
43+
44+
- `npm install @kit-p/json-kit`
45+
- `yarn add @kit-p/json-kit`
46+
- `pnpm add @kit-p/json-kit`
47+
48+
#### _CommonJS_
49+
50+
```js
51+
const { JsonKit } = require("@kit-p/json-kit");
52+
```
53+
54+
#### _ESM_
55+
56+
```js
57+
import { JsonKit } from "@kit-p/json-kit";
58+
```
59+
60+
### For browsers:
61+
62+
#### _CommonJS_
63+
64+
- ```html
65+
<script src="https://cdn.jsdelivr.net/npm/@kit-p/json-kit"></script>
66+
<script>
67+
console.log(JsonKit);
68+
</script>
69+
```
70+
- ```html
71+
<script src="https://unpkg.com/@kit-p/json-kit"></script>
72+
<script>
73+
console.log(JsonKit);
74+
</script>
75+
```
76+
77+
#### _ESM_
78+
79+
- ```html
80+
<script type="module">
81+
import { JsonKit } from "https://cdn.jsdelivr.net/npm/@kit-p/json-kit/+esm";
82+
</script>
83+
```
84+
- ```html
85+
<script type="module">
86+
import { JsonKit } from "https://unpkg.com/@kit-p/json-kit?module";
87+
</script>
88+
```
89+
90+
## Usage
91+
92+
See [the documentation site](https://kit-p.github.io/json-kit/modules.html) or [the repository Wiki page](https://github.com/Kit-p/json-kit/wiki/Exports) or `docs/modules.md`.
93+
94+
## License
95+
96+
[MIT](https://github.com/Kit-p/json-kit/blob/main/LICENSE)

docs/modules.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[@kit-p/json-kit - v2.0.0](README.md) / Exports
2+
3+
# @kit-p/json-kit - v2.0.0
4+
5+
A library to work with JSON and EJSON (Extended JSON).
6+
7+
## Table of contents
8+
9+
### Namespaces
10+
11+
- [JsonKit](modules/JsonKit.md)

docs/modules/JsonKit.Parse.md

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
[@kit-p/json-kit - v2.0.0](../README.md) / [Exports](../modules.md) / [JsonKit](JsonKit.md) / Parse
2+
3+
# Namespace: Parse
4+
5+
[JsonKit](JsonKit.md).Parse
6+
7+
## Table of contents
8+
9+
### Type Aliases
10+
11+
- [ParseOptions](JsonKit.Parse.md#parseoptions)
12+
- [ParseReviverFunction](JsonKit.Parse.md#parsereviverfunction)
13+
14+
### Functions
15+
16+
- [decompressString](JsonKit.Parse.md#decompressstring)
17+
- [parse](JsonKit.Parse.md#parse)
18+
19+
## Type Aliases
20+
21+
### ParseOptions
22+
23+
Ƭ **ParseOptions**: `Object`
24+
25+
Type for the `options` parameter of [parse](JsonKit.Parse.md#parse).
26+
27+
#### Type declaration
28+
29+
| Name | Type | Description |
30+
| :------ | :------ | :------ |
31+
| `decompress?` | `boolean` \| { `enable`: `boolean` } | Specifies if the input string is compressed with [`lz4js.compress()`](https://github.com/Benzinga/lz4js/blob/73728a9c3c6a417ab9ce622fa112dc1cf04b00fd/lz4.js#L557). **`Remarks`** Will automatically disable if the decompression fails. **`Default Value`** `true` |
32+
| `extended?` | `boolean` \| { `enable`: `boolean` ; `relaxed?`: `boolean` } | Specifies if the input string is in JSON or EJSON format, additional options to be passed into [`bson.EJSON.parse()`](https://github.com/mongodb/js-bson#ejsonparsetext-options) can be supplied with the long form (only effective if `enable` is `true`. **`Default Value`** `false` |
33+
| `unminify?` | `boolean` \| { `enable`: `boolean` ; `keyMap?`: `Record`<`string`, `string`\> } | Specifies if the input string is created with the `minify` option enabled in [stringify](JsonKit.Stringify.md#stringify), a custom key map (shortened:original) can be supplied with the long form (only effective if `enable` is `true`. **`Remarks`** Will automatically disable if the unminifcation fails. **`Default Value`** `true` |
34+
35+
#### Defined in
36+
37+
[parse.ts:22](https://github.com/Kit-p/json-kit/blob/af9e51f/src/parse.ts#L22)
38+
39+
___
40+
41+
### ParseReviverFunction
42+
43+
Ƭ **ParseReviverFunction**: (`this`: `any`, `key`: `string`, `value`: `any`) => `any`
44+
45+
#### Type declaration
46+
47+
▸ (`this`, `key`, `value`): `any`
48+
49+
Type for the `reviver` parameter of [parse](JsonKit.Parse.md#parse).
50+
Refer to [the MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter) for more details.
51+
52+
##### Parameters
53+
54+
| Name | Type |
55+
| :------ | :------ |
56+
| `this` | `any` |
57+
| `key` | `string` |
58+
| `value` | `any` |
59+
60+
##### Returns
61+
62+
`any`
63+
64+
#### Defined in
65+
66+
[parse.ts:12](https://github.com/Kit-p/json-kit/blob/af9e51f/src/parse.ts#L12)
67+
68+
## Functions
69+
70+
### decompressString
71+
72+
**decompressString**(`str`): `string`
73+
74+
Decompresses a string with [`lz4js.decompress()`](https://github.com/Benzinga/lz4js/blob/73728a9c3c6a417ab9ce622fa112dc1cf04b00fd/lz4.js#L538).
75+
76+
#### Parameters
77+
78+
| Name | Type | Description |
79+
| :------ | :------ | :------ |
80+
| `str` | `string` | The input string |
81+
82+
#### Returns
83+
84+
`string`
85+
86+
str - The decompressed string
87+
88+
#### Defined in
89+
90+
[parse.ts:352](https://github.com/Kit-p/json-kit/blob/af9e51f/src/parse.ts#L352)
91+
92+
___
93+
94+
### parse
95+
96+
**parse**<`T`\>(`text`, `reviver?`, `options?`, `typeGuard?`): `T`
97+
98+
Turns the input string into an object.
99+
100+
**`Remarks`**
101+
102+
With the custom options, the input string can be either
103+
- a JSON string (identical to [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse))
104+
- an EJSON string (identical to [`bson.EJSON.parse()`](https://github.com/mongodb/js-bson#ejsonparsetext-options))
105+
- a minified version of either of the above, where some or specified keys are replaced with a shorter identifier
106+
- a compressed version (by [`lz4js.compress()`](https://github.com/Benzinga/lz4js/blob/73728a9c3c6a417ab9ce622fa112dc1cf04b00fd/lz4.js#L557)) of either of the above
107+
108+
**`Example`**
109+
110+
```ts
111+
type Foo {
112+
long_key: string
113+
}
114+
115+
parse<Foo>(
116+
"{\"lk\":\"A Large Object\"}",
117+
(key, val) => {
118+
if (key === "lk") {
119+
return "A Modified Large Object"
120+
}
121+
return val
122+
},
123+
{
124+
extended: false,
125+
unminify: { enable: true, keyMap: { "lk": "long_key" } },
126+
decompress: false
127+
},
128+
(obj: any): obj is Foo => {
129+
const _obj: Partial<Foo> | null | undefined = obj
130+
return typeof _obj?.long_key === "string"
131+
}
132+
)
133+
```
134+
135+
#### Type parameters
136+
137+
| Name | Description |
138+
| :------ | :------ |
139+
| `T` | Type of the output object |
140+
141+
#### Parameters
142+
143+
| Name | Type | Description |
144+
| :------ | :------ | :------ |
145+
| `text` | `string` | The input string |
146+
| `reviver?` | ``null`` \| [`ParseReviverFunction`](JsonKit.Parse.md#parsereviverfunction) | The `reviver` parameter of [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#the_reviver_parameter) |
147+
| `options?` | ``null`` \| [`ParseOptions`](JsonKit.Parse.md#parseoptions) | The custom options, refer to [ParseOptions](JsonKit.Parse.md#parseoptions) for details |
148+
| `typeGuard?` | [`TypeGuardFunction`](JsonKit.Types.md#typeguardfunction)<`T`\> | The type guard function, ensures that the output object is of the expected type, refer to [TypeGuardFunction](JsonKit.Types.md#typeguardfunction) for an example. |
149+
150+
#### Returns
151+
152+
`T`
153+
154+
The output object
155+
156+
#### Defined in
157+
158+
[parse.ts:185](https://github.com/Kit-p/json-kit/blob/af9e51f/src/parse.ts#L185)
159+
160+
**parse**<`T`\>(`text`, `options?`, `typeGuard?`): `T`
161+
162+
Turns the input string into an object.
163+
164+
**`Remarks`**
165+
166+
With the custom options, the input string can be either
167+
- a JSON string (identical to [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse))
168+
- an EJSON string (identical to [`bson.EJSON.parse()`](https://github.com/mongodb/js-bson#ejsonparsetext-options))
169+
- a minified version of either of the above, where some or specified keys are replaced with a shorter identifier
170+
- a compressed version (by [`lz4js.compress()`](https://github.com/Benzinga/lz4js/blob/73728a9c3c6a417ab9ce622fa112dc1cf04b00fd/lz4.js#L557)) of either of the above
171+
172+
**`Example`**
173+
174+
```ts
175+
type Foo {
176+
long_key: string
177+
}
178+
179+
parse<Foo>(
180+
"{\"lk\":\"A Large Object\"}",
181+
{
182+
extended: false,
183+
unminify: { enable: true, keyMap: { "lk": "long_key" } },
184+
decompress: false
185+
},
186+
(obj: any): obj is Foo => {
187+
const _obj: Partial<Foo> | null | undefined = obj
188+
return typeof _obj?.long_key === "string"
189+
}
190+
)
191+
```
192+
193+
#### Type parameters
194+
195+
| Name | Description |
196+
| :------ | :------ |
197+
| `T` | Type of the output object |
198+
199+
#### Parameters
200+
201+
| Name | Type | Description |
202+
| :------ | :------ | :------ |
203+
| `text` | `string` | The input string |
204+
| `options?` | ``null`` \| [`ParseOptions`](JsonKit.Parse.md#parseoptions) | The custom options, refer to [ParseOptions](JsonKit.Parse.md#parseoptions) for details |
205+
| `typeGuard?` | [`TypeGuardFunction`](JsonKit.Types.md#typeguardfunction)<`T`\> | The type guard function, ensures that the output object is of the expected type, refer to [TypeGuardFunction](JsonKit.Types.md#typeguardfunction) for an example. |
206+
207+
#### Returns
208+
209+
`T`
210+
211+
The output object
212+
213+
#### Defined in
214+
215+
[parse.ts:230](https://github.com/Kit-p/json-kit/blob/af9e51f/src/parse.ts#L230)

0 commit comments

Comments
 (0)