开发者社区> 镜像站> NPM> apply-transform
apply-transform
Applies a transform to an input string and calls back with result, mostly useful for testing transforms
Last updated 7 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install apply-transform 
SYNC missed versions from official npm registry.

apply-transform build status

testling badge

Applies a transform to an input string and calls back with result, mostly useful for testing transforms

var applyTransform = require('apply-transform')
  , assert = require('assert')
  , through = require('through2');

function toUpper() {
  return through(
    function (chunk, enc, cb) {
      this.push(chunk.toUpperCase());
      cb();
    }
  )
}

var tx = toUpper();
tx._writableState.decodeStrings = false;

applyTransform(tx, 'hello world', function (err, res) {
  if (err) return assert.fail(err); 
  assert.equal(res, 'HELLO WORLD', 'calls back with transformed result')
})  

Installation

npm install apply-transform

API

/**
 * Applies the given transform to the input and calls back with result.
 * 
 * @name 
 * @function
 * @param {TransformStream} transform to apply to the @see input
 * @param {String} input to transform
 * @param {Function} cb function(err, output) { }
 *  - {Error} err: is set if an error occurred
 *  - {String} output: the result of applying the @see transform to the @see input
 * @return {ReadableStream} that streams the input string char by char, useful for debugging failing transforms
 */

License

MIT

Current Tags

  • 0.1.4                                ...           latest (7 years ago)

5 Versions

  • 0.1.4                                ...           7 years ago
  • 0.1.3                                ...           7 years ago
  • 0.1.2                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 3
Dependencies (1)
Dev Dependencies (4)