npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

decorators-js

v4.0.0

Published

Common javascript decorators

Downloads

13

Readme

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.