set-directory v0.1.0
set-directory
Utility for Update, Generate, assemble and verb for creating an object with commonly used path information based on the given directory.
TOC
(TOC generated by verb using markdown-toc)
Install
Install with npm:
$ npm install --save set-directory
Most of the path calculation is done with getters, to ensure updated values are used, and to avoid unncessary processing until a path is actually used.
Usage
var setDirectory = require('set-directory');
API
.base
Function that calculates an absolute path to the given filepath, based on the directory passed to setDirectory
.
Params
filepath
{String}
Example
var paths = setDirectory('foo');
console.log(paths.base('bar'));
//=> '/User/dev/set-directory/foo/bar'
.home
Function that calculates an absolute path to the given filepath
in the user's home directory. (uses node.js os.homedir()
)
Params
filepath
{String}
Example
var paths = setDirectory('foo');
console.log(paths.home('bar'));
//=> '/User/jonschlinkert/bar'
.dest
Function that calculates an absolute dest
path, relative to options.dest
or process.cwd()
.
Params
filepath
{String}
Example
var paths = setDirectory('foo', {dest: 'whatever'});
console.log(paths.dest('bar'));
//=> '/User/dev/set-directory/whatever/bar'
.tmpl
Function that calculates an absolute path from the templates
directory, relative to the directory passed to setDirectory
.
Params
filepath
{String}
Example
var paths = setDirectory('foo');
console.log(paths.tmpl('post.md'));
//=> '/User/dev/set-directory/templates/post.md'
.file
This function makes it simple to allow users to override built-in templates or other source files. Similar to .tmpl
, but looks for the given filename
in paths.home('templates')
, and if the file does not exist, it returns an absolute path to filename
in the templates directory relative to the directory passed to setDirectory
.
Params
filename
{String}
Example
var paths = setDirectory('foo');
// if the path does not exist in user home "templates"
console.log(paths.file('post.md'));
//=> '/User/dev/set-directory/templates/post.md'
// if the path DOES exist in user home "templates"
console.log(paths.file('post.md'));
//=> '/User/jonschlinkert/templates/post.md'
Contributing
This document was generated by verb-readme-generator (a verb generator), please don't edit directly. Any changes to the readme must be made in .verb.md. See Building Docs.
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Or visit the verb-readme-generator project to submit bug reports or pull requests for the readme layout template.
Building docs
(This document was generated by verb-readme-generator (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)
Generate readme and API documentation with verb:
$ npm install -g verb verb-readme-generator && verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Jon Schlinkert
License
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb, v0.9.0, on July 02, 2016.
8 years ago