{"id":16367948,"url":"https://github.com/ephys/dom-string-wrapper","last_synced_at":"2026-02-26T09:30:17.601Z","repository":{"id":57214772,"uuid":"58208003","full_name":"ephys/dom-string-wrapper","owner":"ephys","description":"Wraps parts of a node's textContent with a DOM Range","archived":false,"fork":false,"pushed_at":"2016-05-06T13:30:55.000Z","size":5,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T21:16:21.174Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/ephys.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":"2016-05-06T13:08:30.000Z","updated_at":"2016-05-06T13:09:43.000Z","dependencies_parsed_at":"2022-08-26T13:41:14.018Z","dependency_job_id":null,"html_url":"https://github.com/ephys/dom-string-wrapper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ephys%2Fdom-string-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ephys%2Fdom-string-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ephys%2Fdom-string-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ephys%2Fdom-string-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ephys","download_url":"https://codeload.github.com/ephys/dom-string-wrapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239868779,"owners_count":19710478,"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-10-11T02:51:16.365Z","updated_at":"2026-02-26T09:30:17.569Z","avatar_url":"https://github.com/ephys.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dom-text-finder\n\nUtilitary functions to manipulate a DOM Node's textContent without damaging (reseting) its existing child nodes.\n\n## Installation\n\n`npm install --save dom-string-wrapper`\n\n## Usage\n\nThe package provides 2 functions: `wrapText` and `wrapTextAll`, the first one returns a [`Range`](https://developer.mozilla.org/en/docs/Web/API/Range), the second one returns an array of `Range`s. They allow you to create a range that will wrap a part of a node's textContent.\n\n```\n/* For instance, let's take the following node */\nvar pNode = document.createElement('p');\nvar pNode.innerHTML = '\u003cspan\u003eWell, \u003cstrong\u003eHello\u003c/strong\u003e world :)\u003c/span\u003e';\n\n/* and add an event listener to the span child. */\npNode.querySelector('strong').addEventListener('hover', doSomethingImportant);\n\n/* let's now say that we wish to wrap Hello World in a Anchor node, we could do the following: */\nvar pNode.innerHTML = '\u003cspan\u003eWell, \u003ca href=\"...\"\u003e\u003cstrong\u003eHello\u003c/strong\u003e world\u003c/a\u003e :)\u003c/span\u003e';\n\n/* But that would reset the whole content and we would lose the event listener we added on \u003cstrong\u003e.\n * That's where this module comes in. You can achieve the same goal without resetting anything. */\nvar wrapText = require('dom-string-wrapper').wrapText;\n\n// returns a range wrapping '\u003cstrong\u003eHello\u003c/strong\u003e world'\nvar range = wrapText(pNode, 'Hello world');\n\n/* You can then use the native range methods to manipulate the content. In this case, we need surroundContents. */\nvar aNode = document.createElement('a');\naNode.href = '...';\nrange.surroundContents(aNode);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fephys%2Fdom-string-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fephys%2Fdom-string-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fephys%2Fdom-string-wrapper/lists"}