https://github.com/sauldoescode/simple-msgpack
modern yet tiny msgpack for node and the web. >2.3kb
https://github.com/sauldoescode/simple-msgpack
Last synced: 12 months ago
JSON representation
modern yet tiny msgpack for node and the web. >2.3kb
- Host: GitHub
- URL: https://github.com/sauldoescode/simple-msgpack
- Owner: SaulDoesCode
- License: mit
- Created: 2018-10-31T10:55:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-13T18:09:10.000Z (about 7 years ago)
- Last Synced: 2025-02-05T00:02:33.209Z (about 1 year ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## msgpack for all
[](https://travis-ci.org/SaulDoesCode/simple-msgpack)
``simple-msgpack`` is an adaptation from [ygeo/msgpack.js](https://github.com/ygoe/msgpack.js)
this version is ES7+ and will not work in older browsers.
#### install the lastest
```html
```
or just download msgpack.min.js from the repo
### Weight Currently
raw: ``13.9kb``
minified: ``5.76kb``
minified + gzip: ~``2.2kb``
## API
``.encode`` put in your objects, arrays, or what ever else JSON would have accepted
``.decode`` deserialize raw Uint8Arrays straight into what they were before they were encoded
```js
const person = {
name: 'Bob Guy',
languages: ['javascript', 'golang'],
born: new Date(Date.parse('1 April 1997'))
}
const raw = msgpack.encode(person)
const decodedPerson = msgpack.decode(raw)
if (
decodedPerson.name === person.name &&
+decodedPerson.born === +person.born
) {
console.log('all is well that decodes well!')
}
```
---
#### tip
if you need to decode a msgpack string, like, say from localStorage for example,
then do this:
```js
const data = localStorage
.getItem('msgpack-stored-as-number-string')
const out = msgpack.decode(
Uint8Array.from(
data
.split(',')
.map(i => parseInt(i, 10))
)
)
if (out.rightAsRain) {
console.log('good!')
}
```
---
## LICENSE is MIT
Original creator is Yves github.com/ygoe.
This is an adaptation/simplification of
his original project.
This version, like his, is MIT so do what you will with it.