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

tranz

v0.6.0

Published

The framework for transform anything

Downloads

30

Readme

tranz

Build status Test coverage NPM version NPM Downloads Prettier Conventional Commits

The framework for transform anything

Feature

  • Allow running shell script as processor
  • Allow concurrent multi-processor for fast speed
  • Support runtime configuration

Where use it?

  • Transform git commit message for your self own processor.

    Use it with husky (Git hooks made easy)

    {
      "tranz": {
        "processors": ["echo '$(cat)\n\nbranch: $(git rev-parse --abbrev-ref HEAD)'"]
      },
      "husky": {
        "hooks": {
          "commit-msg": "npx tranz $HUSKY_GIT_PARAMS --write"
        }
      }
    }

    Then the end of commit message would be appended with current branch name.

Installation

npm install tranz
# or use yarn
yarn add tranz

Usage

Package

tranz(input: any, processors: Array<Function | [string, any] | string>, options?): Promise<any>

  • index.js
import { join } from 'path'
import tranz from 'tranz'

tranz(
  'abc',
  [
    // function
    require('./lib/wrapper')({ c: '-' }),
    // return Processor[]
    require('./lib/multi-wrapper')({ c: 0 }),
    // [moduleId: string, options: any]
    ['./wrapper', { c: '_' }],
    // module name with query string
    './wrapper?c=$',
    // shell script
    // get input from stdin
    // output from stdout
    'echo $(cat)-abc'
  ],
  {
    // Resolve processor path's base dir
    // Default: $PWD
    cwd: join(__dirname, 'lib'),
    // Whether run tranz parallelly
    // Note: parallel mode could enabled when all of the processor is typeof `string` (serializable)
    // Default: false
    parallel: false,
    // Search runtime configuration.
    // e.g. 1. `tranz` field in `package.json`
    //      2. file named `.tranzrc`
    //      3. file named `.tranzrc.js`
    // Default: true
    userc: true
  }
).then(output => {
  console.log(output)
})

// Output:
// $_10-abc-01_$-abc
  • lib/wrapper.js
module.exports = ({ c }) =>
  function(input) {
    // this.cwd === __dirname
    // this.parallel === false
    // this.userc === true
    // `this` is equals to options shallowly

    return `${c}${input}${c}`
  }
  • lib/multi-wrapper.js
module.exports = ({ c }) => [input => `${c}${input}${c}`, input => Promise.resolve(`${c + 1}${input}${c + 1}`)]

CLI

npm i tranz -D
npx tranz -h

tranz -i $PWD -p ./upper
cat $PWD | tranz -p ./upper

RC Config

  • package.json
{
  "tranz": {
    "processors": [
      [
        "../processor-wrapper",
        {
          "char": "abc"
        }
      ],
      "../processor-upper",
      "module-p-fix?q=halala"
    ],
    "parallel": false
  }
}

Bulit-in Processor

See source code

  • _json-parse - run JSON.parse(input, reviver?)
  • _json-stringify - run JSON.stringify(input, replacer?, space?)

Example

tranz({ key: 'foo' }, [['_json-stringify', { space: 2 }]]).then(output => {
  // {
  //   "key": "foo"
  // }
})

Processor Inheritance

Write the processor as follow:

// This processor depends `./upper` and `./trimLeft` processor
module.exports = opts => [require('./upper')({}), [require.resolve('./trimLeft'), {}]]

Multi-tranz config in rc config

  • package.json

    {
      "tranz": {
        "foo": {
          "processors": [
            "echo foo"
          ],
          "parallel": true
        }
        "processors": [
          "echo default"
        ],
        "parallel": false
      }
    }
  • Run command in shell

    tranz --input="" # echo default
    tranz --input="" --name="foo" # echo foo

Tests

Unit

npm test

Benchmark

npm run benchmark

Roadmap

  • [ ] file write [tranz-globs]
  • [ ] file glob [tranz-globs]
  • [ ] ignore files [tranz-globs]

Related

Authors

This library is written and maintained by imcuttle, [email protected].

License

MIT