Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
component-type
Advanced tools
The component-type npm package is a simple utility for checking the type of a JavaScript value. It is useful for type checking and validation in JavaScript applications.
Type Checking
This feature allows you to check the type of a given JavaScript value. The function returns a string indicating the type of the value.
"use strict"; var type = require('component-type'); console.log(type([])); // 'array' console.log(type({})); // 'object' console.log(type('')); // 'string' console.log(type(123)); // 'number' console.log(type(true)); // 'boolean' console.log(type(null)); // 'null' console.log(type(undefined)); // 'undefined' console.log(type(function(){})); // 'function' console.log(type(new Date())); // 'date' console.log(type(/a-z/)); // 'regexp' console.log(type(new Error())); // 'error'
The 'typeof' package is similar to 'component-type' in that it provides type checking for JavaScript values. However, 'typeof' might have different ways of type representation and may not cover as many types as 'component-type'.
The 'type-is' package is used to determine the content-type of an object, particularly useful for HTTP requests. While it also deals with types, it is more focused on MIME types rather than JavaScript value types.
The 'is-type-of' package provides type checking functionalities similar to 'component-type'. It includes additional checks for specific JavaScript types like 'error', 'buffer', 'promise', etc., and may offer a more extensive set of type checking utilities.
Type assertions aka less-broken
typeof
npm install component-type
import type from 'component-type';
const date = new Date();
console.log(type(date));
//=> 'date'
type(new Date) === 'date'
type({}) === 'object'
type(null) === 'null'
type(undefined) === 'undefined'
type('hey') === 'string'
type(true) === 'boolean'
type(false) === 'boolean'
type(12) === 'number'
type(type) === 'function'
type(/asdf/) === 'regexp'
type((function(){ return arguments })()) === 'arguments'
type([]) === 'array'
type(document.createElement('div')) === 'element'
type(NaN) === 'nan'
type(new Error('Oh noes')) === 'error'
type(new Buffer) === 'buffer'
It makes no guarantees about the correctness when fed untrusted user-input.
FAQs
Type assertions aka less-broken `typeof`
The npm package component-type receives a total of 1,088,604 weekly downloads. As such, component-type popularity was classified as popular.
We found that component-type demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 21 open source maintainers 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 found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.