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

xui-storex

v1.1.4

Published

Keep the type of storage value unchanged and change array and object directly. Supports listening to changes and setting expires.

Downloads

4

Readme

@yaoapp/storex

English | 中文

A more convenient way to use storage through proxy.

try it on codesandbox.

Install

npm i @yaoapp/storex

Features

Base

Keep the type of storage value unchanged and change array and object directly.

import { local, session } from '@yaoapp/storex';

local.test = 'Hello @yaoapp/storex'; // works
delete local.test; // works

// number
local.test = 0;
local.test === 0; // true

// boolean
local.test = false;
local.test === false; // true

// undefined
local.test = undefined;
local.test === undefined; // true

// null
local.test = null;
local.test === null; // true

// object
local.test = { hello: 'world' };
local.test.hello = '@yaoapp/storex'; // works

// array
local.test = ['hello'];
local.test.push('@yaoapp/storex'); // works
local.test.length // 2

// Date
local.test = new Date('2000-01-01T00:00:00.000Z');
local.test.getTime() === 946684800000; // true

// RegExp
local.test = /d(b+)d/g;
local.test.test("cdbbdbsbz"); // true

// function
local.test = function() {
  return 'Hello @yaoapp/storex!';
};
local.test() === 'Hello @yaoapp/storex!'; // true

Subscribe

listen to the changes.

import { local } from '@yaoapp/storex';

local.on('test', function(newVal, oldVal) {
  console.log('test', newVal, oldVal);
});
local.on('test.a', function(newVal, oldVal) {
  console.log('test.a', newVal, oldVal);
});

local.test = {};
// test {} undefined

local.test.a = 1;
// test.a 1 undefined

on

Subscribe to an item.

  • key: the name of the item to subscribe to. Support obj.a for Object and list[0] for Array, and also Array length.
  • callback: the function to call when the item is changed. Includes newValue and oldValue.

once

Subscribe to an item only once.

  • key: the name of the item to subscribe to. Support obj.a for Object and list[0] for Array.
  • callback: the function to call when the item is changed. Includes newValue and oldValue.

off

Unsubscribe from an item or all items.

  • key(optional): the name of the item to unsubscribe from. If no key is provided, it unsubscribes you from all items.
  • callback(optional): the function used when binding to the item. If no callback is provided, it unsubscribes you from all functions binding to the item.

Expired

set expires for items.

import { local } from '@yaoapp/storex';

local.test = 'hello @yaoapp/storex';
local.setExpires('test', Date.now() + 10000);

// within 10's
local.test // 'hello @yaoapp/storex'

// after 10's
local.test // undefined

The expires is saved to localStorage. So no matter how you reload it within 10's, the value still exists. But after 10's, it has been removed.

setExpires

set expires for an item.

  • key: the name of the item to set expires.
  • expires: accept stringnumber and Date.

getExpires

return the expires(Date) of the item.

  • key: the name of the item that has set expires.

removeExpires

cancel the expires of the item.

  • key: the name of the item that has set expires.