@stdlib/assert-is-primitive
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.6 • Public • Published

    isPrimitive

    NPM version Build Status Coverage Status dependencies

    Test if a value is a JavaScript primitive.

    Installation

    npm install @stdlib/assert-is-primitive

    Usage

    var isPrimitive = require( '@stdlib/assert-is-primitive' );

    isPrimitive( value )

    Tests if a value is a JavaScript primitive.

    var bool = isPrimitive( false );
    // returns true

    Notes

    • Seven primitives:

      • string
      • number
      • boolean
      • null
      • undefined
      • symbol (ES6/ES2015)
      • bigint (ES11/ES2020)

    Examples

    var isPrimitive = require( '@stdlib/assert-is-primitive' );
    
    var bool = isPrimitive( false );
    // returns true
    
    bool = isPrimitive( 0 );
    // returns true
    
    bool = isPrimitive( '' );
    // returns true
    
    bool = isPrimitive( null );
    // returns true
    
    bool = isPrimitive( void 0 );
    // returns true
    
    bool = isPrimitive( [] );
    // returns false
    
    bool = isPrimitive( {} );
    // returns false
    
    bool = isPrimitive( function noop() {} );
    // returns false
    
    bool = isPrimitive( new Boolean() );
    // returns false
    
    bool = isPrimitive( new String() );
    // returns false
    
    bool = isPrimitive( new Array() );
    // returns false
    
    bool = isPrimitive( new Object() );
    // returns false

    Notice

    This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

    For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

    Community

    Chat


    License

    See LICENSE.

    Copyright

    Copyright © 2016-2021. The Stdlib Authors.

    Install

    npm i @stdlib/assert-is-primitive

    Homepage

    stdlib.io

    DownloadsWeekly Downloads

    158

    Version

    0.0.6

    License

    Apache-2.0

    Unpacked Size

    35 kB

    Total Files

    9

    Last publish

    Collaborators

    • stdlib-bot
    • kgryte
    • planeshifter
    • rreusser