relative-path-map
v1.0.1
Published
Configure a map of paths that may refer to each other
Downloads
1
Maintainers
Readme
relative-path-map
Resolves a map of paths where some paths are relative to others in the same object. Useful for describing directory structures and for project configuration.
Install
Install via npm:
npm install --save-dev relative-path-map
Examples
Simple example
var relativePathMap = require('relative-path-map');
relativePathMap({
root: 'root/path',
sub: '[root]/sub' // => 'root/path/sub'
});
Sub-object with relative paths
relativePathMap({
root: 'root/path',
obj: {
sub: '[root]/sub', // => 'root/path/sub'
file: '[sub]/file.js' // => 'root/path/sub/file.js'
}
});
Array with relative paths
relativePathMap({
root: 'root/path',
arr: [
'[root]/sub', // => 'root/path/sub'
'[0]/file.js' // => 'root/path/sub/file.js'
]
});
Placeholder with sub-property
relativePathMap({
obj: {
sub: 'some/path',
},
dot: '[obj.sub]/dot-notation.js' // => // 'some/path/dot-notation.js'
});
API
relativePathMap(map)
Params
map object
An object containing strings representing paths. Paths beginning with a
placeholder [<prop>]
are relative to some other path in the same object, where
<prop>
is a property name, e.g. [root]
, or a sub-property name, e.g
[root.src]
.
Returns
Type: object
Returns an object whose relative paths have been resolved.
License
Copyright © 2016 Akim McMath. Licensed under the MIT License.