HiPack (de)serialization library in JavaScript

Adrian Perez de Castro a58e8dd365 Release version 0.1.5 10 months ago
test b3162fe711 Fix handling of multiple input framed messages 1 year ago
.gitignore beeecd6510 Add Makefile, tweak uglifyjs flags 2 years ago
.travis.yml b0e809647c Travis-CI: Fix language name 2 years ago
CHANGELOG.md a58e8dd365 Release version 0.1.5 10 months ago
Makefile bbfa3e3078 Instruct uglify-js to also generate a source map 2 years ago
README.md d77ffbbe27 Remove references to IoJS 1 year ago
bower.json a58e8dd365 Release version 0.1.5 10 months ago
hipack.js a58e8dd365 Release version 0.1.5 10 months ago
hipack.min.js 65304e5731 Fix cast callback not being invoked for hex numbers 10 months ago
hipack.min.map 65304e5731 Fix cast callback not being invoked for hex numbers 10 months ago
package.json a58e8dd365 Release version 0.1.5 10 months ago

README.md

HiPack (de)serialization library in JavaScript

Builld status

JavaScript module to work with the HiPack serialization format. The implementation and API are intentionally simple.

Features:

  • Reading and writing HiPack formatted messages.
  • Works in NodeJS and browsers.
  • Small, self contained JavaScript implementation.
  • Less than 8kB when minified using UglifyJS2!

Installation

For Node, npm can be used to install the module:

npm install hipack-js

A hipack-js package is also available to be used with Bower:

bower install hipack-js

Usage

(The following examples use Node.)

First, import the module:

var hipack = require("hipack")

To serialize an object containing data, use hipack.dump():

var hiPackText = hipack.dump({
  authors: [
    { name: "Adrián Pérez", email: "aperez@igalia.com" },
    { name: "John Doe", email: "j@doe.org" },
  ]
});
console.info(hiPackText);

The call to console.info() will output the following

authors [
  {
     email: "aperez@igalia.com"
     name: "Adrián Pérez"
  }
  {
    email: "j@doe.org"
    name: "John Doe"
  }
]

Optionally, pass true as a second parameter to hipack.dump() in order to generate a “compact” representation of the data with indentation and whitespace removed, all in a single line.

Parsing is done using the hipack.load() function:

var data = hipack.load(hiPackText);

Browser Usage

The hipack.js script can be directly used with a <script> tag (a minified version is also available):

<!-- This creates a global "hipack" object -->
<script type="text/javascript" src="hipack.js"></script>

If the hipack global name needs to be used for other purposes, a hipack.noConflict() function is provided, which will restore its previous value and return the hipack object:

<script type="text/javascript">
  var myHiPack = hipack.noConflict();
  // Now the API functions are in "myHiPack"
  var data = myHiPack.load( ... );
</script>