Giter Site home page Giter Site logo

elephant.js's Introduction

Elephant.js

Elephants never forget

About

Elephant.js is a simple localStorage wrapper that serializes and deserializes JavaScript objects to a single JSON object using window.localStorage if available.

Browser Support

If window.localStorage isn't available Elephant.js will try to fallback on cookies - but this isn't really reliable for data sets bigger than 4kb. It could also hurt HTTP performance by unnecessarily burdening all HTTP transactions with possible huge cookies.

Use at your own risk.

Usage

Where does an elephant keep his clothes?

In his trunk!

// Setup a store
var store = new Elephant.Trunk('mystore');

// Save a monkey
var monkey = {
	name: 'Bobo',
	age: 3,
	abilities: ['sign language', 'eating bananas']
};

monkey = store.save(monkey);

// Saved objects get guids
console.log(monkey);

// Object
// 	abilities: Array[2]
// 		0: "sign language"
// 		1: "eating bananas"
// 		length: 2
// 		__proto__: Array[0]
// 	age: 3
// 	guid: "53b425a6-47cb-462c-9498-ba236becee06"
// 	name: "Bobo"
// 	__proto__: Object

// Find a monkey
store.find(monkey.guid) === monkey; // true

// Destroy a monkey
monkey = store.destroy(monkey);

monkey.guid === undefined; // true

TODO

  • Implement cookie fallback
  • Look at msgpack instead of JSON
  • Make Backbone.sync compatible

License

MIT License, use this for whatever you want, but at your own risk. See LICENSE.

elephant.js's People

Contributors

jeffremer avatar

Stargazers

Emanuel Kluge avatar  avatar

Watchers

 avatar James Cloos 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.