tag-sieve
v0.1.0
Published
Extract text inside a target tag from streamed text chunks.
Maintainers
Readme
tag-sieve
Extract text inside a target tag from streamed text chunks.
tag-sieve is a tiny TypeScript library for cases where text arrives incrementally and you only want the content inside one exact XML-like tag, such as <Interviewer>...</Interviewer>.
Installation
npm install tag-sieveUsage
import { TagSieve } from "tag-sieve";
const sieve = new TagSieve("Interviewer");
sieve.write("ignored <Inter");
sieve.write("viewer>Hello");
const chunk = sieve.write(" world</Interviewer> ignored");
console.log(chunk); // " world"
const result = sieve.conclude();
console.log(result.input); // "ignored <Interviewer>Hello world</Interviewer> ignored"
console.log(result.output); // "Hello world"API
new TagSieve(tag)
Creates a streaming extractor for one exact tag name.
const sieve = new TagSieve("Interviewer");Valid tag names must start with a letter and contain only letters, numbers, underscores, or hyphens.
sieve.write(chunk)
Adds a text chunk and returns only the newly extracted text found inside the target tag.
const emitted = sieve.write("<Interviewer>Hello</Interviewer>");
// "Hello"sieve.conclude()
Finishes the current stream and returns the complete original input and complete extracted output.
const result = sieve.conclude();
// { input: string, output: string }sieve.reset()
Clears internal state so the same instance can be reused.
createTagSieve(tag)
Factory equivalent to new TagSieve(tag).
extractTagText(input, tag)
Convenience helper for non-streaming input.
import { extractTagText } from "tag-sieve";
const result = extractTagText("<Interviewer>Hello</Interviewer>", "Interviewer");
// { input: "<Interviewer>Hello</Interviewer>", output: "Hello" }Scope
This library intentionally starts small:
- Supports exact tags like
<Interviewer>and</Interviewer>. - Supports tags split across chunks.
- Supports multiple occurrences of the same tag.
- Does not parse HTML/XML attributes.
- Does not implement nested tag semantics.
Development
npm install
npm run checkPublishing
This package is configured for npm Trusted Publishing from GitHub Actions.
Recommended release flow:
npm version patch
git push --follow-tagsThen create a GitHub Release for the tag. The publish workflow runs npm publish --access public with npm Trusted Publishing and automatic provenance.
License
MIT
