GithubHelp home page GithubHelp logo

kriskuiper / storage-sync Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 353 KB

Using JS Proxy to sync an object literal with local- or sessionStorage

Home Page: https://www.npmjs.com/package/web-storage-sync

License: MIT License

JavaScript 100.00%

storage-sync's Introduction

Web storage sync

Using JS Proxy to sync an object literal with local- or sessionStorage.

Installation

Use your package manager to install the package.

npm install web-storage-sync

# OR

yarn add web-storage-sync

Usage

  1. Syncing objects with a storage (works the same in both cases)
import { syncWithLocalStorage } from 'web-storage-sync'

// Automatically sets the object in localStorage under 'person' key
const person = syncWithLocalStorage('person', {
    firstName: 'Firstname',
    lastName: 'Lastname'
})

// When adding or changing a property,
// the object is directly synced with localStorage:
person.age = 20

console.log(JSON.parse(localStorage.getItem('person')))
// > { firstName: 'Firstname', lastName: 'Lastname', age: 20 }

Contributing

Found an issue or have a feature request? Open an issue and we'll discuss if it's worth fixing or adding it. Please make sure to update tests accordingly before creating a Pull Request.

Wishlist

  • Also be able to sync arrays

License

Unless stated otherwise, license is MIT.

storage-sync's People

Contributors

kriskuiper avatar dependabot[bot] avatar renovate-bot avatar renovate[bot] avatar

Stargazers

Jeroen avatar

Watchers

James Cloos avatar  avatar

storage-sync's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Location: renovate.json
Error type: The renovate configuration file contains some invalid settings
Message: The following managers configured in enabledManagers are not supported: "yarn"

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.