Map the destination path for a file based on the given source path and options.
Install
Install with npm
$ npm i map-dest --save
Usage
var mapDest = ;
Table of contents
docs
src
Returns an array when src
is an array
;// [ { options: {}, src: 'a.txt', dest: 'dist/a.txt' },// { options: {}, src: 'b.txt', dest: 'dist/b.txt' } ]
dest
Creates a dest when no dest
argument is passed.
;// [{ options: {}, src: 'a/b/c.txt', dest: 'a/b/c.txt' }]
When no dest
is defined and src
is an array, returns an array with generated dest
paths.
;// [ { options: {}, src: 'a.txt', dest: 'a.txt' },// { options: {}, src: 'b.txt', dest: 'b.txt' } ]
options
options.flatten
Flattens dest
when no dest
argument is passed:
;// [{ options: { flatten: true }, src: 'a/b/c.txt', dest: 'c.txt' }]
options.ext
Replaces the destination extension with given ext
:
;// [{ options: { ext: '.foo', extDot: 'first' },// src: 'a/b/c.txt',// dest: 'a/b/c.foo' }]
options.cwd
When cwd
is defined it will be prepended to src
:
;// [{ options: { cwd: 'one/two' },// src: 'one/two/a/b/c.txt',// dest: 'a/b/c.txt' }]
Prepends cwd
to src
and flattens dest
:
;// [{ options: { cwd: 'one/two', flatten: true },// src: 'one/two/a/b/c.txt',// dest: 'c.txt' }]
Expands tildes in cwd
to make the path relative to the user's home directory:
;// [{ options: { cwd: '/User/jonschlinkert/one/two', flatten: true },// src: 'one/two/a/b/c.txt',// dest: 'c.txt' }]
Expands @
in cwd
to make the path relative to global npm modules:
;// [ { options: { cwd: '/usr/local/lib/node_modules/boilerplate-h5bp' },// src: '/usr/local/lib/node_modules/boilerplate-h5bp/templates/base.hbs',// dest: 'templates/base.hbs' } ]
options.destBase
If destBase
is defined it's prepended to generated dest.
;// [{ options: { destBase: 'one/two' },// src: 'a/b/c.txt',// dest: 'one/two/a/b/c.txt' }]
If destBase
is defined, it will be prepended to dest
;// [{ options: { destBase: 'one/two' },// src: 'a/b/c.txt',// dest: 'one/two/foo/a/b/c.txt' }]
options.rename
A custom rename
function can be used to modify the generated dest
path.
;// [{ options: { rename: [Function] },// src: 'a/b/c.md',// dest: 'dist/c.html' }]
Related projects
- expand-config: Expand tasks, targets and files in a declarative configuration. | homepage
- expand-files: Expand glob patterns in a declarative configuration into src-dest mappings. | homepage
- expand-target: Expand target definitions in a declarative configuration. | homepage
- expand-task: Expand and normalize task definitions in a declarative configuration. | homepage
- files-objects: Expand files objects into src-dest mappings. | homepage
Test coverage
-----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
-----------|----------|----------|----------|----------|----------------|
map-dest/ | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
-----------|----------|----------|----------|----------|----------------|
All files | 100 | 100 | 100 | 100 | |
-----------|----------|----------|----------|----------|----------------|
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on October 30, 2015.