{"_id":"subsume","_rev":"4327211","name":"subsume","description":"Embed data in other data and easily extract it when needed","dist-tags":{"latest":"4.0.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2026-04-07T23:41:57.000Z","created":"2016-11-14T09:35:03.009Z","4.0.0":"2021-08-12T13:36:38.220Z","3.0.0":"2019-05-21T08:01:06.614Z","2.1.0":"2019-04-06T11:34:06.514Z","2.0.0":"2018-06-20T05:42:50.059Z","1.0.0":"2016-11-14T09:35:03.009Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/subsume.git"},"versions":{"4.0.0":{"name":"subsume","version":"4.0.0","description":"Embed data in other data and easily extract it when needed","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/subsume.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"test":"xo && ava && tsd"},"keywords":["subsume","embed","embedded","include","insert","data","string","text","content","compose","parse","extract","encode","decode"],"dependencies":{"escape-string-regexp":"^5.0.0","unique-string":"^3.0.0"},"devDependencies":{"ava":"^3.15.0","tsd":"^0.17.0","xo":"^0.44.0"},"gitHead":"d763fe6775cd34b839875e8bb007bb9bc7c19f58","bugs":{"url":"https://github.com/sindresorhus/subsume/issues"},"homepage":"https://github.com/sindresorhus/subsume#readme","_id":"subsume@4.0.0","_nodeVersion":"12.22.1","_npmVersion":"7.10.0","dist":{"shasum":"506c72bfb76596ebc6f96cbdccceadda41ab0849","size":3706,"noattachment":false,"key":"/subsume/-/subsume-4.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/subsume/download/subsume-4.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/subsume_4.0.0_1628775398094_0.4460534086553276"},"_hasShrinkwrap":false,"publish_time":1628775398220,"_cnpm_publish_time":1628775398220,"_cnpmcore_publish_time":"2021-12-17T08:40:54.924Z"},"3.0.0":{"name":"subsume","version":"3.0.0","description":"Embed data in other data and easily extract it when needed","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/subsume.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["subsume","embed","embedded","include","insert","data","string","text","content","compose","parse","extract","encode","decode"],"dependencies":{"escape-string-regexp":"^2.0.0","unique-string":"^2.0.0"},"devDependencies":{"ava":"^1.4.1","tsd":"^0.7.3","xo":"^0.24.0"},"gitHead":"23f788d042c0f7d5201b6ffc7637fee8f29a4697","bugs":{"url":"https://github.com/sindresorhus/subsume/issues"},"homepage":"https://github.com/sindresorhus/subsume#readme","_id":"subsume@3.0.0","_nodeVersion":"8.16.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"22c92730f441ad72ee9af4bdad42dc4ff830cfaf","size":3746,"noattachment":false,"key":"/subsume/-/subsume-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/subsume/download/subsume-3.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/subsume_3.0.0_1558425666498_0.9587613459199296"},"_hasShrinkwrap":false,"publish_time":1558425666614,"_cnpm_publish_time":1558425666614,"_cnpmcore_publish_time":"2021-12-17T08:40:55.347Z"},"2.1.0":{"name":"subsume","version":"2.1.0","description":"Embed data in other data and easily extract it when needed","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/subsume.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava && tsd"},"keywords":["subsume","embed","embedded","include","insert","data","string","text","content","compose","parse","extract","encode","decode"],"dependencies":{"escape-string-regexp":"^1.0.5","unique-string":"^1.0.0"},"devDependencies":{"ava":"^1.4.1","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"dbabe528a906d220c15521da7bf4f8308898cc56","bugs":{"url":"https://github.com/sindresorhus/subsume/issues"},"homepage":"https://github.com/sindresorhus/subsume#readme","_id":"subsume@2.1.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"9bd263cc6050cf57a8b1c647d3449c2ee33ce106","size":3732,"noattachment":false,"key":"/subsume/-/subsume-2.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/subsume/download/subsume-2.1.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/subsume_2.1.0_1554550446407_0.36796417612987176"},"_hasShrinkwrap":false,"publish_time":1554550446514,"_cnpm_publish_time":1554550446514,"_cnpmcore_publish_time":"2021-12-17T08:40:55.535Z"},"2.0.0":{"name":"subsume","version":"2.0.0","description":"Embed data in other data and easily extract it when needed","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/subsume.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=6"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["subsume","embed","embedded","include","insert","data","string","text","content","compose","parse","extract","encode","decode"],"dependencies":{"escape-string-regexp":"^1.0.5","unique-string":"^1.0.0"},"devDependencies":{"ava":"*","xo":"*"},"gitHead":"f78d3377e12a0bc49f64559270cf2e5e5118037c","bugs":{"url":"https://github.com/sindresorhus/subsume/issues"},"homepage":"https://github.com/sindresorhus/subsume#readme","_id":"subsume@2.0.0","_npmVersion":"5.6.0","_nodeVersion":"8.11.2","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"277ebaac75da6034d95512864d20095816824244","size":3326,"noattachment":false,"key":"/subsume/-/subsume-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/subsume/download/subsume-2.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/subsume_2.0.0_1529473369904_0.12245189432395942"},"_hasShrinkwrap":false,"publish_time":1529473370059,"_cnpm_publish_time":1529473370059,"_cnpmcore_publish_time":"2021-12-17T08:40:55.751Z"},"1.0.0":{"name":"subsume","version":"1.0.0","description":"Embed data in other data and easily extract it when needed","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/subsume.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["subsume","embed","embedded","include","insert","data","string","text","content","compose","parse","extract","encode","decode"],"dependencies":{"escape-string-regexp":"^1.0.5","unique-string":"^1.0.0"},"devDependencies":{"ava":"*","xo":"*"},"xo":{"esnext":true},"gitHead":"21d8212310940152f67317e19b4968d804de9b5e","bugs":{"url":"https://github.com/sindresorhus/subsume/issues"},"homepage":"https://github.com/sindresorhus/subsume#readme","_id":"subsume@1.0.0","_shasum":"da977c7b43da53064e1eb8842a47486aa00a173c","_from":".","_npmVersion":"2.15.9","_nodeVersion":"4.6.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"da977c7b43da53064e1eb8842a47486aa00a173c","size":2524,"noattachment":false,"key":"/subsume/-/subsume-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/subsume/download/subsume-1.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/subsume-1.0.0.tgz_1479116102790_0.1661837357096374"},"directories":{},"publish_time":1479116103009,"_hasShrinkwrap":false,"_cnpm_publish_time":1479116103009,"_cnpmcore_publish_time":"2021-12-17T08:40:55.963Z"}},"readme":"# subsume\n\n> Embed data in other data and easily extract it when needed\n\nCan for example be useful when you run a child process that has multiple entities writing to stdout and you want to handle those outputs differently. I personally use it in [`run-jxa`](https://github.com/sindresorhus/run-jxa) to allow the code run in that context to use `console.log`, but also allow me to send the result of the execution back through `console.log`.\n\n## Install\n\n```\n$ npm install subsume\n```\n\n## Usage\n\n```js\nimport Subsume from 'subsume';\n\nconst subsume = new Subsume();\n\nconsole.log(subsume.id);\n//=> '7febcd0b3806fbc48c01d7cea4ed1219'\n\nconst text = subsume.compose('????');\n//=> '@@[7febcd0b3806fbc48c01d7cea4ed1219]@@????##[7febcd0b3806fbc48c01d7cea4ed1219]##'\n\n// The text can now be embedded in some other text\nconst output = `some${text} random text`;\n//=> 'some@@[7febcd0b3806fbc48c01d7cea4ed1219]@@????##[7febcd0b3806fbc48c01d7cea4ed1219]## random text'\n\n// At a later point we extract it\nsubsume.parse(output);\n//=> {data: '????', rest: 'some random text'}\n\n// Or in a different process by using the `id`\nconst input = 'some@@[7febcd0b3806fbc48c01d7cea4ed1219]@@????##[7febcd0b3806fbc48c01d7cea4ed1219]## random text';\nSubsume.parse(text, '7febcd0b3806fbc48c01d7cea4ed1219');\n//=> {data: '????', rest: 'some random text'}\n```\n\n## API\n\n### `subsume = new Subsume(id?)`\n\nReturns a new instance.\n\n#### id\n\nType: `string`\\\nDefault: Unique ID\n\nYou probably don't need to set this. Can be useful if you need a stable ID.\n\n### subsume\n\n`Subsume` instance.\n\n#### compose(text)\n\nType: `Function`\n\nReturns a wrapped version of `text` that you can embed in other content.\n\n#### parse(text)\n\nType: `Function`\n\nExtract your embedded data from `text`.\n\nReturns an object with properties `.data` for your embedded data and `.rest` for everything else.\n\n#### id\n\nType: `string`\n\nThe used identifier.\n\n#### prefix\n\nType: `string`\n\nPrefix used in `.compose()`.\n\n#### postfix\n\nType: `string`\n\nPostfix used in `.compose()`.\n\n#### regex\n\nType: `RegExp`\n\nRegex used in `.parse()`.\n\n### Subsume.parse(text, id)\n\nExtract embedded data with a specific `id` out of `text`.\n\nUseful when `text` comes from an external source.\n\n### Subsume.parseAll(text, idArray?)\n\nExtract embedded data corresponding to all IDs in `idArray`, if specified. Otherwise it will extract embedded data for all top-level IDs.\n\nReturns an object with properties `.data`, a Map with an entry for each parsed ID, and `.rest` for what remains after all the required IDs have been parsed, as seen below:\n\nThe input:\n\n```\nsome@@[7febcd0b3806fbc48c01d7cea4ed1219]@@????##[7febcd0b3806fbc48c01d7cea4ed1219]## random@@[7febcd0b3806fbc48c01d7cea4ed1218]@@????##[7febcd0b3806fbc48c01d7cea4ed1218]## text@@[7febcd0b3806fbc48c01d7cea4ed1217]@@????##[7febcd0b3806fbc48c01d7cea4ed1217]##\n```\n\nGives the following output:\n\n```js\n{\n\tdata: Map {\n\t\t'7febcd0b3806fbc48c01d7cea4ed1219' => '????',\n\t\t'7febcd0b3806fbc48c01d7cea4ed1218' => '????',\n\t\t'7febcd0b3806fbc48c01d7cea4ed1217' => '????'\n\t},\n\trest: 'some random text'\n}\n```\n","_attachments":{},"homepage":"https://github.com/sindresorhus/subsume#readme","bugs":{"url":"https://github.com/sindresorhus/subsume/issues"},"license":"MIT"}