Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.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
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
The npm package astype receives a total of 25 weekly downloads. As such, astype popularity was classified as not popular.
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.