0.3.0 • Published 4 years ago
tslang-utils v0.3.0
tslang utils
Some functional/semantic codes for TypeScript(JavaScript) development.
installation
$ yarn add tslang-utilstype 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) // falseisFunc
Whether value is Function type
isFunc(() => {}) // true
isFunc(true) // falseisString
isString('') // true
isString(true) // falseisNumber
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) // falseisStrictNumber
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') // falseEnv
isServer
Whether current JS runtime is in the server(node.js) environment.
isSever() // true or falseisBrowser
Whether current JS runtime is in the browser environment.
isBrowser() // true or false