Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@jovulic/lazy-promise

jovulic26MIT1.2.2TypeScript support: included

A lazy promise that waits until you ask it to get to work.

lazy, lazy evaluation, lazy loading, memoization, promise, cache, javascript, typescript, async utilities

readme

Disclaimer

This repository is a personal project created for practicing the process of building and publishing an open-source library.


License: MIT NPM Build Status

LazyPromise

A lazy promise that waits until you ask it to get to work.

📌 Description

LazyPromise is a lightweight utility for lazily initializing values in JavaScript and TypeScript. Specifically, it will not perform any computation until the value is accessed (e.g., awaited). Additionally, LazyPromise supports lazy chaining, allowing you to chain operations that also won’t execute until the result is needed.

✨ Features

Lazy evaluation – Compute values only when first accessed.
Lazy Chaining – Define transformations to values lazily.
Minimal – No dependencies.
TypeScript support – Fully typed.

📦 Installation

Using npm:

npm install @jovulic/lazy-promise

Using yarn:

yarn add @jovulic/lazy-promise

Using pnpm:

pnpm add @jovulic/lazy-promise

🚀 Usage

Basic Example

import { LazyPromise } from "@jovulic/lazy-promise";

const lazyValue = new LazyPromise(async () => {
  return "My Lazy Value";
});

(async () => {
  console.log(await lazyValue); // "My Lazy Value"
  console.log(await lazyValue); // "My Lazy Value" (no recomputation)
})();

Lazy Chaining

import { LazyPromise } from "@jovulic/lazy-promise";

const lazyValue = new LazyPromise(async () => {
  return "My Lazy Value";
});

const transformedValue = lazyValue.later((value) => value.toUpperCase());

console.log(await transformedValue); // "MY LAZY VALUE"

🛠️ Build

This project uses Nix for development to ensuring a consistent and reproducible environment. It is easy enough to build without it, but the following guide will be using Nix.

Follow these steps to build and work on the project locally:

  1. Install Nix: If you don't have Nix installed, follow the instructions for your platform at https://nixos.org/download.html.

  2. Clone the Repository: Clone the lazy-promise repository to your local machine.

    git clone https://github.com/jovulic/lazy-promise.git
    cd lazy-promise
  3. Enter the Development Shell: Use the following command to enter the Nix development shell. This will automatically install all the necessary dependencies defined in the flake.nix file.

    nix develop

    This command might take a while the first time as it downloads and installs the dependencies. Subsequent entries into the shell will be much faster.

  4. Install NPM Dependencies: Once inside the Nix shell, you'll need to install the project's npm dependencies. Even though Nix provides Node.js and npm, the project dependencies are managed by npm. We do this via the ctl command that is added into the development shell.

    ctl setup
  5. Build the Library: You can now build the library.

    ctl build

    This will create a dist directory containing the compiled library files.

changelog

Changelog

1.2.2 (2025-05-27)

Features

  • nix: update nixpkgs to 25.05 (2c9ab48)

1.2.1 (2025-04-01)

Documentation

  • remove extraneous bolding (31fdc42)
  • update build status link (8fb398f)
  • update readme example imports to be correct (98d72c3)
  • update readme install instructions (ec20d9a)

Code Refactoring

  • nix: remove flake-utils for inline system function (ce6ffc6)

Build Changes

  • update release please sections (7192273)

General Changes

  • nix: commit flake lock file updates (58e3650)

1.2.0 (2025-02-11)

Features

  • setup release please workflow (b89a183)

Bug Fixes

  • add id-token permission to release workflow (53b2c7b)

Build Changes

Removals

General Changes

  • remove release release please action config (45aea2b)
  • rename workflow build to check (55347ed)

1.1.1 (2025-02-11)

Bug Fixes

  • add id-token permission to release workflow (53b2c7b)

1.1.0 (2025-02-11)

Features

  • test if this triggers user facing commit (1270d42)