Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
is-primitive
Advanced tools
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.
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.
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
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.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.