
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.
Convert an unknown type to a string, boolean, or number (integer, or float)
$ npm install --save astype
import as from 'astype';
as.number('1'); // 1
as.integer('55.1'); // 55
as.boolean(0); // false
as.string(true); // "true"
number(...)
(aliases: double()
, float()
)
integer(...)
boolean(...)
(aliases: bool()
)string(...)
This will set the behavior anytime a conversion is used.
This allows simplier syntax when using the same rules.
as.setGlobal({
number: { ... },
boolean: { ... },
string: { ... }
});
You can also unset global options as well.
Passing an empty object or null will unset all options under that key.
as.unsetGlobal({
number: { ... },
boolean: { ... },
string: { ... }
})
You can also pass through options in the conversion, these will override any global options.
as.number(..., { ... })
number
allowNull (default: true
)
true
: conversion can return the value null
false
: conversion will return 0
if null
allowUndefined (default: true
)
true
: conversion can return the value undefined
false
: conversion will return 0
if undefined
allowNaN (default: true
)
true
: conversion can return the value NaN
false
: conversion will return 0
if NaN
allowInfinity (default: true
)
true
: conversion can return the value Infinity
false
: conversion will return 0
if Infinity
allowFindInString (default: true
)
true
: conversion can will pick out numbers from a stringfalse
: conversion will return NaN
if allowNaN is true
,
otherwise 0
allowDecimals (default: true
)
true
: will allow decimal places in numbers
(eg: '1.9' => 1.9)false
: will truncate decimal places
(eg: '1.9' => 1)boolean
allowNull (default: true
)
true
: conversion can return the value null
false
: conversion will return 0
if null
allowUndefined (default: true
)
true
: conversion can return the value undefined
false
: conversion will return 0
if undefined
parseString (default: true
)
true
: will parse the strings "true"
and "false"
to true
and false
respectivelyfalse
: will parse the string to a boolean (Boolean("string")
)convertNumbers (default: true
)
true
: if the input is a number (or string that is a number),
it will parse as a number first, then convert to a booleanfalse
: will parse the string to a boolean (Boolean(1)
)string
allowNull (default: true
)
true
: conversion can return the value null
false
: conversion will return 0
if null
allowUndefined (default: true
)
true
: conversion can return the value undefined
false
: conversion will return 0
if undefined
MIT © Tyler Stewart
FAQs
Convert unknown type to certain type
We found that astype 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.