From 9413cecb8dd4293f0f69565a59c4c1b0dc3b7261 Mon Sep 17 00:00:00 2001 From: "kebler.net" Date: Fri, 7 May 2021 14:17:53 -0700 Subject: [PATCH] 0.6.2 add isSymbol checker until type modules adds it. --- package.json | 4 ++-- src/check.js | 7 ++++++- test/cast.test.js | 10 ++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ea675c2..8d56d1c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uci-utils/type", - "version": "0.6.1", + "version": "0.6.2", "description": "A variable type check and casting utility - extension of typechecker package plus type casting", "main": "src/index.js", "type": "module", @@ -36,7 +36,7 @@ }, "devDependencies": { "chai": "^4.3.4", - "mocha": "^8.3.2", + "mocha": "^8.4.0", "nodemon": "^2.0.7" } } diff --git a/src/check.js b/src/check.js index 0abc16b..12407d8 100644 --- a/src/check.js +++ b/src/check.js @@ -13,6 +13,11 @@ customTypeChecker.isBuffer = function isBuffer(obj) { return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) } +customTypeChecker.isSymbol = function isSymbol(x) { + return typeof x === 'symbol' + || typeof x === 'object' && Object.prototype.toString.call(x) === '[object Symbol]'; +} + // Add custom types to typeMap let customTypeMap = { buffer: customTypeChecker.isBuffer, @@ -28,4 +33,4 @@ customTypeChecker.getType = function customGetType(value, _typeMap) { const typeOf = customTypeChecker.getType export default customTypeChecker -export { customTypeChecker as check, typeOf } +export { customTypeChecker as check, typeOf } diff --git a/test/cast.test.js b/test/cast.test.js index fc3142d..db3c81e 100644 --- a/test/cast.test.js +++ b/test/cast.test.js @@ -1,9 +1,15 @@ -import assert from 'assert' -import { check, typecast, cast, toString, toBoolean } from '../src/index.js' +import assert from 'assert' +import { check, typecast, cast, toString, toBoolean } from '../src/index.js' console.log(typecast.boolean) console.log(toBoolean) +describe('symbol', function () { + it('should support isSymbol', function () { + assert(check.isSymbol(Symbol('test'))) + }) +}) + describe('.string()', function () { it('should return a string', function () { assert(typecast.string(2) === '2')