vi-misc

1.14.1 • Public • Published

vi-misc

NPM version build status Test coverage

A set of utils...

misc.function

Utils for functions

  • function.once(...func_list) - make sure the given functions will not be executed more than onece.
  • function.limit(func_list, options) - make sure the given functions will be executed more than a certain count.

misc.number

The number utils

  • number.th - Append 'th' on a number.

misc.object

Utils for objects.

  • clone(object) - Deep clone
  • merge(object, ...sources) - Deep merge
  • each(object, handler) - Apply handlers for each property of the object.
  • hasByKey(object, ...keys) - Test if object.xxx.xxx.xxx exists, which xxx,xxx,xxx as just the param 'keys'
  • setByKeys(object, value, ...keys)
  • getByKeys(object, value, ...keys)
    • This is supposed to be used when keys are dynamic and uncertain. In other cases, use object.xx.xx.xx directly.

misc.path

The path utils

  • path.root - returns the app root, which is the directory of main module file.
  • path.absolute(target) - make target into absolute form and return.
  • path.split(target, sep = path.sep) - split target into array.

misc.async

Promisify with bluebird

  • all(target, options) - Promisify all method for callback(error, result) like cases.
  • catchError(promise) - Catch and return the error the promise throws. Otherwise returns null.

misc.time

The time utils

  • time.format - format time, time.format('YYYY-MM-DD HH:II:SS').

misc.Error

The custom error

  • new Error(message, code) - Create an error with custom code
  • new Error(message, props) - Create an error with properties assigned with argument props

Dependencies (2)

Dev Dependencies (5)

Package Sidebar

Install

npm i vi-misc

Weekly Downloads

10

Version

1.14.1

License

none

Unpacked Size

27.3 kB

Total Files

19

Last publish

Collaborators

  • viringbells