TypeScript: Sync variables with localStorage https://www.npmjs.com/package/var-persist
Go to file
Zakary Timson 039b393eeb
Some checks failed
Build / Build NPM Project (push) Failing after 45s
Build / Tag Version (push) Has been skipped
Build / Publish (push) Has been skipped
Update README.md
2023-12-21 01:01:52 +00:00
.github/workflows Added license & updated build to cache node_modules 2023-12-20 00:16:54 -05:00
src init 2023-12-19 22:32:47 -05:00
tests init 2023-12-19 22:32:47 -05:00
.editorconfig init 2023-12-19 22:32:47 -05:00
.gitignore added workflows 2023-12-19 22:50:23 -05:00
jest.config.js init 2023-12-19 22:32:47 -05:00
LICENSE Added license & updated build to cache node_modules 2023-12-19 23:58:05 -05:00
package-lock.json Added publish steps 2023-12-19 23:35:05 -05:00
package.json Added license & updated build to cache node_modules 2023-12-20 00:16:54 -05:00
README.md Update README.md 2023-12-21 01:01:52 +00:00
tsconfig.json init 2023-12-19 22:32:47 -05:00


Logo

Persist

Typescript Library to Sync Variables with LocalStorage

Version Pull Requests Issues



Table of Contents

About

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Built With

TypeScript

Setup

Production

Prerequisites

Instructions

  1. Install persist: npm i ztimson/persist
  2. Enable decorators inside tsconfig.json:
{
	"compilerOptions": {
		"experimentalDecorators": true,
		...
	},
	...
}
  1. Use persist:
import {Persist} from 'ztimson/persist';

// Proxy Object (Always access/modify using `.value`):
let theme = new Persist<string>('theme', {default: 'os'});

console.log(theme.value) // Output: os
theme.value = 'light'; // Changes will be synced to localStorage['theme'];
import {persist} from 'ztimson/persist';

// Using decorators
class Theme {
	@persist({key: 'theme', default: 'os'}) current!: string;
}
const theme = new Theme();

console.log(theme.current); // Output: light
theme.current = 'dark'; // You can ommit `.value` when using the decorator

Development

Prerequisites

Instructions

  1. Install the dependencies: npm i
  2. Build library & docs: npm build
  3. Run unit tests: npm test

License

Copyright © 2023 Zakary Timson | Available under MIT Licensing

See the license for more information.