├── .gitignore ├── test ├── fixtures │ └── one.js └── test.js ├── .editorconfig ├── index.js ├── package.json ├── README.md └── LICENSE-MIT /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /test/fixtures/one.js: -------------------------------------------------------------------------------- 1 | var one = true 2 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var through = require('through') 3 | 4 | module.exports = function(opts) { 5 | return through(function(file) { 6 | if (typeof opts === 'function') { 7 | var res = opts.call(this, file) 8 | if (res != null) { 9 | file.named = res 10 | this.queue(file) 11 | } 12 | } else { 13 | file.named = path.basename(file.path, path.extname(file.path)) 14 | this.queue(file) 15 | } 16 | }) 17 | } 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vinyl-named", 3 | "description": "Give vinyl files chunk names.", 4 | "version": "1.1.0", 5 | "homepage": "https://github.com/shama/vinyl-named", 6 | "author": { 7 | "name": "Kyle Robinson Young", 8 | "email": "kyle@dontkry.com" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git://github.com/shama/vinyl-named.git" 13 | }, 14 | "bugs": { 15 | "url": "https://github.com/shama/vinyl-named/issues" 16 | }, 17 | "licenses": [ 18 | { 19 | "type": "MIT", 20 | "url": "https://github.com/shama/vinyl-named/blob/master/LICENSE-MIT" 21 | } 22 | ], 23 | "scripts": { 24 | "test": "node test/test.js" 25 | }, 26 | "engines": { 27 | "node": ">= 0.10.0" 28 | }, 29 | "dependencies": { 30 | "through": "^2.3.6" 31 | }, 32 | "devDependencies": { 33 | "tape": "^3.0.0", 34 | "vinyl-fs": "^0.3.9" 35 | }, 36 | "keywords": [ 37 | "vinyl", 38 | "fs", 39 | "name" 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vinyl-named 2 | 3 | Give vinyl files arbitrary chunk names. 4 | 5 | ## example 6 | 7 | ```js 8 | var named = require('vinyl-named') 9 | var fs = require('vinyl-fs') 10 | var through = require('through') 11 | 12 | fs.src('src/*.js') 13 | .pipe(named()) 14 | .pipe(through(function(file) { 15 | // file.named now equals the basename minus the extension 16 | })) 17 | 18 | // Or return a name for a given file 19 | fs.src('src/*.js') 20 | .pipe(named(function(file) { 21 | return 'your own name' 22 | })) 23 | 24 | // Or specify a custom name property 25 | fs.src('src/*.js') 26 | .pipe(named(function(file) { 27 | file.customName = 'your name' 28 | this.queue(file) 29 | })) 30 | ``` 31 | 32 | ## install 33 | 34 | With [npm](http://npmjs.org) do: 35 | 36 | ```shell 37 | npm install vinyl-named 38 | ``` 39 | 40 | ## release history 41 | 42 | * 1.1.0 - renaming `chunkName` to `named` to be more generic 43 | * 1.0.0 - initial release 44 | 45 | ## license 46 | Copyright (c) 2014 Kyle Robinson Young 47 | Licensed under the MIT license. 48 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | var test = require('tape') 2 | var fs = require('vinyl-fs') 3 | var through = require('through') 4 | var named = require('../index') 5 | 6 | test('add named to files', function(t) { 7 | t.plan(1) 8 | fs.src('test/fixtures/one.js') 9 | .pipe(named()) 10 | .pipe(through(function(file) { 11 | t.equal(file.named, 'one', 'named should equal one') 12 | }, t.end)) 13 | }) 14 | 15 | test('add named with factory', function(t) { 16 | t.plan(1) 17 | fs.src('test/fixtures/one.js') 18 | .pipe(named(function(file) { 19 | return 'pineapple' 20 | })) 21 | .pipe(through(function(file) { 22 | t.equal(file.named, 'pineapple', 'named should equal pineapple') 23 | }, t.end)) 24 | }) 25 | 26 | test('add custom name key to files', function(t) { 27 | t.plan(1) 28 | fs.src('test/fixtures/one.js') 29 | .pipe(named(function(file) { 30 | file.customName = 'pineapple' 31 | this.queue(file) 32 | })) 33 | .pipe(through(function(file) { 34 | t.equal(file.customName, 'pineapple', 'customName should equal pineapple') 35 | }, t.end)) 36 | }) 37 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Kyle Robinson Young 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | --------------------------------------------------------------------------------