1.0.2 • Published 2 months ago

typescriptstore v1.0.2

Weekly downloads
4
License
MIT
Repository
-
Last release
2 months ago

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

1.0.2

2 months ago

1.0.1

2 months ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

1.0.0

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago