
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
Bind an object to a defined schema. If type is wrong, it will throw an error.
const mySchema = {
use_constructor_function: String,
use_array_literal: [],
use_array_literal_with_type: [Number],
use_object_literal: {},
use_object_literal_with_definition: {
use_defined_schema: SubSchema // const SubSchema = String;
},
use_a_value_as_default: "es"
};
const myData = {
use_constructor_function: "yes",
use_array_literal: [1, "mixed is ok"],
use_array_literal_with_type: [0, 2, /* "other type will be error" */],
use_object_literal: null, // null is ok
use_object_literal_with_definition: {},
self_property: "hello"
};
const strictBinder = new Schema(Schema.strict, false);
const ignoreBinder = new Schema(Schema.ignoreUndefined, false); // undefined property will be omitted
const fillBinder = new Schema(Schema.fillWithDefault, false); // undefined property will be filled with default value
const extendBinder = new Schema(Schema.fillWithDefault, true); // property not defined in schema will still be append to output
const output1 = strictBinder.bind(myData, mySchema);
//TypeError: BindeError: expected string @ use_object_literal_with_definition.use_defined_schema but get undefined in Symbol(strict) mode.
const output2 = ignoreBinder.bind(myData, mySchema);
/*
{ use_constructor_function: 'yes',
use_array_literal: [ 1, 'mixed is ok' ],
use_array_literal_with_type: [ 0, 2 ],
use_object_literal: null,
use_object_literal_with_definition: {}
}
*/
const output3 = fillBinder.bind(myData, mySchema);
/*
{ use_constructor_function: 'yes',
use_array_literal: [ 1, 'mixed is ok' ],
use_array_literal_with_type: [ 0, 2 ],
use_object_literal: null,
use_object_literal_with_definition: { use_defined_schema: '' },
use_a_value_as_default: 'es'
}
*/
const output4 = extendBinder.bind(myData, mySchema);
/*
{ use_constructor_function: 'yes',
use_array_literal: [ 1, 'mixed is ok' ],
use_array_literal_with_type: [ 0, 2 ],
use_object_literal: null,
use_object_literal_with_definition: { use_defined_schema: '' },
use_a_value_as_default: 'es',
self_property: 'hello'
}
*/
FAQs
A simple schema formater to bind object to defined schema
The npm package es-schema receives a total of 9 weekly downloads. As such, es-schema popularity was classified as not popular.
We found that es-schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.