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.
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) |
yarn: yarn add kindjs
npm: npm install kindjs
import kind from 'kindjs';
kind(['hello', 'world']);
//=> 'array'
// 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
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.
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.