2019-11-21 10:40:24 -08:00
|
|
|
import * as typechecker from 'typechecker'
|
2019-02-16 11:45:22 -08:00
|
|
|
|
2020-03-16 10:24:22 -07:00
|
|
|
// TODO add observable types and other custom uci types
|
|
|
|
|
2019-02-16 11:45:22 -08:00
|
|
|
const customTypeChecker = Object.assign({}, typechecker) // typechecker is frozen
|
|
|
|
|
|
|
|
// add custom types
|
|
|
|
customTypeChecker.isPromise = function isPromise(obj) {
|
|
|
|
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'
|
|
|
|
}
|
|
|
|
|
|
|
|
customTypeChecker.isBuffer = function isBuffer(obj) {
|
|
|
|
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add custom types to typeMap
|
|
|
|
let customTypeMap = {
|
|
|
|
buffer: customTypeChecker.isBuffer,
|
|
|
|
promise: customTypeChecker.isPromise
|
|
|
|
}
|
|
|
|
|
|
|
|
customTypeMap = Object.assign(customTypeMap, customTypeChecker.typeMap)
|
|
|
|
|
|
|
|
customTypeChecker.getType = function customGetType(value, _typeMap) {
|
|
|
|
return typechecker.getType(value, _typeMap || customTypeMap)
|
|
|
|
}
|
|
|
|
|
2020-03-16 10:52:12 -07:00
|
|
|
const typeOf = customTypeChecker.getType
|
|
|
|
|
2019-02-16 11:45:22 -08:00
|
|
|
export default customTypeChecker
|
2020-03-16 10:52:12 -07:00
|
|
|
export { customTypeChecker as check, typeOf }
|