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

tanagra

v0.3.3

Published

Serialization library for javascript

Downloads

315

Readme

tanagra

Shaka, When the Walls Fell

A simple, lightweight node.js serialization library supporting ES6 classes (including Maps). Currently serializes to both JSON and Google Protobuf formats.

Overview

The tanagra project aims to provide javascript developers with the ability to serialize complex, nested classes into a format which can be transmitted over a network or stored in a datastore such as redis. The deserialized objects contain all the data and functions of the original classes, allowing them to be used in code as the originals were. The library requires only standard Javascript (currently tested with ES6 and node.js), with no dependency on experimental features, Babel transpiling or TypeScript.

The project website and API documentation can be found here.

The npm packages can be found here.

Project structure

The project is divided into a number of modules:

  • tanagra-core - common functionality required by the different serialization formats, including the function for marking classes as serializable
  • tanagra-json - serializes the data into JSON format
  • tanagra-protobuf - serializes the data into Google protobuffers format (experimental)
  • tanagra-protobuf-redis-cache - a helper library for storing serialized protobufs in redis
  • tanagra-auto-mapper - walks the module tree in node.js to build up a map of classes, meaning the user doesn't have to specify the type to deserialize to (experimental)

Installation

$ npm add --save tanagra-core
$ npm add --save tanagra-json
$ npm add --save tanagra-protobuf
$ npm add --save tanagra-protobuf-redis-cache
$ npm add --save tanagra-auto-mapper

Alternatively, to install the packages required for default (JSON) serialization:

$ npm add --save tanagra

Basic usage

The following example declares a serializable class, and uses the tanagra-json module to serialize/deserialize it:

const serializable = require('tanagra-core').serializable

class Foo {
  constructor(bar, baz1, baz2, fooBar1, fooBar2) {
    this.someNumber = 123
    this.someString = 'hello, world!'
    this.bar = bar // a complex object with a prototype
    this.bazArray = [baz1, baz2]
    this.fooBarMap = new Map([
      ['a', fooBar1],
      ['b', fooBar2]
    ])
  }
}

// Mark class `Foo` as serializable and containing sub-types `Bar` and `Baz`
module.exports = serializable(Foo, [Bar, Baz], [
  // previous versions of the class
  [Bar, Baz, FooBar], // this version also references FooBar
  [FooBarBaz]         // this version references a different type altogether, FooBarBaz
])

// ...

const json = require('tanagra-json') // alternatively, `require('tanagra-protobuf')`
json.init()                          // `await json.init()` if you're using `tanagra-protobuf`

const foo = new Foo(bar, baz)
const encoded = json.encodeEntity(foo)

// ...

const decoded = json.decodeEntity(encoded, Foo)

Contributing

I welcome contributions to the project. You might want to start with some n00b issues. If you do pick up an issue, you can email me to let me know you're working on it, to avoid duplication.

Roadmap

  • Better handling of dynamic changes to class structure at runtime
  • Better support for pre-ES6 data-structures (functions-as-classes)
  • Full support for Google protobufs (including caching in Redis)
  • Support for client-side Javascript
  • Support for ESNext decorators
  • Support for Typescript