Skip to content

Latest commit

 

History

History
113 lines (81 loc) · 5.64 KB

File metadata and controls

113 lines (81 loc) · 5.64 KB

Helper functions

Helper functions are a collection of commonly used function. This collection should help you to avoid the need of external modules like "underscore" or similiar and allows you to writer smaler plugins.

Table of contents

debounce(func, wait[, immediate])

Debounce a function call.

  • func {Function} Function that is called after wait elapsed.
  • wait {Number} Time in ms to wait before call fnc.
  • immediate {Boolean} Call func immediatly when return function is called.

Returns a function that is called instead directly of func.

extend(target, ...sources)

Merges one or more sources into a single target.

  • target {Object} Target where all sources are merged into.
  • ...sources {Array|Object} Things that are merged into target.

infinty(worker[, delay=3000])

Calls the worker function, passes a "retry" function as only argument. If the retry function is called, its wait the time set as delay and call then the worker code again

  • worker {Function} Worker callback that is with a delay of time called.
  • delay {Number} Delay to wait before callingworker again.

Ifinity function handling. For "redo" every time the "retery" function is called.

iterate(obj, cb)

Iterate over everything inside the object. Including ever item in arrays/sub-objects.

  • obj {Object} Target object on which the iteration is procceded.
  • cb {Function} Function that is called on each iteration step.

mixins(objs, options[, lookup])

Mix/merge a bunch of objects into a single one.

observe(target[, options, getter, setter])

Observe changes on a object.

  • target {Object} to observe.
  • options {Object} Options object.
  • options.intercept {Boolean} Intercept get/set calls. If set, setter/getter must return true/false to permit the opertion
  • getter {Function} Function that is called on get opertions. See handler.get()
  • setter {Function} Function that is called on set opertions. See handler.set()

Returns the observed object, where changes trigger setter/getter

promisify(worker, cb)

Promsify a callback function.

  • worker {Function} Function which is wrapped.
  • cb {Function} Callback, which can be omited. If undefined or set to "falsly" value, a promise is returned.

queue(counter, cb)

Queue a function call to counter.

  • counter {Number} Counter, how often the returned function needed to be called to fire cb.
  • cb {Function} Callback which is fired when the returned function is called counter times.

Returns a function, that needs to be called x times.

request(url[,options[,cb]])

Does a HTTP/HTTPS request to url
Just axios or fetch with build in node.js modules
See http module for more information

  • url {String} URL to the resource
  • options {Object} Options for http request
  • cb {Function} Callback with the result for the request

sanitize.encode(input[,rules])

Replace malicious chars with html encoded entities

  • input {String} String that contains potential malicious input
  • rules {Array} additional rule set

Return the encoded string

sanitize.decode(input[,rules])

Replace html encoded entites with original chars

  • input {String} String that contains potential malicious input
  • rules {Array} additional rule set

Return the decoded string

timeout(time, cb)

Calls a callback function automaticly after time, unless the returned function is not called before timeout is reached.

  • time {Number} Timeout it ms to wait before call cb.
  • cb {Function} Callback which should be called after time.

Return a function that can be called to trigger cb.