Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
JSON Schema utility collection
Install skhema
by running:
$ npm install --save skhema
Error
Error
Object
Number
Object
Boolean
Object
Object
Object
| Null
Error
Kind: static property of skhema
Summary: Schema mismatch error
Access: public
Error
Kind: static property of skhema
Summary: Incompatible schemas error
Access: public
Object
Removes values from a subject schema so that a value that matches the resulting schema will also validate against the restricting schema.
Kind: static method of skhema
Summary: Restrict a schema using another schema
Returns: Object
- restricted schema
Access: public
Param | Type | Description |
---|---|---|
subjectSchema | Object | schema |
restrictingSchema | Object | schema |
Example
const result = skhema.restrictSchema({
type: 'object',
properties: {
foo: {
type: 'number'
},
bar: {
type: 'string'
}
},
required: [ 'foo' ]
}, {
type: 'object',
properties: {
foo: {
type: 'number'
}
},
additionalProperties: false,
required: [ 'foo' ]
})
console.log(result)
> {
> type: 'object',
> properties: {
> foo: {
> type: 'number'
> },
> },
> additionalProperties: false,
> required: [ 'foo' ]
> }
Number
Score a matching object and schema based on specificity. Only works with values that are valid against the provided schema
Kind: static method of skhema
Summary: Score a schema match by specificity
Returns: Number
- score
Access: public
Param | Type | Description |
---|---|---|
schema | Object | JSON schema |
object | Object | object |
Example
const score = skhema.scoreMatch({
type: 'object'
}, {
foo: 'bar'
})
console.log(result) // -> 1
Object
Kind: static method of skhema
Summary: Match an object against a schema
Returns: Object
- results
Access: public
Param | Type | Default | Description |
---|---|---|---|
schema | Object | JSON schema | |
object | Object | object | |
[options] | Object | options | |
[options.schemaOnly] | Boolean | false | Only validate the schema |
Example
const results = skhema.match({
type: 'object'
}, {
foo: 'bar'
})
if (!results.valid) {
for (const error of results.errors) {
console.error(error)
}
}
Boolean
This is a shorthand function for .match()
which can be used
if the caller is not interested in the actual error messages.
Kind: static method of skhema
Summary: Check if an object matches a schema
Returns: Boolean
- whether the object matches the schema
Access: public
Param | Type | Default | Description |
---|---|---|---|
schema | Object | JSON schema | |
object | Object | object | |
[options] | Object | options | |
[options.schemaOnly] | Boolean | false | Only validate the schema |
Example
const isValid = skhema.isValid({
type: 'object'
}, {
foo: 'bar'
})
if (isValid) {
console.log('The object is valid')
}
The .validate()
method will throw if the provided schema isn't
valid or if the object doesn't validate against the schema. If you just want
to validate a schema, you use the schemaOnly
option.
Kind: static method of skhema
Summary: Validate an object and schema and throw if invalid
Access: public
Param | Type | Default | Description |
---|---|---|---|
schema | Object | JSON schema | |
object | Object | object | |
[options] | Object | options | |
[options.schemaOnly] | Boolean | false | Only validate the schema |
Example
skhema.validate({
type: 'object'
}, {
foo: 'bar'
})
Object
Kind: static method of skhema
Summary: Merge two or more JSON Schemas
Returns: Object
- merged JSON Schema
Access: public
Param | Type | Description |
---|---|---|
schemas | Array.<Object> | a set of JSON Schemas |
Example
const result = skhema.merge([
{
type: 'string',
maxLength: 5,
minLength: 2
},
{
type: 'string',
maxLength: 3
}
])
console.log(result)
> {
> type: 'string',
> maxLength: 3,
> minLength: 2
> }
Object
Kind: static method of skhema
Summary: Set fields on a schema which are required but do not appear in properties
Returns: Object
- mutated schema
Access: public
Param | Type | Description |
---|---|---|
schema | Object | schema |
Example
const schema = skhema.normaliseRequires({
type: 'object',
properties: {},
required: [ 'foo' ]
})
console.log(schema.properties)
> { foo: { additionalProperties: false } }
Object
| Null
Kind: static method of skhema
Summary: Filter an object based on a schema
Returns: Object
| Null
- filtered object
Access: public
Param | Type | Default | Description |
---|---|---|---|
schema | Object | schema | |
object | Object | object | |
[options] | Object | options | |
[options.schemaOnly] | Boolean | false | Only validate the schema |
Example
const result = skhema.filter({
type: 'object',
properties: {
foo: {
type: 'number'
}
},
required: [ 'foo' ]
}, {
foo: 1,
bar: 2
})
console.log(result)
> {
> foo: 1
> }
Run the test suite by doing:
$ npm test
We're looking forward to support more operating systems. Please raise an issue or even better, send a PR to increase support!
Before submitting a PR, please make sure that you include tests, and that the linter runs without any warning:
npm run lint
If you're having any problem, please raise an issue on GitHub.
The project is licensed under the Apache 2.0 license.
FAQs
JSON Schema utility collection
The npm package skhema receives a total of 3,589 weekly downloads. As such, skhema popularity was classified as popular.
We found that skhema 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.