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

transformer-pkg

v0.1.3

Published

transformer package helper

Downloads

9

Readme

transformer-pkg

Tool to automate lots of transformer module writing.

dat

Usage

Usage: transformer-pkg <subcommand>

Subcommands:

  init [<kind>]  -- generate module files
  src            -- update transformer.jsonld
  test           -- src, then npm test
  publish        -- src, then npm publish

Flags:

  -f --force  Overwrite existing files.
  -h --help   Show these instructions. :)

Examples

transformer-pkg init type

> ls
> transformer-pkg init type
Transformer kind: type
Transformer type-id ([a-z0-9-]+): unix-time
Transformer description: Unixtime date, number of seconds since 1970.
transformer-pkg --> wrote index.js
transformer-pkg --> wrote test.js
transformer-pkg --> wrote README.md
transformer-pkg --> wrote package.json
transformer-pkg --> wrote transformer.jsonld
transformer-pkg --> init done.

Next, you should:

- run `npm install`
- modify index.js, test.js, and README.md as needed
- run `transformer-pkg test` till it works.
- run `transformer-pkg publish` to ship!

transformer-pkg publish will:

1. run `npm init` to prompt for npm package details
2. update `transformer.jsonld` with the latest src
3. run `npm publish`

> ls
README.md
index.js
package.json
test.js
transformer.jsonld
> cat * # below

type package.json

{
  "name": "transformer.unix-time",
  "version": "0.0.1",
  "description": "transformer type: Unixtime date, number of seconds since 1970.",
  "main": "index.js",
  "transformer": "transformer.jsonld",
  "scripts": {
    "test": "node test.js"
  },
  "keywords": [
    "transformer",
    "transformer-type"
  ],
  "license": "MIT",
  "dependencies": {
    "dat-transformer": "~0.1.3"
  }
}

type index.js

var transformer = require('dat-transformer');

module.exports = new transformer.Type({
  // @context and type filled in automatically.
  'id': 'unix-time',
  'description': 'Unixtime date, number of seconds since 1970.',
  'schema': "string"
});

type test.js

#!/usr/bin/env node
var transformer = require('dat-transformer');
var type = require('./');

// run stock type tests
var test = transformer.test.type(type);


// that should be enough, but you can also run your own tests:
/*

test('your test description', function (t) {
  YOUR TEST CODE HERE
  t.end();
});

*/

transformer-pkg init conversion

> ls
> transformer-pkg init conversion
Transformer kind: conversion
Transformer Convert From type-id ([a-z0-9-]+): unix-time
Transformer Convert To type-id ([a-z0-9-]+): js-date
transformer-pkg --> Transformer conversion-id: unix-time-to-js-date
Conversion is `async` or `sync`: sync
transformer-pkg --> wrote index.js
transformer-pkg --> wrote test.js
transformer-pkg --> wrote README.md
transformer-pkg --> wrote package.json
transformer-pkg --> wrote transformer.jsonld
transformer-pkg --> init done.

Next, you should:

- run `npm install`
- run `npm install --save transformer.unix-time transformer.js-date`
- modify index.js, test.js, and README.md as needed
- run `transformer-pkg test` till it works.
- run `transformer-pkg publish` to ship!

transformer-pkg publish will:

1. run `npm init` to prompt for npm package details
2. update `transformer.jsonld` with the latest src
3. run `npm publish`

> ls
README.md
index.js
package.json
test.js
transformer.jsonld
> cat * # below

conversion package.js

{
  "name": "transformer.unix-time-to-js-date",
  "version": "0.0.1",
  "description": "transformer conversion: unix-time to js-date",
  "main": "index.js",
  "transformer": "transformer.jsonld",
  "scripts": {
    "test": "node test.js"
  },
  "keywords": [
    "transformer",
    "transformer-conversion"
  ],
  "license": "MIT",
  "dependencies": {
    "dat-transformer": "~0.1.3"
  }
}

conversion sync index.js

var transformer = require('dat-transformer');
var tUnixTime = transformer('unix-time');
var tJsDate = transformer('js-date');
// require any other modules you may need here.

module.exports = transformer.Conversion(tUnixTime, tJsDate, convert);

// this is a synchronous conversion.
function convert(input) {
  // compute the conversion output
  var output = YOUR CODE HERE;

  // if an error ocurrs, throw it.
  throw new Error('tUnixTimeToJsDate not implemented');

  // else, return the result.
  return output;
}

conversion async index.js

var transformer = require('dat-transformer');
var tUnixTime = transformer('unix-time');
var tJsDate = transformer('js-date');
// require any other modules you may need here.

module.exports = transformer.Conversion(tUnixTime, tJsDate, convert, {
  async: true, // explicitly mark this callback as async. important.
});

// this is an asynchronous conversion.
function convert(input, callback) {
  // compute the conversion output
  var output = YOUR CODE HERE;

  // if an error ocurrs, send it in the callback (first arg).
  callback(Error('tUnixTimeToJsDate not implemented'));

  // else, call the callback with result (second arg).
  callback(null, output);
}

conversion sync test.js

#!/usr/bin/env node
var transformer = require('dat-transformer');
var conv = require('./');

// run stock conversion tests, and try expected input/output pairs
var test = transformer.test.conversion(conv, [
  // [input, expectedOutput]
  ADD YOUR TEST PAIRS HERE
])


// that should be enough, but you can also run your own tests:
/*

test('your test description', function (t) {
  YOUR TEST CODE HERE
  // test conversions this way:
  test.converts(t, conv, input, expectedOutput)
  t.end();
});

*/