Minimalist Utility Library (ul)

5.2.16 · maintenance · verified Sun Apr 19

ul is a minimalist JavaScript utility library, currently at version 5.2.16, providing essential object manipulation functions such as one-level merging (`merge`), deep merging (`deepMerge`), and deep cloning (`clone`), alongside a cross-platform helper for retrieving the user's home directory (`home`). Its release cadence is primarily focused on documentation updates and maintainer support links, indicating a stable and mature project rather than one under rapid feature development. Key differentiators include its small footprint and straightforward API for common utility tasks, making it suitable for projects that prefer to avoid larger utility libraries like Lodash for basic operations.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates `ul`'s core functionalities: `deepMerge` for recursive object merging, `clone` for creating deep copies, and `home()` or `HOME_DIR` for retrieving the user's home directory path. It also highlights the behavior of `merge` for shallow merging.

import Ul from 'ul';

// Input data
let obj = {
       n: null,
       v: 1
    };
  , def = {
        n: 1,
        v: 10,
        a: 20
    };
  , tmp = null;


// Merge the two objects and store the result in tmp
console.log('Deep Merge Result:', tmp = Ul.deepMerge(obj, def));
// Expected output: { n: null, v: 1, a: 20 }
// Illustrates how `null` values in `obj` are preserved even if `def` has a non-null value.

// Clone the tmp object -- the clone will have a different reference
const clonedTmp = Ul.clone(tmp);
console.log('Cloned Object:', clonedTmp);
console.log('Is clone identical to original reference?', tmp === clonedTmp);
// Expected output: false (demonstrates deep cloning creates a new reference)

// Show the absolute path to the home directory
console.log('Home Directory (function call):', Ul.home());
console.log('Home Directory (property access):', Ul.HOME_DIR);
// Path will vary by OS, e.g., /home/user or C:\Users\user

// One level merge
console.log('One-Level Merge Result:', Ul.merge({
    foo: {
        bar: 42
    }
}, {
    foo: {
        bar: 1,
        baz: 7
    }
}));
// Expected output: { foo: { bar: 42 } } (demonstrates shallow merge behavior, inner 'foo' object from first arg is preserved)

view raw JSON →