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

trucks-plugin-transform

v1.0.7

Published

Runs component tree transforms

Downloads

16

Readme

Transform

Transforms the component tree

Runs plugin functions that visit the component tree nodes and perform transformations.

When transform plugins are defined as strings and do not resolve to an absolute path they are deemed to be modules to require and are prefixed with trucks-transform- such that csp will require the trucks-transform-csp package.

Install

npm i trucks-plugin-transform --save-dev


Usage

This plugin is bundled with the core trucks-compiler library.

If a transforms array is declared on the options it is used:

const options = {
  transforms: ['csp']
}

Configure this plugin using the transform field:

const options {
  conf: {
    plugins: {
      transform: {
        /* plugin configuration */
      }
    }
  }
}

Or as a convenient shortcut use the top-level transform field:

const options {
  transform: {
    /* plugin configuration */
  }
}

Transforms

Transforms are a different type of plugin that are executed when the entire component tree is available.

A transform plugin returns a map of visitor functions and/or lifecycle callbacks:

function plugin(state, conf) {
  return {
    '*': (node, cb) => {
      cb(); 
    }
  }
}

Lifecycle

Lifecycle callbacks are functions that hook into events when iterating the component tree:

  • begin Called before the tree is walked.
  • enter Called when entering a node before visitor functions are invoked.
  • leave Called when leaving a node after visitor functions have been invoked.
  • end Called when the tree walk is complete.

The begin and end functions are passed the component tree so the signature is always:

function(node, cb);

For example you may want to collect all nodes of a type and operate once the walk is completed:

function plugin(state, conf) {
  const styles = [];
  return {
    end: (node, cb) => {
      // operate on the list of styles 
      cb();
    },
    Style: (node, cb) => {
      styles.push(node);
      cb(); 
    }
  }
}

Visitors

Each key in the returned map is evaluated to determine whether the visitor function wants to see a particular node, the wildcard * matches all nodes. Available node types are:

  • Tree Visit tree nodes.
  • File Visit file nodes.
  • Module Visit module nodes.
  • Component Visit component nodes.
  • Template Visit template nodes.
  • Style Visit style nodes.
  • Script Visit script nodes.

Configuration

To configure a transform plugin you can set a configuration object:

const options = {
  files: ['components.html'],
  transforms: ['skate'],
  conf: {
    transforms: {
      skate: {/* plugin configuration goes here */}
    }
  }
};

API

transform

public transform(state, conf)

Runs transform plugins on the component tree.

Returns plugin closure.

  • state Object compiler state.
  • conf Object plugin configuration.

Options

  • transforms Array list of transform plugins.

License

MIT


Created by mkdoc on August 5, 2016