Socket
Socket
Sign inDemoInstall

u3

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

u3

u3 - Utility Functions


Version published
Weekly downloads
63K
decreased by-15.62%
Maintainers
1
Weekly downloads
 
Created
Source

u3 - Utility Functions

This lib contains utility functions for e3, dataflower and other projects.

Documentation

Installation

npm install u3
bower install u3
Usage

In this documentation I used the lib as follows:

var u3 = require("u3"),
    cache = u3.cache,
    eachCombination = u3.eachCombination;

Function wrappers

cache

The cache(fn) function caches the fn results, so by the next calls it will return the result of the first call. You can use different arguments, but they won't affect the return value.

var a = cache(function fn(x, y, z){
    return x + y + z;
});
console.log(a(1, 2, 3)); // 6
console.log(a()); // 6
console.log(a()); // 6

It is possible to cache a value too.

var a = cache(1 + 2 + 3);
console.log(a()); // 6
console.log(a()); // 6
console.log(a()); // 6

Math

eachCombination

The eachCombination(alternativesByDimension, callback) calls the callback(a,b,c,...) on each combination of the alternatives[a[],b[],c[],...].

eachCombination([
      [1, 2, 3],
      ["a", "b"]
  ], console.log);
  /*
      1, "a"
      1, "b"
      
      2, "a"
      2, "b"
      
      3, "a"
      3, "b"
  */

You can use any dimension and number of alternatives. In the current example we used 2 dimensions. By the first dimension we used 3 alternatives: [1, 2, 3] and by the second dimension we used 2 alternatives: ["a", "b"].

License

MIT - 2016 Jánszky László Lajos

Keywords

FAQs

Package last updated on 22 Sep 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc