Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

genson-js

Package Overview
Dependencies
Maintainers
5
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

genson-js - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

2

dist/index.d.ts
export * from './types';
export { extendSchema, mergeSchemas, createSchema } from './schema-builder';
export { extendSchema, mergeSchemas, createSchema, createCompoundSchema } from './schema-builder';
export * from './schema-comparator';

@@ -13,3 +13,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.createSchema = exports.mergeSchemas = exports.extendSchema = void 0;
exports.createCompoundSchema = exports.createSchema = exports.mergeSchemas = exports.extendSchema = void 0;
__exportStar(require("./types"), exports);

@@ -20,3 +20,4 @@ var schema_builder_1 = require("./schema-builder");

Object.defineProperty(exports, "createSchema", { enumerable: true, get: function () { return schema_builder_1.createSchema; } });
Object.defineProperty(exports, "createCompoundSchema", { enumerable: true, get: function () { return schema_builder_1.createCompoundSchema; } });
__exportStar(require("./schema-comparator"), exports);
//# sourceMappingURL=index.js.map

@@ -8,1 +8,2 @@ import { Schema, SchemaGenOptions } from './types';

export declare function extendSchema(schema: Schema, value: any, options?: SchemaGenOptions): Schema;
export declare function createCompoundSchema(values: any[], options?: SchemaGenOptions): Schema;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extendSchema = exports.mergeSchemas = exports.createSchema = exports.wrapAnyOfSchema = exports.unwrapSchemas = exports.unwrapSchema = void 0;
exports.createCompoundSchema = exports.extendSchema = exports.mergeSchemas = exports.createSchema = exports.wrapAnyOfSchema = exports.unwrapSchemas = exports.unwrapSchema = void 0;
const types_1 = require("./types");

@@ -241,2 +241,7 @@ function createSchemaFor(value, options) {

exports.extendSchema = extendSchema;
function createCompoundSchema(values, options) {
const schemas = values.map(value => createSchema(value, options));
return mergeSchemas(schemas, options);
}
exports.createCompoundSchema = createCompoundSchema;
//# sourceMappingURL=schema-builder.js.map
{
"name": "genson-js",
"version": "0.0.3",
"version": "0.0.4",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.js",

# genson-js
![Build](https://github.com/aspecto-io/genson-js/workflows/Build/badge.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![TypeScript](https://badgen.net/npm/types/env-var)](http://www.typescriptlang.org/) [![NPM version](https://img.shields.io/npm/v/genson-js.svg)](https://www.npmjs.com/package/genson-js)
**genson-js** is a user-friendly **JSON Schema** generator built in TypeScript/JavaScript.

@@ -12,3 +14,3 @@

#### Creating schemas
### Creating schemas

@@ -25,27 +27,30 @@ To infer a schema from existing object:

});
```
// will create the following schema:
// {
// type: "object",
// properties: {
// userName: {
// type: "string",
// },
// languages: {
// type: "array",
// items: {
// type: "string",
// },
// },
// age: {
// type: "integer",
// },
// },
// required: ["userName", "languages", "age"],
// };
The following schema will be created:
```json
{
type: "object",
properties: {
userName: {
type: "string",
},
languages: {
type: "array",
items: {
type: "string",
},
},
age: {
type: "integer",
},
},
required: ["userName", "languages", "age"],
};
```
#### Merging schemas
### Merging schemas
You can merge 2 schemas, so that merged schema would be kind of a superset of the schemas that it was built from:
You can merge 2 or more schemas, so that merged schema would be kind of a superset of the schemas that it was built from:

@@ -61,4 +66,22 @@ ```ts

#### Exending schemas
### Create compound schema
Shorthand for createSchema + mergeSchemas.
Can take multiple inputs and create one compound schema:
```ts
import { createCompoundSchema } from 'genson-js';
const schema = createCompoundSchema([{ age: 19, name: 'John' }, { age: 23, admin: true }, { age: 35 }]);
// Will create the following schema:
// {
// type: 'object',
// properties: { admin: { type: 'boolean' }, age: { type: 'integer' }, name: { type: 'string' } },
// required: ['age']
// }
```
### Exending schemas
You can extend existing schema to match some value:

@@ -69,3 +92,3 @@

const extended = extendSchema({ type: ValueType.Number }, 'string');
const extended = extendSchema({ type: ValueType.Number }, 'some string');

@@ -76,5 +99,5 @@ // will create extended schema like this:

#### Comparing schemas
### Comparing schemas
You can extend compare 2 schemas for equality like this:
You can compare 2 schemas for equality like this:

@@ -88,8 +111,6 @@ ```ts

#### Subset
### Subset
You can also check if one schema is a subset of another one like so:
You can extend compare 2 schemas for equality like this:
```ts

@@ -104,3 +125,3 @@ import { isSubset } from 'genson-js';

```
You can find more example in the unit tests.
<hr/>
You can find more examples in the unit tests.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc