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

tr

v1.1.2

Published

Reference code fdr the transform protocol

Downloads

61

Readme

Transform

Reference code for the Transform protocol.

The Transform protocol provides a very simple expression of the instructions of transforming a data record from one format to another. Such transformations are common in many areas of programming, but especially in business applications, where billions of dollars are spent integrating various info-systems.

A Transform document has two uses, as a representation of how the data fields of a record are to be modified between two systems, and as the actual input to a simple program that does the transformation. A working program (reference code for the protocol) is provided here.

The only comparitive technology that comes to mind is XSLT. Anyone who has felt working with XML and XSLT is frustrating and unnecessarily complex may appreciate this approach.
####The Transform Specification The Transform document (a.k.a. object) describes the rules in transforming one JSON document to another.
A Transform object is valid JSON, and a single Javascript object.
The keys in the object correspond to the keys in the source document.
The values for each key must be one of the following:

  • A Javascript function, the result of which is used as the value in the destination document.
  • A Javascript array with two items, the first is the new key in the destination document, the second is a function that returns the value in the destination document.
  • A Javascript array with one item, a string which defines the key in the destination document. The value in the destination document is unchanged.
  • Any key in the source document that is not in the transform object, is not carried over to the destination document.

Example..

$ npm install tr

var transformer = require('tr');

var before = [
    {name: 'Chris', age: 42, home:'IL', height:5 },
    {name: 'Barack', age:50, home:'IL', height:6 },
    {name: 'George', age:65, home:'TX', height:5 },
    {name: 'Bill', age:70, home:'NY', height:6 }
]

var mapping = {
    name: function(s) { return s + '!'},
    age: function(i) { return i > 50 ? 'old' : 'not old' },
    home: ['place', function(s){ return s }],
    height: ['IQ']
}

var after = transformer.transform(before, mapping)

console.log(JSON.stringify(after, null, 4));

Validation of records can also be done, see validation.md