Socket
Socket
Sign inDemoInstall

kind-of

Package Overview
Dependencies
0
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    kind-of

Get the native type of a value.


Version published
Maintainers
1
Install size
8.54 kB
Created

Package description

What is kind-of?

The kind-of npm package is a utility library that allows developers to check the type of a given value in JavaScript. It provides a simple API to determine whether a value is a string, number, array, object, function, and other JavaScript types. This can be particularly useful for type checking and validation in applications where type safety is important.

What are kind-of's main functionalities?

Type checking for primitives

This feature allows you to check the type of primitive values such as numbers, strings, and booleans.

"use strict"; const kindOf = require('kind-of'); console.log(kindOf(1)); // 'number' console.log(kindOf('hello')); // 'string' console.log(kindOf(true)); // 'boolean'

Type checking for objects

This feature allows you to check the type of object-based values such as plain objects, arrays, and regular expressions.

"use strict"; const kindOf = require('kind-of'); console.log(kindOf({})); // 'object' console.log(kindOf([])); // 'array' console.log(kindOf(/foo/)); // 'regexp'

Type checking for functions and undefined

This feature allows you to check the type of functions and the undefined value.

"use strict"; const kindOf = require('kind-of'); console.log(kindOf(function () {})); // 'function' console.log(kindOf(undefined)); // 'undefined'

Type checking for null and dates

This feature allows you to check the type of null values and date objects.

"use strict"; const kindOf = require('kind-of'); console.log(kindOf(null)); // 'null' console.log(kindOf(new Date())); // 'date'

Other packages similar to kind-of

Changelog

Source

[0.1.0] - 2014-9-26

  • first commit

Readme

Source

kind-of NPM version

Get the native type of a value.

Install

Install with npm:
npm i kind-of --save-dev

Run tests

npm test

Usage

var kindOf = require('kind-of');

kindOf(undefined);
//=> 'undefined'

kindOf(null);
//=> 'null'

kindOf(true);
//=> 'boolean'

kindOf(false);
//=> 'boolean'

kindOf(new Boolean(true));
//=> 'boolean'

kindOf(42);
//=> 'number'

kindOf(new Number(42));
//=> 'number'

kindOf("string");
//=> 'string'

kindOf(arguments);
//=> 'arguments'

kindOf({});
//=> 'object'

kindOf(new Test());
//=> 'object'

kindOf(new Date());
//=> 'date'

kindOf([]);
//=> 'array'

kindOf([1, 2, 3]);
//=> 'array'

kindOf(new Array());
//=> 'array'

kindOf(/[\s\S]+/);
//=> 'regexp'

kindOf(new RegExp('^' + 'foo$'));
//=> 'regexp'

kindOf(function () {});
//=> 'function'

kindOf(new Function());
//=> 'function'

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on September 26, 2014.

Keywords

FAQs

Last updated on 26 Sep 2014

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