How to use the vinyl.isVinyl function in vinyl

To help you get started, we’ve selected a few vinyl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jonschlinkert / load-templates / index.js View on Github external
createView(view, options) {
    options = options || {};
    let opts = Object.assign({ cwd: process.cwd() }, this.options);
    let key;

    if (typeOf(view) === 'object') {
      view = File.isVinyl(view) ? view : new File(view);
      opts = Object.assign({}, opts, options);

    } else if (typeof view === 'string') {
      key = view;
      if (File.isVinyl(options)) {
        view = options;
      } else {
        view = new File(Object.assign({ path: key }, options));
        opts = Object.assign({}, opts, options);
      }
      view.cwd = opts.cwd;
    } else {
      throw new TypeError('expected view to be a string or object');
    }

    view.cwd = path.resolve(view.cwd);
    view.base = path.resolve(options.base || view.cwd);

    // prime the view's metadata objects
    view.options = view.options || {};
    view.locals = view.locals || {};
github gulpjs / vinyl-sourcemap / index.js View on Github external
function add(file, callback) {

  // Bail early an error if the file argument is not a Vinyl file
  if (!File.isVinyl(file)) {
    return callback(new Error(PLUGIN_NAME + '-add: Not a vinyl file'));
  }

  // Bail early with an error if file has streaming contents
  if (file.isStream()) {
    return callback(new Error(PLUGIN_NAME + '-add: Streaming not supported'));
  }

  // Bail early successfully if file is null or already has a sourcemap
  if (file.isNull() || file.sourceMap) {
    return callback(null, file);
  }

  var state = {
    path: '', // Root path for the sources in the map
    map: null,
github stevelacy / gulp-git / test / commit.js View on Github external
gitS.on('data', function(data) {
          if (!isVinyl(data)) {
            console.log(data);
            gotData = true;
          }
        });
github assemble / assemble / test / app.create.js View on Github external
return fs.readFileSync(file.path);
      };

      var Views = App.Views;
      var views = new Views({View: Vinyl});

      views.addView('a.hbs', {path: 'a.hbs', content: 'a'});
      views.addView('b.hbs', {path: 'b.hbs', content: 'b'});
      views.addView('c.hbs', {path: 'c.hbs', content: 'c'});

      app = new App();
      app.create('pages', views);

      var a = app.pages.getView('a.hbs');
      assert(a instanceof Vinyl);
      assert(Vinyl.isVinyl(a));
      assert(typeof a.read === 'function');

      views.addView('d.hbs', {path: 'd.hbs', content: 'd'});
      var d = app.pages.getView('d.hbs');
      assert(d instanceof Vinyl);
      assert(Vinyl.isVinyl(d));
    });
  });
github jelz / gulp-metalsmith / test / plugin.js View on Github external
prepare('index.html', {use: badMiddleware}).on('data', function (file) {
    t.notEqual(vinyl, null);
    t.notEqual(file, vinyl);
    t.ok(isVinylFile(file));
  });
github generate / generate / test / app.create.js View on Github external
return fs.readFileSync(file.path);
      };

      var Views = App.Views;
      var views = new Views({View: Vinyl});

      views.addView('a.hbs', {path: 'a.hbs', content: 'a'});
      views.addView('b.hbs', {path: 'b.hbs', content: 'b'});
      views.addView('c.hbs', {path: 'c.hbs', content: 'c'});

      app = new App();
      app.create('pages', views);

      var a = app.pages.getView('a.hbs');
      assert(a instanceof Vinyl);
      assert(Vinyl.isVinyl(a));
      assert.equal(typeof a.read, 'function');

      views.addView('d.hbs', {path: 'd.hbs', content: 'd'});
      var d = app.pages.getView('d.hbs');
      assert(d instanceof Vinyl);
      assert(Vinyl.isVinyl(d));
    });
  });
github addyosmani / critical / src / file.js View on Github external
function isVinyl(file) {
  return (
    Vinyl.isVinyl(file) ||
    file instanceof Vinyl ||
    (file && /function File\(/.test(file.constructor.toString()) && file.contents && file.path)
  );
}
github jonschlinkert / load-templates / index.js View on Github external
createView(view, options) {
    options = options || {};
    let opts = Object.assign({ cwd: process.cwd() }, this.options);
    let key;

    if (typeOf(view) === 'object') {
      view = File.isVinyl(view) ? view : new File(view);
      opts = Object.assign({}, opts, options);

    } else if (typeof view === 'string') {
      key = view;
      if (File.isVinyl(options)) {
        view = options;
      } else {
        view = new File(Object.assign({ path: key }, options));
        opts = Object.assign({}, opts, options);
      }
      view.cwd = opts.cwd;
    } else {
      throw new TypeError('expected view to be a string or object');
    }

    view.cwd = path.resolve(view.cwd);
github jkphl / shortbread / index.js View on Github external
function isVinylFile(file) {
    if (Vinyl.isVinyl(file)) {
        return true;
    }
    if (!file || (typeof file !== 'object')) {
        return false;
    }
    const properties = new Set(Object.getOwnPropertyNames(file));
    if ((!properties.has('cwd') && !properties.has('_cwd'))
        || fileProperties.filter(p => !properties.has(p)).length
    ) {
        return false;
    }
    const content = Object.getOwnPropertyDescriptor(file, '_contents');
    return (typeof content === 'object') && content.writable && content.enumerable && content.configurable;
}

vinyl

Virtual file format.

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis