parent
5d15797fcf
commit
9413cecb8d
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@uci-utils/type",
|
"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",
|
"description": "A variable type check and casting utility - extension of typechecker package plus type casting",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"mocha": "^8.3.2",
|
"mocha": "^8.4.0",
|
||||||
"nodemon": "^2.0.7"
|
"nodemon": "^2.0.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,11 @@ customTypeChecker.isBuffer = function isBuffer(obj) {
|
||||||
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.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
|
// Add custom types to typeMap
|
||||||
let customTypeMap = {
|
let customTypeMap = {
|
||||||
buffer: customTypeChecker.isBuffer,
|
buffer: customTypeChecker.isBuffer,
|
||||||
|
@ -28,4 +33,4 @@ customTypeChecker.getType = function customGetType(value, _typeMap) {
|
||||||
const typeOf = customTypeChecker.getType
|
const typeOf = customTypeChecker.getType
|
||||||
|
|
||||||
export default customTypeChecker
|
export default customTypeChecker
|
||||||
export { customTypeChecker as check, typeOf }
|
export { customTypeChecker as check, typeOf }
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import { check, typecast, cast, toString, toBoolean } from '../src/index.js'
|
import { check, typecast, cast, toString, toBoolean } from '../src/index.js'
|
||||||
|
|
||||||
console.log(typecast.boolean)
|
console.log(typecast.boolean)
|
||||||
console.log(toBoolean)
|
console.log(toBoolean)
|
||||||
|
|
||||||
|
describe('symbol', function () {
|
||||||
|
it('should support isSymbol', function () {
|
||||||
|
assert(check.isSymbol(Symbol('test')))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('.string()', function () {
|
describe('.string()', function () {
|
||||||
it('should return a string', function () {
|
it('should return a string', function () {
|
||||||
assert(typecast.string(2) === '2')
|
assert(typecast.string(2) === '2')
|
||||||
|
|
Loading…
Reference in New Issue