th-gulphelpers
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

What is it ?

Some typescript types for a Gulp plugin e.g

export type GulpStream=NodeJS.ReadWriteStream;
export type GulpPluginWithTranformOptions=(transformOptions?:TransformOptions)=>GulpStream

and

export class FileContentsTypeNotSupportedError extends Error{
    constructor(bufferNotSupported:boolean){
        super(`Only ${bufferNotSupported?"streams":"buffers"} supported for File.contents`);
        this.BufferNotSupported=bufferNotSupported;
    }
    public BufferNotSupported:boolean;
    static create(pluginName:string,bufferNotSupported:boolean){
        return new PluginError(pluginName,new FileContentsTypeNotSupportedError(bufferNotSupported));
    }
}
export function cbErrorIfContentsTypeNotSupported(pluginName:string,file:File,cb:TransformCallback,bufferNotSupported=false,streamNotSupported=true):boolean{
    const threw=file.isStream()&&streamNotSupported||file.isBuffer()&&bufferNotSupported;
    if(threw){
        cb(FileContentsTypeNotSupportedError.create(pluginName,bufferNotSupported));
    }
    return threw;
}

Readme

Keywords

none

Package Sidebar

Install

npm i th-gulphelpers

Weekly Downloads

2

Version

1.0.2

License

ISC

Unpacked Size

5.11 kB

Total Files

4

Last publish

Collaborators

  • tonyhallett