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

@hibas123/utils

v2.2.10

Published

Different Utilities, that are not worth own packages

Downloads

37

Readme

Utils

The utils only use standard JavaScript, so they can be used in Browser and NodeJS.

Also they are very small. Uncompressed and unminified only 3kb.

The utils have TypeScript definitions and are compatible with ES2015.

Lock

Lock is a very simple promise based Locking mechanism for JavaScript.

Usage:

    import { Lock } from "@hibas123/utils";

    const lock = new Lock();

    async doThingThatNeedsLocking() {
        let release = await lock.getLock(); // This will wait till lock from others is released

        // Do stuff that requires lock

        release(); // Release lock
    }

Observable

Very simple and light weight Observable.

Usage:

    import { Observable } from "@hibas123/util";

    const server = new Observable(); // Get new Observable Server

    // Server can send and subscribe to messages
    // The publicAPI will only make the receiving parts available
    const public = server.getPublicApi();

    const func = (data)=>{
        console.log(data);
    }

    // func will be callen when a message is available
    let unsubscribe = public.subscribe(func);

    server.send("Hello World");

    // Unsubscribe using the returned function from subscribe
    unsubscribe();

    // OR

    // This will unsubscribe the function. Please note, that it can
    // only unsubscribe the exact function, that is used in subscribe
    public.unsubscribe(func);

    // This now won't call func anymore
    server.send("Hello World2");

AwaitStore

This component can be used to await a specific value or to act as an variable with events.

Usage:

    import { AwaitStore } from "@hibas123/util";

    const server = new AwaitStore<number>(0); // Set initial value

    // Server can send and subscribe to messages
    // Only receiving is possible using the public API
    const public = server.getPublicApi();

    const func = (data)=>{
        console.log(data);
    }
    
    // awaitValue will also return a .ignore() function, that can be used to abort the promise completely
    public.awaitValue(5).then(()=>console.log("Got 5"));

    // func will be callen when a message is available and once with the current value
    // This will call func with the current value (0) and on every change after.
    public.subscribe(func);

    // This send will trigger the subscribtion func and also release the awaitValue causing "Got 5"
    // to appear in the console
    server.send(5);

    // This will unsubscribe the function. Please note, that it can
    // only unsubscribe the exact function, that is used in subscribe
    public.unsubscribe(func);

    // This now won't call func anymore
    server.send(8);

License

MIT

Copyright (c) 2019 Fabian Stamm

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.