UNPKG

@bmstravel/nvp-cli

Version:

🏆 Command line tool

2,051 lines (1,767 loc) 2.23 MB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('lodash'), require('util'), require('path'), require('fs'), require('tty'), require('os'), require('readline'), require('punycode'), require('url'), require('querystring')) : typeof define === 'function' && define.amd ? define(['lodash', 'util', 'path', 'fs', 'tty', 'os', 'readline', 'punycode', 'url', 'querystring'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.foo = factory(global._, global.util$2, global.path, global.fs, global.tty, global.os, null, global.punycode, global.url, global.querystring)); }(this, (function (_, util$2, path, fs, tty, os, readline, punycode, url, querystring) { 'use strict'; function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var ___default = /*#__PURE__*/_interopDefaultLegacy(_); var util__default = /*#__PURE__*/_interopDefaultLegacy(util$2); var path__default = /*#__PURE__*/_interopDefaultLegacy(path); var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs); var tty__default = /*#__PURE__*/_interopDefaultLegacy(tty); var os__default = /*#__PURE__*/_interopDefaultLegacy(os); var punycode__default = /*#__PURE__*/_interopDefaultLegacy(punycode); var url__default = /*#__PURE__*/_interopDefaultLegacy(url); var querystring__default = /*#__PURE__*/_interopDefaultLegacy(querystring); var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function createCommonjsModule(fn, basedir, module) { return module = { path: basedir, exports: {}, require: function (path, base) { return commonjsRequire(path, (base === undefined || base === null) ? module.path : base); } }, fn(module, module.exports), module.exports; } function getAugmentedNamespace(n) { if (n.__esModule) return n; var a = Object.defineProperty({}, '__esModule', {value: true}); Object.keys(n).forEach(function (k) { var d = Object.getOwnPropertyDescriptor(n, k); Object.defineProperty(a, k, d.get ? d : { enumerable: true, get: function () { return n[k]; } }); }); return a; } function commonjsRequire () { throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); } /*! * for-in <https://github.com/jonschlinkert/for-in> * * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ var forIn = function forIn(obj, fn, thisArg) { for (var key in obj) { if (fn.call(thisArg, obj[key], key, obj) === false) { break; } } }; var toString = Object.prototype.toString; var kindOf = function kindOf(val) { if (val === void 0) return 'undefined'; if (val === null) return 'null'; var type = typeof val; if (type === 'boolean') return 'boolean'; if (type === 'string') return 'string'; if (type === 'number') return 'number'; if (type === 'symbol') return 'symbol'; if (type === 'function') { return isGeneratorFn(val) ? 'generatorfunction' : 'function'; } if (isArray(val)) return 'array'; if (isBuffer(val)) return 'buffer'; if (isArguments(val)) return 'arguments'; if (isDate(val)) return 'date'; if (isError(val)) return 'error'; if (isRegexp(val)) return 'regexp'; switch (ctorName(val)) { case 'Symbol': return 'symbol'; case 'Promise': return 'promise'; // Set, Map, WeakSet, WeakMap case 'WeakMap': return 'weakmap'; case 'WeakSet': return 'weakset'; case 'Map': return 'map'; case 'Set': return 'set'; // 8-bit typed arrays case 'Int8Array': return 'int8array'; case 'Uint8Array': return 'uint8array'; case 'Uint8ClampedArray': return 'uint8clampedarray'; // 16-bit typed arrays case 'Int16Array': return 'int16array'; case 'Uint16Array': return 'uint16array'; // 32-bit typed arrays case 'Int32Array': return 'int32array'; case 'Uint32Array': return 'uint32array'; case 'Float32Array': return 'float32array'; case 'Float64Array': return 'float64array'; } if (isGeneratorObj(val)) { return 'generator'; } // Non-plain objects type = toString.call(val); switch (type) { case '[object Object]': return 'object'; // iterators case '[object Map Iterator]': return 'mapiterator'; case '[object Set Iterator]': return 'setiterator'; case '[object String Iterator]': return 'stringiterator'; case '[object Array Iterator]': return 'arrayiterator'; } // other return type.slice(8, -1).toLowerCase().replace(/\s/g, ''); }; function ctorName(val) { return typeof val.constructor === 'function' ? val.constructor.name : null; } function isArray(val) { if (Array.isArray) return Array.isArray(val); return val instanceof Array; } function isError(val) { return val instanceof Error || (typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number'); } function isDate(val) { if (val instanceof Date) return true; return typeof val.toDateString === 'function' && typeof val.getDate === 'function' && typeof val.setDate === 'function'; } function isRegexp(val) { if (val instanceof RegExp) return true; return typeof val.flags === 'string' && typeof val.ignoreCase === 'boolean' && typeof val.multiline === 'boolean' && typeof val.global === 'boolean'; } function isGeneratorFn(name, val) { return ctorName(name) === 'GeneratorFunction'; } function isGeneratorObj(val) { return typeof val.throw === 'function' && typeof val.return === 'function' && typeof val.next === 'function'; } function isArguments(val) { try { if (typeof val.length === 'number' && typeof val.callee === 'function') { return true; } } catch (err) { if (err.message.indexOf('callee') !== -1) { return true; } } return false; } /** * If you need to support Safari 5-7 (8-10 yr-old browser), * take a look at https://github.com/feross/is-buffer */ function isBuffer(val) { if (val.constructor && typeof val.constructor.isBuffer === 'function') { return val.constructor.isBuffer(val); } return false; } // accessor descriptor properties var accessor = { get: 'function', set: 'function', configurable: 'boolean', enumerable: 'boolean' }; function isAccessorDescriptor(obj, prop) { if (typeof prop === 'string') { var val = Object.getOwnPropertyDescriptor(obj, prop); return typeof val !== 'undefined'; } if (kindOf(obj) !== 'object') { return false; } if (has(obj, 'value') || has(obj, 'writable')) { return false; } if (!has(obj, 'get') || typeof obj.get !== 'function') { return false; } // tldr: it's valid to have "set" be undefined // "set" might be undefined if `Object.getOwnPropertyDescriptor` // was used to get the value, and only `get` was defined by the user if (has(obj, 'set') && typeof obj[key] !== 'function' && typeof obj[key] !== 'undefined') { return false; } for (var key in obj) { if (!accessor.hasOwnProperty(key)) { continue; } if (kindOf(obj[key]) === accessor[key]) { continue; } if (typeof obj[key] !== 'undefined') { return false; } } return true; } function has(obj, key) { return {}.hasOwnProperty.call(obj, key); } /** * Expose `isAccessorDescriptor` */ var isAccessorDescriptor_1 = isAccessorDescriptor; var isDataDescriptor = function isDataDescriptor(obj, prop) { // data descriptor properties var data = { configurable: 'boolean', enumerable: 'boolean', writable: 'boolean' }; if (kindOf(obj) !== 'object') { return false; } if (typeof prop === 'string') { var val = Object.getOwnPropertyDescriptor(obj, prop); return typeof val !== 'undefined'; } if (!('value' in obj) && !('writable' in obj)) { return false; } for (var key in obj) { if (key === 'value') continue; if (!data.hasOwnProperty(key)) { continue; } if (kindOf(obj[key]) === data[key]) { continue; } if (typeof obj[key] !== 'undefined') { return false; } } return true; }; var isDescriptor = function isDescriptor(obj, key) { if (kindOf(obj) !== 'object') { return false; } if ('get' in obj) { return isAccessorDescriptor_1(obj, key); } return isDataDescriptor(obj, key); }; var defineProperty = function defineProperty(obj, prop, val) { if (typeof obj !== 'object' && typeof obj !== 'function') { throw new TypeError('expected an object or function.'); } if (typeof prop !== 'string') { throw new TypeError('expected `prop` to be a string.'); } if (isDescriptor(val) && ('set' in val || 'get' in val)) { return Object.defineProperty(obj, prop, val); } return Object.defineProperty(obj, prop, { configurable: true, enumerable: false, writable: true, value: val }); }; /*! * Determine if an object is a Buffer * * @author Feross Aboukhadijeh <https://feross.org> * @license MIT */ // The _isBuffer check is for Safari 5-7 support, because it's missing // Object.prototype.constructor. Remove this eventually var isBuffer_1 = function (obj) { return obj != null && (isBuffer$1(obj) || isSlowBuffer(obj) || !!obj._isBuffer) }; function isBuffer$1 (obj) { return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) } // For Node v0.10 support. Remove this eventually. function isSlowBuffer (obj) { return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer$1(obj.slice(0, 0)) } var toString$1 = Object.prototype.toString; /** * Get the native `typeof` a value. * * @param {*} `val` * @return {*} Native javascript type */ var kindOf$1 = function kindOf(val) { // primitivies if (typeof val === 'undefined') { return 'undefined'; } if (val === null) { return 'null'; } if (val === true || val === false || val instanceof Boolean) { return 'boolean'; } if (typeof val === 'string' || val instanceof String) { return 'string'; } if (typeof val === 'number' || val instanceof Number) { return 'number'; } // functions if (typeof val === 'function' || val instanceof Function) { return 'function'; } // array if (typeof Array.isArray !== 'undefined' && Array.isArray(val)) { return 'array'; } // check for instances of RegExp and Date before calling `toString` if (val instanceof RegExp) { return 'regexp'; } if (val instanceof Date) { return 'date'; } // other objects var type = toString$1.call(val); if (type === '[object RegExp]') { return 'regexp'; } if (type === '[object Date]') { return 'date'; } if (type === '[object Arguments]') { return 'arguments'; } if (type === '[object Error]') { return 'error'; } // buffer if (isBuffer_1(val)) { return 'buffer'; } // es6: Map, WeakMap, Set, WeakSet if (type === '[object Set]') { return 'set'; } if (type === '[object WeakSet]') { return 'weakset'; } if (type === '[object Map]') { return 'map'; } if (type === '[object WeakMap]') { return 'weakmap'; } if (type === '[object Symbol]') { return 'symbol'; } // typed arrays if (type === '[object Int8Array]') { return 'int8array'; } if (type === '[object Uint8Array]') { return 'uint8array'; } if (type === '[object Uint8ClampedArray]') { return 'uint8clampedarray'; } if (type === '[object Int16Array]') { return 'int16array'; } if (type === '[object Uint16Array]') { return 'uint16array'; } if (type === '[object Int32Array]') { return 'int32array'; } if (type === '[object Uint32Array]') { return 'uint32array'; } if (type === '[object Float32Array]') { return 'float32array'; } if (type === '[object Float64Array]') { return 'float64array'; } // must be a plain object return 'object'; }; var types = { 'arguments': 'an arguments object', 'array': 'an array', 'boolean': 'a boolean', 'buffer': 'a buffer', 'date': 'a date', 'error': 'an error', 'float32array': 'a float32array', 'float64array': 'a float64array', 'function': 'a function', 'int16array': 'an int16array', 'int32array': 'an int32array', 'int8array': 'an int8array', 'map': 'a Map', 'null': 'null', 'number': 'a number', 'object': 'an object', 'regexp': 'a regular expression', 'set': 'a Set', 'string': 'a string', 'symbol': 'a symbol', 'uint16array': 'an uint16array', 'uint32array': 'an uint32array', 'uint8array': 'an uint8array', 'uint8clampedarray': 'an uint8clampedarray', 'undefined': 'undefined', 'weakmap': 'a WeakMap', 'weakset': 'a WeakSet' }; function type(val) { return types[kindOf$1(val)]; } type.types = types; type.typeOf = kindOf$1; /** * Expose `type` */ var typeofArticle = type; var handlebarsUtils = createCommonjsModule(function (module, exports) { var utils = exports = module.exports; /** * This code was taken directly from handlebars. * https://github.com/wycats/handlebars.js/blob/b55a120e8222785db3dc00096f6afbf91b656e8a/LICENSE * Released under the MIT License * Copyright (C) 2011-2016 by Yehuda Katz */ utils.extend = extend; utils.indexOf = indexOf; utils.escapeExpression = escapeExpression; utils.isEmpty = isEmpty; utils.createFrame = createFrame; utils.blockParams = blockParams; utils.appendContextPath = appendContextPath; var escape = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#x27;', '`': '&#x60;', '=': '&#x3D;' }; var badChars = /[&<>"'`=]/g; var possible = /[&<>"'`=]/; function escapeChar(chr) { return escape[chr]; } function extend(obj /* , ...source */) { for (var i = 1; i < arguments.length; i++) { for (var key in arguments[i]) { if (Object.prototype.hasOwnProperty.call(arguments[i], key)) { obj[key] = arguments[i][key]; } } } return obj; } var toString = Object.prototype.toString; utils.toString = toString; // Sourced from lodash // https://github.com/bestiejs/lodash/blob/master/LICENSE.txt /* eslint-disable func-style */ var isFunction = function isFunction(value) { return typeof value === 'function'; }; // fallback for older versions of Chrome and Safari /* istanbul ignore next */ if (isFunction(/x/)) { utils.isFunction = isFunction = function(value) { return typeof value === 'function' && toString.call(value) === '[object Function]'; }; } utils.isFunction = isFunction; /* eslint-enable func-style */ /* istanbul ignore next */ var isArray = Array.isArray || function(value) { return value && typeof value === 'object' ? toString.call(value) === '[object Array]' : false; }; utils.isArray = isArray; // Older IE versions do not directly support indexOf so we must implement our own, sadly. function indexOf(array, value) { for (var i = 0, len = array.length; i < len; i++) { if (array[i] === value) { return i; } } return -1; } function escapeExpression(string) { if (typeof string !== 'string') { // don't escape SafeStrings, since they're already safe if (string && string.toHTML) { return string.toHTML(); } else if (string == null) { return ''; } else if (!string) { return string + ''; } // Force a string conversion as this will be done by the append regardless and // the regex test will do this transparently behind the scenes, causing issues if // an object's to string has escaped characters in it. string = '' + string; } if (!possible.test(string)) { return string; } return string.replace(badChars, escapeChar); } function createFrame(object) { var frame = extend({}, object); frame._parent = object; return frame; } function blockParams(params, ids) { params.path = ids; return params; } function appendContextPath(contextPath, id) { return (contextPath ? contextPath + '.' : '') + id; } // // The code below this line was not sourced from handlebars // -------------------------------------------------------- // utils.expectedType = function(param, expected, actual) { var exp = typeofArticle.types[expected]; var val = util__default['default'].inspect(actual); return "expected " + param + " to be " + exp + " but received " + typeofArticle(actual) + ": " + val; }; /** * Returns true if a helper is a block helper. * * ```js * Handlebars.registerHelper('example', function(options) { * if (utils.isBlock(options)) { * // do something if this is a block helper * } else { * // do something else if this is a not block helper * } * }); * ``` * @param {Object} `options` Helper options object * @return {Boolean} * @api public */ utils.isBlock = function(options) { return utils.isOptions(options) && typeof options.fn === 'function' && typeof options.inverse === 'function'; }; /** * Returns the given value or renders the block if it's a block helper. * * ```js * Handlebars.registerHelper('example', function(val, locals, options) { * return utils.fn(val, locals, options); * }); * ``` * @param {any} `val` * @param {Object} `options` * @param {Object} `context` * @return {String} Either returns the value, or renders the block. * @api public */ utils.fn = function(val, context, options) { if (utils.isOptions(val)) { return utils.fn('', val, options); } if (utils.isOptions(context)) { return utils.fn(val, {}, context); } return utils.isBlock(options) ? options.fn(context) : val; }; /** * Returns the given value or renders the inverse block if it's a block helper. * * ```js * Handlebars.registerHelper('example', function(val, locals, options) { * return utils.inverse(val, locals, options); * }); * ``` * @param {any} `val` * @param {Object} `options` * @param {Object} `context` * @return {String} Either returns the value, or renders the inverse block. * @api public */ utils.inverse = function(val, context, options) { if (utils.isOptions(val)) { return utils.identity('', val, options); } if (utils.isOptions(context)) { return utils.inverse(val, {}, context); } return utils.isBlock(options) ? options.inverse(context) : val; }; /** * Gets the return value for a helper, by either rendering the block * or inverse block if it's a block helper, or returning the given value * (when truthy) or an empty string (when falsey) if it's a non-block expression. * * ```js * Handlebars.registerHelper('example', function(val, locals, options) { * return utils.value(val, locals, options); * }); * ``` * @param {any} `val` * @param {Object} `options` * @param {Object} `context` * @return {String} * @api public */ utils.value = function(val, context, options) { if (utils.isOptions(val)) { return utils.value(null, val, options); } if (utils.isOptions(context)) { return utils.value(val, {}, context); } if (utils.isBlock(options)) { return !!val ? options.fn(context) : options.inverse(context); } return val; }; /** * Returns true if the given value is a handlebar `options` object. * * ```js * Handlebars.registerHelper('example', function(val, locals, options) { * if (utils.isOptions(locals)) { * options = locals; * locals = {}; * } * // do stuff * }); * ``` * @param {Object} `val` * @return {Boolean} * @api public */ utils.isOptions = function(val) { return utils.isObject(val) && utils.isObject(val.hash); }; /** * Returns true if the given value is `undefined` or is a handlebars * options hash (which means that a value was not passed by the user). * * ```js * Handlebars.registerHelper('example', function(val, options) { * if (utils.isUndefined(val)) { * return ''; * } * // do stuff * }); * ``` * @param {any} `value` * @return {Boolean} * @api public */ utils.isUndefined = function(val) { return val == null || (utils.isOptions(val) && val.hash != null); }; /** * Returns true if an `app` propery is on the context, which means * the context was created by [assemble][], [templates][], [verb][], * or any other library that follows this convention. * * ```js * Handlebars.registerHelper('example', function(val, options) { * var context = options.hash; * if (utils.isApp(this)) { * context = Object.assign({}, this.context, context); * } * // do stuff * }); * ``` * @param {any} `value` * @return {Boolean} * @api public */ utils.isApp = function(thisArg) { return utils.isObject(thisArg) && utils.isObject(thisArg.options) && utils.isObject(thisArg.app); }; /** * Creates an options object from the `context`, `locals` and `options.` * Handlebars' `options.hash` is merged onto the options, and if the context * is created by [templates][], `this.options` will be merged onto the * options as well. * * @param {Object} `context` * @param {Object} `locals` Options or locals * @param {Object} `options` * @return {Boolean} * @api public */ utils.options = function(thisArg, locals, options) { if (utils.isOptions(thisArg)) { return utils.options({}, locals, thisArg); } if (utils.isOptions(locals)) { return utils.options(thisArg, options, locals); } options = options || {}; if (!utils.isOptions(options)) { locals = Object.assign({}, locals, options); } var opts = Object.assign({}, locals, options.hash); if (utils.isObject(thisArg)) { opts = Object.assign({}, thisArg.options, opts); } if (opts[options.name]) { opts = Object.assign({}, opts[options.name], opts); } return opts; }; /** * Get the context to use for rendering. * * @param {Object} `thisArg` Optional invocation context `this` * @return {Object} * @api public */ utils.context = function(thisArg, locals, options) { if (utils.isOptions(thisArg)) { return utils.context({}, locals, thisArg); } // ensure args are in the correct order if (utils.isOptions(locals)) { return utils.context(thisArg, options, locals); } var appContext = utils.isApp(thisArg) ? thisArg.context : {}; options = options || {}; // if "options" is not handlebars options, merge it onto locals if (!utils.isOptions(options)) { locals = Object.assign({}, locals, options); } // merge handlebars root data onto locals if specified on the hash if (utils.isOptions(options) && options.hash.root === true) { locals = Object.assign({}, options.data.root, locals); } var context = Object.assign({}, appContext, locals, options.hash); if (!utils.isApp(thisArg)) { context = Object.assign({}, thisArg, context); } if (utils.isApp(thisArg) && thisArg.view && thisArg.view.data) { context = Object.assign({}, context, thisArg.view.data); } return context; }; /** * Returns true if the given value is an object. * * ```js * console.log(utils.isObject(null)); * //=> false * console.log(utils.isObject([])); * //=> false * console.log(utils.isObject(function() {})); * //=> false * console.log(utils.isObject({})); * //=> true * ``` * @param {Object} `val` * @return {Boolean} * @api public */ utils.isObject = function(val) { return kindOf(val) === 'object'; }; /** * Returns true if the given value is "empty". * * ```js * console.log(utils.isEmpty(0)); * //=> false * console.log(utils.isEmpty('')); * //=> true * console.log(utils.isEmpty([])); * //=> true * console.log(utils.isEmpty({})); * //=> true * ``` * @name .isEmpty * @param {any} `value` * @return {Boolean} * @api public */ function isEmpty(val) { if (val === 0 || typeof val === 'boolean') { return false; } if (val == null) { return true; } if (utils.isObject(val)) { val = Object.keys(val); } if (!val.length) { return true; } return false; } /** * Returns the given value. If the value is a function it will be * called with the current context, otherwise the value is returned. * * ```js * console.log(utils.result('foo')); * //=> 'foo' * console.log(utils.result(function() { * return 'foo'; * })); * //=> 'foo' * ``` * @param {any} `val` * @return {any} * @api public */ utils.result = function(val) { if (typeof val === 'function') { return val.apply(this, [].slice.call(arguments, 1)); } return val; }; /** * Returns the given value as-is, unchanged. * * ```js * console.log(utils.result('foo')); * //=> 'foo' * console.log(utils.result(function() { * return 'foo'; * })); * //=> [function] * ``` * @param {any} `val` * @return {any} * @api public */ utils.identity = function(val) { return val; }; /** * Return true if `val` is a non-empty string. * * @param {any} `val` The value to check * @return {Boolean} * @api public */ utils.isString = function(val) { return typeof val === 'string' && val !== ''; }; /** * Cast the given `val` to an array. * * ```js * console.log(utils.arrayify('')); * //=> [] * console.log(utils.arrayify('foo')); * //=> ['foo'] * console.log(utils.arrayify(['foo'])); * //=> ['foo'] * ``` * @param {any} `val` * @return {Array} * @api public */ utils.arrayify = function(val) { return val != null ? (Array.isArray(val) ? val : [val]) : []; }; /** * Try to parse the given `string` as JSON. Fails * gracefully and always returns an object if the value cannot be parsed. * * @param {String} `string` * @return {Object} * @api public */ utils.tryParse = function(str) { try { return JSON.parse(str); } catch (err) {} return {}; }; }); /*! * Determine if an object is a Buffer * * @author Feross Aboukhadijeh <https://feross.org> * @license MIT */ // The _isBuffer check is for Safari 5-7 support, because it's missing // Object.prototype.constructor. Remove this eventually var isBuffer_1$1 = function (obj) { return obj != null && (isBuffer$2(obj) || isSlowBuffer$1(obj) || !!obj._isBuffer) }; function isBuffer$2 (obj) { return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) } // For Node v0.10 support. Remove this eventually. function isSlowBuffer$1 (obj) { return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer$2(obj.slice(0, 0)) } var toString$2 = Object.prototype.toString; /** * Get the native `typeof` a value. * * @param {*} `val` * @return {*} Native javascript type */ var kindOf$2 = function kindOf(val) { // primitivies if (typeof val === 'undefined') { return 'undefined'; } if (val === null) { return 'null'; } if (val === true || val === false || val instanceof Boolean) { return 'boolean'; } if (typeof val === 'string' || val instanceof String) { return 'string'; } if (typeof val === 'number' || val instanceof Number) { return 'number'; } // functions if (typeof val === 'function' || val instanceof Function) { return 'function'; } // array if (typeof Array.isArray !== 'undefined' && Array.isArray(val)) { return 'array'; } // check for instances of RegExp and Date before calling `toString` if (val instanceof RegExp) { return 'regexp'; } if (val instanceof Date) { return 'date'; } // other objects var type = toString$2.call(val); if (type === '[object RegExp]') { return 'regexp'; } if (type === '[object Date]') { return 'date'; } if (type === '[object Arguments]') { return 'arguments'; } if (type === '[object Error]') { return 'error'; } // buffer if (isBuffer_1$1(val)) { return 'buffer'; } // es6: Map, WeakMap, Set, WeakSet if (type === '[object Set]') { return 'set'; } if (type === '[object WeakSet]') { return 'weakset'; } if (type === '[object Map]') { return 'map'; } if (type === '[object WeakMap]') { return 'weakmap'; } if (type === '[object Symbol]') { return 'symbol'; } // typed arrays if (type === '[object Int8Array]') { return 'int8array'; } if (type === '[object Uint8Array]') { return 'uint8array'; } if (type === '[object Uint8ClampedArray]') { return 'uint8clampedarray'; } if (type === '[object Int16Array]') { return 'int16array'; } if (type === '[object Uint16Array]') { return 'uint16array'; } if (type === '[object Int32Array]') { return 'int32array'; } if (type === '[object Uint32Array]') { return 'uint32array'; } if (type === '[object Float32Array]') { return 'float32array'; } if (type === '[object Float64Array]') { return 'float64array'; } // must be a plain object return 'object'; }; var toObjectPath = function toPath(args) { if (kindOf$2(args) !== 'arguments') { args = arguments; } return filter(args).join('.'); }; function filter(arr) { var len = arr.length; var idx = -1; var res = []; while (++idx < len) { var ele = arr[idx]; if (kindOf$2(ele) === 'arguments' || Array.isArray(ele)) { res.push.apply(res, filter(ele)); } else if (typeof ele === 'string') { res.push(ele); } } return res; } function isValidKey(key) { return key !== '__proto__' && key !== 'constructor' && key !== 'prototype'; } /** * Defines a getter function on an object using property path notation. * * ```js * var obj = {}; * getter(obj, 'foo', function() { * return 'bar'; * }); * ``` * @param {Object} `obj` Object to add property to. * @param {String|Array} `prop` Property string or array to add. * @param {Function} `getter` Getter function to add as a property. * @api public */ function setGetter(obj, prop, getter) { var key = toObjectPath(arguments); return define(obj, key, getter); } /** * Define getter function on object or object hierarchy using dot notation. * * @param {Object} `obj` Object to define getter property on. * @param {String} `prop` Property string to define. * @param {Function} `getter` Getter function to define. * @return {Object} Returns original object. */ function define(obj, prop, getter) { if (!~prop.indexOf('.')) { if (isValidKey(prop)) { defineProperty$1(obj, prop, getter); } return obj; } var keys = prop.split('.').filter(isValidKey); var last = keys.pop(); var target = obj; var key; while ((key = keys.shift())) { while (key.slice(-1) === '\\') { key = key.slice(0, -1) + '.' + keys.shift(); } target = target[key] || (target[key] = {}); } defineProperty$1(target, last, getter); return obj; } /** * Define getter function on object as a configurable and enumerable property. * * @param {Object} `obj` Object to define property on. * @param {String} `prop` Property to define. * @param {Function} `getter` Getter function to define. */ function defineProperty$1(obj, prop, getter) { Object.defineProperty(obj, prop, { configurable: true, enumerable: true, get: getter }); } /** * Expose `setGetter` */ var setGetter_1 = setGetter; /** * Cache results of the first function call to ensure only calling once. * * ```js * var utils = require('lazy-cache')(require); * // cache the call to `require('ansi-yellow')` * utils('ansi-yellow', 'yellow'); * // use `ansi-yellow` * console.log(utils.yellow('this is yellow')); * ``` * * @param {Function} `fn` Function that will be called only once. * @return {Function} Function that can be called to get the cached function * @api public */ function lazyCache(requireFn) { var cache = {}; return function proxy(name, alias) { var key = alias; // camel-case the module `name` if `alias` is not defined if (typeof key !== 'string') { key = camelcase(name); } // create a getter to lazily invoke the module the first time it's called function getter() { return cache[key] || (cache[key] = requireFn(name)); } // trip the getter if `process.env.UNLAZY` is defined if (unlazy(process.env)) { getter(); } setGetter_1(proxy, key, getter); return getter; }; } /** * Return true if `process.env.LAZY` is true, or travis is running. */ function unlazy(env) { return env.UNLAZY === 'true' || env.UNLAZY === true || env.TRAVIS; } /** * Camelcase the the given module `name`. */ function camelcase(str) { if (str.length === 1) { return str.toLowerCase(); } str = str.replace(/^[\W_]+|[\W_]+$/g, '').toLowerCase(); return str.replace(/[\W_]+(\w|$)/g, function(_, ch) { return ch.toUpperCase(); }); } /** * Expose `lazyCache` */ var lazyCache_1 = lazyCache; /*! * Determine if an object is a Buffer * * @author Feross Aboukhadijeh <https://feross.org> * @license MIT */ // The _isBuffer check is for Safari 5-7 support, because it's missing // Object.prototype.constructor. Remove this eventually var isBuffer_1$2 = function (obj) { return obj != null && (isBuffer$3(obj) || isSlowBuffer$2(obj) || !!obj._isBuffer) }; function isBuffer$3 (obj) { return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) } // For Node v0.10 support. Remove this eventually. function isSlowBuffer$2 (obj) { return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer$3(obj.slice(0, 0)) } var toString$3 = Object.prototype.toString; /** * Get the native `typeof` a value. * * @param {*} `val` * @return {*} Native javascript type */ var kindOf$3 = function kindOf(val) { // primitivies if (typeof val === 'undefined') { return 'undefined'; } if (val === null) { return 'null'; } if (val === true || val === false || val instanceof Boolean) { return 'boolean'; } if (typeof val === 'string' || val instanceof String) { return 'string'; } if (typeof val === 'number' || val instanceof Number) { return 'number'; } // functions if (typeof val === 'function' || val instanceof Function) { return 'function'; } // array if (typeof Array.isArray !== 'undefined' && Array.isArray(val)) { return 'array'; } // check for instances of RegExp and Date before calling `toString` if (val instanceof RegExp) { return 'regexp'; } if (val instanceof Date) { return 'date'; } // other objects var type = toString$3.call(val); if (type === '[object RegExp]') { return 'regexp'; } if (type === '[object Date]') { return 'date'; } if (type === '[object Arguments]') { return 'arguments'; } if (type === '[object Error]') { return 'error'; } // buffer if (isBuffer_1$2(val)) { return 'buffer'; } // es6: Map, WeakMap, Set, WeakSet if (type === '[object Set]') { return 'set'; } if (type === '[object WeakSet]') { return 'weakset'; } if (type === '[object Map]') { return 'map'; } if (type === '[object WeakMap]') { return 'weakmap'; } if (type === '[object Symbol]') { return 'symbol'; } // typed arrays if (type === '[object Int8Array]') { return 'int8array'; } if (type === '[object Uint8Array]') { return 'uint8array'; } if (type === '[object Uint8ClampedArray]') { return 'uint8clampedarray'; } if (type === '[object Int16Array]') { return 'int16array'; } if (type === '[object Uint16Array]') { return 'uint16array'; } if (type === '[object Int32Array]') { return 'int32array'; } if (type === '[object Uint32Array]') { return 'uint32array'; } if (type === '[object Float32Array]') { return 'float32array'; } if (type === '[object Float64Array]') { return 'float64array'; } // must be a plain object return 'object'; }; var isNumber = function isNumber(num) { var type = kindOf$3(num); if (type === 'string') { if (!num.trim()) return false; } else if (type !== 'number') { return false; } return (num - num + 1) >= 0; }; /*! * is-number <https://github.com/jonschlinkert/is-number> * * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ var isNumber$1 = function isNumber(num) { var type = typeof num; if (type === 'string' || num instanceof String) { // an empty string would be coerced to true with the below logic if (!num.trim()) return false; } else if (type !== 'number' && !(num instanceof Number)) { return false; } return (num - num + 1) >= 0; }; /** * Cache results of the first function call to ensure only calling once. * * ```js * var utils = require('lazy-cache')(require); * // cache the call to `require('ansi-yellow')` * utils('ansi-yellow', 'yellow'); * // use `ansi-yellow` * console.log(utils.yellow('this is yellow')); * ``` * * @param {Function} `fn` Function that will be called only once. * @return {Function} Function that can be called to get the cached function * @api public */ function lazyCache$1(requireFn) { var cache = {}; return function proxy(name, alias) { var key = alias; // camel-case the module `name` if `alias` is not defined if (typeof key !== 'string') { key = camelcase$1(name); } // create a getter to lazily invoke the module the first time it's called function getter() { return cache[key] || (cache[key] = requireFn(name)); } // trip the getter if `process.env.UNLAZY` is defined if (unlazy$1(process.env)) { getter(); } setGetter_1(proxy, key, getter); return getter; }; } /** * Return true if `process.env.LAZY` is true, or travis is running. */ function unlazy$1(env) { return env.UNLAZY === 'true' || env.UNLAZY === true || env.TRAVIS; } /** * Camelcase the the given module `name`. */ function camelcase$1(str) { if (str.length === 1) { return str.toLowerCase(); } str = str.replace(/^[\W_]+|[\W_]+$/g, '').toLowerCase(); return str.replace(/[\W_]+(\w|$)/g, function(_, ch) { return ch.toUpperCase(); }); } /** * Expose `lazyCache` */ var lazyCache_1$1 = lazyCache$1; var utils = lazyCache_1$1(commonjsRequire); var fn = commonjsRequire; commonjsRequire = utils; /** * Lazily required module dependencies */ commonjsRequire('define-property', 'define'); commonjsRequire('extend-shallow', 'extend'); commonjsRequire('isobject', 'isObject'); commonjsRequire = fn; /** * Expose `utils` modules */ var utils_1 = utils; var createFrame = function createFrame(data) { if (!utils_1.isObject(data)) { throw new TypeError('createFrame expects data to be an object'); } var extend = utils_1.extend; var frame = extend({}, data); frame._parent = data; utils_1.define(frame, 'extend', function(data) { extend(this, data); }); if (arguments.length > 1) { var args = [].slice.call(arguments, 1); var len = args.length, i = -1; while (++i < len) { frame.extend(args[i] || {}); } } return frame; }; var utils$1 = lazyCache_1(commonjsRequire); var fn$1 = commonjsRequire; commonjsRequire = utils$1; // Array utils commonjsRequire('array-sort', 'sortBy'); commonjsRequire('arr-flatten', 'flatten'); // Html utils commonjsRequire('to-gfm-code-block', 'block'); commonjsRequire('html-tag', 'tag'); // JavaScript language utils commonjsRequire('kind-of', 'typeOf'); // matching utils commonjsRequire('micromatch', 'mm'); // Number utils // Object utils commonjsRequire('get-value', 'get'); // Path utils commonjsRequire = fn$1; /** * Expose `utils` */ var utils_1$1 = utils$1; /** * Returns true if the given value contains the given * `object`, optionally passing a starting index. * * @param {Array} val * @param {Object} obj * @param {Number} start * @return {Boolean} */ utils_1$1.contains = function(val, obj, start) { if (val == null || obj == null || !utils_1$1.isNumber(val.length)) { return false; } return val.indexOf(obj, start) !== -1; }; /** * Remove leading and trailing whitespace and non-word * characters from the given string. * * @param {String} `str` * @return {String} */ utils_1$1.chop = function(str) { if (!handlebarsUtils.isString(str)) return ''; var re = /^[-_.\W\s]+|[-_.\W\s]+$/g; return str.trim().replace(re, ''); }; /** * Change casing on the given `string`, optionally * passing a delimiter to use between words in the * returned string. * * ```handlebars * utils.changecase('fooBarBaz'); * //=> 'foo bar baz' * * utils.changecase('fooBarBaz' '-'); * //=> 'foo-bar-baz' * ``` * @param {String} `string` The string to change. * @return {String} * @api public */ utils_1$1.changecase = function(str, fn) { if (!handlebarsUtils.isString(str)) return ''; if (str.length === 1) { return str.toLowerCase(); } str = utils_1$1.chop(str).toLowerCase(); if (typeof fn !== 'function') { fn = utils_1$1.identity; } var re = /[-_.\W\s]+(\w|$)/g; return str.replace(re, function(_, ch) { return fn(ch); }); }; /** * Generate a random number * * @param {Number} `min` * @param {Number} `max` * @return {Number} * @api public */ utils_1$1.random = function(min, max) { return min + Math.floor(Math.random() * (max - min + 1)); }; /** * Expose `utils` */ var utils_1$2 = utils_1$1; var array = createCommonjsModule(function (module) { var helpers = module.exports; /** * Returns all of the items in an array after the specified index. * Opposite of [before](#before). * * ```handlebars * <!-- array: ['a', 'b', 'c'] --> * {{after array 1}} * <!-- results in: '["c"]' --> * ``` * @param {Array} `array` Collection * @param {Number} `n` Starting index (number of items to exclude) * @return {Array} Array exluding `n` items. * @api public */ helpers.after = function(array, n) { if (handlebarsUtils.isUndefined(array)) return ''; return array.slice(n); }; /** * Cast the given `value` to an array. * * ```handlebars * {{arrayify "foo"}} * <!-- results in: [ "foo" ] --> * ``` * @param {any} `value` * @return {Array} * @api public */ helpers.arrayify = function(value) { return value ? (Array.isArray(value) ? value : [value]) : []; }; /** * Return all of the items in the collection before the specified * count. Opposite of [after](#after). * * ```handlebars * <!-- array: ['a', 'b', 'c'] --> * {{before array 2}} * <!-- results in: '["a", "b"]' --> * ``` * @param {Array} `array` * @param {Number} `n` * @return {Array} Array excluding items after the given number. * @api public */ helpers.before = function(array, n) { if (handlebarsUtils.isUndefined(array)) return ''; return array.slice(0, -n); }; /** * ```handlebars * <!-- array: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] --> * {{#eachIndex array}} * {{item}} is {{index}} * {{/eachIndex}} * ``` * @param {Array} `array` * @param {Object} `options` * @return {String} * @block * @api public */ helpers.eachIndex = function(array, options) { var result = ''; for (var i = 0; i < array.length; i++) { result += options.fn({item: array[i], index: i}); } return result; }; /** * Block helper that filters the given array and renders the block for values that * evaluate to `true`, otherwise the inverse block is returned. * * ```handlebars * <!-- array: ['a', 'b', 'c'] --> * {{#filter array "foo"}}AAA{{else}}BBB{{/filter}} * <!-- results in: 'BBB' --> * ``` * @param {Array} `array` * @param {any} `value` * @param {Object} `options` * @return {String} * @block * @api public */ helpers.filter = function(array, value, options) { var content = ''; var results = []; // filter on a specific property var prop = options.hash && (options.hash.property || options.hash.prop); if (prop) { results = array.filter(function(val) { return value === utils_1$2.get(val, prop); }); } else { // filter on a string value results = array.filter(function(v) { return value === v; }); } if (results && results.length > 0) { for (var i = 0; i < results.length; i++) { content += options.fn(results[i]); } return content; } return options.inverse(this); }; /** * Returns the first item, or first `n` items of an array. * * ```handlebars * {{first "['a', 'b', 'c', 'd', 'e']" 2}} * <!-- results in: '["a", "b"]' --> * ``` * @param {Array} `array` * @param {Number} `n` Number of items to return, starting at `0`. * @return {Array} * @api public */ helpers.first = function(array, n) { if (handlebarsUtils.isUndefined(array)) return ''; if (!utils_1$2.isNumber(n)) { return array[0]; } return array.slice(0, n); }; /** * Iterates over each item in an array and exposes the current item * in the array as context to the inner block. In addition to * the current array item, the helper exposes the following variables * to the inner block: * * - `index` * - `total` * - `isFirst` * - `isLast` * * Also, `@index` is exposed as a private variable, and additional * private variables may be defined as hash arguments. * * ```handlebars * <!-- accounts = [ * {'name': 'John', 'email': 'john@example.com'}, * {'name': 'Malcolm', 'email': 'malcolm@example.com'}, * {'name': 'David', 'email': 'david@example.com'} * ] --> * * {{#forEach accounts}} * <a href="mailto:{{ email }}" title="Send an email to {{ name }}"> * {{ name }} * </a>{{#unless isLast}}, {{/unless}} * {{/forEach}} * ``` * @source <http://stackoverflow.com/questions/13861007> * @param {Array} `array` * @return {String} * @block * @api public */ helpers.forEach = function(array, options) { var data = utils_1$2.createFrame(options, options.hash); var len = array.length; var buffer = ''; var i = -1; while (++i < len) { var item = array[i]; data.index = i; item.index = i + 1; item.total = len; item.isFirst = i === 0; item.isLast = i === (len - 1); buffer += options.fn(item, {data: data}); } return buffer; }; /** * Block helper that renders the block if an array has the * given `value`. Optionally specify an inverse block to render * when the array does not have the given value. * * ```handlebars * <!-- array: ['a', 'b', 'c'] --> * {{#inArray array "d"}} * foo * {{else}} * bar * {{/inArray}} * <!-- results in: 'bar' --> * ``` * @param {Array} `array` * @param {any} `value` * @param {Object} `options` * @return {String} * @block * @api public */ helpers.inArray = function(array, value, options) { return handlebarsUtils.value(handlebarsUtils.indexOf(array, value) > -1, this, options); }; /** * Returns true if `value` is an es5 array. * * ```handlebars * {{isArray "abc"}} * <!-- results in: false --> * * <!-- array: [1, 2, 3] --> * {{isArray array}} * <!-- results in: true --> * ``` * @param {any} `value` The value to test. * @return {Boolean} * @api public */ helpers.isArray = function(value) { return Array.isArray(value); }; /** * Returns the item from `array` at index `idx`. * * ```handlebars * <!-- array: ['a', 'b', 'c'] --> * {{itemAt array 1}} * <!-- results in: 'b' --> * ``` * @param {Array} `array` * @param {Number} `idx` * @return {any} `value` * @block * @api public */ helpers.itemAt = function(array, idx) { array = handlebarsUtils.result(array); if (Array.isArray(array)) { idx = utils_1$2.isNumber(idx) ? +idx : 0; if (idx < 0) { return array[array.length + idx]; } if (idx < array.length) { return array[idx]; } } }; /** * Join all elements of array into a string, optionally using a * given separator. * * ```handlebars * <!-- array: ['a', 'b', 'c'] --> * {{join array}} * <!-- results in: 'a, b, c' --> * * {{join array '-'}} * <!-- results in: 'a-b-c' --> * ``` * @param {Array} `array` * @param {String} `separator` The separator to use. Defaults to `, `. * @return {String} * @api public */ helpers.join = function(array, separator) { if (typeof array === 'string') return array; if (!Array.isArray(array)) return ''; separator = handlebarsUtils.isString(separator) ? separator : ', '; return array.join(separator); }; /** * Returns true if