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

serialization

v0.2.0

Published

serialize and deserialize objects with function arguments in Node.js

Downloads

119

Readme

serialize

Serialize Javascript object hierarchies that contain multiple types and functions.

This library was built with the following use-case in mind:

You have a complex classifier, such as in the limud.js framework. For example, it may be a hierarchical multi-label classifier, based on a binary classifier, with a custom feature extractor.

You want to train the classifier on your computer, and use the trained classifier on another machine. The another machine may be, for example, a web-server that uses the trained classifier to classify new samples on demand.

So, you would like to save the trained classifier to a file, then transfer the file to the remote server, and then read the classifier from the file on that remote server.

Unfortunately, this task is not natively supported in Node.js. The native Node.js serialization mechanism is JSON.stringify/JSON.parse, but, these functions handle only data fields - not functions or class prototypes.

This library suggests the following solution (pseudo-code).

On the home machine:

function createNewClassifier() {
	// Write code to create a fresh  (untrained) classifier.
	// This code should be stand-alone - it should include all the 'require' statements
	//   required for creating the classifier.
	// Use "__dirname" to refer to the current folder, 
	//   so that the result will be able to run on another folder. 
}

var myClassifier = createNewClassifier();

myClassifier.train(dataset);

var serialize = require('serialize'); // require the current package

var myClassifierString = serialize.toString(myClassifier, createNewClassifier);

// save myClassifierString to a file, and send to the remote server.
// the createNewClassifier function is also saved.

On the remote server:

var myClassifierString = // read from file

var serialize = require('serialize'); // require the current package

var baseFolder = __dirname; // this comes in place of the "__dirname"s in createNewClassifier 

var myClassifier = serialize.fromString(myClassifierString, baseFolder);

myClassifier.classify(sample);

The demos folder contains two working demos (demo1 and demo2), and one non-working demo (demo3) that is left for future work.