{"name":"get-source","version":"2.0.7","description":"Fetch source-mapped sources. Peek by file, line, column. Node & browsers. Sync & async.","main":"get-source","types":"./get-source.d.ts","scripts":{"test-browser":"mocha test/test.browser --reporter spec","test-node":"mocha test/test.node --reporter spec","test-path":"mocha test/test.path --reporter spec","test":"nyc --reporter=html --reporter=text mocha test/test.path test/test.node --reporter spec","coveralls":"nyc report --reporter=text-lcov | coveralls"},"repository":{"type":"git","url":"git+https://github.com/xpl/get-source.git"},"keywords":["sources","sourcemap","read source","cached sources"],"author":{"name":"Vitaly Gordon","email":"rocket.mind@gmail.com"},"license":"Unlicense","bugs":{"url":"https://github.com/xpl/get-source/issues"},"homepage":"https://github.com/xpl/get-source","devDependencies":{"chai":"^3.5.0","coveralls":"^3.0.3","istanbul":"^0.4.5","memory-fs":"^0.3.0","mocha":"^8.0.1","nyc":"^15.1.0","webpack":"^4.43.0"},"dependencies":{"data-uri-to-buffer":"^2.0.0","source-map":"^0.6.1"},"gitHead":"5ed44b1d63f7e62ee077523738ab24dd9fd73635","_id":"get-source@2.0.7","_nodeVersion":"10.21.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-BGYRmFRGPZF4GnYNDD/kAnkDfeyGOUzuD4DOHRR1LC3ChyE28zHaNQAypEx8xztGSHfGp+oWmq1vwozt5VqMcw==","shasum":"a6ed84c1fa2044c2d81d423051e94625a1ccda28","tarball":"http://registry-npm.ywwl.com/get-source/download/get-source-2.0.7.tgz","fileCount":22,"unpackedSize":34397,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe9nBBCRA9TVsSAnZWagAArjAP/1E8gNNoq45tOaVkhdlR\nE8RAAc2C/MkdR5JZg+sjXHMGNC1/NuEI8cp2Gz5twVZUytaYWlzgLrsSBJ7p\nG0n3SN6pIzIU0yopl96hBs7MqcUHj54UnJ7cFDTZ3+trYl9l5Vl0I58Wu6JT\nuYj+ecFER0s3whIcKW1YyEJQpqiqWTf3ov7tWBhdDEukzxVbqXzO2rMApb2p\n41+x5eL5XQjbMVP9qmcy8N54OaglVTshh0spoezCFIHn29DqAm8iqmIBupZ+\nyBk8h4gvM+D/Tb4yfkW07/po3kVm1i9JYVziE41Vdvreooi+5g1JFSy0XSrB\nkENCHkaZutkWc8MsTRjjEpE8Qu8MDZ8iSHJT/1rFGdELu7s9JbqwZqZcy2Je\nVCpc3n7UVIwZVM5Gp3M9i5DT98WY1ey1e1SImPOQfvdwCpJY7HF1avrJTgNC\nY/gABXnWtmIcPj+u/M73dOPOYxJzV+twmk8Tcr3kH3c0xXYGhczPPzVdwlhR\nop0/YZDPgI38Pm6xCpSwVBx5fCIdPLdzx6X3notNtml8m4yDqgAibRkeuEcT\nHrrxM9WIk+oVHivqS5uuTQTj1wxwsgLwRlP3La+MyC1ArhZgHa7Y4wvwtFpc\nSQQZbSU2DUIsqwqGQQB9BPTyyBZcG7MYhS4N3BEAAqUv0+TFfO+PhGNuAji0\nnZmF\r\n=Q3P7\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIB3DwDtfBrOoMUK2RJs6h8r3WxObN+I4QCIhsQAAeSxPAiEArEAlqpc9lIvbC+mtfhctnOH5qOcdewvdJbrOGxvkyxc="}],"size":10603,"noattachment":false,"key":"/get-source/-/get-source-2.0.7.tgz"},"maintainers":[{"name":"x84","email":"igor.kroitor@gmail.com"},{"name":"xpl","email":"rocket.mind@gmail.com"}],"_npmUser":{"name":"xpl","email":"rocket.mind@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/get-source_2.0.7_1593208897006_0.8137423531169239"},"_hasShrinkwrap":false,"readme":"# get-source\n\n[![Build Status](https://travis-ci.org/xpl/get-source.svg?branch=master)](https://travis-ci.org/xpl/get-source) [![Coverage Status](https://coveralls.io/repos/github/xpl/get-source/badge.svg)](https://coveralls.io/github/xpl/get-source) [![npm](https://img.shields.io/npm/v/get-source.svg)](https://npmjs.com/package/get-source)\n\nFetch source-mapped sources. Peek by file, line, column. Node & browsers. Sync & async.\n\n```bash\nnpm install get-source\n```\n\n## Features\n\n- [x] Allows to read source code files in Node and browsers\n- [x] Full sourcemap support (path resolving, external/embedded/inline linking, and long chains)\n- [x] **Synchronous** API — good for CLI tools (e.g. [logging](https://github.com/xpl/ololog)). Works in browsers!\n- [x] **Asynchronous** API — good for everything web!\n- [x] Built-in cache\n\n## What for\n\n- [x] Call stacks enhanced with source code information (see the [StackTracey](https://github.com/xpl/stacktracey) library)\n- [x] [Advanced logging](https://github.com/xpl/ololog) / assertion printing\n- [x] [Error displaying components](https://github.com/xpl/panic-overlay) for front-end web development\n\n## Usage (Synchronous)\n\n```javascript\nimport getSource from 'get-source'\n```\n```javascript\nfile = getSource ('./scripts/index.min.js')\n```\n\nWill read the file synchronously (either via XHR or by filesystem API, depending on the environment) and return it's cached representation. Result will contain the following fields:\n\n```javascript\nfile.path  // normalized file path\nfile.text  // text contents\nfile.lines // array of lines\n```\n\nAnd the `resolve` method:\n\n```javascript\nfile.resolve ({ line: 1, column: 8 }) // indexes here start from 1 (by widely accepted convention). Zero indexes are invalid.\n```\n\nIt will look through the sourcemap chain, returning following:\n\n```javascript\n{\n   line:       <original line number>,\n   column:     <original column number>,\n   sourceFile: <original source file object>,\n   sourceLine: <original source line text>\n}\n```\n\nIn that returned object, `sourceFile` is the same kind of object that `getSource` returns. So you can access its `text`, `lines` and `path` fields to obtain the full information. And the `sourceLine` is returned just for the convenience, as a shortcut.\n\n## Usage (Asynchronous)\n\nPretty much the same as synchronous, except it's `getSource.async`. It returns awaitable promises:\n\n```javascript\nfile     = await getSource.async ('./scripts/index.min.js')\nlocation = await file.resolve ({ line: 1, column: 8 })\n```\n\n## Error handling\n\nIn synchronous mode, it never throws (due to backward compatibility reasons with existing code):\n\n```javascript\nnonsense = getSource ('/some/nonexistent/file')\n\nnonsense.text  // should be '' (so it's safe to access without checking)\nnonsense.error // should be an Error object, representing an actual error thrown during reading/parsing\n```\n```javascript\nresolved = nonsense.resolve ({ line: 5, column: 0 })\n\nresolved.sourceLine // empty string (so it's safe to access without checking)\nresolved.error      // should be an Error object, representing an actual error thrown during reading/parsing\n```\n\nIn asychronous mode, it throws an error:\n\n```javascript\ntry { \n   file     = await getSource.async ('/some/file')\n   location = await file.resolve ({ line: 5, column: 0 })\n} catch (e) {\n   ...\n}\n```\n\n## Resetting Cache\n\nE.g. when you need to force-reload files:\n\n```javascript\ngetSource.resetCache ()        // sync cache\ngetSource.async.resetCache ()  // async cache\n```\n\nAlso, viewing cached files:\n\n```javascript\ngetSource.getCache ()        // sync cache\ngetSource.async.getCache ()  // async cache\n```\n","publish_time":1593208897102,"_cnpm_publish_time":1593208897102,"dist-tags":{"latest":"2.0.12"}}