{"id":13447927,"url":"https://github.com/fregante/zip-text-nodes","last_synced_at":"2025-04-15T06:51:15.622Z","repository":{"id":57406091,"uuid":"188271819","full_name":"fregante/zip-text-nodes","owner":"fregante","description":"Merge the DOM of 2 elements with the same textContent.","archived":false,"fork":false,"pushed_at":"2021-11-29T19:04:35.000Z","size":10,"stargazers_count":33,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T18:46:52.031Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npm.im/zip-text-nodes","language":"TypeScript","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/fregante.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":"2019-05-23T16:39:54.000Z","updated_at":"2024-02-22T08:25:21.000Z","dependencies_parsed_at":"2022-09-11T23:21:35.861Z","dependency_job_id":null,"html_url":"https://github.com/fregante/zip-text-nodes","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fregante%2Fzip-text-nodes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fregante%2Fzip-text-nodes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fregante%2Fzip-text-nodes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fregante%2Fzip-text-nodes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fregante","download_url":"https://codeload.github.com/fregante/zip-text-nodes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249023708,"owners_count":21199958,"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-07-31T05:01:30.586Z","updated_at":"2025-04-15T06:51:15.606Z","avatar_url":"https://github.com/fregante.png","language":"TypeScript","funding_links":[],"categories":["JavaScript","TypeScript"],"sub_categories":[],"readme":"# \u003cimg align=\"right\" width=\"350\" src=\"https://user-images.githubusercontent.com/1402241/143927245-d92f27a8-a3c5-4195-a29a-bfea2271023d.png\"\u003e zip-text-nodes [![][badge-gzip]][link-bundlephobia]\n\n[badge-gzip]: https://img.shields.io/bundlephobia/minzip/zip-text-nodes.svg?label=gzipped\n[link-bundlephobia]: https://bundlephobia.com/result?p=zip-text-nodes\n\n\u003e Merge the DOM of 2 elements with the same textContent.\n\nGiven 2 elements:\n\n```html\nHello, \u003cstrong\u003eworld!\u003c/strong\u003e\n```\n\nand:\n\n```html\n\u003cem\u003eHello\u003c/em\u003e, world!\n```\n\nthey are merged into:\n\n```html\n\u003cem\u003eHello\u003c/em\u003e, \u003cstrong\u003eworld!\u003c/strong\u003e\n```\n\nThis can be useful when running some transformations on the content of an element and successively merging the results or restoring the original markup.\n\n```js\nconst base = \u003c\u003eI live in \u003ca href=\"it\"\u003eItaly\u003c/a\u003e\u003c/\u003e;\nconst grammar = highlightVerb(base);\n// \u003c\u003eI \u003cem\u003elive\u003c/em\u003e in Italy\u003c/\u003e // e.g. the link was lost\n\nzipTextNodes(base, grammar);\n// \u003c\u003eI \u003cem\u003elive\u003c/em\u003e in \u003ca href=\"it\"\u003eItaly\u003c/a\u003e\u003c/\u003e\n// The new `em` is copied from `grammar` to `base`\n```\n\nSupports overlapping and nested elements.\n\n\n## Install\n\n```\nnpm install zip-text-nodes\n```\n\n\n## Setup\n\n```js\nconst zipTextNodes = require('zip-text-nodes');\n```\n\n```js\nimport zipTextNodes from 'zip-text-nodes';\n```\n\n\n## API\n\n### zipTextNodes(target, source)\n\n#### target\n\nType: `Element` `DocumentFragment`\n\nThe element into which the new children are copied. This element is modified.\n\n#### source\n\nType: `Element` `DocumentFragment`\n\nThe element from which the new children are copied.\n\n# Related\n\n- [insert-text-textarea](https://github.com/fregante/insert-text-textarea) - Insert text in a textarea (supports Firefox and Undo).\n- [fit-textarea](https://github.com/fregante/fit-textarea) - Automatically expand a `\u003ctextarea\u003e` to fit its content, in a few bytes.\n- [delegate-it](https://github.com/fregante/delegate-it) - DOM event delegation, in \u003c1KB.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffregante%2Fzip-text-nodes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffregante%2Fzip-text-nodes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffregante%2Fzip-text-nodes/lists"}