add isSymbol checker until type modules adds it.
master
Kebler Network System Administrator 2021-05-07 14:17:53 -07:00
parent 5d15797fcf
commit 9413cecb8d
3 changed files with 16 additions and 5 deletions

View File

@ -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"
}
}

View File

@ -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 }

View File

@ -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')