All Projects → cferdinandi → Bin

cferdinandi / Bin

Licence: mit
A tiny (<1kb) localStorage and sessionStorage helper library.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Bin

Fine Uploader
Multiple file upload plugin with image previews, drag and drop, progress bars. S3 and Azure support, image scaling, form support, chunking, resume, pause, and tons of other features.
Stars: ✭ 8,158 (+11554.29%)
Mutual labels:  javascript-library, vanilla-js, vanilla-javascript
Ng2 Webstorage
Localstorage and sessionstorage manager - Angular service
Stars: ✭ 395 (+464.29%)
Mutual labels:  localstorage, sessionstorage
Josh.js
A JavaScript library to animate content on page scroll.
Stars: ✭ 345 (+392.86%)
Mutual labels:  javascript-library, vanilla-javascript
Darken
🌑 Dark mode made easy
Stars: ✭ 571 (+715.71%)
Mutual labels:  javascript-library, vanilla-javascript
Vanilla Datatables
A lightweight, dependency-free javascript HTML table plugin
Stars: ✭ 314 (+348.57%)
Mutual labels:  vanilla-js, vanilla-javascript
Angular Locker
🗄️ A simple & configurable abstraction for local/session storage in angular js projects
Stars: ✭ 318 (+354.29%)
Mutual labels:  localstorage, sessionstorage
Bunny
BunnyJS - Lightweight native (vanilla) JavaScript (JS) and ECMAScript 6 (ES6) browser library, package of small stand-alone components without dependencies: FormData, upload, image preview, HTML5 validation, Autocomplete, Dropdown, Calendar, Datepicker, Ajax, Datatable, Pagination, URL, Template engine, Element positioning, smooth scrolling, routing, inversion of control and more. Simple syntax and architecture. Next generation jQuery and front-end framework. Documentation and examples available.
Stars: ✭ 473 (+575.71%)
Mutual labels:  vanilla-js, vanilla-javascript
Vanillajs Spa
a simple SPA in vanilla js
Stars: ✭ 265 (+278.57%)
Mutual labels:  vanilla-js, vanilla-javascript
Vanilla Lazyload
LazyLoad is a lightweight, flexible script that speeds up your website by deferring the loading of your below-the-fold images, backgrounds, videos, iframes and scripts to when they will enter the viewport. Written in plain "vanilla" JavaScript, it leverages IntersectionObserver, supports responsive images and enables native lazy loading.
Stars: ✭ 6,596 (+9322.86%)
Mutual labels:  vanilla-js, vanilla-javascript
Recoil Persist
Package for recoil state manager to persist and rehydrate store
Stars: ✭ 66 (-5.71%)
Mutual labels:  localstorage, sessionstorage
Storagedb
MongoDB-like API for HTML5 Storage (localStorage and sessionStorage)
Stars: ✭ 16 (-77.14%)
Mutual labels:  localstorage, sessionstorage
Selectr
A lightweight, vanilla javascript select box replacement. No dependencies.
Stars: ✭ 293 (+318.57%)
Mutual labels:  vanilla-js, vanilla-javascript
Learn Vanilla Js
Open source list of paid & free resources to learn vanilla JavaScript
Stars: ✭ 945 (+1250%)
Mutual labels:  vanilla-js, vanilla-javascript
Darkmode Js
DarkModeJS helps you to auto detect user's time and switch theme to darkside
Stars: ✭ 328 (+368.57%)
Mutual labels:  vanilla-js, vanilla-javascript
Immortaldb
🔩 A relentless key-value store for the browser.
Stars: ✭ 2,962 (+4131.43%)
Mutual labels:  localstorage, sessionstorage
Vue Ls
💥 Vue plugin for work with local storage, session storage and memory storage from Vue context
Stars: ✭ 468 (+568.57%)
Mutual labels:  localstorage, sessionstorage
pAppwords
Vanilla JS plug-in with zero configuration integrate with HaveIBeenPwned API v2
Stars: ✭ 21 (-70%)
Mutual labels:  vanilla-javascript, vanilla-js
Bs Stepper
A stepper for Bootstrap 4.x
Stars: ✭ 261 (+272.86%)
Mutual labels:  vanilla-js, vanilla-javascript
Web Storage Cache
对localStorage 和sessionStorage 进行了扩展,添加了超时时间,序列化方法
Stars: ✭ 582 (+731.43%)
Mutual labels:  localstorage, sessionstorage
Proxy Storage
Provides an adapter for storage mechanisms (cookies, localStorage, sessionStorage, memoryStorage) and implements the Web Storage interface
Stars: ✭ 10 (-85.71%)
Mutual labels:  localstorage, sessionstorage

Bin Build Status

A tiny (< 1kb) localStorage and sessionStorage helper library.

It automatically parses objects and arrays into strings (and back). It also let's you validate and expire localStorage data after a set period of time.

Installation | API | Browser Compatibility | License


Want to learn how to write your own vanilla JS libraries? Check out my Vanilla JS Pocket Guides or join the Vanilla JS Academy and level-up as a web developer. 🚀


Installation

Compiled and production-ready code can be found in the dist directory. The src directory contains development code.

Direct Download

You can download the files directly from GitHub.

<script src="path/to/bin.min.js"></script>

CDN

You can also use the jsDelivr CDN. I recommend linking to a specific version number or version range to prevent major updates from breaking your site. Bin uses semantic versioning.

<!-- Always get the latest version -->
<!-- Not recommended for production sites! -->
<script src="https://cdn.jsdelivr.net/gh/cferdinandi/bin/dist/bin.min.js"></script>

<!-- Get minor updates and patch fixes within a major version -->
<script src="https://cdn.jsdelivr.net/gh/cferdinandi/[email protected]/dist/bin.min.js"></script>

<!-- Get patch fixes within a minor version -->
<script src="https://cdn.jsdelivr.net/gh/cferdinandi/[email protected]/dist/bin.min.js"></script>

<!-- Get a specific version -->
<script src="https://cdn.jsdelivr.net/gh/cferdinandi/[email protected]/dist/bin.min.js"></script>

NPM

You can also use NPM (or your favorite package manager).

npm install storagebinjs

API

Before working with Bin, you need to instantiate a new instance. Pass in the ID you would like to use for your localStorage/sessionStorage data as an argument.

Bin defaults to localStorage. You can optionally pass in true as a second argument to use sessionStorage instead.

// Instantiate a new localStorage instance
var myBin = new Bin('myBinID');

// Instantiate a new sessionStorage instance
var myBinSession = new Bin('myBinSessionID', true);

set()

Save data to storage.

Pass in your data as an argument. It can be an object, array, string, number---any valid JavaScript object type. Bin will automatically convert it to a string for storage.

// Store an object
myBin.set({
	sandwich: 'turkey',
	drink: 'soda',
	chips: true
});

// Store an array
myBin.set([
	'turkey',
	'tuna',
	'pb&j'
]);

// Store a string
myBin.set('I love Cape Cod potato chips!');

// Store a number
myBin.set(42);

get()

Get data from storage. You can optionally pass in a fallback to use if no data is found.

// Get data from storage
myBin.get();

// Use a fallback object
myBin.get({});

// Use a fallback array
myBin.get([]);

// Use a fallback string
myBin.get('');

// Use a fallback number
myBin.get(0);

isValid()

Check if a certain amount of time has passed since the data was saved to storage. Pass in the amount of time in milliseconds that the data is good for as an argument.

// 1 hour
myBin.isValid(1000 * 60 * 60);

// 1 day
myBin.isValid(1000 * 60 * 60 * 24);

// 1 week
myBin.isValid(1000 * 60 * 60 * 24 * 7);

// 1 year
myBin.isValid(1000 * 60 * 60 * 24 * 365);

// 15 minutes
myBin.isValid(1000 * 60 * 15);

// 2 days
myBin.isValid(1000 * 60 * 60 * 24 * 2);

remove()

Remove data from storage. The instance will remain available, but the data will be wiped from localStorage/sessionStorage.

myBin.remove();

Browser Compatibility

Bin works in all modern browsers, and IE 8 and above.

License

The code is available under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].