@murmurations/jsig
Version:
JSON Schema Instance Generator (JSIG)
99 lines (72 loc) • 2.08 kB
Markdown
> This project is licensed under the terms of the GNU General Public License v3.0
Using npm:
```sh
npm install @murmurations/jsig
```
```javascript
import { parseSchemas } from '@murmurations/jsig'
const url = 'https://example.com/schema.json'
const schemaNames = ['schema1', 'schema2']
try {
const result = await parseSchemas(url, schemaNames)
console.log(result)
} catch (error) {
console.error(error)
}
```
```javascript
import { generateSchemaInstance } from '@murmurations/jsig'
const schema = {
// Schema definition
}
// The following data is an example of the data, you should use the formData directly
const data = {
// Input data
name: ['John Doe'],
age: [30],
email: ['john.doe@example.com'],
// If key contains ".", it will be parsed to an Object
'address.zip': [10000],
'address.city': ['City'],
// If key contains "[]", it will be parsed to an Array
'tags[0]': ['self']
}
// data should be directly from the formData without making any changes
const formData = new FormData(event.target)
let data = {}
for (let key of formData.keys()) {
data[key] = formData.getAll(key)
}
try {
const result = await generateSchemaInstance(schema, data)
console.log(result)
} catch (error) {
console.error(error)
}
```
```sh
npm install
```
```sh
npm run build
```
```sh
npm install --no-save ../JSONSchemaInstanceGenerator
```
```sh
npm install @murmurations/jsig@pre
```
1. [ECMAScript Modules in Node.js](https://www.typescriptlang.org/docs/handbook/esm-node.html)
2. [Best practices for creating a modern npm package](https://snyk.io/blog/best-practices-create-modern-npm-package/)
3. [Gotchas in Remix](https://remix.run/docs/en/main/pages/gotchas)