{"_id":"sl-convert-source-map","_rev":"1-3ac1ca9132c798ac0851a8ecea4d78de","name":"sl-convert-source-map","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"sl-convert-source-map","version":"1.0.0","keywords":["convert","sourcemap","source","map","browser","debug"],"author":{"name":"Sealights"},"license":"MIT","_id":"sl-convert-source-map@1.0.0","maintainers":[{"name":"sealights","email":"devops@sealights.io"}],"homepage":"https://github.com/Sealights/sl-convert-source-map","bugs":{"url":"https://github.com/Sealights/sl-convert-source-map/issues"},"dist":{"shasum":"797684b777540d845ed4fd022486e1374ff11c3f","tarball":"https://registry.npmjs.org/sl-convert-source-map/-/sl-convert-source-map-1.0.0.tgz","fileCount":4,"integrity":"sha512-B1u7ALNIttlrsAiJysTUr0oULXNwpPsbw4xYYsFq56cvJ5KbFIomgHcBG1kWDSER6rOVD/xoS89VE67PMXJpfg==","signatures":[{"sig":"MEUCIQDTY642kkOOt4f2Qg4A60odbgq9ZjyiZc+0PhfdMf79jAIgLXLTkPHLjOLJsOF9kes1z5dDujGCRFCC1U1zzjoERdk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16873},"main":"index.js","engine":{"node":">=4"},"gitHead":"8b59d917b050d181570b8a88cb572bc81889e97f","scripts":{"test":"tap test/*.js --color"},"_npmUser":{"name":"sealights","email":"devops@sealights.io"},"repository":{"url":"git://github.com/Sealights/sl-convert-source-map.git","type":"git"},"_npmVersion":"10.9.2","description":"Fork of convert-source-map with improved sourcemap parsing","directories":{},"_nodeVersion":"23.4.0","_hasShrinkwrap":false,"devDependencies":{"tap":"~9.0.0","inline-source-map":"~0.6.2"},"_npmOperationalInternal":{"tmp":"tmp/sl-convert-source-map_1.0.0_1739798592649_0.14791304837497865","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"sl-convert-source-map","version":"1.0.1","description":"Fork of convert-source-map with improved sourcemap parsing","main":"index.js","scripts":{"test":"tap test/*.js --color"},"repository":{"type":"git","url":"git://github.com/Sealights/sl-convert-source-map.git"},"homepage":"https://github.com/Sealights/sl-convert-source-map","devDependencies":{"inline-source-map":"~0.6.2","tap":"~9.0.0"},"keywords":["convert","sourcemap","source","map","browser","debug"],"author":{"name":"Sealights"},"license":"MIT","engine":{"node":">=4"},"_id":"sl-convert-source-map@1.0.1","gitHead":"8b59d917b050d181570b8a88cb572bc81889e97f","bugs":{"url":"https://github.com/Sealights/sl-convert-source-map/issues"},"_nodeVersion":"23.4.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-w4+ksHfOBH8nV9jBZ7GUh87SOnAVwxU3hm9pWIMpPjRleLobrYNGC+vaNJVxv5K/u+o9qRyme6MwIRSFfH8LWw==","shasum":"f069e6b949d791fc3913a5ae6d51d574cb4c0d08","tarball":"https://registry.npmjs.org/sl-convert-source-map/-/sl-convert-source-map-1.0.1.tgz","fileCount":4,"unpackedSize":16873,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQD/THChGHz1O0dwAVR5H6Uc2+ZpF2Gx6Qly7hYG/zowmwIgIlAuw6+IJR3XcZCUbvb8nAlYUcZNQt8rGfqHkln0hZ0="}]},"_npmUser":{"name":"sealights","email":"devops@sealights.io"},"directories":{},"maintainers":[{"name":"sealights","email":"devops@sealights.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sl-convert-source-map_1.0.1_1739798688918_0.9740877186366093"},"_hasShrinkwrap":false}},"time":{"created":"2025-02-17T13:23:12.649Z","modified":"2025-02-17T13:24:49.325Z","1.0.0":"2025-02-17T13:23:12.826Z","1.0.1":"2025-02-17T13:24:49.093Z"},"bugs":{"url":"https://github.com/Sealights/sl-convert-source-map/issues"},"author":{"name":"Sealights"},"license":"MIT","homepage":"https://github.com/Sealights/sl-convert-source-map","keywords":["convert","sourcemap","source","map","browser","debug"],"repository":{"type":"git","url":"git://github.com/Sealights/sl-convert-source-map.git"},"description":"Fork of convert-source-map with improved sourcemap parsing","maintainers":[{"name":"sealights","email":"devops@sealights.io"}],"readme":"# sl-convert-source-map\n\nFork of [convert-source-map](https://github.com/thlorenz/convert-source-map) with improved sourcemap parsing.\n\n## Improvements\n\n- Better handling of malformed sourcemap comments\n- More robust base64 extraction\n- Improved error handling for invalid sourcemaps\n\n## License\n\nMIT, see LICENSE file.\n\nOriginal work Copyright (c) 2013 Thorsten Lorenz\nModified work Copyright (c) 2024 Sealights\n\nConverts a source-map from/to  different formats and allows adding/changing properties.\n\n```js\nvar convert = require('convert-source-map');\n\nvar json = convert\n  .fromComment('//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVpbGQvZm9vLm1pbi5qcyIsInNvdXJjZXMiOlsic3JjL2Zvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=')\n  .toJSON();\n\nvar modified = convert\n  .fromComment('//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVpbGQvZm9vLm1pbi5qcyIsInNvdXJjZXMiOlsic3JjL2Zvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=')\n  .setProperty('sources', [ 'SRC/FOO.JS' ])\n  .toJSON();\n\nconsole.log(json);\nconsole.log(modified);\n```\n\n```json\n{\"version\":3,\"file\":\"build/foo.min.js\",\"sources\":[\"src/foo.js\"],\"names\":[],\"mappings\":\"AAAA\",\"sourceRoot\":\"/\"}\n{\"version\":3,\"file\":\"build/foo.min.js\",\"sources\":[\"SRC/FOO.JS\"],\"names\":[],\"mappings\":\"AAAA\",\"sourceRoot\":\"/\"}\n```\n\n## Upgrading\n\nPrior to v2.0.0, the `fromMapFileComment` and `fromMapFileSource` functions took a String directory path and used that to resolve & read the source map file from the filesystem. However, this made the library limited to nodejs environments and broke on sources with querystrings.\n\nIn v2.0.0, you now need to pass a function that does the file reading. It will receive the source filename as a String that you can resolve to a filesystem path, URL, or anything else.\n\nIf you are using `convert-source-map` in nodejs and want the previous behavior, you'll use a function like such:\n\n```diff\n+ var fs = require('fs'); // Import the fs module to read a file\n+ var path = require('path'); // Import the path module to resolve a path against your directory\n- var conv = convert.fromMapFileSource(css, '../my-dir');\n+ var conv = convert.fromMapFileSource(css, function (filename) {\n+   return fs.readFileSync(path.resolve('../my-dir', filename), 'utf-8');\n+ });\n```\n\n## API\n\n### fromObject(obj)\n\nReturns source map converter from given object.\n\n### fromJSON(json)\n\nReturns source map converter from given json string.\n\n### fromURI(uri)\n\nReturns source map converter from given uri encoded json string.\n\n### fromBase64(base64)\n\nReturns source map converter from given base64 encoded json string.\n\n### fromComment(comment)\n\nReturns source map converter from given base64 or uri encoded json string prefixed with `//# sourceMappingURL=...`.\n\n### fromMapFileComment(comment, readMap)\n\nReturns source map converter from given `filename` by parsing `//# sourceMappingURL=filename`.\n\n`readMap` must be a function which receives the source map filename and returns either a String or Buffer of the source map (if read synchronously), or a `Promise` containing a String or Buffer of the source map (if read asynchronously).\n\nIf `readMap` doesn't return a `Promise`, `fromMapFileComment` will return a source map converter synchronously.\n\nIf `readMap` returns a `Promise`, `fromMapFileComment` will also return `Promise`. The `Promise` will be either resolved with the source map converter or rejected with an error.\n\n#### Examples\n\n**Synchronous read in Node.js:**\n\n```js\nvar convert = require('convert-source-map');\nvar fs = require('fs');\n\nfunction readMap(filename) {\n  return fs.readFileSync(filename, 'utf8');\n}\n\nvar json = convert\n  .fromMapFileComment('//# sourceMappingURL=map-file-comment.css.map', readMap)\n  .toJSON();\nconsole.log(json);\n```\n\n\n**Asynchronous read in Node.js:**\n\n```js\nvar convert = require('convert-source-map');\nvar { promises: fs } = require('fs'); // Notice the `promises` import\n\nfunction readMap(filename) {\n  return fs.readFile(filename, 'utf8');\n}\n\nvar converter = await convert.fromMapFileComment('//# sourceMappingURL=map-file-comment.css.map', readMap)\nvar json = converter.toJSON();\nconsole.log(json);\n```\n\n**Asynchronous read in the browser:**\n\n```js\nvar convert = require('convert-source-map');\n\nasync function readMap(url) {\n  const res = await fetch(url);\n  return res.text();\n}\n\nconst converter = await convert.fromMapFileComment('//# sourceMappingURL=map-file-comment.css.map', readMap)\nvar json = converter.toJSON();\nconsole.log(json);\n```\n\n### fromSource(source)\n\nFinds last sourcemap comment in file and returns source map converter or returns `null` if no source map comment was found.\n\n### fromMapFileSource(source, readMap)\n\nFinds last sourcemap comment in file and returns source map converter or returns `null` if no source map comment was found.\n\n`readMap` must be a function which receives the source map filename and returns either a String or Buffer of the source map (if read synchronously), or a `Promise` containing a String or Buffer of the source map (if read asynchronously).\n\nIf `readMap` doesn't return a `Promise`, `fromMapFileSource` will return a source map converter synchronously.\n\nIf `readMap` returns a `Promise`, `fromMapFileSource` will also return `Promise`. The `Promise` will be either resolved with the source map converter or rejected with an error.\n\n### toObject()\n\nReturns a copy of the underlying source map.\n\n### toJSON([space])\n\nConverts source map to json string. If `space` is given (optional), this will be passed to\n[JSON.stringify](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/stringify) when the\nJSON string is generated.\n\n### toURI()\n\nConverts source map to uri encoded json string.\n\n### toBase64()\n\nConverts source map to base64 encoded json string.\n\n### toComment([options])\n\nConverts source map to an inline comment that can be appended to the source-file.\n\nBy default, the comment is formatted like: `//# sourceMappingURL=...`, which you would\nnormally see in a JS source file.\n\nWhen `options.encoding == 'uri'`, the data will be uri encoded, otherwise they will be base64 encoded.\n\nWhen `options.multiline == true`, the comment is formatted like: `/*# sourceMappingURL=... */`, which you would find in a CSS source file.\n\n### addProperty(key, value)\n\nAdds given property to the source map. Throws an error if property already exists.\n\n### setProperty(key, value)\n\nSets given property to the source map. If property doesn't exist it is added, otherwise its value is updated.\n\n### getProperty(key)\n\nGets given property of the source map.\n\n### removeComments(src)\n\nReturns `src` with all source map comments removed\n\n### removeMapFileComments(src)\n\nReturns `src` with all source map comments pointing to map files removed.\n\n### commentRegex\n\nProvides __a fresh__ RegExp each time it is accessed. Can be used to find source map comments.\n\nBreaks down a source map comment into groups: Groups: 1: media type, 2: MIME type, 3: charset, 4: encoding, 5: data.\n\n### mapFileCommentRegex\n\nProvides __a fresh__ RegExp each time it is accessed. Can be used to find source map comments pointing to map files.\n\n### generateMapFileComment(file, [options])\n\nReturns a comment that links to an external source map via `file`.\n\nBy default, the comment is formatted like: `//# sourceMappingURL=...`, which you would normally see in a JS source file.\n\nWhen `options.multiline == true`, the comment is formatted like: `/*# sourceMappingURL=... */`, which you would find in a CSS source file.\n\n[ci-url]: https://github.com/thlorenz/convert-source-map/actions?query=workflow:ci\n[ci-image]: https://img.shields.io/github/actions/workflow/status/thlorenz/convert-source-map/ci.yml?branch=master&style=flat-square\n","readmeFilename":"README.md"}