npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@joookiwi/lazy

v1.4.0

Published

A Javascript implementation of the Kotlin lazy

Downloads

18

Readme

Lazy (javascript version)

Table of content

This project is a simple implementation of the Kotlin Lazy. And if in any shape or form, there is a NPM usage from the Kotlin team itself, this will become deprecated.

With that clarified, here is how it can be used.

Installation

npm install @joookiwi/lazy
npm i @joookiwi/lazy

npm install --save @joookiwi/lazy
npm i -S @joookiwi/lazy

npm install --save-dev @joookiwi/lazy
npm i -D @joookiwi/lazy

Usage

The usage is similar to the kotlin usage like val value by lazy { someValue } in kotlin as well as the non-lazy implementation like val value = lazyOf(someValue).

But since there is no apparent dependency toward this specifically. Here is a simple implementation of the lazy via 2 functions

  • lazy to load the value later
  • lazyOf to have a Lazy but with an already loaded value

Lazy value

Using the lazy value will always return a Lazy object holding a value.

import {lazy} from "@joookiwi/lazy"

const firstValue = lazy(() => 2)
firstValue.isInitialized // false
firstValue.value         // 2
firstValue.isInitialized // true

Non-lazy value

If the value is already known, then just use lazyOf() in order to have a Lazy with an already loaded value.

import {lazyOf} from "@joookiwi/lazy"

const firstValue = lazyOf(2)
firstValue.isInitialized // true
firstValue.value         // 2
firstValue.isInitialized // true

Common lazy

When using the lazy methods, it always creates a new instance.

But, there could be some cases where an already known value is there.

Here is the full list of the common Lazy instances:

| Value | With string | With character | With BigInt | |----------------------------------------------------|:------------|:---------------|:------------| | null | yes | | | | undefined | yes | | | | true / false | yes | | | | -1 / 0 / 1 / 2 | yes | yes | yes | | NaN / Infinity / -Infinity | yes | | | | ln(2) / ln(10) | | | | | log₂(E) / log₁₀(E) | | | | | E, PI | | | | | / \t / \n | | yes | | | epoch / now / tomorrow / yesterday | | | | | invalid Date | yes | | | | empty String → '' | | | | | empty object → Readonly<{}> | | | | | empty Array → readonly [] | | | | | empty Set → ReadonlySet<never> | | | | | empty WeakSet → Readonly<WeakSet<never>> | | | | | empty Map → ReadonlyMap<unknown, never> | | | | | empty WeakMap → Readonly<WeakMap<object, never>> | | | |

Contribution

You can contribute to great simple packages. All with similar behaviour across different languages (like Java, Kotlin, C# and PHP). It can be done 2 different ways: