Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
A JavaScript module for checking variable runtime type
var oftype = require('oftype');
var x = 123;
var y = true;
var z = /abc/;
var u = undefined;
var n = null;
function Obj() {
this.name = 'ABC';
}
var o = new Obj();
//check if variable x is of Number type.
oftype(123, Number); //true
//check if variable y is of Boolean type.
oftype(y, Boolean); //true
//check if variable z is of RegExp type.
oftype(z, RegExp); //true
//check if variable u is of undefined type.
//undefined is a type which has an only value undefined.
oftype(u, undefined); //true
//check if variable n is of null type.
//stricly, null is no actually a type, but here we treat
// it as a type just like how we treat undefined.
oftype(n, null); //true;
//check if variable o is of Obj type.
oftype(o, Obj); //true;
//check if variable o is of Object type.
oftype(o, Object); //true;
The signature of oftype
is
oftype(value, type, options);
value
: could be any variable or value;
type
: could be any type identifier, e.g.: Number, Boolean, String, Date, RegExp, Array, Object and any other customized complex type.
options
is optional and has below hash values:
nullAsObject
: treat null
value as Object
type, so with this option testing null
against Object
type returns true
. Default value of this option is false
.
primitiveObject
: treat primitive object as primitive type. for example, testing new Number(1)
against Number will return false
when this option is set to false
; but will return true
when this option is set to true
.
Alternatively, to avoid setting the options in every function call, the options could also be set globally:
oftype.nullAsObject = true;
oftype.primitiveObject = true;
Make sure mocha
is installed globally
npm test
MIT
FAQs
A JavaScript module for checking variable runtime type
The npm package oftype receives a total of 3 weekly downloads. As such, oftype popularity was classified as not popular.
We found that oftype 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.