tslang-utils
v0.3.0
Published
Some functional/semantic codes for TypeScript(JavaScript) development.
Downloads
239
Readme
tslang utils
Some functional/semantic codes for TypeScript(JavaScript) development.
installation
$ yarn add tslang-utils
type checker
isDef
Whether value isn't undefined
or null
.
const a = { name: 'github user', bio: null }
isDef(a.name) // true
isDef(a.age) // false
isDef(a.bio) // false
isFunc
Whether value is Function
type
isFunc(() => {}) // true
isFunc(true) // false
isString
isString('') // true
isString(true) // false
isNumber
Whether value is Number
type. It will omit NaN
when we set second parameter to true
.
isNumber(0) // true
isNumber(NaN) // true
isNumber(NaN, true) // false
isStrictNumber
Equivalent to isNumber(/* value */, true)
.
hasOwnProp
Whether an object has a property with the specified name.
const a = { name: 'github user', bio: null }
hasOwnProp(a, 'name') // true
hasOwnProp(a, 'toString') // false
Env
isServer
Whether current JS runtime is in the server(node.js) environment.
isSever() // true or false
isBrowser
Whether current JS runtime is in the browser environment.
isBrowser() // true or false