From 3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 Mon Sep 17 00:00:00 2001 From: Minteck Date: Thu, 23 Feb 2023 19:34:56 +0100 Subject: Updated 40 files, added 37 files, deleted 1103 files and renamed 3905 files (automated) --- .../string-strip-html/examples/_quickTake.js | 28 ---------- .../string-strip-html/examples/api.json | 1 - .../examples/cb-which-does-nothing.js | 33 ------------ .../examples/extract-html-head-contents.js | 42 --------------- .../string-strip-html/examples/inline-tags.js | 23 -------- .../string-strip-html/examples/leave-only-html.js | 24 --------- .../examples/leave-only-opening-td.js | 62 ---------------------- .../string-strip-html/examples/leave-only-td.js | 33 ------------ .../string-strip-html/examples/minimal-ranges.js | 33 ------------ .../string-strip-html/examples/remove-html.js | 18 ------- .../string-strip-html/examples/strip-from-json.js | 41 -------------- .../examples/title-case-with-tag-skipping.js | 54 ------------------- .../examples/widow-word-removal-from-html.js | 25 --------- 13 files changed, 417 deletions(-) delete mode 100644 school/node_modules/string-strip-html/examples/_quickTake.js delete mode 100644 school/node_modules/string-strip-html/examples/api.json delete mode 100644 school/node_modules/string-strip-html/examples/cb-which-does-nothing.js delete mode 100644 school/node_modules/string-strip-html/examples/extract-html-head-contents.js delete mode 100644 school/node_modules/string-strip-html/examples/inline-tags.js delete mode 100644 school/node_modules/string-strip-html/examples/leave-only-html.js delete mode 100644 school/node_modules/string-strip-html/examples/leave-only-opening-td.js delete mode 100644 school/node_modules/string-strip-html/examples/leave-only-td.js delete mode 100644 school/node_modules/string-strip-html/examples/minimal-ranges.js delete mode 100644 school/node_modules/string-strip-html/examples/remove-html.js delete mode 100644 school/node_modules/string-strip-html/examples/strip-from-json.js delete mode 100644 school/node_modules/string-strip-html/examples/title-case-with-tag-skipping.js delete mode 100644 school/node_modules/string-strip-html/examples/widow-word-removal-from-html.js (limited to 'school/node_modules/string-strip-html/examples') diff --git a/school/node_modules/string-strip-html/examples/_quickTake.js b/school/node_modules/string-strip-html/examples/_quickTake.js deleted file mode 100644 index 741f1ea..0000000 --- a/school/node_modules/string-strip-html/examples/_quickTake.js +++ /dev/null @@ -1,28 +0,0 @@ -// Quick Take - -import { strict as assert } from "assert"; -import { stripHtml } from "../dist/string-strip-html.esm.js"; - -assert.equal( - stripHtml(`Some text and text.`).result, - `Some text and text.` -); - -// prevents accidental string concatenation -assert.equal(stripHtml(`aaa
bbb
ccc`).result, `aaa bbb ccc`); - -// tag pairs with content, upon request -assert.equal( - stripHtml(`a
void a;
b`, { - stripTogetherWithTheirContents: [ - "script", // default - "style", // default - "xml", // default - "pre", // <-- custom-added - ], - }).result, - `a b` -); - -// detects raw, legit brackets: -assert.equal(stripHtml(`a < b and c > d`).result, `a < b and c > d`); diff --git a/school/node_modules/string-strip-html/examples/api.json b/school/node_modules/string-strip-html/examples/api.json deleted file mode 100644 index 28adb26..0000000 --- a/school/node_modules/string-strip-html/examples/api.json +++ /dev/null @@ -1 +0,0 @@ -{"_quickTake.js":{"title":"Quick Take","content":"import { strict as assert } from \"assert\";\nimport { stripHtml } from \"string-strip-html\";\n\nassert.equal(\n stripHtml(`Some text and text.`).result,\n `Some text and text.`\n);\n\n// prevents accidental string concatenation\nassert.equal(stripHtml(`aaa
bbb
ccc`).result, `aaa bbb ccc`);\n\n// tag pairs with content, upon request\nassert.equal(\n stripHtml(`a
void a;
b`, {\n stripTogetherWithTheirContents: [\n \"script\", // default\n \"style\", // default\n \"xml\", // default\n \"pre\", // <-- custom-added\n ],\n }).result,\n `a b`\n);\n\n// detects raw, legit brackets:\nassert.equal(stripHtml(`a < b and c > d`).result, `a < b and c > d`);"},"cb-which-does-nothing.js":{"title":"A Bypass Callback and a Do-Nothing Callback","content":"import { strict as assert } from \"assert\";\nimport { stripHtml } from \"string-strip-html\";\n\n// this callback just pushes proposed result to \"rangesArr\",\n// that's what gets used in the result calculation:\nconst cb1 = ({\n tag,\n deleteFrom,\n deleteTo,\n insert,\n rangesArr,\n proposedReturn,\n}) => {\n rangesArr.push(deleteFrom, deleteTo, insert);\n};\nconst result1 = stripHtml(\"abc
def\", { cb: cb1 }).result;\nassert.equal(result1, `abc def`);\n\n// to prove it works, don't do anything:\nconst cb2 = ({\n tag,\n deleteFrom,\n deleteTo,\n insert,\n rangesArr,\n proposedReturn,\n}) => {\n // nothing here πŸ™ˆ\n};\nconst result2 = stripHtml(\"abc
def\", { cb: cb2 }).result;\nassert.equal(result2, \"abc
def\");"},"extract-html-head-contents.js":{"title":"Extract HTML `` contents","content":"import { strict as assert } from \"assert\";\nimport { stripHtml } from \"string-strip-html\";\n\nconst someHtml = `\n\n \n \n the title\n \n \n the content\n \n`;\n\n// The task asks not to include and .\n// First, extract head tag-to-head tag, including contents\nconst headWithHeadTags = stripHtml(someHtml, {\n onlyStripTags: [\"head\"],\n stripTogetherWithTheirContents: [\"head\"],\n})\n .filteredTagLocations.reduce(\n (acc, [from, to]) => `${acc}${someHtml.slice(from, to)}`,\n \"\"\n )\n .trim();\n\nassert.equal(\n headWithHeadTags,\n `\n \n the title\n `\n);\n\nconst headContents = headWithHeadTags.replace(/<\\/?head>/g, \"\").trim();\nassert.equal(\n headContents,\n `\n the title`\n);"},"inline-tags.js":{"title":"Just deletes inline tags","content":"import { strict as assert } from \"assert\";\nimport { stripHtml } from \"string-strip-html\";\n\nconst someHtml = `This has an unbold word.`;\n\n// default behaviour:\nassert.equal(stripHtml(someHtml).result, `This has an un bold word.`);\n\n// let's tackle inline tags:\nassert.equal(\n stripHtml(someHtml, {\n cb: ({ tag, deleteFrom, deleteTo, insert, rangesArr }) => {\n if ([\"b\", \"strong\"].includes(tag.name)) {\n rangesArr.push(tag.lastOpeningBracketAt, tag.lastClosingBracketAt + 1);\n } else {\n rangesArr.push(deleteFrom, deleteTo, insert);\n }\n },\n }).result,\n `This has an unbold word.`\n);"},"leave-only-html.js":{"title":"Leave only HTML","content":"import { strict as assert } from \"assert\";\nimport { stripHtml } from \"string-strip-html\";\n\nconst someHtml = `\n\n \n \n \n \n \n

Title

\n Some text.\n \n`;\n\nassert.equal(\n stripHtml(someHtml).allTagLocations.reduce(\n (acc, [from, to]) => `${acc}${someHtml.slice(from, to)}`,\n \"\"\n ),\n `

`\n);"},"leave-only-opening-td.js":{"title":"Leave only opening `td` tags","content":"import { strict as assert } from \"assert\";\nimport { stripHtml } from \"string-strip-html\";\n\nconst someHtml = `\n \n \n \n \n \n \n \n \n
\n cell1\n \n cell2\n
\n cell3\n \n cell4\n
`;\n\n// the first way\n// -----------------------------------------------------------------------------\n\nassert.equal(\n stripHtml(someHtml, {\n // notice there's no: onlyStripTags: [\"td\"]\n // we operate purely via callback\n cb: ({ tag, deleteFrom, deleteTo, insert, rangesArr, proposedReturn }) => {\n if (tag.name === \"td\" && !tag.slashPresent) {\n rangesArr.push(proposedReturn);\n }\n },\n }).ranges.reduce(\n (acc, [from, to]) => `${acc}${someHtml.slice(from, to).trim()}`,\n \"\"\n ),\n ``\n);\n\n// the second way:\n// -----------------------------------------------------------------------------\n\nlet resultStr = \"\";\n// notice we don't even assign stripHtml() output to anything - we rely only\n// on the callback, it mutates the \"resultStr\" in the upper scope\nstripHtml(someHtml, {\n // notice there's no: onlyStripTags: [\"td\"]\n // we operate purely via callback\n cb: ({ tag, deleteFrom, deleteTo, insert, rangesArr, proposedReturn }) => {\n if (tag.name === \"td\" && !tag.slashPresent) {\n resultStr += someHtml.slice(deleteFrom, deleteTo).trim();\n }\n },\n});\nassert.equal(\n resultStr,\n ``\n);"},"leave-only-td.js":{"title":"Leave only `td` tags","content":"import { strict as assert } from \"assert\";\nimport { stripHtml } from \"string-strip-html\";\n\nconst someHtml = `\n \n \n \n \n \n \n \n \n
\n cell1\n \n cell2\n
\n cell3\n \n cell4\n
`;\n\nassert.equal(\n stripHtml(someHtml, {\n onlyStripTags: [\"td\"],\n }).filteredTagLocations.reduce(\n (acc, [from, to]) => `${acc}${someHtml.slice(from, to)}`,\n \"\"\n ),\n ``\n);"},"minimal-ranges.js":{"title":"Minimal example using Ranges","content":"// We strip tags and fix apostrophes\n// that's part of what https://codsen.com/os/detergent/ does\n\nimport { strict as assert } from \"assert\";\nimport { rApply } from \"ranges-apply\";\nimport { stripHtml } from \"string-strip-html\";\nimport { convertAll } from \"string-apostrophes\";\n\nfunction stripAndFixApos(str) {\n if (!str || typeof str !== \"string\") {\n return \"\";\n }\n // Keep in mind, Ranges are array of 2-3 element arrays.\n // But absent Ranges are marked as null, not empty array.\n // It's so that we could test in \"if-else\" easily - null\n // is falsy but empty array is truthy.\n // That's why below we take precautions with \"|| []\".\n return rApply(\n str,\n (stripHtml(str).ranges || []).concat(convertAll(str).ranges || [])\n );\n}\n\n// strips tags and fixes apostrophes:\nassert.equal(\n stripAndFixApos(`Let's Go Larval`),\n `Let’s Go Larval`\n);\n\n// no tags, no apostrophes:\nassert.equal(stripAndFixApos(`zzz`), `zzz`);"},"remove-html.js":{"title":"Remove all HTML from a string","content":"import { strict as assert } from \"assert\";\nimport { stripHtml } from \"string-strip-html\";\n\nconst someHtml = `\n\n \n \n \n \n \n

Title

\n Some text.\n \n`;\n\nassert.equal(stripHtml(someHtml).result, `Title\\nSome text.`);"},"strip-from-json.js":{"title":"Strip HTML from a raw JSON string","content":"import { strict as assert } from \"assert\";\nimport { stripHtml } from \"string-strip-html\";\nimport { traverse } from \"ast-monkey-traverse\";\n\nconst stripFromJsonStr = (str) => {\n return traverse(JSON.parse(str), (key, val) => {\n // if currently an object is traversed, you get both \"key\" and \"val\"\n // if it's array, only \"key\" is present, \"val\" is undefined\n const current = val !== undefined ? val : key;\n if (\n // ensure it's a plain object, not array (monkey will report only \"key\" in\n // arrays and \"val\" will be undefined)\n // also ensure object's value a string, not boolean or number, because we\n // don't strip HTML from booleans or numbers or anything else than strings\n typeof val === \"string\"\n ) {\n // monkey's callback is like Array.map - whatever you return gets written:\n return stripHtml(val).result;\n }\n // default return, do nothing:\n return current;\n });\n};\n\n// nothing to strip, \"<\" is false alarm:\nassert.equal(\n JSON.stringify(stripFromJsonStr(`{\"Operator\":\"<\",\"IsValid\":true}`), null, 0),\n `{\"Operator\":\"<\",\"IsValid\":true}`\n);\n\n// some HTML within one of key values, monkey will skip the boolean:\nassert.equal(\n JSON.stringify(\n stripFromJsonStr(`{\"Operator\":\"a
b
c\",\"IsValid\":true}`),\n null,\n 0\n ),\n `{\"Operator\":\"a b c\",\"IsValid\":true}`\n);"},"title-case-with-tag-skipping.js":{"title":"Set the title case using `title` package","content":"// This program will not touch any single tags (
for example)\n// or in case of paired tags, paired tags and content between\n\nimport { strict as assert } from \"assert\";\nimport title from \"title\";\nimport { rInvert } from \"ranges-invert\";\nimport { rApply } from \"ranges-apply\";\nimport { rRegex } from \"ranges-regex\";\nimport { stripHtml } from \"string-strip-html\";\n\nfunction tagAwareTitle(str) {\n const whitelist = [\"eslint\", \"readme\", \"npm\"];\n const { filteredTagLocations } = stripHtml(str, {\n stripTogetherWithTheirContents: [\"*\"],\n });\n const inverted = rInvert(\n filteredTagLocations.concat(\n whitelist.reduce((acc, curr) => {\n const rangesFindings = rRegex(new RegExp(curr, \"gi\"), str);\n if (rangesFindings) {\n return acc.concat(rangesFindings);\n }\n return acc;\n }, [])\n ),\n str.length\n );\n\n if (Array.isArray(inverted) && inverted.length) {\n // take inverted ranges, for example, [[3, 4], [10, 15]]\n // and add third element, replacement, which is same character\n // indexes only processed through \"title\":\n return rApply(\n str,\n inverted.map(([from, to]) => [from, to, title(str.slice(from, to))])\n );\n }\n // otherwise, just apply title() on the whole string:\n return title(str);\n}\n\n// middle:\nassert.equal(\n tagAwareTitle(`This is a title with some code in it`),\n `This Is a Title with Some code In It`\n);\n\n// leading:\nassert.equal(\n tagAwareTitle(`abc defgh ESLint`),\n `abc Defgh ESLint`\n);"},"widow-word-removal-from-html.js":{"title":"Widow word removal from text within HTML","content":"import { strict as assert } from \"assert\";\nimport { stripHtml } from \"string-strip-html\";\nimport { removeWidows } from \"string-remove-widows\";\n\nconst someHtml = `The quick brown fox jumps of the lazy dog.
`;\n\n// default widow word removal libs are not aware of HTML:\n// -----------------------------------------------------------------------------\n\nassert.equal(\n removeWidows(someHtml).res,\n `The quick brown fox jumps of the lazy dog.` // 😱\n);\n\n// luckily, removeWidows() consumes optional HTML tag locations\nassert.equal(\n removeWidows(someHtml, {\n tagRanges: stripHtml(someHtml)\n // remove the third argument, what to insert (\" \" string in these cases)\n .ranges.map(([from, to]) => [from, to]),\n }).res,\n `The quick brown fox jumps of the lazy dog.
` // βœ…\n);"}} \ No newline at end of file diff --git a/school/node_modules/string-strip-html/examples/cb-which-does-nothing.js b/school/node_modules/string-strip-html/examples/cb-which-does-nothing.js deleted file mode 100644 index 2145c46..0000000 --- a/school/node_modules/string-strip-html/examples/cb-which-does-nothing.js +++ /dev/null @@ -1,33 +0,0 @@ -// A Bypass Callback and a Do-Nothing Callback - -import { strict as assert } from "assert"; -import { stripHtml } from "../dist/string-strip-html.esm.js"; - -// this callback just pushes proposed result to "rangesArr", -// that's what gets used in the result calculation: -const cb1 = ({ - tag, - deleteFrom, - deleteTo, - insert, - rangesArr, - proposedReturn, -}) => { - rangesArr.push(deleteFrom, deleteTo, insert); -}; -const result1 = stripHtml("abc
def", { cb: cb1 }).result; -assert.equal(result1, `abc def`); - -// to prove it works, don't do anything: -const cb2 = ({ - tag, - deleteFrom, - deleteTo, - insert, - rangesArr, - proposedReturn, -}) => { - // nothing here πŸ™ˆ -}; -const result2 = stripHtml("abc
def", { cb: cb2 }).result; -assert.equal(result2, "abc
def"); diff --git a/school/node_modules/string-strip-html/examples/extract-html-head-contents.js b/school/node_modules/string-strip-html/examples/extract-html-head-contents.js deleted file mode 100644 index 5c09d52..0000000 --- a/school/node_modules/string-strip-html/examples/extract-html-head-contents.js +++ /dev/null @@ -1,42 +0,0 @@ -// 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` -); diff --git a/school/node_modules/string-strip-html/examples/inline-tags.js b/school/node_modules/string-strip-html/examples/inline-tags.js deleted file mode 100644 index 622999a..0000000 --- a/school/node_modules/string-strip-html/examples/inline-tags.js +++ /dev/null @@ -1,23 +0,0 @@ -// Just deletes inline tags - -import { strict as assert } from "assert"; -import { stripHtml } from "../dist/string-strip-html.esm.js"; - -const someHtml = `This has an unbold word.`; - -// default behaviour: -assert.equal(stripHtml(someHtml).result, `This has an un bold word.`); - -// let's tackle inline tags: -assert.equal( - stripHtml(someHtml, { - cb: ({ tag, deleteFrom, deleteTo, insert, rangesArr }) => { - if (["b", "strong"].includes(tag.name)) { - rangesArr.push(tag.lastOpeningBracketAt, tag.lastClosingBracketAt + 1); - } else { - rangesArr.push(deleteFrom, deleteTo, insert); - } - }, - }).result, - `This has an unbold word.` -); diff --git a/school/node_modules/string-strip-html/examples/leave-only-html.js b/school/node_modules/string-strip-html/examples/leave-only-html.js deleted file mode 100644 index 93e21a8..0000000 --- a/school/node_modules/string-strip-html/examples/leave-only-html.js +++ /dev/null @@ -1,24 +0,0 @@ -// Leave only HTML - -import { strict as assert } from "assert"; -import { stripHtml } from "../dist/string-strip-html.esm.js"; - -const someHtml = ` - - - - - - -

Title

- Some text. - -`; - -assert.equal( - stripHtml(someHtml).allTagLocations.reduce( - (acc, [from, to]) => `${acc}${someHtml.slice(from, to)}`, - "" - ), - `

` -); diff --git a/school/node_modules/string-strip-html/examples/leave-only-opening-td.js b/school/node_modules/string-strip-html/examples/leave-only-opening-td.js deleted file mode 100644 index e8ba37f..0000000 --- a/school/node_modules/string-strip-html/examples/leave-only-opening-td.js +++ /dev/null @@ -1,62 +0,0 @@ -// Leave only opening `td` tags - -import { strict as assert } from "assert"; -import { stripHtml } from "../dist/string-strip-html.esm.js"; - -const someHtml = ` - - - - - - - - -
- cell1 - - cell2 -
- cell3 - - cell4 -
`; - -// the first way -// ----------------------------------------------------------------------------- - -assert.equal( - stripHtml(someHtml, { - // notice there's no: onlyStripTags: ["td"] - // we operate purely via callback - cb: ({ tag, deleteFrom, deleteTo, insert, rangesArr, proposedReturn }) => { - if (tag.name === "td" && !tag.slashPresent) { - rangesArr.push(proposedReturn); - } - }, - }).ranges.reduce( - (acc, [from, to]) => `${acc}${someHtml.slice(from, to).trim()}`, - "" - ), - `` -); - -// the second way: -// ----------------------------------------------------------------------------- - -let resultStr = ""; -// notice we don't even assign stripHtml() output to anything - we rely only -// on the callback, it mutates the "resultStr" in the upper scope -stripHtml(someHtml, { - // notice there's no: onlyStripTags: ["td"] - // we operate purely via callback - cb: ({ tag, deleteFrom, deleteTo, insert, rangesArr, proposedReturn }) => { - if (tag.name === "td" && !tag.slashPresent) { - resultStr += someHtml.slice(deleteFrom, deleteTo).trim(); - } - }, -}); -assert.equal( - resultStr, - `` -); diff --git a/school/node_modules/string-strip-html/examples/leave-only-td.js b/school/node_modules/string-strip-html/examples/leave-only-td.js deleted file mode 100644 index af0b2cd..0000000 --- a/school/node_modules/string-strip-html/examples/leave-only-td.js +++ /dev/null @@ -1,33 +0,0 @@ -// Leave only `td` tags - -import { strict as assert } from "assert"; -import { stripHtml } from "../dist/string-strip-html.esm.js"; - -const someHtml = ` - - - - - - - - -
- cell1 - - cell2 -
- cell3 - - cell4 -
`; - -assert.equal( - stripHtml(someHtml, { - onlyStripTags: ["td"], - }).filteredTagLocations.reduce( - (acc, [from, to]) => `${acc}${someHtml.slice(from, to)}`, - "" - ), - `` -); diff --git a/school/node_modules/string-strip-html/examples/minimal-ranges.js b/school/node_modules/string-strip-html/examples/minimal-ranges.js deleted file mode 100644 index 91dcbf7..0000000 --- a/school/node_modules/string-strip-html/examples/minimal-ranges.js +++ /dev/null @@ -1,33 +0,0 @@ -// Minimal example using Ranges - -// We strip tags and fix apostrophes -// that's part of what https://codsen.com/os/detergent/ does - -import { strict as assert } from "assert"; -import { rApply } from "../../ranges-apply"; -import { stripHtml } from "../dist/string-strip-html.esm.js"; -import { convertAll } from "../../string-apostrophes"; - -function stripAndFixApos(str) { - if (!str || typeof str !== "string") { - return ""; - } - // Keep in mind, Ranges are array of 2-3 element arrays. - // But absent Ranges are marked as null, not empty array. - // It's so that we could test in "if-else" easily - null - // is falsy but empty array is truthy. - // That's why below we take precautions with "|| []". - return rApply( - str, - (stripHtml(str).ranges || []).concat(convertAll(str).ranges || []) - ); -} - -// strips tags and fixes apostrophes: -assert.equal( - stripAndFixApos(`Let's Go Larval`), - `Let’s Go Larval` -); - -// no tags, no apostrophes: -assert.equal(stripAndFixApos(`zzz`), `zzz`); diff --git a/school/node_modules/string-strip-html/examples/remove-html.js b/school/node_modules/string-strip-html/examples/remove-html.js deleted file mode 100644 index b45894e..0000000 --- a/school/node_modules/string-strip-html/examples/remove-html.js +++ /dev/null @@ -1,18 +0,0 @@ -// Remove all HTML from a string - -import { strict as assert } from "assert"; -import { stripHtml } from "../dist/string-strip-html.esm.js"; - -const someHtml = ` - - - - - - -

Title

- Some text. - -`; - -assert.equal(stripHtml(someHtml).result, `Title\nSome text.`); diff --git a/school/node_modules/string-strip-html/examples/strip-from-json.js b/school/node_modules/string-strip-html/examples/strip-from-json.js deleted file mode 100644 index 95d8bd0..0000000 --- a/school/node_modules/string-strip-html/examples/strip-from-json.js +++ /dev/null @@ -1,41 +0,0 @@ -// Strip HTML from a raw JSON string - -import { strict as assert } from "assert"; -import { stripHtml } from "../dist/string-strip-html.esm.js"; -import { traverse } from "../../ast-monkey-traverse"; - -const stripFromJsonStr = (str) => { - return traverse(JSON.parse(str), (key, val) => { - // if currently an object is traversed, you get both "key" and "val" - // if it's array, only "key" is present, "val" is undefined - const current = val !== undefined ? val : key; - if ( - // ensure it's a plain object, not array (monkey will report only "key" in - // arrays and "val" will be undefined) - // also ensure object's value a string, not boolean or number, because we - // don't strip HTML from booleans or numbers or anything else than strings - typeof val === "string" - ) { - // monkey's callback is like Array.map - whatever you return gets written: - return stripHtml(val).result; - } - // default return, do nothing: - return current; - }); -}; - -// nothing to strip, "<" is false alarm: -assert.equal( - JSON.stringify(stripFromJsonStr(`{"Operator":"<","IsValid":true}`), null, 0), - `{"Operator":"<","IsValid":true}` -); - -// some HTML within one of key values, monkey will skip the boolean: -assert.equal( - JSON.stringify( - stripFromJsonStr(`{"Operator":"a
b
c","IsValid":true}`), - null, - 0 - ), - `{"Operator":"a b c","IsValid":true}` -); diff --git a/school/node_modules/string-strip-html/examples/title-case-with-tag-skipping.js b/school/node_modules/string-strip-html/examples/title-case-with-tag-skipping.js deleted file mode 100644 index c248346..0000000 --- a/school/node_modules/string-strip-html/examples/title-case-with-tag-skipping.js +++ /dev/null @@ -1,54 +0,0 @@ -// Set the title case using `title` package - -// This program will not touch any single tags (
for example) -// or in case of paired tags, paired tags and content between - -import { strict as assert } from "assert"; -import title from "title"; -import { rInvert } from "../../ranges-invert"; -import { rApply } from "../../ranges-apply"; -import { rRegex } from "../../ranges-regex"; -import { stripHtml } from "../dist/string-strip-html.esm.js"; - -function tagAwareTitle(str) { - const whitelist = ["eslint", "readme", "npm"]; - const { filteredTagLocations } = stripHtml(str, { - stripTogetherWithTheirContents: ["*"], - }); - const inverted = rInvert( - filteredTagLocations.concat( - whitelist.reduce((acc, curr) => { - const rangesFindings = rRegex(new RegExp(curr, "gi"), str); - if (rangesFindings) { - return acc.concat(rangesFindings); - } - return acc; - }, []) - ), - str.length - ); - - if (Array.isArray(inverted) && inverted.length) { - // take inverted ranges, for example, [[3, 4], [10, 15]] - // and add third element, replacement, which is same character - // indexes only processed through "title": - return rApply( - str, - inverted.map(([from, to]) => [from, to, title(str.slice(from, to))]) - ); - } - // otherwise, just apply title() on the whole string: - return title(str); -} - -// middle: -assert.equal( - tagAwareTitle(`This is a title with some code in it`), - `This Is a Title with Some code In It` -); - -// leading: -assert.equal( - tagAwareTitle(`abc defgh ESLint`), - `abc Defgh ESLint` -); diff --git a/school/node_modules/string-strip-html/examples/widow-word-removal-from-html.js b/school/node_modules/string-strip-html/examples/widow-word-removal-from-html.js deleted file mode 100644 index bcc07b1..0000000 --- a/school/node_modules/string-strip-html/examples/widow-word-removal-from-html.js +++ /dev/null @@ -1,25 +0,0 @@ -// Widow word removal from text within HTML - -import { strict as assert } from "assert"; -import { stripHtml } from "../dist/string-strip-html.esm.js"; -import { removeWidows } from "../../string-remove-widows"; - -const someHtml = `The quick brown fox jumps of the lazy dog.
`; - -// default widow word removal libs are not aware of HTML: -// ----------------------------------------------------------------------------- - -assert.equal( - removeWidows(someHtml).res, - `The quick brown fox jumps of the lazy dog.` // 😱 -); - -// luckily, removeWidows() consumes optional HTML tag locations -assert.equal( - removeWidows(someHtml, { - tagRanges: stripHtml(someHtml) - // remove the third argument, what to insert (" " string in these cases) - .ranges.map(([from, to]) => [from, to]), - }).res, - `The quick brown fox jumps of the lazy dog.
` // βœ… -); -- cgit