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

@lumjs/gulp-transform

v3.1.0

Published

A Gulp plugin for applying custom transformations to the contents of files

Downloads

4

Readme

@lumjs/gulp-transform

version build coverage dependencies

A Gulp plugin for applying custom transformations to the contents of files.

About this fork

This is a fork of the original gulp-transform with Teamop's replace-gulp-util pull request applied, and the version number bumped a bit. I've placed it into my @lumjs namespace to avoid any conflicts with the original package, but seeing as that package has not been updated since 2017, and there's been pull requests ignored since 2018, I think it's safe to say it's abandoned.

In a future update, I am planning to update the versions of all dependencies, but that will be a much bigger task. In addition to working around several major version upgrades, the upgrade process itself will be a major pain thanks to the unfathomable decisions of the DefinitelyTyped maintainers that caused major backwards-compatibility breakage, and has joined the list of utterly absurd open-source clusterfucks I've witnessed in the past three decades of working in the IT industry.

When I finally get this fully updated, I will bump the major version number.

Install

Install via npm:

npm install --save-dev gulp @lumjs/gulp-transform

Usage

Synchronous usage

This example adds a timestamp to the beginning of each source file. The comment format is inferred from the file extension. Files with unrecognized extensions are not modified.

gulpfile.js

const gulp = require('gulp');
const transform = require('@lumjs/gulp-transform');
const path = require('path');

const TIMESTAMP = Date();

gulp.task('timestamp', () => {
  return gulp.src('src/**/*')
    .pipe(transform('utf8', timestamp))
    .pipe(gulp.dest('out'));
});

function timestamp(content, file) {
  switch (path.extname(file.path)) {
    case '.js':
    case '.ts':
      return `// ${TIMESTAMP}\n\n${content}`;
    case '.coffee':
      return `# ${TIMESTAMP}\n\n${content}`;
    default:
      return content;
  }
}

src/hello.js

console.log('Hello, world.');

out/hello.js

// Thu Jul 27 2017 15:56:14 GMT-0700 (PDT)

console.log('Hello, world.');

Asynchronous usage

This example uses xml2js to convert XML to JSON. The callback returns a Promise since the operation is asynchronous.

gulpfile.js

const gulp = require('gulp');
const transform = require('@lumjs/gulp-transform');
const rename = require('gulp-rename');
const xml2js = require('xml2js');

gulp.task('xml-to-json', () => {
  return gulp.src('src/**/*.xml')
    .pipe(transform('utf8', xmlToJson))
    .pipe(rename({ extname: '.json' }))
    .pipe(gulp.dest('out'));
});

function xmlToJson(content) {
  return new Promise((resolve, reject) => {
    xml2js.parseString(content, (error, data) => {
      if (error) {
        reject(error);
      } else {
        resolve(JSON.stringify(data, null, 2));
      }
    });
  });
}

src/cities.xml

<cities>
  <city>Amsterdam</city>
  <city>Rotterdam</city>
  <city>The Hague</city>
</cities>

out/cities.json

{
  "cities": {
    "city": [
      "Amsterdam",
      "Rotterdam",
      "The Hague"
    ]
  }
}

API

transform([options], callback)

Creates a stream that transforms the contents of File objects. Files in both streaming and buffer mode are accepted.

To transform contents as a string, a character encoding must be specified; otherwise, contents will be passed to the callback as a Buffer.

The contents of each File are replaced with the return value of the callback. Or, to perform an asynchronous transformation, a Promise may be returned.

Parameters

TypeScript

TypeScript declarations are included in the package.

npm i -D typescript ts-node gulp @types/gulp gulp-transform

gulpfile.ts

import gulp = require("gulp");
import transform = require("@lumjs/gulp-transform");

gulp.task("build", () => {
  gulp.src("src/**/*")
    .pipe(transform("utf8", () => { /* transform contents */ }))
    .pipe(gulp.dest("out"));
});

License

Copyright © 2016–2017 Akim McMath. Licensed under the MIT License.