charcode-is-valid-xml-name-character

Does a given character belong to XML spec's "Production 4 OR 4a" type (is acceptable for XML element's name)

Usage no npm install needed!

<script type="module">
  import charcodeIsValidXmlNameCharacter from 'https://cdn.skypack.dev/charcode-is-valid-xml-name-character';
</script>

README

charcode-is-valid-xml-name-character

Does a given character belong to XML spec's "Production 4 OR 4a" type (is acceptable for XML element's name)

Install

The latest version is ESM only: Node 12+ is needed to use it and it must be imported instead of required. If your project is not on ESM yet and you want to use require, use an older version of this program, 1.13.0.

npm i charcode-is-valid-xml-name-character

Quick Take

import { strict as assert } from "assert";

import {
  isProduction4,
  isProduction4a,
  validFirstChar,
  validSecondCharOnwards,
} from "charcode-is-valid-xml-name-character";

// Spec: https://www.w3.org/TR/REC-xml/#NT-NameStartChar

assert.equal(isProduction4("Z"), true);
assert.equal(isProduction4("?"), false);

assert.equal(isProduction4a("?"), false);
assert.equal(isProduction4a("-"), true);

assert.equal(validFirstChar("a"), true);
assert.equal(validFirstChar("1"), false);

assert.equal(validSecondCharOnwards("a"), true);
assert.equal(validSecondCharOnwards("?"), false);

Documentation

Please visit codsen.com for a full description of the API.

Contributing

To report bugs or request features or assistance, raise an issue on GitHub.

Licence

MIT License

Copyright (c) 2010-2022 Roy Revelt and other contributors

ok codsen star