Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
A more precise version of JavaScript's typeof
kind()
returns a useful name for a variable's type. It breaks down objects into more precise terms: array, null, element, etc.
Examples:
Input | typeof | kind |
---|---|---|
[1, 2, 3] | "object" | "array" |
null | "object" | "null" |
document.getElementById('id') | "object" | "element" |
document.getElementsByTagName('div') | "object" | "nodelist" |
document.createTextNode('') | "object" | "node" |
new Date() | "object" | "date" |
{} | "object" | "object" (if no special type was detected — see full list below) |
npm: npm install kindjs
Bower: bower install kind
Or just download kind.js and reference it in your page with a <script>
tag.
Available as a CommonJS module (e.g with RequireJS) or as a global method, kind()
.
// Objects that aren't *really* objects
kind(null); // "null"
kind([1, 2, 3]); // "array"
kind(arguments); // "arraylike"
kind(new Date()); // "date"
kind(document.getElementById('id')); // "element"
kind(document.getElementsByTagName('div')); // "nodelist"
// This one's actually just an object
kind({}); // "object"
// Also works on standard types
kind("text"); // "string"
kind(2); // "number"
kind(alert); // "function"
You may add a second, boolean parameter to tell kind
to perform a deeper test for some types. For example, instead of "number" it could return "integer" or "float".
kind(1); // "number"
kind(1, true); // "integer"
kind(1.21); // "number"
kind(1.21, true); // "float"
kind(evt); // "event"
kind(evt, true); // "mouseevent" (i.e. if the event was a click)
A complete list is noted below
typeof
:
function
, undefined
, boolean
string
string
or emptystring
number
integer
or float
array
arraylike
.length
propertynull
element
node
text
, comment
)nodelist
event
mouseevent
, keyboardevent
)regexp
date
error
errorevent
math
typeof
FAQs
Precise type-checker for JavaScript
The npm package kindjs receives a total of 0 weekly downloads. As such, kindjs popularity was classified as not popular.
We found that kindjs 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
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.