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

util-easy

v0.2.1

Published

Simplify your code! A collection of lightweight JavaScript utilities for effortless coding. Boost your productivity with ease.

Downloads

12

Readme

Util-Easy

Welcome to Util-Easy! This package provides easy-to-use utilities for managing browser storage and optimizing function performance. It's currently in the early stages of development, with many more features planned in the pipeline.

Installation

You can install Util-Easy via npm:

npm install util-easy

Features

Browser Storage Management

Util-Easy offers simple interfaces to handle browser storage efficiently. It provides functions for setting, getting, and clearing properties in both local and session storage.

Local Storage

import { handleLocalStorage } from 'util-easy';

// Initialize local storage handler
const localStorageHandler = handleLocalStorage();

// Set an item in local storage
localStorageHandler.setProperty({ key: 'user', item: { name: 'John' } });

// Get an item from local storage
const user = localStorageHandler.getProperty<{ name: string }>({ key: 'user' });
console.log(user); // { name: 'John' }

// Clear an item from local storage
const result = localStorageHandler.clearProperty<{ name: string }>({ key: 'user' });
console.log(result.success); // true

Session Storage

import { handleSessionStorage } from 'util-easy';

// Initialize session storage handler
const sessionStorageHandler = handleSessionStorage();

// Set an item in session storage
sessionStorageHandler.setProperty({ key: 'token', item: 'abc123' });

// Get an item from session storage
const token = sessionStorageHandler.getProperty<string>({ key: 'token' });
console.log(token); // abc123

// Clear an item from session storage
const result = sessionStorageHandler.clearProperty<string>({ key: 'token' });
console.log(result.success); // true

Function Memoization

Util-Easy includes memoization utilities to optimize function performance, particularly for asynchronous tasks.

import { memoize, memoizeAsync } from 'util-easy';

// Synchronous function memoization
const add = (a: number, b: number) => a + b;
const memoizedAdd = memoize({ callback: add });

console.log(memoizedAdd(2, 3)); // Output: 5 (function called)
console.log(memoizedAdd(2, 3)); // Output: 5 (cached result)

// Asynchronous function memoization
const asyncTask = async (value: number) => {
    await new Promise(resolve => setTimeout(resolve, 1000));
    return value * 2;
};
const memoizedAsyncTask = memoizeAsync({ callback: asyncTask });

memoizedAsyncTask(5).then(result => console.log(result)); // Output: 10 (function called)
memoizedAsyncTask(5).then(result => console.log(result)); // Output: 10 (cached result)

Cache Optimization

import { unstable_cacheFunctionBrowser } from 'util-easy';

// Cache function results in local storage
const cachedFunction = unstable_cacheFunctionBrowser({
    callback: (a: number, b: number) => a + b,
    cacheType: 'localStorage'
});

console.log(cachedFunction?.(2, 3)); // Output: 5 (function called)
console.log(cachedFunction?.(2, 3)); // Output: 5 (cached result)

Low Priority Execution

import { lowPriority, lowPriorityWithTimeout } from 'util-easy';

// Execute a task at low priority
lowPriority(() => console.log('Executing at low priority'));

// Execute a task at low priority with a timeout
lowPriorityWithTimeout({ 
    callback: () => console.log('Executing at low priority with timeout'),
    timeout: 1000
});

Contribution

Contributions are welcome! Feel free to open issues or submit pull requests on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.