time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (2657B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # isSymbol
     22 
     23 > Test if a value is a [symbol][mdn-symbol].
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var isSymbol = require( '@stdlib/assert/is-symbol' );
     31 ```
     32 
     33 #### isSymbol( value )
     34 
     35 Tests if a value is a [symbol][mdn-symbol].
     36 
     37 ```javascript
     38 var Symbol = require( '@stdlib/symbol/ctor' );
     39 
     40 var bool = isSymbol( Symbol( 'beep' ) );
     41 // returns true
     42 
     43 bool = isSymbol( Object( Symbol( 'beep' ) ) );
     44 // returns true
     45 ```
     46 
     47 #### isSymbol.isPrimitive( value )
     48 
     49 Tests if a `value` is a primitive [symbol][mdn-symbol].
     50 
     51 ```javascript
     52 var Symbol = require( '@stdlib/symbol/ctor' );
     53 
     54 var bool = isSymbol.isPrimitive( Symbol( 'beep' ) );
     55 // returns true
     56 
     57 bool = isSymbol.isPrimitive( Object( Symbol( 'boop' ) ) );
     58 // returns false
     59 ```
     60 
     61 #### isSymbol.isObject( value )
     62 
     63 Tests if a `value` is a [`Symbol`][mdn-symbol] object.
     64 
     65 ```javascript
     66 var Symbol = require( '@stdlib/symbol/ctor' );
     67 
     68 var bool = isSymbol.isObject( Symbol( 'beep' ) );
     69 // returns false
     70 
     71 bool = isSymbol.isObject( Object( Symbol( 'boop' ) ) );
     72 // returns true
     73 ```
     74 
     75 </section>
     76 
     77 <!-- /.usage -->
     78 
     79 <section class="examples">
     80 
     81 ## Examples
     82 
     83 <!-- eslint-disable no-restricted-syntax, no-empty-function -->
     84 
     85 <!-- eslint no-undef: "error" -->
     86 
     87 ```javascript
     88 var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' );
     89 var Symbol = require( '@stdlib/symbol/ctor' );
     90 var isSymbol = require( '@stdlib/assert/is-symbol' );
     91 
     92 var bool;
     93 if ( hasSymbolSupport() ) {
     94     bool = isSymbol( Symbol( 'beep' ) );
     95     // returns true
     96 } else {
     97     console.log( 'Environment does not support symbols.' );
     98 }
     99 bool = isSymbol( 'beep' );
    100 // returns false
    101 
    102 bool = isSymbol( {} );
    103 // returns false
    104 
    105 bool = isSymbol( [] );
    106 // returns false
    107 
    108 bool = isSymbol( null );
    109 // returns false
    110 
    111 bool = isSymbol( void 0 );
    112 // returns false
    113 
    114 bool = isSymbol( true );
    115 // returns false
    116 
    117 bool = isSymbol( function foo() {} );
    118 // returns false
    119 ```
    120 
    121 </section>
    122 
    123 <!-- /.examples -->
    124 
    125 <section class="links">
    126 
    127 [mdn-symbol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
    128 
    129 </section>
    130 
    131 <!-- /.links -->