Skip to content

encodes and decodes JS objects in Base62 - useful for maintaining state in a URL hash

License

Notifications You must be signed in to change notification settings

rolyatmax/encode-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

encode-object

Encodes and decodes JS objects in Base62. Useful for maintaining state in a URL hash. Right now, only works with ints.

experimental

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.

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

License

MIT, see LICENSE.md for details.

About

encodes and decodes JS objects in Base62 - useful for maintaining state in a URL hash

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published