u3 Utility Functions

0.1.1 · abandoned · verified Sun Apr 19

The package `u3` (version 0.1.1) provides a small collection of general-purpose utility functions, primarily demonstrated with `cache` for function memoization and `eachCombination` for iterating through all permutations of given alternatives. First released in 2016, its low version number and lack of recent updates strongly suggest it is no longer actively maintained, making it an abandoned project. Its primary differentiators are its minimal footprint and specific focus on these two common patterns, likely intended for internal project use rather than a broad utility library like Lodash or Underscore. It exclusively uses CommonJS modules, reflecting its age, and does not appear to have a defined release cadence beyond its initial publication. It was designed to offer basic helper functions for related projects such as `e3` and `dataflower`.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import `u3` using CommonJS `require`, utilize the `cache` function for memoizing both function results and raw values, and iterate through combinations using `eachCombination`.

const u3 = require('u3');

// Use the cache function for memoization
const memoizedSum = u3.cache(function calculateSum(x, y, z) {
    console.log('Calculating sum for:', x, y, z);
    return x + y + z;
});

console.log('Memoized sum (first call):', memoizedSum(1, 2, 3)); // Output: Calculating sum for: 1 2 3, Memoized sum (first call): 6
console.log('Memoized sum (subsequent call, arguments ignored):', memoizedSum(10, 20, 30)); // Output: Memoized sum (subsequent call, arguments ignored): 6

// Cache a simple value directly
const cachedValue = u3.cache(Math.PI * 2);
console.log('Cached value:', cachedValue()); // Output: Cached value: 6.283185307179586

// Use eachCombination to iterate through permutations
console.log('\n--- Combinations ---');
u3.eachCombination([
    [10, 20, 30],
    ['A', 'B']
], function() {
    console.log.apply(console, arguments);
});
/* Expected console output for combinations:
10, A
10, B
20, A
20, B
30, A
30, B
*/

view raw JSON →