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

@wessberg/marshaller

v3.0.11

Published

A lightweight way to serialize and deserialize complex data types non-destructively

Downloads

147

Readme

A lightweight way to serialize and deserialize complex data types non-destructively

Description

Marshaller provides a lightweight way to serialize and deserialize complex data types non-destructively. Essentially, it is JSON.parse() and JSON.stringify with support for far more data types, circular references, and with the guarantee that whatever is serialized can be deserialized into the exact same representation without losing any information.

You can consider this to be direct replacements for the JSON.[stringify|parse] methods, provided through marshall for serialization and demarshall for deserialization.

Features

  • "JSON.parse/JSON.stringify on steroids"
  • Non-destructive serialization/deserialization of data
  • Supports Circular references
  • A wide variety of supported data types - from simple things as strings to complex things such as Maps, Sets and Typed Arrays

Table of Contents

Install

NPM

$ npm install @wessberg/marshaller

Yarn

$ yarn add @wessberg/marshaller

Supported data types and features

  • Anything that is JSON serializable today: number, boolean, string, array, object literal
  • References, including circular references
  • RegExp
  • Date
  • Map
  • Set
  • Symbol
  • BigInt
  • undefined
  • null
  • Int8Array
  • Int16Array
  • Int32Array
  • UInt8Array
  • UInt8ClampedArray
  • UInt16Array
  • UInt32Array
  • Float32Array
  • Float64Array
  • String
  • Number
  • Boolean

Usage

import {marshall, demarshall} from "@wessberg/marshaller";

// Marshall some complex data that wouldn't normally be JSON serializable
const marshallResult = marshall({
	a: new Set([1, 2, /foo/, {a: new Date(), b: new Float32Array([1, 2, 3])}])
});

// Demarshall it to get a structurally identical representation back of the data
const demarshallResult = demarshall(marshallResult);

Contributing

Do you want to contribute? Awesome! Please follow these recommendations.

Maintainers

| | | --------------------------------------------------------------------------------------------------------------------------------- | | Frederik Wessberg@FredWessbergLead Developer |

Backers

Patreon

Become a backer and get your name, avatar, and Twitter handle listed here.

FAQ

Why are functions not supported

First, there are security considerations. But more importantly, functions can reference identifiers that lives in a lexical environment that is declared outside of the local scope of that function. Marshalling this data would require passing in a sandboxed environment which breaks the promise of the library - simple replacement for JSON, with non-destructive serialization/deserialization.

License

MIT © Frederik Wessberg (@FredWessberg) (Website)