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

spud

v2.0.1

Published

Load and convert content bundles to and from different formats, including .properties, .json, etc.

Downloads

3,927

Readme

Spud

Lead Maintainer: Aria Stewart

Build Status

Load and convert content bundles to and from different formats, including .properties, .json, etc.

API

spud.registerSerializer(name, serializer)

Register a custom serializer. See the "Plugins" section below for more information on custom serializers

var mySerializer = require('node-mySerializer');
require('spud').registerSerializer('mySerializer', mySerializer);

spud.convert(source, sourceType, targetType, [writeStream], [callback])

Deserializes the source (file, buffer, or Read Stream) of type sourceType and serializes to targetType, writing the results to the optional writeStream, or providing them to the optional callback. The callback should have the signature function (err, data);

var spud = require('spud'),
	fs = require('fs'),
	readStream = fs.createReadStream('./config.json'),
	writeStream = fs.createWriteStream('./config.properties');

spud.convert(readStream, 'json', 'properties', writeStream, function (err) {
	console.log('Conversion complete.');
});

spud.deserialize(source, sourceType, callback)

Deserializes the source (file, buffer, or Read Stream) of type sourceType and invokes the provided callback with the result or any error that occurred. The callback should have the signature function (err, data);

var spud = require('spud'),
	fs = require('fs'),
	readStream = fs.createReadStream('./config.json');

spud.deserialize(readStream, 'json', function (err, data) {
	console.log(err || data);
	console.log('Conversion complete.');
});

spud.serialize(source, targetType, [writeStream], [callback])

Serializes the source (String) to targetType and invokes the provided callback with the result or any error that occurred. The callback should have the signature function (err, data);

var spud = require('spud'),
	fs = require('fs'),
	writeStream = fs.createWriteStream('./config.json');

var settings = {
	host: "www.paypal.com",
	port: 8080
};

spud.serialize(settings, 'json', writeStream, function (err) {
	console.log('Conversion complete.');
});

Serializers supported out of the box

properties: Java-style properties files, treated as UTF-8. Some effort is made build a richer object model from structured keys.

value=A Value
array[0]=First Entry
array[1]=Second Entry
map[US]=United States
map[GB]=United Kingdom
include=../file.properties

json: A simple, direct output of the data structure as JSON

{
    "value": "A Value",
    "array": [
        "First Entry",
        "Second Entry"
    ],
    "map": {
        "US": "United States",
        "GB": "United Kingdom"
    },
    "include": "../file.json"
}

Includes are processed at load time, using paths resolved relative to the source files, just like paths in require(modulename). Which serializer is used is controlled by the file extension.

Plugins

Writing serializers is easy. It's just 3 steps:

  1. Make sure your module exports an object with a property called 'Reader' and one called 'Writer' whose values are the constructors for your deserializer and serialzer, respectively:
// index.js
module.exports = {
	Reader: MyReader,
	Writer: MyWriter
};
  1. Build out your deserializer implementation. It merely needs to implement a method called _doDeserialize that accepts data (in the form of a string) and callback arguments, and invokes the callback with error and deserialized data.
function MyReader() {
    MyReader.super_.call(this);
}

util.inherits(MyReader, spud.AbstractReader);

MyReader.prototype._doDeserialize = function(input, callback) {
    // TODO: Implement
    var data = null;
    // ...
    callback(null, data);
};
  1. Build out your serializer implementation and a Read Stream for outputting the serialized data.
function MyWriter() {
    MyWriter.super_.call(this);
}

util.inherits(MyWriter, spud.AbstractWriter);

MyWriter.prototype._doCreateReadStream = function (data) {
    return new CustomReadStream(data);
};

The stream must accept a data object in its constructor and implement the NodeJS Read Stream interface. It is likely that this where your serialization implementation will go. When chunks of data are availble/serialized, write them out using the 'data' event.

var util = require('util');

function CustomReadStream(data) {
	Stream.call(this);
	this._data = data;
}
util.inherits(ReadStream, Stream);

MyStream.prototype._read = function (size) {
	var serialized = null;
	// TODO: Serialize this._data
	this.push(serialized);
};