@primitive/is-primitive
v1.1.0
Published
Determine if a value is primitive
Downloads
3
Readme
is-primitive
Determine if a value is primitive.
A value is primitive if it is of a primitive type.
Usage
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;
}
Content Delivery Network (CDN)
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>
Build & Test
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.
License
Refer to the LICENSE
file for license information.