Skip to content

aperezdc/hipack-js

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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>

About

HiPack (de)serialization library in JavaScript

Resources

Stars

Watchers

Forks

Packages

No packages published