
Security News
Federal Audit Finds NIST Wasted Funds With No Plan to Clear NVD Backlog
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.
guarantee-type
Advanced tools
guarantee the type of a plain object
When we use Typescript, in some point we want to use types everywere.
But in some cases is very dificult to avoid the use of any.
For example, when we get data from LocalStorage, we transfer data in the network
or we retieve from the database and ower ORM
is no typed enought.
type Person = {
name: string,
age?: number,
active: boolean,
due: Date
};
function print(person: Person){
// ...
};
print(JSON.parse(localStorage['person1'])) // 💩 receiving any
// Using https://node-postgres.com/
const res = await client.query('SELECT $1::text as message', ['Hello world!'])
console.log(res.rows[0].messagggge) // 💩 receiving undefined because the typo
Currently Typescript do not avoid the use of any in the
right hand of an assignation. But regardless of that we need a way to validate
and set types of received data.
import { guarantee, is, GuaranteedType } from "guarantee-type";
var descriptionPerson = is.object({
name: is.string,
age: is.optional.number,
active: is.boolean,
due: is.class(Date) // for Date class only you can write is.Date
});
type Person = GuaranteedType<typeof descriptionPerson>;
function print(person: Person){
// ...
};
print(guarantee(descriptionPerson, JSON.parse(localStorage['person1']))); // 👍 ok, type guaranteed!
// Using https://node-postgres.com/
const res = await client.query('SELECT $1::text as message', ['Hello world!'])
console.log(guarantee( is.object({message: is.string}), res.rows[0]).messagggge) // 👍 ok, typo detected!
Using is for describe the type is optional.
The descriptions can be defined in a plain Javascript object that
can be serializable and enceded with JSON.
For example descriptionPerson can be writen like this:
var descriptionPerson = {
object: {
name: { string: {} },
age: { optional: { number: {} },
active: { boolean: {} },
due: { class: Date }
}
};
FAQs
guarantee the type of a plain object
We found that guarantee-type demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.

Research
/Security News
The North Korean malware loader hides in a Packagist-listed package and its GitHub branch to fetch and execute remote code in a likely Contagious Interview-style lure.