all-named-html-entities examples

Table of Contents

Quick Take

import { strict as assert } from "assert";
import {
  allNamedEntities,
  allNamedEntitiesSetOnly,
  allNamedEntitiesSetOnlyCaseInsensitive,
  entStartsWith,
  entEndsWith,
  entStartsWithCaseInsensitive,
  entEndsWithCaseInsensitive,
  brokenNamedEntities,
  decode,
  minLength,
  maxLength,
  uncertain,
} from "all-named-html-entities";

assert.equal(
  Object.keys(allNamedEntities).length,
  2125
);
assert.equal(entStartsWith.A.E[0], "AElig");

allNamedEntities

import { strict as assert } from "assert";
import { allNamedEntities } from "all-named-html-entities";

// total named entities count:
assert.equal(
  Object.keys(allNamedEntities).length,
  2125
);

// show the first-one:
assert.equal(
  Object.keys(allNamedEntities).sort()[0],
  "AElig"
);

// Æ decoded:
assert.equal(allNamedEntities.AElig, "Æ");

entEndsWith

import { strict as assert } from "assert";
import { entEndsWith } from "all-named-html-entities";

// here's list of named HTML entities which end with character "2":
assert.deepEqual(entEndsWith["2"], {
  1: ["blk12", "frac12"],
  p: ["sup2"],
});

// query directly
assert.equal(entEndsWith["2"].p[0], "sup2");

entStartsWith

import { strict as assert } from "assert";
import { entStartsWith } from "all-named-html-entities";

// for perf reasons, they're pre-grouped by first two letters
assert.deepEqual(entStartsWith.A, {
  a: ["Aacute"],
  b: ["Abreve"],
  c: ["Acirc", "Acy"],
  E: ["AElig"],
  f: ["Afr"],
  g: ["Agrave"],
  l: ["Alpha"],
  m: ["Amacr"],
  M: ["AMP"],
  n: ["And"],
  o: ["Aogon", "Aopf"],
  p: ["ApplyFunction"],
  r: ["Aring"],
  s: ["Ascr", "Assign"],
  t: ["Atilde"],
  u: ["Auml"],
});

// query directly
assert.equal(entStartsWith.A.E[0], "AElig");

entStartsWithCaseInsensitive

import { strict as assert } from "assert";
import { entStartsWithCaseInsensitive } from "all-named-html-entities";

// case-insensitive "entStartsWithCaseInsensitive" is useful
// when looking for possibly mis-typed entities; emlint uses it

// which entities, lowercased, start with "j"?
assert.deepEqual(entStartsWithCaseInsensitive.j, {
  c: ["jcirc", "jcy"],
  f: ["jfr"],
  m: ["jmath"],
  o: ["jopf"],
  s: ["jscr", "jsercy"],
  u: ["jukcy"],
});