{"_id":"magic-string-extra","_rev":"2777790","name":"magic-string-extra","description":"Extended magic-string with extra utilities","dist-tags":{"latest":"0.1.2"},"maintainers":[{"name":"antfu","email":""}],"time":{"modified":"2022-06-06T08:18:44.000Z","created":"2022-02-28T15:46:36.541Z","0.1.2":"2022-02-28T17:00:31.303Z","0.1.1":"2022-02-28T16:42:33.607Z","0.1.0":"2022-02-28T16:16:38.091Z","0.0.0":"2022-02-28T15:46:36.541Z"},"users":{},"author":"Anthony Fu <anthonyfu117@hotmail.com>","repository":{"type":"git","url":"git+https://github.com/antfu/magic-string-extra.git"},"versions":{"0.1.2":{"name":"magic-string-extra","version":"0.1.2","description":"Extended magic-string with extra utilities","keywords":["magic-string","sourcemap"],"homepage":"https://github.com/antfu/magic-string-extra#readme","bugs":{"url":"https://github.com/antfu/magic-string-extra/issues"},"repository":{"type":"git","url":"git+https://github.com/antfu/magic-string-extra.git"},"funding":{"url":"https://github.com/sponsors/antfu"},"license":"MIT","author":"Anthony Fu <anthonyfu117@hotmail.com>","sideEffects":false,"exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","dependencies":{"magic-string":"^0.25.7"},"devDependencies":{"@antfu/eslint-config":"^0.16.1","@antfu/ni":"^0.13.2","@rollup/plugin-commonjs":"^21.0.2","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^13.1.3","@types/node":"^17.0.21","bumpp":"^7.1.1","eslint":"^8.10.0","esno":"^0.14.1","rimraf":"^3.0.2","rollup":"^2.68.0","rollup-plugin-dts":"^4.1.0","rollup-plugin-esbuild":"^4.8.2","typescript":"^4.5.5","vite":"^2.8.4","vitest":"^0.5.7"},"scripts":{"build":"rimraf dist && rollup -c","dev":"rollup -c -w","lint":"eslint --ext .js,.ts .","release":"bumpp --commit --push --tag && pnpm publish","start":"esno src/index.ts","test":"vitest"},"_id":"magic-string-extra@0.1.2","_integrity":"sha512-0mEfrnh9PLC2HqAfWOtOjVw1zAHVzP/MdVi9WP39I1DkFN/5JHefTp5wI4X1G9WZ24htHEHYpnrfUzGl1J1eeg==","_resolved":"/Users/antfu/i/magic-string-extra/magic-string-extra-0.1.2.tgz","_from":"file:magic-string-extra-0.1.2.tgz","_nodeVersion":"16.13.0","_npmVersion":"8.1.0","dist":{"shasum":"67cf4d89f989683ea0c3e6651be99a085d96a8d6","size":6121,"noattachment":false,"key":"/magic-string-extra/-/magic-string-extra-0.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/magic-string-extra/download/magic-string-extra-0.1.2.tgz"},"_npmUser":{"name":"antfu","email":"anthonyfu117@hotmail.com"},"directories":{},"maintainers":[{"name":"antfu","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/magic-string-extra_0.1.2_1646067631133_0.3004804386239963"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-02-28T17:04:30.554Z","deprecated":"Utils have been back ported to magic-string@^0.26.0, this package is no longer needed","publish_time":1646067631303,"_cnpm_publish_time":1646067631303},"0.1.1":{"name":"magic-string-extra","version":"0.1.1","description":"Extended magic-string with extra utilities","keywords":["magic-string","sourcemap"],"homepage":"https://github.com/antfu/magic-string-extra#readme","bugs":{"url":"https://github.com/antfu/magic-string-extra/issues"},"repository":{"type":"git","url":"git+https://github.com/antfu/magic-string-extra.git"},"funding":{"url":"https://github.com/sponsors/antfu"},"license":"MIT","author":"Anthony Fu <anthonyfu117@hotmail.com>","sideEffects":false,"exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","dependencies":{"magic-string":"^0.25.7"},"devDependencies":{"@antfu/eslint-config":"^0.16.1","@antfu/ni":"^0.13.2","@rollup/plugin-commonjs":"^21.0.2","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^13.1.3","@types/node":"^17.0.21","bumpp":"^7.1.1","eslint":"^8.10.0","esno":"^0.14.1","rimraf":"^3.0.2","rollup":"^2.68.0","rollup-plugin-dts":"^4.1.0","rollup-plugin-esbuild":"^4.8.2","typescript":"^4.5.5","vite":"^2.8.4","vitest":"^0.5.7"},"scripts":{"build":"rimraf dist && rollup -c","dev":"rollup -c -w","lint":"eslint --ext .js,.ts .","release":"bumpp --commit --push --tag && pnpm publish","start":"esno src/index.ts","test":"vitest"},"_id":"magic-string-extra@0.1.1","_integrity":"sha512-cQnwetVaPlwqDywWpGcJBGbcKxtaG2S2A+CMcIP8l82jBOkhBb5Rz7tGLHn/NXKJ70WXNwez80N2cZ6O0QJIcA==","_resolved":"/Users/antfu/i/magic-string-extra/magic-string-extra-0.1.1.tgz","_from":"file:magic-string-extra-0.1.1.tgz","_nodeVersion":"16.13.0","_npmVersion":"8.1.0","dist":{"shasum":"26a41ad1eb1a41b0b80f474cc3add956a99452ff","size":6120,"noattachment":false,"key":"/magic-string-extra/-/magic-string-extra-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/magic-string-extra/download/magic-string-extra-0.1.1.tgz"},"_npmUser":{"name":"antfu","email":"anthonyfu117@hotmail.com"},"directories":{},"maintainers":[{"name":"antfu","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/magic-string-extra_0.1.1_1646066553437_0.7720559071762771"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-02-28T16:42:36.845Z","deprecated":"Utils have been back ported to magic-string@^0.26.0, this package is no longer needed","publish_time":1646066553607,"_cnpm_publish_time":1646066553607},"0.1.0":{"name":"magic-string-extra","version":"0.1.0","description":"Extended magic-string with extra utilities","keywords":["magic-string","sourcemap"],"homepage":"https://github.com/antfu/magic-string-extra#readme","bugs":{"url":"https://github.com/antfu/magic-string-extra/issues"},"repository":{"type":"git","url":"git+https://github.com/antfu/magic-string-extra.git"},"funding":{"url":"https://github.com/sponsors/antfu"},"license":"MIT","author":"Anthony Fu <anthonyfu117@hotmail.com>","sideEffects":false,"exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","dependencies":{"magic-string":"^0.25.7"},"devDependencies":{"@antfu/eslint-config":"^0.16.1","@antfu/ni":"^0.13.2","@rollup/plugin-commonjs":"^21.0.2","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^13.1.3","@types/node":"^17.0.21","bumpp":"^7.1.1","eslint":"^8.10.0","esno":"^0.14.1","rimraf":"^3.0.2","rollup":"^2.68.0","rollup-plugin-dts":"^4.1.0","rollup-plugin-esbuild":"^4.8.2","typescript":"^4.5.5","vite":"^2.8.4","vitest":"^0.5.7"},"scripts":{"build":"rimraf dist && rollup -c","dev":"rollup -c -w","lint":"eslint --ext .js,.ts .","release":"bumpp --commit --push --tag && pnpm publish","start":"esno src/index.ts","test":"vitest"},"_id":"magic-string-extra@0.1.0","_integrity":"sha512-3gVCDOrqpjvrySeKVdEnC95cfL9H5SGndkO+OBSlPd9angLMJXRgtfkXr8qoGOS7iLrxFgZMghLmpBqzU9NVOQ==","_resolved":"/Users/antfu/i/magic-string-extra/magic-string-extra-0.1.0.tgz","_from":"file:magic-string-extra-0.1.0.tgz","_nodeVersion":"16.13.0","_npmVersion":"8.1.0","dist":{"shasum":"e5a7edcb8740416749f07c1629d304ea77ff84bd","size":5788,"noattachment":false,"key":"/magic-string-extra/-/magic-string-extra-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/magic-string-extra/download/magic-string-extra-0.1.0.tgz"},"_npmUser":{"name":"antfu","email":"anthonyfu117@hotmail.com"},"directories":{},"maintainers":[{"name":"antfu","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/magic-string-extra_0.1.0_1646064997936_0.9548722773659541"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-02-28T16:20:06.374Z","deprecated":"Utils have been back ported to magic-string@^0.26.0, this package is no longer needed","publish_time":1646064998091,"_cnpm_publish_time":1646064998091},"0.0.0":{"name":"magic-string-extra","version":"0.0.0","description":"Extended magic-string with extra utilities","keywords":["magic-string","sourcemap"],"homepage":"https://github.com/antfu/magic-string-extra#readme","bugs":{"url":"https://github.com/antfu/magic-string-extra/issues"},"repository":{"type":"git","url":"git+https://github.com/antfu/magic-string-extra.git"},"funding":"https://github.com/sponsors/antfu","license":"MIT","author":{"name":"Anthony Fu","email":"anthonyfu117@hotmail.com"},"sideEffects":false,"exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","scripts":{"build":"rimraf dist && rollup -c","dev":"rollup -c -w","lint":"eslint --ext .js,.ts .","prepublishOnly":"nr build","release":"bumpp --commit --push --tag && pnpm publish","start":"esno src/index.ts","test":"vitest"},"dependencies":{"magic-string":"^0.25.7"},"devDependencies":{"@antfu/eslint-config":"^0.16.1","@antfu/ni":"^0.13.2","@rollup/plugin-commonjs":"^21.0.2","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^13.1.3","@types/node":"^17.0.21","bumpp":"^7.1.1","eslint":"^8.10.0","esno":"^0.14.1","rimraf":"^3.0.2","rollup":"^2.68.0","rollup-plugin-dts":"^4.1.0","rollup-plugin-esbuild":"^4.8.2","typescript":"^4.5.5","vite":"^2.8.4","vitest":"^0.5.7"},"gitHead":"c6066c9698de24651f485b5eda14ea852379c426","_id":"magic-string-extra@0.0.0","_nodeVersion":"16.13.0","_npmVersion":"8.1.0","dist":{"shasum":"72c3fc8f9b18da9573c96e2b7ff99425c58e41d1","size":3963,"noattachment":false,"key":"/magic-string-extra/-/magic-string-extra-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/magic-string-extra/download/magic-string-extra-0.0.0.tgz"},"_npmUser":{"name":"antfu","email":"anthonyfu117@hotmail.com"},"directories":{},"maintainers":[{"name":"antfu","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/magic-string-extra_0.0.0_1646063196383_0.9152996371498352"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-02-28T15:46:40.653Z","deprecated":"Utils have been back ported to magic-string@^0.26.0, this package is no longer needed","publish_time":1646063196541,"_cnpm_publish_time":1646063196541}},"readme":"# magic-string-extra\n\n[![NPM version](https://img.shields.io/npm/v/magic-string-extra?color=a1b858&label=)](https://www.npmjs.com/package/magic-string-extra)\n\nExtended [Rich-Harris/magic-string](https://github.com/Rich-Harris/magic-string) with extra utilities.\n\n## Install\n\n```bash\nnpm i magic-string-extra\n```\n\n`magic-string-extra` can be a drop-in replacement for `magic-string`:\n\n```diff\n- import MagicString from 'magic-string'\n+ import MagicString from 'magic-string-extra'\n```\n\n## Extra Utils\n\nCheck [`magic-string`](https://github.com/Rich-Harris/magic-string)'s documentation for the base utils.\n\n### `.replace()`\n\nShares the same signature as [`String.prototype.replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace). Supports RegExp and replacer functions.\n\n```ts\nimport MagicString from 'magic-string-extra'\n\nconst s = new MagicString(source)\n\ns.replace(foo, 'bar')\ns.replace(/foo/g, 'bar')\ns.replace(/(\\w)(\\d+)/g, (_, $1, $2) => $1.toUpperCase() + $2)\n```\n\nThe differences between `String.replace`:\n- It will always match against the **original string**\n- It mutates the magic string state (use `.clone()` to be immutable)\n\n### `.hasChanged()`\n\nIn some cases, when the string does not change you might be able to skip the sourcemap generation to improve the performance (e.g. Rollup and Vite's transform hook). This function allows you to check the state without tracking it externally.\n\n```ts\nimport MagicString from 'magic-string-extra'\n\nconst s = new MagicString(source)\n\ns.hasChanged() // false\n\ns.prepend('foo')\n\ns.hasChanged() // true\n```\n\n### `.toRollupResult()`\n\nIt's common to use the magic string for code transformations in plugins. This function provides a shorthand to generate the result in Rollup's `TransformResult` format. When the string has not changed, `null` will be returned skip the Rollup transformation.\n\n```ts\nimport MagicString from 'magic-string-extra'\n\nconst s = new MagicString(source)\n\ns.toRollupResult() // { code, map } | null\n```\n\n## Included Upstream PRs\n\n- [#183 - fix(types): mark MagicString options as optional](https://github.com/Rich-Harris/magic-string/pull/183)\n- [#179 - docs: add TSDoc](https://github.com/Rich-Harris/magic-string/pull/179)\n\n## Sponsors\n\n<p align=\"center\">\n  <a href=\"https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg\">\n    <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>\n  </a>\n</p>\n\n## License\n\n[MIT](./LICENSE) License © 2022 [Anthony Fu](https://github.com/antfu)\n","_attachments":{},"homepage":"https://github.com/antfu/magic-string-extra#readme","bugs":{"url":"https://github.com/antfu/magic-string-extra/issues"},"license":"MIT"}