Code Monkey home page Code Monkey logo

vinyl-contents's Introduction

vinyl-contents

NPM version Downloads Build Status Coveralls Status

Utility to read the contents of a vinyl file.

Usage

/*
  WARNING: This is a very naive plugin implementation
  It is only meant for demonstation purposes.
  For a more complete implementation, see: https://github.com/gulp-community/gulp-pug
*/
var { Transform } = require('streamx');
var pug = require('pug');
var vinylContents = require('vinyl-contents');

function gulpPug(options) {
  return new Transform({
    transform: function (file, cb) {
      vinylContents(file, function (err, contents) {
        if (err) {
          return cb(err);
        }

        if (!contents) {
          return cb();
        }

        file.contents = pug.compile(contents.toString(), options)();
        cb(null, file);
      });
    },
  });
}

API

vinylContents(file, callback)

Warning: Only use this if interacting with a library that can only receive strings or buffers. This loads all streaming contents into memory which can cause unexpected results for your end-users.

Takes a Vinyl file and an error-first callback. Calls the callback with an error if one occur (or if the first argument is not a Vinyl file), or the file contents if no error occurs.

If the Vinyl contents are:

  • A Buffer, will be returned directly.
  • A Stream, will be buffered into a BufferList and returned.
  • Empty, will be undefined.

License

MIT

vinyl-contents's People

Contributors

github-actions[bot] avatar phated avatar sttk avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vinyl-contents's Issues

Becoming package maintainer

It looks like you guys are busy, so maybe I can become a maintainer? It shouldn't be too much trouble, as I really need this package quite often. Let me know what you think!

Support for promises

Would it be possible to add support for promises? This would make it significantly easier to use in my code base.

I can fire up a pull request if you want; I just have to make sure that the old API still works.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.