• Stars
    star
    409
  • Rank 101,726 (Top 3 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 9 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple, lightweight JavaScript API for handling browser localStorage , it is easy to pick up and use, has a reasonable footprint 2.36kb(gzipped: 1.04kb), and has no dependencies.

JavaScript localStorage

Downloads Build and test storejs Coverage Status README-zh.md

A simple, lightweight JavaScript API for handling browser localStorage, it is easy to pick up and use, has a reasonable footprint 2.08kb(gzipped: 0.97kb), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks.

Old v1 version document preview.

Features:

🚀 Has no dependencies
🌱 Works in all browsers
🔥 Heavily tested
📦 Supports AMD/CommonJS
💥 store.min.js 2.08kb(gzipped: 0.97kb)

Usage

Installed via npm. You will need Node.js installed on your system.

$ npm install storejs --save
import store from 'storejs';

store('test', 'tank', 1)

Or manually download and link storejs in your HTML, It can also be downloaded via UNPKG or jsDelivr CDN:

CDN: UNPKG | jsDelivr | Githack | Statically | bundle.run

<script src="https://unpkg.com/storejs/dist/store.js"></script>
<script type="text/javascript">
  store('test', 'tank');
</script>

Basic Usage

store(key, data);                 // Single storage string data
store({key: data, key2: data2});  // Bulk storage of multiple string data
store(key);              // Get `key` string data
store('?key');           // Determine if the `key` exists
store();                 // Get all key/data
//store(false);🔫        // (Deprecated) because it is easy to empty the storage because of a null value or an error
//store(key, false); 🔫  // (Deprecated)

store.set(key, data[, overwrite]);    // === store(key, data);
store.set({key: data, key2: data2})   // === store({key: data, key2: data});
store.get(key[, alt]);                // === store(key);
store.get('?key');                    // Determine if the `key` exists
store.get('key1', 'key2', 'key3');    // Get `key1`,`key2`,`key3` data
store.remove(key);                    // ===store(key,false)
store.clear();                        // Clean all key/data
store.keys();                         // Returns an array of all the keys
store.forEach(callback);              // Loop traversal, return false to end traversal
store.search(string);                 // Search method

store.has(key); //⇒ Determine if there is a return true/false

//⇒ Provide callback method to process data
store('test', (key,val) => {
  console.log(val) // Processing the data obtained through the test here
  return [3,4,5] // Return data and set store
})

store(['key', 'key2'], (key) => {
  // Get data processing of multiple keys, return and save;
  console.log('key:', key)
  return '逐个更改数据'
})

API

set

Store or delete string data individually store.set(key, data[, overwrite]);. Same effect store(key, data);.

store.set('wcj', '1')   //⇒  1
store.set('wcj')        //⇒  Delete `wcj` and string data

get

Get the string data of the key store.get(key[, alt]). Same effect store(key).

store.get('wcj1') // Get the string data of `wcj1`
store('wcj1')     // Same function as above

setAll

Bulk storage of multiple string data store.setAll(data[, overwrite]). Same effect store({key: data, key2: data});.

store.setAll({
  "wcj1": 123,
  "wcj2": 345
}) // Store two string data

store.setAll(["w1", "w2", "w3"]) 
// Store three strings of data
//  0⇒ "w1"
//  1⇒ "w2"
//  2⇒ "w3"

getAll 🔫

Get all key/data store.getAll(). Same effect store().

store.getAll() // ⇒ JSON
store() // Same function as above

clear

Clear all key/data. store.clear()

⚠️ Deprecate store(false) because it is easy to empty the library because of passing in a null value or reporting an error

store.clear()

keys

Return an array of all keys. store.keys().

store.keys() //⇒ ["w1", "w2", "w3"]

has

Judge whether it exists, return true/false store.has(key).

store.has('w1'); //⇒ true

remove

Delete key string data including key store.remove(key)

store.remove('w1');  // Delete w1 and return the value of w1
store('w1', false)   // So also delete w1

forEach

Loop traversal, return false to end the traversal

store.forEach((k, d) => {
  console.log(k, d);
  if (k== 3) return false
});

Storage Event

Responding to storage changes with the StorageEvent

if (window.addEventListener) {
  window.addEventListener('storage', handleStorage,false);
} else if (window.attachEvent){
  window.attachEvent('onstorage', handleStorage);
}
function handleStorage(e) {
  if(!e) { e=window.event; }
  //showStorage();
}
Property Type Description
key String The named key that was added, removed, or moddified
oldValue Any The previous value(now overwritten), or null if a new item was added
newValue Any The new value, or null if an item was added
url/uri String The page that called the method that triggered this change

Chained Call

store.set('ad', 234).get('ad')

TODO

  • store.get([key,key2]) Get method, return json
  • store([key,key2]) Get method, return json
  • onStorage Method test cases, and implementation

Related

  • cookiejs 🍪 A simple, lightweight JavaScript API for handling browser cookies , it is easy to pick up and use, has a reasonable footprint(~2kb, gzipped: 0.95kb), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks.

License

Licensed under the MIT License.

More Repositories

1

awesome-mac

 Now we have become very big, Different from the original idea. Collect premium software in various categories.
JavaScript
69,299
star
2

linux-command

Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。https://git.io/linux
Markdown
28,447
star
3

reference

为开发人员分享快速参考备忘清单(速查表)
Dockerfile
8,374
star
4

hotkeys-js

➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
JavaScript
6,170
star
5

handbook

放置我的笔记、搜集、摘录、实践,保持好奇心。看文需谨慎,后果很严重。
Markdown
4,148
star
6

mysql-tutorial

MySQL入门教程(MySQL tutorial book)
4,022
star
7

github-rank

🕷️Github China/Global User Ranking, Global Warehouse Star Ranking (Github Action is automatically updated daily).
TypeScript
1,837
star
8

awesome-uikit

Collect JS Frameworks, Web components library and Admin Template.
Dockerfile
1,441
star
9

iNotify

📢 JS achieve the browser title flashing, scrolling, voice prompts, Chrome/Safari/FireFox/IE notice. has no dependencies. It not interfere with any JavaScript libraries or frameworks. has a reasonable footprint 5.05kb (gzipped: 1.75kb)
JavaScript
992
star
10

nginx-tutorial

Nginx安装维护入门学习笔记,以及各种实例。
795
star
11

docker-tutorial

🐳 Docker入门学习笔记
785
star
12

oscnews

Chrome 插件,查看开源中国软件更新资讯,文档导航,GitHub 趋势榜,linux命令索引,浏览历史记录和时钟页面。
JavaScript
737
star
13

vim-web

◈ 搞得像IDE一样的Vim,安装配置自己的Vim。
Vim Script
594
star
14

validator.js

⁉️ Lightweight JavaScript form validation, that had minimal configuration and felt natural to use. No dependencies, support UMD.
TypeScript
539
star
15

golang-tutorial

Go语言快速入门
Go
520
star
16

mocker-api

mocker-api that creates mocks for REST APIs. It will be helpful when you try to test your application without the actual REST API server.
JavaScript
471
star
17

FED

✪ 这是一个很酷炫的前端网站搜集器,导航网 http://jaywcjlove.github.io/FED
JavaScript
453
star
18

svgtofont

Read a set of SVG icons and ouput a TTF/EOT/WOFF/WOFF2/SVG font.
TypeScript
450
star
19

react-hotkeys

React component to listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts.
TypeScript
396
star
20

shell-tutorial

Shell入门教程(Shell tutorial book)
Shell
391
star
21

git-tips

这里是我的笔记,记录一些git常用和一些记不住的命令。
Markdown
372
star
22

translater.js

♣︎ This is a use of HTML comments page translation solution. For a small amount of static pages, this solution is more simple. it has no dependents, Compression only (4KB)
JavaScript
323
star
23

idoc

📖 Simple document generation tool! Dependence Node.js run.
TypeScript
233
star
24

sgo

A dev server for rapid prototyping. Setting a directory to a static server.It provides a 404 neat interface for listing the directory's contents and switching into sub folders.
EJS
205
star
25

regexp-example

正则表达式实例搜集,通过实例来学习正则表达式。
HTML
200
star
26

amac

This is developed for Awesome-Mac.
JavaScript
200
star
27

swiftui-example

SwiftUI 示例,技巧和技术集合,帮助我构建应用程序,解决问题以及了解SwiftUI的实际工作方式。
Swift
196
star
28

cookie.js

🍪 A simple, lightweight JavaScript API for handling browser cookies , it is easy to pick up and use, has a reasonable footprint(~2kb, gzipped: 0.95kb), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks. https://jaywcjlove.github.io/cookie.js/
JavaScript
181
star
29

rdoc

⚛️📄🚀 Fast static site generator for React, Just write Markdown file. @react-doc
JavaScript
155
star
30

wxmp

微信公众号文章 Markdown 编辑器,使用 markdown 语法创建一篇简介美观大方的微信公众号图文。
TypeScript
119
star
31

sb

SVG badges to display
JavaScript
106
star
32

onlinenetwork

js判断是否断网了
JavaScript
97
star
33

tsbb

TSBB is a CLI tool for developing, testing and publishing modern TypeScript projects with zero configuration, and can also be used for module or react component development. @tsbbjs
TypeScript
97
star
34

package.json

文件 package.json 的说明文档。
96
star
35

tools

Many many useful Web Online Tools For Web Developers & Programmers
TypeScript
94
star
36

icongo

Search SVG Icons. Easily include popular icons in your React projects and provide an easy tool to convert SVG into React components. @icongo
TypeScript
85
star
37

magic-input

CSS3 Styles for Checkbox and Radio Button inputs look prettier. with only one element.
HTML
84
star
38

colors-cli

ಠ_ಠ Terminal string styling done right.
JavaScript
74
star
39

swift-tutorial

Swift入门教程、读书笔记
74
star
40

wcj

🙈 Node.js make command-line tool for learning.
JavaScript
57
star
41

c-tutorial

C语言教程
C
53
star
42

swiftui-markdown

Render Markdown text in SwiftUI.
Swift
52
star
43

loading-cli

Terminal loading effect.
JavaScript
49
star
44

dev-site

开发者网址导航,Chrome 插件 oscnews 的子仓库。https://jaywcjlove.github.io/dev-site
JavaScript
48
star
45

date.js

JavaScript function for converting timestamps or Date objects to formatted strings, manipulate dates.
TypeScript
46
star
46

stylus-px2rem

Stylus convert px to rem in css files with optional fallback to px.
Stylus
42
star
47

markdown-to-html-cli

Command line tool that converts markdown to HTML.
TypeScript
42
star
48

hexoThemeKacper

hexo theme
CSS
36
star
49

rollup-demo

Rollup.js 下一代的ES6模块打包机 demo
JavaScript
36
star
50

jaywcjlove

readme for github.com/jaywcjlove
JavaScript
31
star
51

changelog-generator

A GitHub Action that compares the commit differences between two branches
TypeScript
30
star
52

nginx-editor

Nginx language for Monaco Editor.
TypeScript
28
star
53

rehype-attr

New syntax to add attributes to Markdown.
TypeScript
28
star
54

github-action-contributors

Github action generates dynamic image URL for contributor list to display it!
JavaScript
24
star
55

google

This is the Google Mirror Index.
TypeScript
22
star
56

html-to-markdown-cli

Command line tool that converts HTML to markdown.
TypeScript
22
star
57

parcel-plugin-markdown-string

📦@parcel-bundler plugin for loader markdown string, markdown output HTML.
TypeScript
21
star
58

jaywcjlove.github.io

About Me
TypeScript
21
star
59

console-emojis

Custom Console Logging with Emoji.
TypeScript
21
star
60

github-actions

测试 GitHub Actions
JavaScript
20
star
61

rust-cn-document-for-docker

Rust cn document for docker
Dockerfile
20
star
62

webpack-react-demo

学习和收集的一些WebPack和React插件例子
JavaScript
20
star
63

webpack-plugin-manifest

Generates HTML5 Cache Manifest files
JavaScript
19
star
64

github-action-package

Read and modify the contents of package.json.
TypeScript
19
star
65

AutoPrefixCSS

Break free from CSS prefix hell!摆脱CSS前缀地狱!
CSS
19
star
66

rehype-rewrite

Rewrite element with rehype.
TypeScript
18
star
67

local-ip-url

Get current machine IP.
JavaScript
16
star
68

table-of-general-standard-chinese-characters

Table of General Standard Chinese Characters(通用规范汉字表)
JavaScript
16
star
69

refs-cli

Command line tool to generate Quick Reference website.
CSS
15
star
70

code-image

Create beautiful images of your source code.
TypeScript
13
star
71

markdown-to-html

Converts markdown text to HTML.
TypeScript
13
star
72

generated-badges

Create a badge using GitHub Actions and GitHub Workflow CPU time (no 3rd parties servers)
JavaScript
13
star
73

coverage-badges-cli

Create coverage badges from coverage reports (no 3rd parties servers).
TypeScript
12
star
74

dark-mode

🌓 Add dark mode/night mode custom elements to your website.
JavaScript
12
star
75

create-tag-action

Auto create tags from commit or package.json
TypeScript
12
star
76

react-native

一些 React Native 开发上遇到的问题简单记录。
12
star
77

nxylene

练习nodejs大法,使用nodejs+mongodb+express4.x做个小实例。
JavaScript
11
star
78

MDEditor

Simple Markdownd Editor
JavaScript
11
star
79

react-native-doc

这里是本地离线预览 React Native 文档的方法,解决因官网 CDN 资源导致无法打开官方文档网站。
JavaScript
11
star
80

bannerjs

Add a banner to the string. Get one-line/multi-line comment banner based on package.json.
TypeScript
11
star
81

react-native-typescript-example

React Native TypeScript Example
Java
9
star
82

logo

Chrome 插件 oscnews 的子仓库,存储网址导航logo的仓库。
JavaScript
9
star
83

image2uri

Convert image file to data URI.
TypeScript
9
star
84

github-action-modify-file-content

Replace text content and submit content
TypeScript
9
star
85

awesome-chatgpt

8
star
86

vue-koa-demo

A koa + Vue.js + webpack project
JavaScript
7
star
87

react-dynamic-loadable

A higher order component for loading components with dynamic imports.
JavaScript
7
star
88

IE6PNG

解决IE6不支持PNG的方法搜集
JavaScript
7
star
89

docs

Centrally manage various development documents through docker.
JavaScript
7
star
90

code-example

Language code example & sample.
JavaScript
7
star
91

rehype-video

Add improved video syntax: links to `.mp4` and `.mov` turn into videos.
TypeScript
7
star
92

generate-password

Generate Password is a generating random and unique passwords.
TypeScript
7
star
93

gitke

A simple git server written in NodeJS.
JavaScript
6
star
94

FrontEndBlogCN

前端博客相关网站搜集
6
star
95

outdatedbrowser

提示升级浏览器
JavaScript
6
star
96

appstore

Appstore应用程序,半成品...
Objective-C
6
star
97

github-action-read-file

Read file contents.
TypeScript
6
star
98

compile-less

All `.less` files are compiled into `.css` files.
TypeScript
6
star
99

typenexus

TypeNexus is a great tool for API encapsulation and management. It offers a clean and lightweight way to bundle TypeORM + Expressjs functionality, helping you to build applications faster while reducing template code redundancy and type conversion work.
TypeScript
5
star
100

colors-named-decimal

A array with color name -> decimal rgbs.
TypeScript
4
star