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

gulptransformbase

v1.0.6

Published

Base transform class

Downloads

15

Readme

What is it

An abstract Transform class to be used as a base class for a gulp transform.

Typescript constructor signature

export interface GulpTransformBaseOptions{
    supportsBuffer?:boolean,
    supportsStream?:boolean,
    pluginName?:string
}

export abstract class GulpTransformBase<T> extends Transform{

    constructor(options?:T,baseOptions?:GulpTransformBaseOptions,transformOptions?:TransformOptions){
        super({...transformOptions,...{objectMode:true}});
....

Note that objectMode does not need to be provided. Provided options are available through this.options.

Transforms the transform process

It provides the _transform method and changes the functionality for derived classes through template methods to make the transformation easier.

There are two pre process methods that can be overridden, ignoreFile and filterFile with the base class returning false for both.

protected ignoreFile(file:File):boolean
protected  filterFile(file:File):boolean

Returning true for ignoreFile will pass the file through the callback and there will be no further processing. Returning true for filterFile will call the callback without the file thus removing the file from down streams.

If the file has not been ignored or filtered then the file content type is determined and the applicable transformBufferFile, transformStreamFile or transformNullFile is called. These methods work like the normal _transform method. The transformBufferFile and transformStreamFile methods have the file contents as an additional argument. Override as necessary.

e.g transformBufferFile(file:File,file.contents:Buffer,encoding:string,callback:(err?: any, data?: File)=>void)

Error management

No need to call the callback

It wraps all calls to template methods in try/catch handlers. Any exceptions are wrapped in a PluginError and the _transform callback called appropriately. You can throw a string or an error. If an error has no message a default error message will be added, as the PluginError itself will throw otherwise.

Ensures transformed file is same type as original

This class ensures that your plugin can only return file contents of the same type ( Buffer | Stream ) that it received. It will throw a PluginError if you do not adhere to this.

Supported file types

Through options or default values ( supportsBuffer:true,supportsStream:false ) it deals with unsupported file contents type, throwing a PluginError wrapping a FileContentsTypeNotSupportedError whose BufferNotSupported property will be true if received an unsupported buffer or false if received an unsupported stream.

Plugin name

Created PluginError instances have the plugin name taken from ctor option or by using the name of the derived class. The default plugin name is the class name to lowercase with the word transform removed, prefixed with 'gulp-'.