Determine if a value is primitive.
A value is primitive if it is of a primitive type.
npm install @primitive/is-primitive --save # Install package via NPM
yarn add @primitive/is-primitive # Install package via Yarn
import { expect } from "chai";
import isPrimitive from "@primitive/is-primitive";
expect(isPrimitive("Boo")).to.be.true;
expect(isPrimitive(42)).to.be.true;
expect(isPrimitive(new Symbol("boo"))).to.be.true;
expect(isPrimitive(isPrimitive)).to.be.true;
expect(isPrimitive(undefined)).to.be.true;
expect(isPrimitive(null)).to.be.true;
expect(isPrimitive(true)).to.be.true;
expect(isPrimitive({ foo: "bar" })).to.be.false;
expect(isPrimitive(new String("boo"))).to.be.false;
This package contains TypeScript type declarations. Furthermore, the package uses TypeScript type guards to allow type inference to influence intellisense.
if (isPrimitive(x)) {
// IntelliSense now knows `x` is a primitive value.
let y: Primitive = x;
}
This package can be imported via unpkg as demonstrated below.
<script src="https://unpkg.com/@primitive/is-primitive/dist/index.min.js">
<script type="application/javascript">
var x = 42;
if (isPrimitive(x)) {
// `x` is of a primitive type!
}
</script>
This package uses Gulp for building, and Chai and Mocha for testing.
npm install # Installs dependencies.
npm run build # Build the project.
npm test # Run tests.
Refer to the LICENSE
file for license information.