Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rolyatmax/encode-object
encodes and decodes JS objects in Base62 - useful for maintaining state in a URL hash
https://github.com/rolyatmax/encode-object
encoding state-management url-hash
Last synced: about 1 month ago
JSON representation
encodes and decodes JS objects in Base62 - useful for maintaining state in a URL hash
- Host: GitHub
- URL: https://github.com/rolyatmax/encode-object
- Owner: rolyatmax
- License: mit
- Created: 2016-07-09T05:55:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-08-01T00:35:12.000Z (over 8 years ago)
- Last Synced: 2024-10-03T22:16:41.861Z (about 1 month ago)
- Topics: encoding, state-management, url-hash
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# encode-object
Encodes and decodes JS objects in Base62. Useful for maintaining state in a URL hash.
Right now, only works with ints.[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)
## Usage
`createEncoder` takes a config which maps each key it should find in an object to a `[max, min, step]`. `step` is optional and defaults to `1`.
```js
const config = {
foo: [0, 5],
bar: [10, 1000, 10],
baz: [0, 1],
qux: [-10, 10, 2],
};const obj = {
foo: 3,
bar: 250,
baz: 0,
qux: -6,
};const { encodeObject, decodeObject } = createEncoder(config);
encodeObject(obj); // returns '601BU'
decodeObject('601BU'); // returns object with the same keys and values as `obj`
```[![NPM](https://nodei.co/npm/encode-object.png)](https://www.npmjs.com/package/encode-object)
## License
MIT, see [LICENSE.md](http://github.com/rolyatmax/encode-object/blob/master/LICENSE.md) for details.