regex-empty-conditional-comments1.8.63

Regular expression for matching HTML empty conditional comments

§ Quick Take

import { strict as assert } from "assert";
import emptyCondCommentRegex from "regex-empty-conditional-comments";

// empty comment which was meant to target Outlook-only
assert.equal(
  emptyCondCommentRegex().test(`<!--[if !mso]>
<![endif]-->`),
  true
);

// empty comment which was meant to target non-Outlook-only
assert.equal(
  emptyCondCommentRegex().test(`<!--[if !mso]><!-- -->
<!--<![endif]-->`),
  true
);

assert.equal(
  emptyCondCommentRegex().test(`<!--[if !mso]><!-- -->
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<!--<![endif]-->`),
  false
);

assert.equal(
  emptyCondCommentRegex()
    .test(`<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml><![endif]-->`),
  false
);

assert.equal(
  emptyCondCommentRegex().exec(
    "<html><!--[if !mso]><![endif]--><title>"
  )[0],
  "<!--[if !mso]><![endif]-->"
);

assert.deepEqual(
  `<html> <!--[if !mso]><![endif]--> <title>text</title> <!--[if gte mso 9]>
<xml>
<![endif]-->`.match(emptyCondCommentRegex()),
  ["<!--[if !mso]><![endif]-->"]
);

§ API

emptyCondCommentRegex()

In other words, it's a function which returns a RegExp object.

§ Licence

MITopens in a new tab

Copyright © 2010–2020 Roy Revelt and other contributors

Related packages:

📦 arrayiffy-if-string 3.11.38
Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else.
📦 array-of-arrays-into-ast 1.9.50
turns an array of arrays of data into a nested tree of plain objects
📦 array-includes-with-glob 2.12.42
like _.includes but with wildcards
📦 array-pull-all-with-glob 4.12.72
pullAllWithGlob - like _.pullAll but pulling stronger, with globs
📦 array-of-arrays-sort-by-col 2.12.13
sort array of arrays by column, rippling the sorting outwards from that column
📦 all-named-html-entities 1.3.7
List of all named HTML entities
📦 array-group-str-omit-num-char 2.1.48
Groups array of strings by omitting number characters