npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hyrious/marshal

v0.3.3

Published

Ruby marshal for the browser and node.js

Downloads

4,515

Readme

@hyrious/marshal

version npm package size downloads

Ruby marshal for the browser and Node.js.

Install

npm add @hyrious/marshal

Usage

import { dump, load } from "@hyrious/marshal";
dump(null); // Uint8Array(3) [ 4, 8, 48 ]
load("\x04\b0"); // null

// in Node.js
load(fs.readFileSync("data"));

// in Browser
load(await file.arrayBuffer());

Ruby ↔ JavaScript

| Ruby | JavaScript | | ------------ | ------------------------------------------- | | nil | null | | "string" | "string" | | :symbol | Symbol("symbol") [^1] | | 123456 | 123456 (number) | | 123.456 | 123.456 (number) | | /cat/im | /cat/im (RegExp) | | [] | [] [^2] | | {} | {} (plain object) [^3] | | Object.new | RubyObject { class: Symbol(object) } [^2] |

[^1]: Symbols are always decoded in UTF-8 even if they may have other encodings. [^2]: Instance variables are stored directly as props, i.e. obj[Symbol(@a)] = 1. [^3]: String/symbol/number keys are always decoded as JS object props.

String

Because users may store binary data that cannot be decoded as UTF-8 in Ruby, strings are decoded into Uint8Array firstly, then converted to string using TextDecoder if seeing an instance variable indicating the encoding.

load('\x04\b"\0'); //=> Uint8Array []
load('\x04\bI"\0\x06:\x06ET'); //=> ""

The special instance variables are:

| name | value | encoding | | ----------- | ------------ | ------------- | | :E | true / false | UTF-8 / ASCII | | :encoding | "enc" | enc |

So for strict compatibility, you should check if a string is Uint8Array before using it:

var a = load(data);
if (a instanceof Uint8Array) a = decode(a); // if you know it must be a string
if (typeof a === "string") do_something(a);

Or you can use options.string to control the behavior, see options.string.

Symbols

You can use Symbol.keyFor(sym) in JavaScript to get the symbol name in string.

RegExp

Only i (ignore case) and m (multi-line) flags are preserved.

Hash

This library decodes Hash as plain object by default, which means unusual keys like an object is ignored. However, it is still possible to keep these keys using Map or wrapper classes, see options.hash.

Instance Variables

This library decodes instance variables (often @a = 1) as object props. It is guaranteed that you can retrieve these properties using Object.getOwnPropertySymbols(). It is possible to convert these symbols to strings, see options.ivarToString.

API Reference

FAQ

ChangeLog

Develop

  • Run npm t to run tests.
  • Run npm t clone to only run clone.ts.

Reference

License

MIT @ hyrious