UNPKG

817 BJavaScriptView Raw
1'use strict';
2
3var util = require('util');
4var path = require('path');
5var utils = require('../utils');
6
7/**
8 * Normalize the given `--cwd` value to be an absolute filepath.
9 *
10 * ```sh
11 * $ --cwd=foo
12 * ```
13 * @name cwd
14 * @api public
15 */
16
17module.exports = function(app, base, options) {
18 return function(val, key, config, schema) {
19 if (typeof val === 'undefined') {
20 return;
21 }
22
23 // fix path that were mistaken as dot-notation
24 if (utils.isObject(val)) {
25 val = utils.stringify(val);
26 }
27
28 if (typeof val === 'string') {
29 return path.resolve(val);
30 }
31
32 if (typeof val === 'boolean') {
33 val = config[key] = { show: true };
34 return val;
35 }
36
37 val = util.inspect(val);
38 throw new TypeError('--toc: expected a string or boolean, but received: ' + val);
39 };
40};