// Extract HTML `` contents import { strict as assert } from "assert"; import { stripHtml } from "../dist/string-strip-html.esm.js"; const someHtml = ` the title the content `; // The task asks not to include and . // First, extract head tag-to-head tag, including contents const headWithHeadTags = stripHtml(someHtml, { onlyStripTags: ["head"], stripTogetherWithTheirContents: ["head"], }) .filteredTagLocations.reduce( (acc, [from, to]) => `${acc}${someHtml.slice(from, to)}`, "" ) .trim(); assert.equal( headWithHeadTags, ` the title ` ); const headContents = headWithHeadTags.replace(/<\/?head>/g, "").trim(); assert.equal( headContents, ` the title` );