What is is-symbol?
The `is-symbol` npm package is designed to provide a simple and efficient way to check if a given value is a Symbol. This can be particularly useful when working with ES6 Symbols, ensuring that operations or functions that require a symbol as an argument are provided with the correct type of value.
What are is-symbol's main functionalities?
Check if a value is a Symbol
This feature allows you to verify whether a given value is a Symbol. It's useful in scenarios where the type of a variable needs to be asserted before performing operations that are specific to Symbols.
const isSymbol = require('is-symbol');
console.log(isSymbol(Symbol('foo'))); // true
console.log(isSymbol('bar')); // false
Other packages similar to is-symbol
lodash.issymbol
Part of the Lodash library, `lodash.issymbol` provides a similar functionality to `is-symbol` by checking if a given value is a Symbol. However, it comes as part of the larger Lodash utility library, which includes a wide range of functions for different types of data manipulation and checking, potentially making it a heavier choice for projects that only require symbol checking.
#is-symbol
Is this an ES6 Symbol value?
Example
var isSymbol = require('is-symbol');
assert(!isSymbol(function () {}));
assert(!isSymbol(null));
assert(!isSymbol(function* () { yield 42; return Infinity; });
assert(isSymbol(Symbol.iterator));
assert(isSymbol(Symbol('foo')));
assert(isSymbol(Symbol.for('foo')));
assert(isSymbol(Object(Symbol('foo'))));
Tests
Simply clone the repo, npm install
, and run npm test