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

@ethico/fakestore

v1.0.6

Published

Its a simple package to store your data in your browser's localstorage

Downloads

3

Readme

FakeStore

npm version License

FakeStore is a JavaScript package that provides a simple way to store, retrieve, and delete items from local storage in the browser. It uses object-oriented programming principles to provide a clean and easy-to-use interface.

Table of Content

Installation

To use FakeStore, simply download the code from this repository and include it in your project. You can install the package using npm:

npm install @ethico/fakestore

Alternatively, you can download the FakeStore.js file and include it in your project manually. or You can use the CDN for it

<script src="https://cdn.jsdelivr.net/gh/Shariar-Hasan/FakeStore/dist/FakeStore.min.js"></script>

for importing :

import FakeStore from "@ethico/fakestore";

Usage

Creating a new instance of the FakeStore class requires specifying the name of the collection to create or access:

const store = new FakeStore("mydb");

Best way to do this, create a global store.js and inside it, write likie this

export const store = new FakeStore("my collection");

if you have multiple collection, try this:

export const collection_1 = new FakeStore("collection_1");
export const collection_2 = new FakeStore("collection_2");
export const collection_3 = new FakeStore("collection_3");

Methods

FakeStore provides several methods for interacting with the database:

get(key)

Retrieves one or more items from the database. If a key is provided, only the item with that key will be returned. Otherwise, all items in the database will be returned.

// get all items
const allItems = store.get();

// get item with specific key
const singleItem = store.get("1fk2str");

push(key, item)

Adds an item to the database. If a key is provided, the item will be added with that key. Otherwise, a unique ID will be generated for the item. If an item with the same key already exists in the database, an error will be thrown.

// add item with automatically generated key
store.push({ name: "John", age: 30 });

// add item with specific key
store.push("1fk2str", { name: "Jane", age: 25 });

update(key, item)

Updates an existing item in the database with new data. The item to update is identified by its key. If either the key or the updated data is missing, an error will be thrown.

// update item with specific key
store.update("1fk2str", { name: "Jane Doe", age: 26 });

remove(key)

Removes one or all items from the database. The item to remove is identified by its key. If no key is provided, then it will delete all item in the database.

// remove item with specific key
store.remove("1fk2str");

clear()

Drop/ Delete whole database from the localstorage.

// clear all items
store.clear();

createUID()

Generates a unique ID for an item. This method is mainly used internally by push() when a key is not provided. But you can use it for making key to push data to FakeStore

// generate unique ID
const id = store.createUID(); 
//Output: 2319075320750
const id2 = store.createUID({ start: "user-" }); 
//Output: user-7503207231950
const id3 = store.createUID({ end: "-id" }); 
//Output: 3207523190750-id
const id4 = store.createUID({ start: "user-", end: "-id" }); 
//Output: user-7532231900750-id

Contribution

Contribution on this repository is welcomed. Feel free to contribute, with your excellent idea.

License

This code is released under the MIT License.