Git Product home page Git Product logo

vinyl's Introduction

vinyl NPM version Build Status Coveralls Status Dependency Status

Information

Packagevinyl
DescriptionA virtual file format
Node Version>= 0.9

What is this?

Read this for more info about how this plays into the grand scheme of things https://medium.com/@eschoff/3828e8126466

File

var File = require('vinyl');

var coffeeFile = new File({
  cwd: "/",
  base: "/test/",
  path: "/test/file.coffee",
  contents: new Buffer("test = 123")
});

isVinyl

When checking if an object is a vinyl file, you should not use instanceof. Use the isVinyl function instead.

var File = require('vinyl');

var dummy = new File({stuff});
var notAFile = {};

File.isVinyl(dummy); // true
File.isVinyl(notAFile); // false

constructor(options)

options.cwd

Type: String

Default: process.cwd()

options.base

Used for relative pathing. Typically where a glob starts.

Type: String

Default: options.cwd

options.path

Full path to the file.

Type: String

Default: undefined

options.history

Path history. Has no effect if options.path is passed.

Type: Array

Default: options.path ? [options.path] : []

options.stat

The result of an fs.stat call. See fs.Stats for more information.

Type: fs.Stats

Default: null

options.contents

File contents.

Type: Buffer, Stream, or null

Default: null

isBuffer()

Returns true if file.contents is a Buffer.

isStream()

Returns true if file.contents is a Stream.

isNull()

Returns true if file.contents is null.

clone([opt])

Returns a new File object with all attributes cloned.
By default custom attributes are deep-cloned.

If opt or opt.deep is false, custom attributes will not be deep-cloned.

If opt.contents is false, it will copy file.contents Buffer's reference.

pipe(stream[, opt])

If file.contents is a Buffer, it will write it to the stream.

If file.contents is a Stream, it will pipe it to the stream.

If file.contents is null, it will do nothing.

If opt.end is false, the destination stream will not be ended (same as node core).

Returns the stream.

inspect()

Returns a pretty String interpretation of the File. Useful for console.log.

contents

The Stream or Buffer of the file as it was passed in via options, or as the result of modification.

For example:

if (file.isBuffer()) {
    console.log(file.contents.toString()); // logs out the string of contents
}

path

Absolute pathname string or undefined. Setting to a different value pushes the old value to history.

history

Array of path values the file object has had, from history[0] (original) through history[history.length - 1] (current). history and its elements should normally be treated as read-only and only altered indirectly by setting path.

relative

Returns path.relative for the file base and file path.

Example:

var file = new File({
  cwd: "/",
  base: "/test/",
  path: "/test/file.coffee"
});

console.log(file.relative); // file.coffee

dirname

Gets and sets path.dirname for the file path.

Example:

var file = new File({
  cwd: "/",
  base: "/test/",
  path: "/test/file.coffee"
});

console.log(file.dirname); // /test

file.dirname = '/specs';

console.log(file.dirname); // /specs
console.log(file.path); // /specs/file.coffee
`

basename

Gets and sets path.basename for the file path.

Example:

var file = new File({
  cwd: "/",
  base: "/test/",
  path: "/test/file.coffee"
});

console.log(file.basename); // file.coffee

file.basename = 'file.js';

console.log(file.basename); // file.js
console.log(file.path); // /test/file.js
`

stem

Gets and sets stem (filename without suffix) for the file path.

Example:

var file = new File({
  cwd: "/",
  base: "/test/",
  path: "/test/file.coffee"
});

console.log(file.stem); // file

file.stem = 'foo';

console.log(file.stem); // foo
console.log(file.path); // /test/foo.coffee
`

extname

Gets and sets path.extname for the file path.

Example:

var file = new File({
  cwd: "/",
  base: "/test/",
  path: "/test/file.coffee"
});

console.log(file.extname); // .coffee

file.extname = '.js';

console.log(file.extname); // .js
console.log(file.path); // /test/file.js
`

vinyl's People

Contributors

popomore avatar yocontra avatar phated avatar pdehaan avatar jmm avatar soslan avatar hughsk avatar whyrusleeping avatar felixrabe avatar jeremyruppel avatar nfroidure avatar shinnn avatar tatsuyafw avatar bnjmnt4n avatar bobintornado avatar danielhusar avatar pgilad avatar vvakame avatar pascalduez avatar shuhei avatar laurelnaiad avatar vweevers avatar

Watchers

 avatar

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.