Socket
Socket
Sign inDemoInstall

lazy-val

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazy-val


Version published
Maintainers
1
Created

Package description

What is lazy-val?

The lazy-val npm package provides a way to lazily evaluate values. This means that the value is only computed when it is needed, which can help improve performance and reduce unnecessary computations.

What are lazy-val's main functionalities?

Lazy Value Initialization

This feature allows you to define a value that is only computed when it is first accessed. Subsequent accesses to the value will return the cached result without recomputing it.

const { Lazy } = require('lazy-val');

const lazyValue = new Lazy(() => {
  console.log('Computing the value...');
  return 42;
});

console.log('Before accessing the value');
console.log(lazyValue.value); // Logs 'Computing the value...' and then '42'
console.log('After accessing the value');
console.log(lazyValue.value); // Logs '42' without recomputing

Resetting the Lazy Value

This feature allows you to reset the lazy value, forcing it to recompute the next time it is accessed.

const { Lazy } = require('lazy-val');

const lazyValue = new Lazy(() => {
  console.log('Computing the value...');
  return Math.random();
});

console.log(lazyValue.value); // Computes and logs the value
lazyValue.reset();
console.log(lazyValue.value); // Recomputes and logs the new value

Other packages similar to lazy-val

Readme

Source

lazy-val

Lazy value.

class Lazy<T> {
    constructor(creator: () => Promise<T>)
    readonly hasValue: boolean
    value: Promise<T>
}

FAQs

Last updated on 14 May 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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc