Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
type-of-is
Advanced tools
Determine and test types using constructor or Object.toString
2.0.0
npm install type-of-is
or in package.json
{
...
"dependencies": {
"type-of-is": "2.0.0"
}
}
var Type = require('type-of-is');
Type(obj) provides constructor type of an object
Type.string(obj) provides type as String from {}.toString
Type.is(obj, type) tests whether obj is of type (constructor or String)
var Type = require('type-of-is');
console.log(Type('hi there ok')); // [Function: String]
console.log(Type(342)); // [Function: Number]
console.log(Type(342)); // [Function: Number]
console.log(Type({})); // [Function: Object]
console.log(Type([1, 2, 3])); // [Function: Array]
console.log(Type(null)); // null
console.log(Type(undefined)); // undefined
console.log(Type(true)); // [Function: Boolean]
console.log(Type(function () {})); // [Function: Function]
console.log(Type(/abcd/)); // [Function: RegExp]
console.log(Type(new Date())); // [Function: Date]
console.log(Type(new Error())); // [Function: Error]
console.log(Type.string('hi there ok')); // "String"
console.log(Type.string(342)); // "Number"
console.log(Type.string({})); // "Object"
console.log(Type.string([1, 2, 3])); // "Array"
console.log(Type.string(null)); // "Null"
console.log(Type.string(undefined)); // "Undefined"
console.log(Type.string(true)); // "Boolean"
console.log(Type.string(function () {})); // "Function"
console.log(Type.string(/abcd/)); // "RegExp"
console.log(Type.string(new Date())); // "Date"
console.log(Type.string(new Error())); // "Error"
console.log(Type.is(true, Boolean)); // true
console.log(Type.is("1231", Number)); // false
console.log(Type.is("1231", String)); // true
console.log(Type.is("1231", "String")); // true
console.log(Type.is("1231", Object)); // false
console.log(Type.is([], Object)); // false
console.log(Type.is({}, Object)); // true
console.log(Type.is([], Array)); // true
console.log(Type.is(new Date(), Date)); // true
console.log(Type.is(new Date(), Object)); // false
var s = "hihihi";
var Stringy = Type(s);
var t = new Stringy("hihihi");
console.log((s == t)); // true
console.log((s === t)); // false
FAQs
Determine and test types using constructor or {}.toString
The npm package type-of-is receives a total of 63,745 weekly downloads. As such, type-of-is popularity was classified as popular.
We found that type-of-is 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
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.