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

type-collector

v1.1.12

Published

type-collector is a fast, simple (and rich), zero-configuration node package that manage effective browser application storage for Typescript. Web Storage can only store strings. This factory module let you handle Object, Array and other types to be store

Downloads

10

Readme

type-collector

type-collector is a typescript package that management LocalStorage, Session Storage and Cookies for Typescript, Objects, Array and Primitives types.

using npm

npm i type-collector --save

using yarn

yarn add type-collector

Usage

import {TypeCollector} from 'type-collector';

Local Storage

let storage = TypeCollector.Factory.Storage;
Add Primitive Types
storage.add("token","ooo.ooo.ooo")
       .add("IDE",12)
       .add("is-auth",true);                    
Add Object / Array Type
interface User{
  id: string,
  name: string;
  age: number;
  isActive: boolean;
}

let users: Array<User> = new Array<User>();

users.push(
    {
      id: TypeCollector.uuid(),
      name: "Michael M. Delagarza",
      age: 34,
      isActive: true
    },
    {
      id: TypeCollector.uuid(),
      name: "Anita Alvarenga",
      age: 23,
      isActive: false
    });

storage.add("users",users);
Get Primitives Values
storage.get("token").then(res => {
       console.log(res) //ooo.ooo.ooo
})

storage.get("is-auth").then(res => {
       console.log(res) //true
})
Get Objescts Values
storage.get<Array<User>>("users").then(users => {
     users.forEach(user => {
        console.log(user)
     })  
});

/*
{id: "2795f29d-c3b6-404e-baba-6e5a50fab87f", name: "Michael M. Delagarza", age: 34, isActive: true}
{id: "559d98de-a217-4125-9659-09851c419e53", name: "Anita Alvarenga", age: 23, isActive: false}
*/
Remove Values from Storage
storage.remove("token")
       .remove("users")
Remove All Values from Storage
storage.removeAll();

Session Storage

Session Storage similar to Local Storage but expires when the browser closed

let session = TypeCollector.Factory.Session;
Add Sessions
session.add("id", TypeCollector.uuid())
       .add("secure", false)
       .add("post",{
              message: "some post goes here",
              date: new Date()
           })
Get Session
session.get<Object>("post").then(post => {
       console.log(post)
       //{message: "some post goes here", date: "2019-06-11T13:28:11.892Z"}
}).catch(error => {
       console.log(error)
})
Remove Sessions
session.remove("id")
       .remove("posts") 
Remove All Sessions
session.removeAll();

Cookies

Cookies similar to Local Storage besides expiration date parameter

let cookie = TypeCollector.Factory.Cookie;
Add Cookies
//add expired date
let expired = new Date("2020-01-01")

cookie.add("uuid",TypeCollector.uuid(), expired)
      .add("users",users) //users array
Get Cookies
cookie.get("uuid").then(uuid => console.log(uuid))
//cb3b619e-0d13-4d5c-a77a-5e5104a0cbc7

cookie.get<Array<User>>("users").then(users => {
       users.forEach(user => {
       console.log("id",user.id)
       })
});
//b4a1d009-d86d-447e-976d-e2727ade9c9f
//b4a1d009-d86d-447e-976d-e2727ade9c9f
Remove Cookie
session.remove("uuid")
       .remove("users") 
Remove All Cookies
session.removeAll();