{"id":15938726,"url":"https://github.com/ticky/hastml","last_synced_at":"2026-01-21T01:32:11.532Z","repository":{"id":40310577,"uuid":"104136826","full_name":"ticky/hastml","owner":"ticky","description":"🚶🏻‍♀️ Hasty HTML, XML and SGML walker","archived":false,"fork":false,"pushed_at":"2026-01-19T19:35:49.000Z","size":154,"stargazers_count":2,"open_issues_count":11,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2026-01-20T01:21:15.890Z","etag":null,"topics":["but-really-just-a-walker","html","quote-unquote-parser","sgml","xhtml","xml"],"latest_commit_sha":null,"homepage":"","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/ticky.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-09-19T22:41:32.000Z","updated_at":"2024-06-14T03:19:25.000Z","dependencies_parsed_at":"2024-12-21T23:23:00.096Z","dependency_job_id":"e7ef2406-2097-4075-8173-8491e6a6792a","html_url":"https://github.com/ticky/hastml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ticky/hastml","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ticky%2Fhastml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ticky%2Fhastml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ticky%2Fhastml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ticky%2Fhastml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ticky","download_url":"https://codeload.github.com/ticky/hastml/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ticky%2Fhastml/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28621627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T23:49:58.628Z","status":"ssl_error","status_checked_at":"2026-01-20T23:47:29.996Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["but-really-just-a-walker","html","quote-unquote-parser","sgml","xhtml","xml"],"created_at":"2024-10-07T05:41:31.992Z","updated_at":"2026-01-21T01:32:11.518Z","avatar_url":"https://github.com/ticky.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hasty HTML, XML and SGML walker\n[![npm](https://img.shields.io/npm/v/hastml.svg?maxAge=2592000)](https://www.npmjs.com/package/hastml) ![hastml](https://img.shields.io/npm/l/hastml.svg?maxAge=2592000) [![Build Status](https://travis-ci.org/ticky/hastml.svg?branch=develop)](https://travis-ci.org/ticky/hastml) [![codecov](https://codecov.io/gh/ticky/hastml/branch/develop/graph/badge.svg)](https://codecov.io/gh/ticky/hastml)\n\n🚶🏻‍♀️ A quick and _extremely_ permissive way to process XML-like inputs.\n\n## Installation\n\n```shell\nyarn add hastml\n```\n\n\\~_or_\\~\n\n```shell\nnpm install --save hastml\n```\n\n## API\n\n### `walk` (default)\n\nThe `walk` function accepts two arguments. The text, and a callback.\n\n```javascript\nimport walk from 'hastml';\n\nconst myHtml = '\u003ctitle\u003ehello!\u003c/title\u003e';\n\nconst callback = (match, tagFragment, offset, string, thisTag, stack) =\u003e {\n  console.log(tagFragment, offset);\n};\n\nconst output = walk(\n  myHtml,\n  callback\n);\n\n// Console output:\n//  =\u003e '\u003c', 0\n//  =\u003e '\u003e', 6\n//  =\u003e '\u003c/', 13\n//  =\u003e '\u003e', 20\n```\n\n#### Callback function\n\nThe callback function is passed six arguments denoting the state of the walker.\n\n- `match`: The text which will be replaced if the callback returns a string value.\n- `tagFragment`: The part of the HTML tag we're currently stepping over.\n  One of `\u003c`, `\u003e`, `\u003c/`, `/\u003e`, `\u003c!--` or `--\u003e`.\n- `offset`: Numeric index of the current match.\n- `string`: The full HTML string which is being walked over.\n- `thisTag`: An object representing the state of the current tag.\n- `stack`: Array representing the path to the current tag through the document's structure.\n\nIf the callback function returns a string value, that string will replace the value of `match` in the output from `walk`. Otherwise, no change is made.\n\n#### Tag objects\n\nTag objects contain data about tags being processed. What information they contain depends on where the walker is in relation to the tag it represents.\n\nIf the walker is at the start of the tag, for instance, it will only contain the `tagName`, `openIndex` and an `\"open\"` `state`. If the walker has reached the closing tag, it will contain more indexes, and have changed state.\n\nThe tag objects (passed to the callback function as `thisTag`, and within the `stack`) can contain the following information:\n\n- `tagName`: The tag name, i.e. `\u003chtml\u003e` would give `html`.\n- `state`: The current state of the tag.\n- `openIndex`: The index at which the tag was opened.\n- `contentIndex`: The index immediately before content of the tag begins. Not included for void elements.\n- `closingIndex`: The index where the closing part of the tag begins. Not included for void elements.\n- `closeIndex`: The index at which the tag was closed.\n\nThe indexes can be visualised as follows:\n\n```\nopenIndex       contentIndex     closeIndex\n    ↓                 ↓               ↓\n    \u003cspan class=\"text\"\u003eThis span\u003c/span\u003e\n                                ↑\n                          closingIndex\n\n    \u003cimg src=\"//plz-give.cat/random.jpg\" /\u003e\n    ↑                                     ↑\nopenIndex                           closeIndex\n```\n\n#### Tag object `state`\n\nThe `state` property of tag objects indicate where the walker is in relation to the tag. The following states are possible:\n\n- `\"open\"`: The opening part of the tag has been found.\n- `\"content\"`: The tag's content has been walked to.\n- `\"closing\"`: The closing part of the tag has been found.\n\nThese states can be visualised as follows:\n\n```\n\"open\"           \"content\"\n   ↓                 ↓\n   \u003cspan class=\"text\"\u003eThis span\u003c/span\u003e\n                               ↑\n                           \"closing\"\n\n   \u003cimg src=\"//plz-give.cat/random.jpg\" /\u003e\n   ↑\n\"open\"\n```\n\nNote that there is not currently a \"closed\" state indicating the tag has no further content or closing tag. This may be added in the future. A tag object with a populated `closeIndex` and `state` of either `\"open\"` or `\"content\"` indicates this state.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fticky%2Fhastml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fticky%2Fhastml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fticky%2Fhastml/lists"}