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

koloocheh

v4.0.5

Published

**Koloocheh**: A lightweight JavaScript library designed to simplify the management of cookies, localStorage, sessionStorage, and IndexedDB on the frontend. With its easy-to-use API, Koloocheh allows developers to effortlessly handle data storage and re

Downloads

30

Readme

Koloocheh

A simple JavaScript package for managing cookies, localStorage, sessionStorage, and IndexedDB on the frontend. This package provides functions for cookie management (setCookie, getCookie, deleteCookie, clearCookie), localStorage management (setLocal, getLocal, removeLocal, clearLocal), sessionStorage management (setSession, getSession, removeSession, clearSession), and IndexedDB management (IndexedDBManager).

Installation

You can install the package using npm:

npm install koloocheh

Cookie Functions

setCookie(name, value, days, path = '/', secure = false, sameSite = false)

Sets a cookie with the specified parameters. If days is set to 0, the cookie will not have an expiration date.

  • name: The name of the cookie (String).
  • value: The value of the cookie (String).
  • days: The number of days until the cookie expires (Number). Use 0 to create a session cookie with no expiration.
  • path: The path where the cookie is accessible (String, optional, default: /).
  • secure: Indicates if the cookie should only be transmitted over secure protocols (Boolean, optional, default: false).
  • sameSite: Indicates if the cookie should be restricted to first-party or same-site contexts (Boolean, optional, default: false).

Example:

setCookie('username', 'JohnDoe', 7, '/', true, true); // Expires in 7 days
setCookie('session_id', '123456', 0); // Session cookie with no expiration

getCookie(name)

Retrieves the value of the specified cookie.

  • name: The name of the cookie to retrieve (String).

Returns: The value of the cookie or null if the cookie does not exist.

Example:

const username = getCookie('username');
console.log(username); // Outputs: JohnDoe

deleteCookie(name, path = '/')

Deletes the specified cookie.

  • name: The name of the cookie to delete (String).
  • path: The path where the cookie is accessible (String, optional, default: /).

Example:

deleteCookie('username', '/');

clearCookie()

Deletes all cookies.

Example:

clearCookie();

localStorage Functions

setLocal(key, value)

Stores a value in localStorage under the specified key.

  • key: The key to store the value under (String).
  • value: The value to store (Any type, will be stringified).

Example:

setLocal('userData', { name: 'John', age: 30 });

getLocal(key)

Retrieves the value stored in localStorage under the specified key.

  • key: The key of the value to retrieve (String).

Returns: The parsed value from localStorage or null if the key does not exist.

Example:

const userData = getLocal('userData');
console.log(userData); // Outputs: { name: 'John', age: 30 }

removeLocal(key)

Removes the specified key from localStorage.

  • key: The key to remove (String).

Example:

removeLocal('userData');

clearLocal()

Clears all values from localStorage.

Example:

clearLocal();

sessionStorage Functions

setSession(key, value)

Stores a value in sessionStorage under the specified key.

  • key: The key to store the value under (String).
  • value: The value to store (Any type, will be stringified).

Example:

setSession('sessionData', { token: 'abc123' });

getSession(key)

Retrieves the value stored in sessionStorage under the specified key.

  • key: The key of the value to retrieve (String).

Returns: The parsed value from sessionStorage or null if the key does not exist.

Example:

const sessionData = getSession('sessionData');
console.log(sessionData); // Outputs: { token: 'abc123' }

removeSession(key)

Removes the specified key from sessionStorage.

  • key: The key to remove (String).

Example:

removeSession('sessionData');

clearSession()

Clears all values from sessionStorage.

Example:

clearSession();

IndexedDB Manager

IndexedDBManager

A class for managing IndexedDB databases.

Constructor

const dbManager = new IndexedDBManager(dbName, dbVersion = 1, indexes);
  • dbName: The name of the database (String).
  • dbVersion: The version of the database (Number, optional, default: 1).
  • indexes: An array of index objects. Each object should have a key (String) and keyPath (String), and an optional unique property (Boolean).

Methods

  • openDatabase(): Opens the database. Returns a promise that resolves with the database instance.
  • addData(data): Adds or updates data in the database. Returns a promise that resolves when the data is added or updated.
  • getData(index, key): Retrieves data from the database using an index. Returns a promise that resolves with the retrieved data.
  • updateData(index, key, newValue): Updates existing data in the database. Returns a promise that resolves when the data is updated.
  • deleteData(index, key): Deletes data from the database. Returns a promise that resolves when the data is deleted.
  • deleteDataBase(): Deletes the database. Returns a promise that resolves when the database is deleted.

Example:

const dbManager = new IndexedDBManager('myDatabase', 1, [
    { key: 'name', keyPath: 'name', unique: false },
    { key: 'age', keyPath: 'age', unique: false }
]);

dbManager.addData({ name: 'John', age: 30 }).then(console.log).catch(console.error);

Contributing

If you want to contribute to this project, please fork the repository and create a pull request.