Socket
Socket
Sign inDemoInstall

component-type

Package Overview
Dependencies
0
Maintainers
21
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    component-type

Type assertions aka less-broken `typeof`


Version published
Weekly downloads
1.3M
decreased by-2.49%
Maintainers
21
Install size
3.95 kB
Created
Weekly downloads
 

Package description

What is component-type?

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.

What are component-type's main functionalities?

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'

Other packages similar to component-type

Readme

Source

component-type

Type assertions aka less-broken typeof

Install

npm install component-type

Usage

import type from 'component-type';

const date = new Date();

console.log(type(date));
//=> 'date'

API

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.

Keywords

FAQs

Last updated on 16 Nov 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc