
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
cast-with-schema
Advanced tools
The way to cast data to types specified with JSON schema.
source (object)
- Source object to be casted.schema (object)
- JSON schema containing types definitions.options (object)
allowNaN
— Whether or not to return NaN
for non-parseable numbers. The default is false
which will cast NaN
to 0
.May be used for query params casting:
const qs = require('qs');
const castWithSchema = require('cast-with-schema');
const schema = {
type: "object",
properties: {
param1: {
type: 'string',
},
param2: {
type: 'integer',
},
param3: {
type: 'number',
},
param4: {
type: 'boolean',
},
}
};
const query = 'param1=value¶m2=777¶m3=7.77¶m4=false';
const parsed = qs.parse(query);
const casted = castWithSchema(query, schema);
/*
`casted` is now:
{
param1: 'value',
param2: 777,
param3: 7.77,
param4: false,
}
*/
Supports null
if schema is either:
type: ['..', 'null']
or
anyOf: [
{ type: '..' },
{ type: 'null' }
]
Check out tinsypec for more smart JSON schema use cases.
FAQs
Casting JS objects to correct types using JSON schemas
The npm package cast-with-schema receives a total of 3,037 weekly downloads. As such, cast-with-schema popularity was classified as popular.
We found that cast-with-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.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.