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

funcs-js

v2.0.0

Published

Function wrappers for enhanced behavior.

Downloads

1,101

Readme

funcs-js

NPM Version CI Coverage Status Known Vulnerabilities Inline docs License Total Downloads

Function wrappers for enhanced behavior.

Overview

The funcs-js provides different utility functions which enable to wrap functions and modify their behavior.

This library requires no external dependencies, and it is supported for both browser and node.js environments.

Usage

In order to use the library in browser, you first must add the relevant dependency:

<script type="text/javascript" src="funcs.js"></script>

When using an AMD loader (such as RequireJS) or CommonJS type loader, the funcs object is not automatically defined on the window scope.

For node.js, simply require the module as follows:

var funcs = require('funcs-js');

'funcs.once(fn, [options]) ⇒ function'

Ensures the provided function is invoked only once. This is the same as calling funcs.maxTimes(fn, 1) This function output can be chained with other funcs apis.

Example

const onlyOnceCallback = funcs.once(callback);

//can also chain multiple modifications (chained functions do not require original function as argument)
const asyncOnceCallback = funcs.once(callback).async();

'funcs.maxTimes(fn, times, [options]) ⇒ function'

Wraps the provided function and ensures it is invoked no more than the provided amount. This function output can be chained with other funcs apis.

Example

const onlyOnceCallback = funcs.maxTimes(callback, 1);

//can also chain multiple modifications (chained functions do not require original function as argument)
const delayedMaxTimesCallback = funcs.maxTimes(callback, 5).delay(500);

'funcs.async(fn, [options]) ⇒ function'

Ensures the function is invoked only in the next cycle. This is the same as calling funcs.delay(fn, 0) This function output can be chained with other funcs apis.

Example

const asyncCallback = funcs.async(callback);

//can also chain multiple modifications (chained functions do not require original function as argument)
const asyncOnceCallback = funcs.async(callback).once();

'funcs.delay(fn, [delay], [options]) ⇒ function'

Trigger the actual function only after the provided delay. This function output can be chained with other funcs apis.

Example

const delayedCallback = funcs.delay(callback, 500);

//can also chain multiple modifications (chained functions do not require original function as argument)
const delayedMaxTimesCallback = funcs.delay(callback, 500).maxTimes(5);

'funcs.isFunction([fn]) ⇒ Boolean'

Returns true if the provided argument is a function.

Example

const isFn = funcs.isFunction(myFunction);

funcs.isFunction(function () {}); //true
funcs.isFunction(); //false
funcs.isFunction(5); //false
funcs.isFunction(true); //false

'funcs.noop() ⇒ undefined'

Empty function.

'funcs.ensure([fn]) ⇒ function'

Ensures a return function. If a function is provided, it will be returned, otherwise a noop function will be returned.

Example

const handler = funcs.ensure(maybeHandler);

Installation

Run npm install in your project as follows:

npm install --save funcs-js

Or if you are using bower, you can install it as follows:

bower install funcs-js --save

API Documentation

See full docs at: API Docs

Contributing

See contributing guide

Release History

| Date | Version | Description | | ----------- | ------- | ----------- | | 2020-05-12 | v2.0.0 | Migrate to github actions, upgrade minimal node version and remove bower | | 2019-02-08 | v1.0.18 | Maintenance | | 2017-04-28 | v1.0.1 | Offical release | | 2017-04-28 | v0.0.6 | Docs | | 2017-04-28 | v0.0.5 | Rename package as funcs-js | | 2017-04-27 | v0.0.1 | Initial release |

License

Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.