(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Stacky = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o', // A list of Strings/RegExps that will be stripped from `location` values on // each line (via `String#replace`). locationStrip: [], // A list of Strings/RegExps that indicate that a line is *not* important, and // should be styled as such. unimportantLocation: [], // A filter function to completely remove lines filter: function() { return false; }, // styles are functions that take a string and return that string when styled. styles: { method: passthrough, location: passthrough, line: passthrough, column: passthrough, unimportant: passthrough, }, }; // See Tero Tolonen's answer at // http://stackoverflow.com/questions/17575790/environment-detection-node-js-or-browser /*jshint -W054 */ var isNode = new Function('try {return this===global;}catch(e){return false;}'); // For Stacky-in-Node, we default to colored stacks. if (isNode()) { var chalk = require('chalk'); scope.defaults.styles = { method: chalk.magenta, location: chalk.blue, line: chalk.cyan, column: chalk.cyan, unimportant: chalk.dim }; } function pretty(stackOrParsed, options) { options = mergeDefaults(options || {}, scope.defaults); var lines = Array.isArray(stackOrParsed) ? stackOrParsed : parse(stackOrParsed); lines = clean(lines, options); var padSize = methodPadding(lines, options); var parts = lines.map(function(line) { var method = line.method || options.methodPlaceholder; var pad = options.indent + padding(padSize - method.length); var locationBits = [ options.styles.location(line.location), options.styles.line(line.line), ]; if ('column' in line) { locationBits.push(options.styles.column(line.column)); } var location = locationBits.join(':'); var text = pad + options.styles.method(method) + ' at ' + location; if (!line.important) { text = options.styles.unimportant(text); } return text; }); return parts.join('\n'); } function clean(lines, options) { var result = []; for (var i = 0, line; line = lines[i]; i++) { if (options.filter(line)) continue; line.location = cleanLocation(line.location, options); line.important = isImportant(line, options); result.push(line); } return result; } // Utility function passthrough(string) { return string; } function mergeDefaults(options, defaults) { var result = Object.create(defaults); Object.keys(options).forEach(function(key) { var value = options[key]; if (typeof value === 'object' && !Array.isArray(value)) { value = mergeDefaults(value, defaults[key]); } result[key] = value; }); return result; } function methodPadding(lines, options) { var size = options.methodPlaceholder.length; for (var i = 0, line; line = lines[i]; i++) { size = Math.min(options.maxMethodPadding, Math.max(size, line.method.length)); } return size; } function padding(length) { var result = ''; for (var i = 0; i < length; i++) { result = result + ' '; } return result; } function cleanLocation(location, options) { if (options.locationStrip) { for (var i = 0, matcher; matcher = options.locationStrip[i]; i++) { location = location.replace(matcher, ''); } } return location; } function isImportant(line, options) { if (options.unimportantLocation) { for (var i = 0, matcher; matcher = options.unimportantLocation[i]; i++) { if (line.location.match(matcher)) return false; } } return true; } scope.clean = clean; scope.pretty = pretty; })(typeof module !== 'undefined' ? module.exports : (this.Stacky = this.Stacky || {})); },{"./parsing":4,"chalk":undefined}],2:[function(require,module,exports){ /** * @license * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. * * This code may only be used under the BSD style license found at polymer.github.io/LICENSE.txt * The complete set of authors may be found at polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also subject to * an additional IP rights grant found at polymer.github.io/PATENTS.txt */ 'use strict'; var formatting = require('./formatting'); var normalization = require('./normalization'); var parsing = require('./parsing'); module.exports = { // Shorthands for your convenience. normalize: normalization.normalize, parse: parsing.parse, pretty: formatting.pretty, // Or the full modules. formatting: formatting, normalization: normalization, parsing: parsing, }; },{"./formatting":1,"./normalization":3,"./parsing":4}],3:[function(require,module,exports){ /** * @license * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. * * This code may only be used under the BSD style license found at polymer.github.io/LICENSE.txt * The complete set of authors may be found at polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also subject to * an additional IP rights grant found at polymer.github.io/PATENTS.txt */ (function(scope) { 'use strict'; var parse = scope.parse || require('./parsing').parse; var pretty = scope.pretty || require('./formatting').pretty; function normalize(error, prettyOptions) { if (error.parsedStack) return error; var message = error.message || error.description || error || ''; var parsedStack = []; try { parsedStack = parse(error.stack || error.toString()); } catch (error) { // Ah well. } if (parsedStack.length === 0 && error.fileName) { parsedStack.push({ method: '', location: error.fileName, line: error.lineNumber, column: error.columnNumber, }); } if (!prettyOptions || !prettyOptions.showColumns) { for (var i = 0, line; line = parsedStack[i]; i++) { delete line.column; } } var prettyStack = message; if (parsedStack.length > 0) { prettyStack = prettyStack + '\n' + pretty(parsedStack, prettyOptions); } var cleanErr = Object.create(Error.prototype); cleanErr.message = message; cleanErr.stack = prettyStack; cleanErr.parsedStack = parsedStack; return cleanErr; } scope.normalize = normalize; })(typeof module !== 'undefined' ? module.exports : (this.Stacky = this.Stacky || {})); },{"./formatting":1,"./parsing":4}],4:[function(require,module,exports){ /** * @license * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. * * This code may only be used under the BSD style license found at polymer.github.io/LICENSE.txt * The complete set of authors may be found at polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also subject to * an additional IP rights grant found at polymer.github.io/PATENTS.txt */ (function(scope) { 'use strict'; function parse(stack) { var rawLines = stack.split('\n'); var stackyLines = compact(rawLines.map(parseStackyLine)); if (stackyLines.length === rawLines.length) return stackyLines; var v8Lines = compact(rawLines.map(parseV8Line)); if (v8Lines.length > 0) return v8Lines; var geckoLines = compact(rawLines.map(parseGeckoLine)); if (geckoLines.length > 0) return geckoLines; throw new Error('Unknown stack format: ' + stack); } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack var GECKO_LINE = /^(?:([^@]*)@)?(.*?):(\d+)(?::(\d+))?$/; function parseGeckoLine(line) { var match = line.match(GECKO_LINE); if (!match) return null; return { method: match[1] || '', location: match[2] || '', line: parseInt(match[3]) || 0, column: parseInt(match[4]) || 0, }; } // https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi var V8_OUTER1 = /^\s*(eval )?at (.*) \((.*)\)$/; var V8_OUTER2 = /^\s*at()() (\S+)$/; var V8_INNER = /^\(?([^\(]+):(\d+):(\d+)\)?$/; function parseV8Line(line) { var outer = line.match(V8_OUTER1) || line.match(V8_OUTER2); if (!outer) return null; var inner = outer[3].match(V8_INNER); if (!inner) return null; var method = outer[2] || ''; if (outer[1]) method = 'eval at ' + method; return { method: method, location: inner[1] || '', line: parseInt(inner[2]) || 0, column: parseInt(inner[3]) || 0, }; } // Stacky.formatting.pretty var STACKY_LINE = /^\s*(.+) at (.+):(\d+):(\d+)$/; function parseStackyLine(line) { var match = line.match(STACKY_LINE); if (!match) return null; return { method: match[1] || '', location: match[2] || '', line: parseInt(match[3]) || 0, column: parseInt(match[4]) || 0, }; } // Helpers function compact(array) { var result = []; array.forEach(function(value) { if (value) { result.push(value); } }); return result; } scope.parse = parse; scope.parseGeckoLine = parseGeckoLine; scope.parseV8Line = parseV8Line; scope.parseStackyLine = parseStackyLine; })(typeof module !== 'undefined' ? module.exports : (this.Stacky = this.Stacky || {})); },{}]},{},[2])(2) });