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

ts-json-schema

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-json-schema - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

1

lib/index.js

@@ -5,2 +5,3 @@ "use strict";

}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./JsonSchemaBuilder"));
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

10

lib/JsonSchemaBuilder.d.ts

@@ -18,3 +18,3 @@ import { JsonSchema } from './JsonSchema';

boolean: string;
'null': string;
null: string;
};

@@ -55,3 +55,3 @@ export declare const Format: {

description(description: string): this;
'default'(defaultValue: any): this;
default(defaultValue: any): this;
multipleOf(value: number): this;

@@ -156,3 +156,3 @@ maximum(value: number): this;

*
* @param {string} name
* @param {(string | string[])} path
* @param {(JsonSchema | PropSchemaCB)} [schema] The schema to use as

@@ -164,3 +164,3 @@ * @param {PropSchemaCB} [cb]

*/
property(name: string, schema?: JsonSchema | PropSchemaCB, cb?: PropSchemaCB): this;
property(path: string | string[], schema?: JsonSchema | PropSchemaCB, cb?: PropSchemaCB): this;
/**

@@ -172,3 +172,3 @@ * Enumerate the acceptable values

*/
'enum'(values: any[]): this;
enum(values: any[]): this;
/**

@@ -175,0 +175,0 @@ * Sets the type of the schema

"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
/**

@@ -23,3 +29,3 @@ * JSON Schema is ultimately a nested definition system. The root should always contain the $schema property,

boolean: 'boolean',
'null': 'null',
null: 'null',
};

@@ -38,3 +44,3 @@ exports.Format = {

};
var JsonSchemaBuilder = (function () {
var JsonSchemaBuilder = /** @class */ (function () {
/**

@@ -84,3 +90,3 @@ * Optionally takes an existing json schema to build on top of

};
JsonSchemaBuilder.prototype['default'] = function (defaultValue) {
JsonSchemaBuilder.prototype.default = function (defaultValue) {
this.schema.default = defaultValue;

@@ -260,3 +266,3 @@ return this;

*
* @param {string} name
* @param {(string | string[])} path
* @param {(JsonSchema | PropSchemaCB)} [schema] The schema to use as

@@ -268,4 +274,22 @@ * @param {PropSchemaCB} [cb]

*/
JsonSchemaBuilder.prototype.property = function (name, schema, cb) {
JsonSchemaBuilder.prototype.property = function (path, schema, cb) {
var propBuilder;
var rootSchema = this.schema;
var rootSchemaProperty;
if (Array.isArray(path)) {
rootSchemaProperty = path[path.length - 1];
for (var i = 1; i < path.length; i++) {
var propPath = path[i - 1];
if (!rootSchema.properties) {
rootSchema.properties = {};
}
if (!rootSchema.properties[propPath]) {
rootSchema.properties[propPath] = {};
}
rootSchema = rootSchema.properties[propPath];
}
}
else {
rootSchemaProperty = path;
}
if (typeof schema === 'function') {

@@ -275,6 +299,5 @@ cb = schema;

else if (schema) {
this.schema.properties = this.schema.properties || {};
this.schema.properties[name] = schema;
rootSchema.properties[rootSchemaProperty] = schema;
}
propBuilder = new JsonSchemaPropertyBuilder(name, this.schema);
propBuilder = new JsonSchemaPropertyBuilder(rootSchemaProperty, rootSchema);
if (cb) {

@@ -295,3 +318,3 @@ cb(propBuilder);

*/
JsonSchemaBuilder.prototype['enum'] = function (values) {
JsonSchemaBuilder.prototype.enum = function (values) {
this.schema.enum = values;

@@ -415,6 +438,6 @@ return this;

exports.JsonSchemaBuilder = JsonSchemaBuilder;
var JsonSchemaPropertyBuilder = (function (_super) {
var JsonSchemaPropertyBuilder = /** @class */ (function (_super) {
__extends(JsonSchemaPropertyBuilder, _super);
function JsonSchemaPropertyBuilder(property, parentSchema) {
var _this;
var _this = this;
if (!parentSchema.properties) {

@@ -421,0 +444,0 @@ parentSchema.properties = {};

{
"name": "ts-json-schema",
"version": "1.0.1",
"version": "1.1.0",
"description": "A fluent builder for json schemas",

@@ -9,4 +9,6 @@ "main": "./lib/index.js",

"build": "node_modules/typescript/bin/tsc -p .",
"test": "mocha lib/tests",
"clean": "rm -rf lib"
"test": "jest -c src/__test__/unit.config.json",
"test:watch": "jest -c src/__test__/unit.config.json --watch",
"clean": "rm -rf lib",
"prepublish": "npm-run-all clean test build"
},

@@ -21,2 +23,3 @@ "repository": {

"schema",
"typescript",
"builder"

@@ -32,6 +35,8 @@ ],

"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.2.0",
"typescript": "^2.1.4"
"@types/jest": "^22.0.0",
"jest": "^22.0.4",
"npm-run-all": "^4.1.2",
"ts-jest": "^22.0.0",
"typescript": "^2.6.2"
}
}

@@ -6,2 +6,6 @@ # JSON Schema Builder

Currently with zero dependencies
![Awwww yeah](https://i.imgur.com/1H9wWCt.gif)
## Developing

@@ -11,2 +15,14 @@

Compiled using typescript 2.1
### Testing
* `yarn test` will run the unit tests
* `yarn test:watch` will run run the unit tests in watch mode.
Compiled using typescript 2.6
## Change Log
### 1.1.0
* Added the ability to have an array of strings for the path of the property in the builder
* Switched typescript comiler to v2.6.2
* Added .npmignore to ignore source files when releasing
* Switched testing framework to jest
* excluded testing files from built files

@@ -14,4 +14,6 @@ {

"test",
"lib"
"lib",
"__test__",
"**/*.spec.ts"
]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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