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

transform-chain

v0.0.1

Published

Build a chain of transforms

Downloads

5

Readme

transform-chain Build Status

Build a chain of transforms

Provides a means of managing a list of transforms. Built with require.extensions transforms in mind, but not limited to that use case.

Install

$ npm install --save transform-chain

Usage

import TransformChain from 'transform-chain';
const chain = new TransformChain();

chain.appendTransform((code, filename, next) => {
  // true if downstream transforms want to manipulate this file too.
  next.hasMatch(filename); 

  // transform the code - no additional transforms applied
  return doTransform(code);
  
  // transform the code and forward it down the chain
  return next(doTransform(code), filename);
  
  // forward down the chain, and perform the transform after
  return doTransform(next(code, filename));
});

This module is also my first attempt at auto generating documentation using documentation.js and JSDoc.

HTML Documentation: http://jamestalmage.github.io/transform-chain/

API

TransformChain

Creates a new transform chain.

appendTransform

Appends a transform to the end of the chain.

Parameters

  • transform Transform or TransformDefinition the transform to append.

hasMatch

Check if the chain has a matching transform for a particular file.

Parameters

  • filename string the path to the file.

Returns boolean true if at least one transform in the chain matches the file.

notifyPostLoadHooks

Notify every transform that a file has been loaded. Included for legacy istanbul support.

Parameters

  • filename string Passed to every transforms postLoadHook (regardless of whether the transform matches the loaded file).

prependTransform

Prepends a transform at the beginning of the chain.

Parameters

  • transform Transform or TransformDefinition the transform to prepend.

transform

Transform an input using the matching transforms from the chain.

Parameters

  • code Any The object to be transformed using the chain. Usually this will always be a string, but it is not required. Whatever type it is. All transforms in the chain must support it.
  • filename string

Returns Any The transformed results. Again, this is almost always going to be a string.

Transform

Create a new transform.

Parameters

  • opts Object or transformCallback
    • opts.transform [transformCallback] The transform function. (optional, default noop)
    • opts.match [Function or string or Array<string> or RegExp] Used to filter whether or not this transform is applied to a given file.
    • opts.extensions [Array<string>] List of file extensions this transform applies to. (optional, default '.js')
    • opts.verbose [boolean] If true, every invocation of the transform will be logged. (optional, default false)
    • opts.name [string] The name of this transform, used in logging and error reporting.

Returns Transform A new transform instance

matches

Check whether this transform should be applied to a given file. transformCallback

Parameters

  • filename string The name of the file

Returns boolean true if this transform should be applied to the file.

transform

Perform the transform. Called with the same parameters as transformCallback.

Parameters

  • code string or Any
  • filename string
  • next Function

Returns string or Any

transformCallback

A callback that performs a transform

Parameters

  • code string or Any The input to be transformed.
  • filename string The name of the file being transformed.
  • next Function Execute the rest of the transform synchronously
    • next.hasNext Function Check if any of the transforms remaining in the chain can handle the file. You can optionally pass a string to change the name of the file.

License

MIT © James Talmage