Socket
Socket
Sign inDemoInstall

decorators-js

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    decorators-js

Common javascript decorators


Version published
Weekly downloads
13
increased by1200%
Maintainers
1
Install size
44.7 kB
Created
Weekly downloads
 

Readme

Source

decorators-js

Common javascript decorators and combinators I use all the time. While I love libraries like Ramda this is a lightweight poor man's alternative.

API

curry

n=f.length -> f: Function -> * -> *

Curries function f allowing arguments to be received piecemeal. Can be set to a specific arity, defaults to the arity of the curried function. Works for class constructors as well.

maybe

(f: Function, strict=true) -> * -> null|*

Returns a function that returns null if any of its arguments are null or undefined, otherwise returns the result of applying the function to the arguments. If the passed-in function has an arity of 0 it may be successfully called with no arguments. If strict is set to false the pre-emptive null is only returned if all the arguments are null or undefined.

debounce

(delay: Integer, immediate=false, f: Function) -> * -> Integer

Delay in milliseconds. Returns the timer ID so caller can cancel. The optional boolean parameter is whether the function fires on the leading edge or trailing edge.

throttle (curried)

delay: Integer -> f: Function -> * -> Integer

Throttles passed in function. Returns the setTimeout handle so caller can cancel.

denodeify

f: Function -> * -> Promise<*>

Takes a function that accepts a nodejs-style (error-first) callback and returns a function that returns a Promise of the result instead. If the callback receives multiple non-error parameters then it will return a Promise of an array of the results.

apply (curried)

f: Function -> args: Array<*> -> *

Takes a function that takes positional arguments and returns a function that takes an Array of arguments.

applyConstructor (curried)

class: Class -> args: Array<*> -> Object

Allows a class constructor that takes positional arguments to be given an Array instead. Useful for mapping a constructor over an Array of initialization data.

bindArity (curried)

n: Integer -> f: Function -> * -> *

Applies only the first n received arguments to f. Useful for e.g. mapping parseInt over an Array of Strings: [1, 2, 3] === ["1", "2", "3"].map(d.bindArity(1, parseInt)).

unary

A partial application of bindArity and 1.

pipe

(f: Function, g: Function ...) -> * -> *

Forward function composition. All functions except the first should be unary.

trampoline

f: Function -> * -> *

Uses bounded stack space to run thunk-returning tail-recursive functions.

memoize

f: Function -> * -> *

Caches the result of function calls to avoid re-computation.

bindPromise

f: Function -> Promise<*> -> Promise<*>

Takes a function f from a -> b or a -> Promise b and returns a function Promise a -> Promise b.

Keywords

FAQs

Last updated on 26 May 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc