Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
cast an object's values to a specified schema
npm install castaway
Given an object, and a schema defining the types of the objects properties, castaway will convert the values to the appropriate JS primitives.
var cast = require('castaway');
var obj = { foo: '1337'},
schema = { foo: { type: Number }};
cast(obj, schema);
console.log(typeof obj.foo); // number
Supported type
values are:
Arrays also support defining member schemas via an each
property, and specifying the schema or types:
Here's an example of specifying the schema via each
for an array...
var schema = {
foo: {
type: Array,
each: {
schema: {
id: { type: Number },
when: { type: Date }
}
}
}
},
obj = { foo: [
{ id: '1', hee: 'haw', when: '2013-02-28 16:31:13' },
{ id: '2', hee: 'hoo', when: '2013-02-28' }
]};
cast(obj, schema);
// for each entry in foo, id is a Number, when is a Date, hee is still a String
And here's an example of just specifying the type
for an array via each
...
var schema = { foo: { type: Array, each: { type: Number } } },
obj = { foo: '1,2,3,4,5,6,7,8,9' };
cast(obj, schema);
// foo is an array of numbers
FAQs
cast JS objects to a specified schema, ahoy!
We found that castaway 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.