Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typescriptstore

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescriptstore

LocalStorage and SessionStorage for typescript

  • 1.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
2
Weekly downloads
 
Created
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

Package last updated on 13 Mar 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc