Socket
Socket
Sign inDemoInstall

typescriptstore

Package Overview
Dependencies
133
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    typescriptstore

LocalStorage and SessionStorage for typescript


Version published
Maintainers
2
Created

Readme

Source

tsStoreNPM

LocalStorage and SessionStorage for typescript

Build Status

Installation

$ npm i typescriptstore

tsStoreNPM requires Typescript v3.7+ to run.

How to use

Model need to inherit from TsStoreItem Object

import { TsStoreItem } from 'typescriptstore/lib/tsStoreItem';

export class UserStoreModel extends TsStoreItem {
    public username: string = '';
    public name: string = '';
    public age: number = 0;
}

export class ProductStoreModel extends TsStoreItem {
    public productType: string = '';
    public productName: string = '';
}

Import relative objects

import { UserStoreModel, ProductStoreModel } from './model/testModel';
import { TsStore } from 'typescriptstore/lib/tsStore';
import { TsStoreQueryType } from 'typescriptstore/lib/queryTypes';

Init store to use

let userStore: TsStore = TsStore.getStore('userStore');

Insert or update item

let item: UserStoreModel = new UserStoreModel();
item.username = 'user' + i;
item.name = 'USER' + i;
item.age = i + 2;
item = userStore.insertOrUpdate(item)

Remove item by id

userStore.remove(item.storeItemId);

Clear all items in store

userStore.clear();

Find item by query condition base on #QueryType

let findItems: UserStoreModel[] = userStore.find('age', 2, TsStoreQueryType.Equal);
QueryType
export enum TsStoreQueryType {
    Equal,
    NotEqual,
    GreaterThan,
    GreaterThanOrEqual,
    LessThan,
    LessThanOrEqual
}

Get all items in store

let allItems: UserStoreModel[] = userStore.all();

Get first item in store

let fistItem: UserStoreModel = userStore.first();

Get last item in store

let lastItem: UserStoreModel = userStore.last();

Download & run demo for more clearly(Angular2+ required).

$ cd tsStoreDemo
$ npm install
$ npm start

License

MIT

FAQs

Last updated on 13 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc