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 🙏

© 2025 – Pkg Stats / Ryan Hefner

autojs-storages

v0.4.6

Published

Autojs Pro V9的本地存储模块。

Downloads

3

Readme

autojs-storages

目前Autojs Pro V9的nodejs模式还没有rhino模式的storages本地存储模块,于是我自己写了一个。

数据会以文件的形式存储在app的内部files目录内,当然前提是aj的nodejs脚本,非aj环境会存储在项目根目录内。

快速开始

保存整数等简单数据。

1. 安装

npm install autojs-storages

2. 使用

CJS:

const storages = require('autojs-storages');
var storage = storages.create("Auto.js例子:简单数据");
var a = 1234;
var b = true;
var str = "hello";
//保存
storage.put("a", a);
storage.put("b", b);
storage.put("str", str);

//取出
console.log("a = " + storage.get("a"));
console.log("b = " + storage.get("b"));
console.log("str = " + storage.get("str"));

ESM:

import storages from 'autojs-storages';
var storage = storages.create("Auto.js例子:简单数据");
var a = 1234;
var b = true;
var str = "hello";
//保存
storage.put("a", a);
storage.put("b", b);
storage.put("str", str);

//取出
console.log("a = " + storage.get("a"));
console.log("b = " + storage.get("b"));
console.log("str = " + storage.get("str"));

API

storages

new storages(name[, maxSize = 5 * 1024])

storages.create(name[, maxSize = 5 * 1024])

创建一个本地存储并返回一个Storage对象。

| | | | --------- | ---------------------------------------- | | name | 本地存储名称 String | | maxSize | 可选,本地存储大小上限,默认5kb Number |

不同名称的本地存储的数据是隔开的,而相同名称的本地存储的数据是共享的。

实际上本模块会根据名称创建文件夹,用以存储数据文件。

例如在一个脚本中,创建名称为ABC的存储并存入a=123:

import storages from 'autojs-storages';
var storage = storages.create("ABC");
storage.put("a", 123);

而在另一个脚本中是可以获取到ABC以及a的值的:

import storages from 'autojs-storages';
var storage = storages.create("ABC");
console.log("a = " + storage.get("a"));

因此,本地存储的名称比较重要,尽量使用含有域名、作者邮箱等唯一信息的名称来避免冲突,例如:

import storages from 'autojs-storages';
var storage = storages.create("[email protected]:ABC");

storages.remove(name)

| | | | --------- | ---------------------------------------- | | name | 本地存储名称 String |

删除一个本地存储以及他的全部数据。如果该存储不存在,返回false;否则返回true。

Storages

Storage.set(key[, defaultValue])

Storage.setItem(key[, defaultValue])

Storage.put(key[, defaultValue])

| | | | --------- | ---------------------------------------- | | key | 键值 String | | defaultValue | 可选,默认值 Any |

从本地存储中取出键值为key的数据并返回。

如果该存储中不包含该数据,这时若指定了默认值参数则返回默认值,否则返回undefined。

返回的数据可能是任意数据类型,这取决于保存该键值的数据时的数据类型。

Storage.set(key, value)

Storage.setItem(key, value)

Storage.put(key, value)

| | | | --------- | ---------------------------------------- | | key | 键值 String | | value | 值 Any |

把值value保存到本地存储中。value可以是undefined以外的任意数据类型。如果value为undefined则抛出TypeError。

存储的过程实际上是使用JSON.stringify把value转换为字符串再保存,因此value必须是可序列化的才能被接受。

Storage.remove(key)

Storage.removeItem(key)

| | | | --------- | ---------------------------------------- | | key | 键值 String |

移除键值为key的数据。不返回任何值。

Storage.contains(key)

Storage.containsItem(key)

Storage.has(key)

| | | | --------- | ---------------------------------------- | | key | 键值 String |

返回该本地存储是否包含键值为key的数据。是则返回true,否则返回false。

Storage.clear()

移除该本地存储的所有数据。不返回任何值。