
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
jsonschema-extra
Advanced tools
Extends jsonschema validator with some common custom types and attributes
Extends jsonschema validator with some common custom types and attributes
npm install jsonschema-extra --save
var jsonschema = require('jsonschema');
var extra = require('jsonschema-extra');
var validator = new (jsonschema.Validator)();
extra(validator);
// regexp
validator.validate(/abc/, { type: 'regexp' });
// error
validator.validate(new Error(), { type: 'error' });
// mongodb objectid
validator.validate('123456789012345678901234', { type: 'objectId' });
See jsonschema
documentation for more detailed documentation on custom attributes.
Custom validator when jsonschema
just isn't what you are after. This one is my absolute favourite! It comes in handy whenever you are trying to do something complex.
One of the features of jsonschema is that you can share it across client and server which is exactly what I do! However, if your schema contains a validate attribute it will no longer be valid json. This is not a big issue if you are ok for client side code to not contain all your validation logic if schema is sent from the server.
Single validator
var schema = {
validate: function(instance, schema, options) {
// do your crazy validation here
// return an error string if not valid
return 'is not a valid instance';
}
};
Multiple validators
var schema = {
validate: [
function(instance, schema, options) {
// do your crazy validation here
// return an error string if not valid
return 'is not a valid instance';
},
function(instance, schema, options) {
// do your crazy validation here
// return an error string if not valid
return 'is not a valid instance';
}
]
};
Supported types:
validator.validate(new Error(), { type: 'error' });
validator.validate(/regexp/, { type: 'regexp' });
validator.validate(function() {}, { type: 'function' });
validator.validate(function *() {}, { type: 'generatorFunction' });
validator.validate('123456789012345678901234', { type: 'objectId' });
validator.validate(new ObjectID(), { type: 'objectId' });
validator.validate({ a: 'a', b: 'b' }, { type: 'plainObject' });
Quantity types supported by js-quantities
validator.validate('1 meter', { type: 'qty.length' });
validator.validate('45.3 seconds', { type: 'qty.time' });
// can also validate Qty instances
var Qty = require('js-quantities');
var qty = Qty.parse('2 meters');
validator.validate(qty, { type: 'qty.length' });
Install mocha
globally
$ npm install mocha -g
Run tests
$ npm test
validate
propertyspeed
typeFAQs
Extends jsonschema validator with some common custom types and attributes
The npm package jsonschema-extra receives a total of 806 weekly downloads. As such, jsonschema-extra popularity was classified as not popular.
We found that jsonschema-extra 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.