Skip to content

Parse Ruby's Marshal strings into JavaScript objects/JSON

License

Notifications You must be signed in to change notification settings

mockingbot/node-marshal

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-marshal

Build Status codecov

Parse Ruby's Marshal strings into JavaScript objects/JSON.

This module could not have been built without this awesome blog post series.

Installation

npm install marshal

Use

Basic use

var Marshal = require('marshal');
var m = new Marshal('0408220a68656c6c6f', 'hex');
console.log(m.parsed); // 'hello'

Decode a Rails cookie

This library was purpose-built for sharing a Rails cookie with an Express session.

See instore/rails-cookie-parser for an example.

Features / Limitations

Able to convert a Marshal string into a JavaScript object (not all types are supported, if you see one you would like supported please create an issue). i.e. Marshal.load()

Unable to convert a JavaScript object into a Marshal string. i.e. Marshal.dump()

Supported Types

  • nil (converted to null)
  • booleans
  • integers
  • floats (thank you @tgriesser!)
  • bignums (bignums are broken after v0.2.0, if you need bignum support please use v0.2.0)
  • raw strings
  • symbols
  • symbol links
  • object links
  • IVARs (encoded strings, regular expressions are not supported)
  • arrays
  • objects
  • hashes

Unsupported Types

Notes

From what I can tell, positive integers are unsigned and negative integers are signed. Thus, positive integers have twice the range as negative integers.

Acknowledgements

The bignum base conversion algorithm was adapted from MikeMcl/decimal.js which is copyright Michael Mclaughlin.

About

Parse Ruby's Marshal strings into JavaScript objects/JSON

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%