├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.{json,yml}] 11 | indent_size = 2 12 | indent_style = space 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - 'iojs' 5 | - '0.12' 6 | - '0.10' 7 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var objectAssign = require('object-assign'); 3 | var Transform = require('readable-stream/transform'); 4 | 5 | module.exports = function (opts) { 6 | opts = opts || {}; 7 | 8 | return new Transform({ 9 | objectMode: true, 10 | transform: function (file, enc, cb) { 11 | if (file.isNull()) { 12 | cb(null, file); 13 | return; 14 | } 15 | 16 | if (file.isStream()) { 17 | cb(new Error('Streaming is not supported')); 18 | return; 19 | } 20 | 21 | cb(null, objectAssign(file, opts)); 22 | } 23 | }); 24 | }; 25 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Kevin Mårtensson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vinyl-assign", 3 | "version": "1.2.1", 4 | "description": "Apply custom attributes to vinyl files", 5 | "license": "MIT", 6 | "repository": "kevva/vinyl-assign", 7 | "author": { 8 | "name": "Kevin Mårtensson", 9 | "email": "kevinmartensson@gmail.com", 10 | "url": "https://github.com/kevva" 11 | }, 12 | "engines": { 13 | "node": ">=0.10.0" 14 | }, 15 | "scripts": { 16 | "test": "xo && node test.js" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [], 22 | "dependencies": { 23 | "object-assign": "^4.0.1", 24 | "readable-stream": "^2.0.0" 25 | }, 26 | "devDependencies": { 27 | "ava": "^0.0.4", 28 | "vinyl-file": "^1.1.1", 29 | "xo": "*" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # vinyl-assign [![Build Status](http://img.shields.io/travis/kevva/vinyl-assign.svg?style=flat)](https://travis-ci.org/kevva/vinyl-assign) 2 | 3 | > Assign custom attributes to vinyl files 4 | 5 | 6 | ## Install 7 | 8 | ``` 9 | $ npm install --save vinyl-assign 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | var gulp = require('gulp'); 17 | var vinylAssign = require('vinyl-assign'); 18 | 19 | gulp.task('default', function () { 20 | return gulp.src('foo.txt') 21 | .pipe(vinylAssign({foo: 'bar'})) 22 | .pipe(gulp.dest('dest')); 23 | }); 24 | ``` 25 | 26 | 27 | ## License 28 | 29 | MIT © [Kevin Mårtensson](https://github.com/kevva) 30 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var test = require('ava'); 3 | var vinylFile = require('vinyl-file'); 4 | var vinylAssign = require('./'); 5 | 6 | test('assign custom attributes', function (t) { 7 | t.plan(1); 8 | 9 | var file = vinylFile.readSync('index.js'); 10 | var stream = vinylAssign({foo: 'bar'}); 11 | 12 | stream.on('data', function (file) { 13 | t.assert(file.foo === 'bar', file.foo); 14 | }); 15 | 16 | stream.end(file); 17 | }); 18 | --------------------------------------------------------------------------------