ng2-logger
Version:
isomorphic logger for browser/server in typescript
1,000 lines (896 loc) • 31.4 kB
JavaScript
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 5);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", { value: true });
var Level;
(function (Level) {
Level[Level["DATA"] = 0] = "DATA";
Level[Level["INFO"] = 1] = "INFO";
Level[Level["WARN"] = 2] = "WARN";
Level[Level["ERROR"] = 3] = "ERROR";
Level[Level["__NOTHING"] = 4] = "__NOTHING";
})(Level = exports.Level || (exports.Level = {}));
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isBrowser = (typeof window !== 'undefined' && window.document);
exports.isNode = !exports.isBrowser;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", { value: true });
const level_1 = __webpack_require__(0);
const helper_1 = __webpack_require__(1);
const backend_logging_1 = __webpack_require__(8);
if (helper_1.isNode) {
}
class Display {
static msg(message, params, moduleName, moduleColor, level, moduleWidth) {
let color = 'gray';
if (level === level_1.Level.INFO)
color = 'deepskyblue';
if (level === level_1.Level.ERROR)
color = 'red';
if (level === level_1.Level.WARN)
color = 'orange';
if (moduleWidth) {
const diff = moduleWidth - moduleName.length;
if (diff > 0) {
for (let i = 0; i < diff; i++) {
moduleName += ' ';
}
}
}
if (helper_1.isBrowser) {
if (typeof message === 'string') {
let a1 = '%c ' + moduleName + ' %c ' + message + ' ';
let a2 = 'background: ' + moduleColor + ';color:white; border: 1px solid ' + moduleColor + '; ';
let a3 = 'border: 1px solid ' + color + '; ';
params.unshift(a3);
params.unshift(a2);
params.unshift(a1);
}
else {
let a1 = '%c ' + moduleName + ' ';
let a2 = 'background: ' + moduleColor + ';color:white; border: 1px solid ' + color + '; ';
params.push(message);
params.unshift(a2);
params.unshift(a1);
}
console.log.apply(console, params);
}
if (helper_1.isNode) {
let a1 = chalk.bgHex(moduleColor)(chalk.black(moduleName));
let p = params;
if (typeof message === 'string') {
a1 = a1 + chalk.keyword(color)(' [') + chalk.dim(message) + chalk.keyword(color)('] ');
}
else {
p = [message].concat(params);
}
backend_logging_1.consoleLog(a1, level);
backend_logging_1.displayParams(p, level);
}
}
}
exports.Display = Display;
/***/ }),
/* 3 */
/***/ (function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", { value: true });
function contain(arr, item) {
return arr.filter(l => l === item || ((item.match && typeof item.match === 'function') ? item.match(l) : false)).length > 0;
}
exports.contain = contain;
;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
;
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(__webpack_require__(6));
__export(__webpack_require__(0));
__export(__webpack_require__(1));
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = __webpack_require__(7);
const level_1 = __webpack_require__(0);
const display_1 = __webpack_require__(2);
const include_1 = __webpack_require__(4);
const helper_1 = __webpack_require__(1);
if (helper_1.isNode) {
var randomcolor = __webpack_require__(14);
}
class Log {
static create(name, ...level) {
let i;
if (Log.instances[name] === undefined) {
i = new logger_1.Logger(name, Log.getRandomColor(), Log.isDevelopmentMode, level, Log.isMutedModule(name), Log.levels.length > 0 ? Log.fixedWidth : undefined, Log.levels.length > 0 ? Log.display : undefined);
Log.instances[name] = i;
}
else {
i = Log.instances[name];
}
return i;
}
static getRandomColor() {
if (helper_1.isNode) {
return randomcolor({ luminosity: 'light', count: 10 });
}
let letters = '012345'.split('');
let color = '#';
color += letters[Math.round(Math.random() * 5)];
letters = '0123456789ABCDEF'.split('');
for (let i = 0; i < 5; i++) {
color += letters[Math.round(Math.random() * 15)];
}
if (color === undefined)
return this.getRandomColor();
return color;
}
static display(name, data, incomming, moduleName) {
if (!include_1.contain(Log.levels, incomming))
return;
if (incomming === level_1.Level.DATA) {
display_1.Display.msg(name, data, name, Log.instances[moduleName].color, level_1.Level.DATA, Log.instances[moduleName].fixedWidth);
}
if (incomming === level_1.Level.ERROR) {
display_1.Display.msg(name, data, name, Log.instances[moduleName].color, level_1.Level.ERROR, Log.instances[moduleName].fixedWidth);
}
if (incomming === level_1.Level.INFO) {
display_1.Display.msg(name, data, name, Log.instances[moduleName].color, level_1.Level.INFO, Log.instances[moduleName].fixedWidth);
}
if (incomming === level_1.Level.WARN) {
display_1.Display.msg(name, data, name, Log.instances[moduleName].color, level_1.Level.WARN, Log.instances[moduleName].fixedWidth);
}
}
static onlyLevel(...level) {
if (Log._logOnly) {
console.error('You should use funcion onlyLevel only once');
return;
}
if (Log._logOnly)
Log._logOnly = true;
if (level.length === 0)
return;
Log.levels = level;
}
static onlyModules(...modules) {
if (Log._logModules) {
console.error('You should use funcion onlyModules only once');
return;
}
if (modules.length === 0)
return;
Log.modules = modules;
Log.muteAllOtherModules();
}
static isMutedModule(moduleName) {
if (Log.modules.length == 0)
return false;
if (!include_1.contain(Log.modules, moduleName))
return true;
return false;
}
static muteAllOtherModules() {
for (var moduleName in Log.instances) {
if (!include_1.contain(Log.modules, moduleName))
Log.instances[moduleName].mute();
}
}
static setProductionMode() {
if (Log.modeIsSet) {
console.error('Mode is already set');
return;
}
if (console !== undefined && console.clear !== undefined) {
setTimeout(() => {
console.clear();
console.log = () => { };
console.error = () => { };
console.warn = () => { };
console.info = () => { };
});
}
logger_1.Logger.isProductionMode = true;
Log.isDevelopmentMode = false;
}
}
Log.instances = {};
Log.fixedWidth = 0;
Log._logOnly = false;
Log.levels = [];
Log._logModules = false;
Log.modules = [];
Log.isDevelopmentMode = true;
Log.modeIsSet = false;
exports.Log = Log;
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", { value: true });
const level_1 = __webpack_require__(0);
const display_1 = __webpack_require__(2);
const include_1 = __webpack_require__(4);
class Logger {
constructor(name, color, developmentMode, allowed, isMuted, fixedWidth, display) {
this.name = name;
this.color = color;
this.developmentMode = developmentMode;
this.allowed = allowed;
this.isMuted = isMuted;
this.fixedWidth = fixedWidth;
this.display = display;
/** @deprecated Use data(...)
* @see data
*/
this.d = (name, ...data) => this._data(name, data);
/** @deprecated Use error(...)
* @see error
*/
this.er = (name, ...data) => this._error(name, data);
/** @deprecated Use info(...)
* @see info
*/
this.i = (name, ...data) => this._info(name, data);
/** @deprecated Use warn(...)
* @see warn
*/
this.w = (name, ...data) => this._warn(name, data);
/**
* Logs message and data with the level=data
* @param message The message
* @param otherParams Additional parameters
*/
this.data = (message, ...otherParams) => { return this._data(message, otherParams); };
/**
* Logs message and data with the level=error
* @param message The message
* @param otherParams Additional parameters
*/
this.error = (message, ...otherParams) => this._error(message, otherParams);
/**
* Logs message and data with the level=info
* @param message The message
* @param otherParams Additional parameters
*/
this.info = (message, ...otherParams) => this._info(message, otherParams);
/**
* Logs message and data with the level=warn
* @param message The message
* @param otherParams Additional parameters
*/
this.warn = (message, ...otherParams) => this._warn(message, otherParams);
}
_data(name, ...data) {
if (this.allowed.length >= 1 && include_1.contain(this.allowed, level_1.Level.__NOTHING)
&& !include_1.contain(this.allowed, level_1.Level.DATA))
return this;
if (Logger.isProductionMode)
return this;
if (this.display !== undefined)
this.display(name, data, level_1.Level.DATA, this.name);
else if (this.allowed.length === 0 || include_1.contain(this.allowed, level_1.Level.DATA)) {
display_1.Display.msg.apply(undefined, [name, ...data, this.name, this.color, level_1.Level.DATA, this.fixedWidth]);
}
return this;
}
_error(name, ...data) {
if (this.allowed.length >= 1 && include_1.contain(this.allowed, level_1.Level.__NOTHING)
&& !include_1.contain(this.allowed, level_1.Level.ERROR))
return this;
if (Logger.isProductionMode)
return this;
if (this.display !== undefined)
this.display(name, data, level_1.Level.ERROR, this.name);
else if (this.allowed.length === 0 || include_1.contain(this.allowed, level_1.Level.ERROR)) {
display_1.Display.msg.apply(undefined, [name, ...data, this.name, this.color, level_1.Level.ERROR, this.fixedWidth]);
}
return this;
}
_info(name, ...data) {
if (this.allowed.length >= 1 && include_1.contain(this.allowed, level_1.Level.__NOTHING)
&& !include_1.contain(this.allowed, level_1.Level.INFO))
return this;
if (Logger.isProductionMode)
return this;
if (this.display !== undefined)
this.display(name, data, level_1.Level.INFO, this.name);
else if (this.allowed.length === 0 || include_1.contain(this.allowed, level_1.Level.INFO)) {
display_1.Display.msg.apply(undefined, [name, ...data, this.name, this.color, level_1.Level.INFO, this.fixedWidth]);
}
return this;
}
_warn(name, ...data) {
if (this.allowed.length >= 1 && include_1.contain(this.allowed, level_1.Level.__NOTHING)
&& !include_1.contain(this.allowed, level_1.Level.WARN))
return this;
if (Logger.isProductionMode)
return this;
if (this.display !== undefined)
this.display(name, data, level_1.Level.WARN, this.name);
else if (this.allowed.length === 0 || include_1.contain(this.allowed, level_1.Level.WARN)) {
display_1.Display.msg.apply(undefined, [name, ...data, this.name, this.color, level_1.Level.WARN, this.fixedWidth]);
}
return this;
}
_logMessage(name, level, ...data) {
if (this.isMuted)
return this;
if (this.allowed.length >= 1 && include_1.contain(this.allowed, level)
&& !include_1.contain(this.allowed, level))
return this;
if (Logger.isProductionMode)
return this;
if (this.display !== undefined)
this.display(name, data, level, this.name);
else if (this.allowed.length === 0 || include_1.contain(this.allowed, level)) {
display_1.Display.msg(name, data, this.name, this.color, level, this.fixedWidth);
}
return this;
}
level(l) {
this._level = l;
return this;
}
mute() {
this.isMuted = true;
}
}
Logger.isProductionMode = false;
exports.Logger = Logger;
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
;
/* WEBPACK VAR INJECTION */(function(process) {
Object.defineProperty(exports, "__esModule", { value: true });
const level_1 = __webpack_require__(0);
const helper_1 = __webpack_require__(1);
if (helper_1.isNode) {
var chalk = __webpack_require__(9);
var path = __webpack_require__(10);
var fs = __webpack_require__(11);
var JSON5 = __webpack_require__(12);
var stringify = __webpack_require__(13);
}
function consoleLog(data, level) {
if (level === level_1.Level.INFO)
console.info(data);
else if (level === level_1.Level.ERROR)
console.error(data);
else if (level === level_1.Level.WARN)
console.warn(data);
else
console.log(data);
}
exports.consoleLog = consoleLog;
function displayParams(params = [], level) {
params.forEach(param => {
if (typeof param === 'object') {
handleObjectData(param, level);
}
else if (isObjectAfterStringify(param)) {
handleObjectData(JSON5.parse(param), level);
}
else {
consoleLog(param, level);
}
});
}
exports.displayParams = displayParams;
function replace(out, match, char, color) {
let m = out.match(match);
let outer = out;
if (m)
m.forEach(p => {
const rep = p
.slice(1)
.replace(char, '');
outer = outer.replace(`"${rep}":`, `"${color.call(null, rep)}":`);
});
return outer;
}
function handleObjectData(param, level) {
if (istartedInVscode()) {
consoleLog(param, level);
return;
}
let out = stringify(param, null, 4);
out = replace(out, /\".*"\:\ \"/g, /\"\: "/, chalk.green);
out = replace(out, /\".*"\:\ \{/g, /\"\: \{/, chalk.yellow);
out = replace(out, /\".*"\:\ \[/g, /\"\: \[/, chalk.red);
out = replace(out, /\".*"\:\ true/g, /\"\: true/, chalk.blue);
out = replace(out, /\".*"\:\ false/g, /\"\: false/, chalk.blue);
out = replace(out, /\".*"\:\ (\-|[0-9])/g, /\"\: (\-|[0-9])/, chalk.magenta);
out = out.replace(/\"/g, chalk.dim('"'))
.replace(/\{/g, chalk.dim('{'))
.replace(/\}/g, chalk.dim('}'))
.replace(/\}/g, chalk.dim('}'));
if (process.stdout.columns && process.stdout.columns > 0) {
out = out.split('\n').map(line => {
return (line.length < process.stdout.columns ?
line :
line.slice(0, process.stdout.columns - 6) + chalk.dim('...'));
}).join('\n');
}
consoleLog(out, level);
}
function istartedInVscode() {
let args = process.execArgv;
if (args) {
return args.some((arg) => /^--debug=?/.test(arg) ||
/^--debug-brk=?/.test(arg) ||
/^--inspect=?/.test(arg) ||
/^--inspect-brk=?/.test(arg));
}
return false;
}
exports.istartedInVscode = istartedInVscode;
function isObjectAfterStringify(s) {
try {
const json = JSON5.parse(s);
return true;
}
catch (error) {
return false;
}
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3)))
/***/ }),
/* 9 */
/***/ (function(module, exports) {
module.exports = require("chalk");
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// resolves . and .. elements in a path array with directory names there
// must be no slashes, empty elements, or device names (c:\) in the array
// (so also no leading and trailing slashes - it does not distinguish
// relative and absolute paths)
function normalizeArray(parts, allowAboveRoot) {
// if the path tries to go above the root, `up` ends up > 0
var up = 0;
for (var i = parts.length - 1; i >= 0; i--) {
var last = parts[i];
if (last === '.') {
parts.splice(i, 1);
} else if (last === '..') {
parts.splice(i, 1);
up++;
} else if (up) {
parts.splice(i, 1);
up--;
}
}
// if the path is allowed to go above the root, restore leading ..s
if (allowAboveRoot) {
for (; up--; up) {
parts.unshift('..');
}
}
return parts;
}
// Split a filename into [root, dir, basename, ext], unix version
// 'root' is just a slash, or nothing.
var splitPathRe =
/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
var splitPath = function(filename) {
return splitPathRe.exec(filename).slice(1);
};
// path.resolve([from ...], to)
// posix version
exports.resolve = function() {
var resolvedPath = '',
resolvedAbsolute = false;
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path = (i >= 0) ? arguments[i] : process.cwd();
// Skip empty and invalid entries
if (typeof path !== 'string') {
throw new TypeError('Arguments to path.resolve must be strings');
} else if (!path) {
continue;
}
resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charAt(0) === '/';
}
// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)
// Normalize the path
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
return !!p;
}), !resolvedAbsolute).join('/');
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
};
// path.normalize(path)
// posix version
exports.normalize = function(path) {
var isAbsolute = exports.isAbsolute(path),
trailingSlash = substr(path, -1) === '/';
// Normalize the path
path = normalizeArray(filter(path.split('/'), function(p) {
return !!p;
}), !isAbsolute).join('/');
if (!path && !isAbsolute) {
path = '.';
}
if (path && trailingSlash) {
path += '/';
}
return (isAbsolute ? '/' : '') + path;
};
// posix version
exports.isAbsolute = function(path) {
return path.charAt(0) === '/';
};
// posix version
exports.join = function() {
var paths = Array.prototype.slice.call(arguments, 0);
return exports.normalize(filter(paths, function(p, index) {
if (typeof p !== 'string') {
throw new TypeError('Arguments to path.join must be strings');
}
return p;
}).join('/'));
};
// path.relative(from, to)
// posix version
exports.relative = function(from, to) {
from = exports.resolve(from).substr(1);
to = exports.resolve(to).substr(1);
function trim(arr) {
var start = 0;
for (; start < arr.length; start++) {
if (arr[start] !== '') break;
}
var end = arr.length - 1;
for (; end >= 0; end--) {
if (arr[end] !== '') break;
}
if (start > end) return [];
return arr.slice(start, end - start + 1);
}
var fromParts = trim(from.split('/'));
var toParts = trim(to.split('/'));
var length = Math.min(fromParts.length, toParts.length);
var samePartsLength = length;
for (var i = 0; i < length; i++) {
if (fromParts[i] !== toParts[i]) {
samePartsLength = i;
break;
}
}
var outputParts = [];
for (var i = samePartsLength; i < fromParts.length; i++) {
outputParts.push('..');
}
outputParts = outputParts.concat(toParts.slice(samePartsLength));
return outputParts.join('/');
};
exports.sep = '/';
exports.delimiter = ':';
exports.dirname = function(path) {
var result = splitPath(path),
root = result[0],
dir = result[1];
if (!root && !dir) {
// No dirname whatsoever
return '.';
}
if (dir) {
// It has a dirname, strip trailing slash
dir = dir.substr(0, dir.length - 1);
}
return root + dir;
};
exports.basename = function(path, ext) {
var f = splitPath(path)[2];
// TODO: make this comparison case-insensitive on windows?
if (ext && f.substr(-1 * ext.length) === ext) {
f = f.substr(0, f.length - ext.length);
}
return f;
};
exports.extname = function(path) {
return splitPath(path)[3];
};
function filter (xs, f) {
if (xs.filter) return xs.filter(f);
var res = [];
for (var i = 0; i < xs.length; i++) {
if (f(xs[i], i, xs)) res.push(xs[i]);
}
return res;
}
// String.prototype.substr - negative index don't work in IE8
var substr = 'ab'.substr(-1) === 'b'
? function (str, start, len) { return str.substr(start, len) }
: function (str, start, len) {
if (start < 0) start = str.length + start;
return str.substr(start, len);
}
;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3)))
/***/ }),
/* 11 */
/***/ (function(module, exports) {
/***/ }),
/* 12 */
/***/ (function(module, exports) {
module.exports = require("json5");
/***/ }),
/* 13 */
/***/ (function(module, exports) {
module.exports = require("json-stringify-safe");
/***/ }),
/* 14 */
/***/ (function(module, exports) {
module.exports = require("randomcolor");
/***/ })
/******/ ])));