Coder Social home page Coder Social logo

itoic / store.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jaywcjlove/store.js

0.0 0.0 0.0 353 KB

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.

Home Page: http://jaywcjlove.github.io/store.js

License: Other

JavaScript 100.00%

store.js's Introduction

JavaScript localStorage

Build Status Coverage Status GitHub issues GitHub forks GitHub stars store.js

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.

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:

<script src="https://unpkg.com/cookiejs/dist/cookie.min.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 '้€ไธชๆ›ดๆ”นๆ•ฐๆฎ'
})

Storage Event

Responding to storage changes with the StorageEvent

if(window.addEventListener){
  window.addEventListener("storage",handle_storage,false);
}else if(window.attachEvent){
  window.attachEvent("onstorage",handle_storage);
}
function handle_storage(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

License

Licensed under the MIT License.

store.js's People

Contributors

jaywcjlove avatar cbbfcd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.