Skip to content

Commit 50f479e

Browse files
committed
feat: add proper readme
1 parent 2dbaa9d commit 50f479e

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

README.md

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,77 @@
1-
# jsonpilot
1+
# JSON Pilot
2+
3+
A library designed to help version JSON objects and migrate through them while also providing default data.
4+
5+
## Features
6+
7+
- **Minimal Modification:** Everything JSON Pilot needs to work is under `__pilot` to minimize potential collisions.
8+
- **Plug'n play:** Have an existing object? No problem! JSON Pilot will add it's necessary metadata and treat it as "version 0."
9+
- **Non-destructive:** If a property already exist, JSON Pilot doesn't change it. It only changes what it needs to change.
10+
- **Automatic Sorting:** Option to enable sorting of all properties in the object.
11+
- **CommonJS and ESM Support:** JSONPilot leverages SWC to export the library in both CommonJS and ESM.
12+
13+
## Getting Started
14+
15+
### Installation
16+
17+
```bash
18+
npm install jsonpilot
19+
# or
20+
yarn add jsonpilot
21+
# or
22+
pnpm add jsonpilot
23+
```
24+
25+
### Basic Usage
26+
27+
```typescript
28+
import { migrate, MigrateVersions } from 'jsonpilot'
29+
30+
const originalObject = {
31+
some_value: '123',
32+
}
33+
34+
const versions: MigrateVersions = [
35+
{
36+
version: 1,
37+
migration: {
38+
some_value: null,
39+
},
40+
},
41+
{
42+
version: 2,
43+
migration: {
44+
another_value: 0,
45+
},
46+
},
47+
]
48+
49+
/**
50+
* This will return the following object
51+
* {
52+
* some_value: '123',
53+
* another_value: 0
54+
* }
55+
*/
56+
const migratedObject = migrate(originalObject, versions)
57+
```
58+
59+
## API Reference
60+
61+
### Migrate
62+
63+
#### `migrate(source, versions, options)`
64+
65+
- `source`: JSON object that is already defined and you want to migrate (if needed).
66+
- `versions`: An array of version definitions. The version number is not semantic versioning and follows a simple incremental pattern.
67+
- `options`: Optional options to use to further adjust the migration process.
68+
- `targetVersion`: If you want to override the default versioning process (to the latest). Defaults to `-1` to always upgrade the object to the latest version available.
69+
- `sort`: Sorts the object (and nested objects) properties alphabetically. Defaults to false.
70+
71+
## License
72+
73+
JSON Pilot is licensed under Mozilla Public License Version 2.0.
74+
75+
## Support
76+
77+
While there's no official support, you can always create a new [discussion](https://github.com/MatthewSH/jsonpilot/discussions) or if you encounter a bug please feel free to [open an issue](https://github.com/MatthewSH/jsonpilot/issues)

0 commit comments

Comments
 (0)