Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
is-primitive
Advanced tools
Returns `true` if the value is a primitive.
Weekly downloads
Package description
The is-primitive npm package is used to check if a given value is a JavaScript primitive. A primitive in JavaScript is data that is not an object and has no methods. In JavaScript, there are 7 primitive data types: string, number, bigint, boolean, undefined, symbol, and null. This package provides a simple and straightforward way to determine if a value belongs to one of these types.
Check if a value is a primitive
This feature allows you to check if a value is a primitive type. The function returns true for primitive values and false for objects (including arrays and functions).
const isPrimitive = require('is-primitive');
console.log(isPrimitive(42)); // true
console.log(isPrimitive('hello')); // true
console.log(isPrimitive(false)); // true
console.log(isPrimitive({})); // false
console.log(isPrimitive([])); // false
console.log(isPrimitive(function() {})); // false
The 'is' package provides a comprehensive set of type-check functions, including checks for primitives. It offers more functionality than is-primitive by including type checks for objects, arrays, regexes, functions, and more.
The 'type-check' package allows you to check the types of JavaScript values with an extended type syntax. It is more complex and feature-rich compared to is-primitive, as it supports custom type definitions and more intricate type checking.
The 'is-type-of' package has a similar purpose to is-primitive but includes additional checks for specific JavaScript types and structures, such as streams, buffers, and errors, making it more versatile for certain applications.
Readme
Returns
true
if the value is a primitive.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm:
$ npm install --save is-primitive
The Mozilla docs for "Primitive values" defines specifies six data types that are primitives:
Boolean
Null
Undefined
Number
String
Symbol
(new in ECMAScript 6)var isPrimitive = require('is-primitive');
All of the following return true
:
console.log(isPrimitive(false));
console.log(isPrimitive(true));
console.log(isPrimitive(null));
console.log(isPrimitive());
console.log(isPrimitive(42));
console.log(isPrimitive('abc'));
console.log(isPrimitive(Symbol()));
//=> true
Everything else returns false
:
console.log(isPrimitive({}));
console.log(isPrimitive([]));
console.log(isPrimitive(function(){}));
console.log(isPrimitive(new Date()));
// et cetera...
//=> false
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
You might also be interested in these projects:
Object
constructor. | homepageCommits | Contributor |
---|---|
11 | jonschlinkert |
1 | ljharb |
1 | bttmly |
1 | hemanth |
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on November 23, 2017.
FAQs
Returns `true` if the value is a primitive.
The npm package is-primitive receives a total of 2,237,586 weekly downloads. As such, is-primitive popularity was classified as popular.
We found that is-primitive demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.