0.3.0 • Published 3 years ago

tslang-utils v0.3.0

Weekly downloads
9
License
MIT
Repository
github
Last release
3 years ago

tslang utils

Some functional/semantic codes for TypeScript(JavaScript) development.

Pipeline

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

License

MIT © Liu Bowen