Negligible Participation Metric

    bpd-storage
    TypeScript icon, indicating that this package has built-in type declarations

    0.4.0 • Public • Published

    Bpd Storage

    Provides a simple wrap on storage in the browser To serialize objects it uses JSON.stringify, JSON.parse. To serialize arrays it joins values (with ;) when serializing and splits during deserialization.

    Initialization

    Create instance of BpdStorage

    import { BpdStorage } from "./node_modules/bpd-storage/dist/esm/index";
    
    let storage = new BpdStorage(type, name?)

    where type is:

    • local - creates local storage instance
    • session - creates session storage instance

    and name is a an optional storage name.

    Methods

    Provides following methods // Instead of returning null or false object will throw validation errors when argument are incorrect/empty

    throwValidationErrors(flag: boolean): void;

    // Retrives storage item value

    getItem(key: string): string;

    // Retrives storage item value as int

    getNumber(key: string): number;

    // Retrives storage item value as boolean

    NOTE! Keep in mind that this method returns proper result only when value was set by using setBoolean

    getBoolean(key: string): boolean;

    // Retrives storage item value as any item - shall be used JSON based values

    getAny(key: string): any;

    // Retrives storage item value as array item

    getArray(key: string): string[];

    // Checks whether key exsits in storage

    has(key: string): boolean;

    // Sets item in storage

    setItem(key: string, value: any): void;

    // Sets number in storage

    setNumber(key: string, value: any): void;

    // Sets boolean in storage - as serialized value

    setBoolean(key: string, value: any): void;

    // Sets object in storage

    setAny(key: string, value: any): void;

    // Sets array in storage

    setArray(key: string, value: any): void;

    // Performs test on storage

    isAccessible(): boolean;

    // Retrives number of elements in storage

    length(): number;

    // Removes specific item from storage

    removeItem(key: string): void;

    // Clears the storage

    clear(): void

    // Returns actual storage object

    get(): Storage;

    Keywords

    Install

    npm i bpd-storage

    DownloadsWeekly Downloads

    10

    Version

    0.4.0

    License

    MIT

    Unpacked Size

    84.4 kB

    Total Files

    9

    Last publish

    Collaborators

    • bpd_dev