{"id":17402863,"url":"https://github.com/thlorenz/stack-mapper","last_synced_at":"2025-04-14T19:53:21.450Z","repository":{"id":12791779,"uuid":"15465501","full_name":"thlorenz/stack-mapper","owner":"thlorenz","description":"Initialize it with a source map, then feed it error stacks to have the trace locations mapped to the original files.","archived":false,"fork":false,"pushed_at":"2021-12-06T17:43:39.000Z","size":404,"stargazers_count":39,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T08:12:04.113Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/thlorenz/stack-mapper","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thlorenz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-27T03:22:45.000Z","updated_at":"2023-05-25T16:55:29.000Z","dependencies_parsed_at":"2022-09-17T00:01:34.894Z","dependency_job_id":null,"html_url":"https://github.com/thlorenz/stack-mapper","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thlorenz%2Fstack-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thlorenz%2Fstack-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thlorenz%2Fstack-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thlorenz%2Fstack-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thlorenz","download_url":"https://codeload.github.com/thlorenz/stack-mapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248951950,"owners_count":21188420,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-16T18:32:49.752Z","updated_at":"2025-04-14T19:53:21.432Z","avatar_url":"https://github.com/thlorenz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stack-mapper [![build status](https://secure.travis-ci.org/thlorenz/stack-mapper.png)](http://travis-ci.org/thlorenz/stack-mapper)\n\n[![testling badge](https://ci.testling.com/thlorenz/stack-mapper.png)](https://ci.testling.com/thlorenz/stack-mapper)\n\nInitialize it with a source map, then feed it error stacks to have the trace locations mapped to the original files.\n\n```js\nvar stackMapper = require('stack-mapper');\n\n// it is up to you to create stack-mapper compatible frame objects\n// this will depend on your environment\nvar inframes = [{\n  filename: '/full/path/to/bundle.js',\n  line: 5,\n  column: 10\n}, {\n  filename: '/full/path/to/bundle.js',\n  line: 9,\n  column: 10\n}, {\n  filename: '/full/path/to/bundle.js',\n  line: 20,\n  column: 12\n}, {\n  filename: '/full/path/to/bundle.js',\n  line: 22,\n  column: 10,\n}, {\n  filename: '/Users/thlorenz/dev/js/projects/stack-mapper/test/twofiles.js',\n  line: 18,\n  column: 21\n}];\n\nvar map = { version: 3,\n  file: 'generated.js',\n  sources:\n   [ '/Users/thlorenz/dev/js/projects/stack-mapper/test/twofiles/barbar.js',\n     '/Users/thlorenz/dev/js/projects/stack-mapper/test/twofiles/main.js' ],\n  names: [],\n  mappings: ';AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACTA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA',\n  sourcesContent:\n   [ '\\'use strict\\';\\n\\nfunction foobar() {\\n  return new Error();\\n}\\n\\nvar go = module.exports = function () {\\n  return foobar();  \\n};\\n',\n     '\\'use strict\\';\\n\\nvar barbar = require(\\'./barbar\\');\\n\\nmodule.exports = function main() {\\n  var a = 1;\\n  function bar() {\\n    return barbar();\\n  }\\n  return bar();\\n}\\n' ] }\n\nvar sm = stackMapper(map);\nvar frames = sm.map(inframes);\n\nconsole.log(frames);\n```\n\n#### Output\n\n```\n[{\n    filename: '/Users/thlorenz/dev/js/projects/stack-mapper/test/twofiles/barbar.js',\n    line: 4,\n    column: 10\n}, {\n    filename: '/Users/thlorenz/dev/js/projects/stack-mapper/test/twofiles/barbar.js',\n    line: 8,\n    column: 10\n}, {\n ...\n}]\n```\n\n## Obtaining the source map\n\nYou need to pass the source map as an object as shown in the example. If your source map happens to be in a different\nformat, please use the [convert-source-map](https://github.com/thlorenz/convert-source-map) module in order to convert it.\n\n[browserify](https://github.com/substack/node-browserify) attaches source maps to the bottom of the bundle if the `--debug` flag is set, here is an example how to\nobtain and convert it to use with `stack-mapper`.\n\n```js\nvar browserify =  require('browserify')\n  , convert    =  require('convert-source-map')\n\nbrowserify()\n  .require(entry)\n  .bundle({ debug: true }, function (err, src) {\n    if (err) return cb(err);\n\n    var map = convert.fromSource(src).toObject();\n  });\n```\n\n## Installation\n\n    npm install stack-mapper\n\n## API\n\n### stackMapper(sourcemap)\n\n```\n/**\n * Returns a Stackmapper that will use the given source map to map error trace locations.\n * \n * @name stackMapper\n * @function\n * @param {Object} sourcemap source map for the generated file\n * @return {StackMapper} stack mapper for the particular source map\n */\n```\n\n### stackMapper.map(frames, includeSource)\n\n```\n/**\n * Maps the trace statements of the given error stack and replaces locations\n * referencing code in the generated file with the locations inside the original files.\n * \n * @name map\n * @function\n * @param {Array} array of callsite objects (see readme for details about Callsite object)\n * @param {boolean} includeSource if set to true, the source code at the first traced location is included\n * @return {Array.\u003cObject\u003e} info about the error stack with adapted locations, each with the following properties\n *    - filename: original filename \n *    - line: origial line in that filename of the trace\n *    - column: origial column on that line of the trace\n */\n```\n\n## Stack Frames\n\nThe frames array passed to stackMapper.map should contain at least the following items\n\n* filename\n* line\n* column\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthlorenz%2Fstack-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthlorenz%2Fstack-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthlorenz%2Fstack-mapper/lists"}