mark utility to handle character codes.
- What is this?
- When should I use this?
- Install
- Use
- API
asciiAlpha(code)asciiAlphanumeric(code)asciiAtext(code)asciiControl(code)asciiDigit(code)asciiHexDigit(code)asciiPunctuation(code)checker(test)eos(code)htab(code)idContinue(code)idStart(code)isCode(value)lineEndingOrWhitespace(code)lineEnding(code)space(code)streamBreak(code)unicodePunctuation(code)unicodeWhitespace(code)vtab(code)whitespace(code)
- Types
- Project
- Related
This package exposes algorithms for checking whether character codes match certain groups.
This package is useful when creating your own your own mark extensions and utilities.
This package is ESM only.
In Node.js with yarn:
yarn add @flex-development/mark-util-characterSee Git - Protocols | Yarn for details regarding installing from Git.
In Deno with esm.sh:
import { asciiAlpha } from 'https://esm.sh/@flex-development/mark-util-character'In browsers with esm.sh:
<script type="module">
import { asciiAlpha } from 'https://esm.sh/@flex-development/mark-util-character'
</script>import { asciiAlpha, streamBreak } from '@flex-development/mark-util-character'
import { codes } from '@flex-development/mark-util-symbol'
console.dir(asciiAlpha(codes.atSign)) // false
console.dir(asciiAlpha(codes.uppercaseA)) // true
console.dir(streamBreak(codes.eos)) // false
console.dir(streamBreak(codes.break)) // trueThis package exports the following identifiers:
asciiAlphaasciiAlphanumericasciiAtextasciiControlasciiDigitasciiHexDigitasciiPunctuationcheckereoshtabidContinueidStartisCodelineEndingOrWhitespacelineEndingspacestreamBreakunicodePunctuationunicodeWhitespacevtabwhitespace
There is no default export.
Check whether a character code represents an ASCII alpha (a through z, case insensitive).
An ASCII alpha is an ASCII upper alpha or ASCII lower alpha.
An ASCII upper alpha is a character in the inclusive range U+0041 (A) to U+005A (Z).
An ASCII lower alpha is a character in the inclusive range U+0061 (a) to U+007A (z).
code(Code) — the character code to check
(boolean) Whether the character code matches
Check whether a character code represents an ASCII alphanumeric (a through z, case insensitive, or 0 through 9).
An ASCII alphanumeric is an ASCII digit (see asciiDigit)
or ASCII alpha (see asciiAlpha).
code(Code) — the character code to check
(boolean) Whether the character code matches
Check whether a character code represents an ASCII atext.
atext is an ASCII alphanumeric (see asciiAlphanumeric),
or a character in the following inclusive ranges:
U+0023NUMBER SIGN (#) toU+0027APOSTROPHE (')U+002AASTERISK (*)U+002BPLUS SIGN (+)U+002DDASH (-)U+002FSLASH (/)U+003DEQUALS TO (=)U+003FQUESTION MARK (?)U+005ECARET (^) toU+0060GRAVE ACCENT (`)U+007BLEFT CURLY BRACE ({) toU+007ETILDE (~)
See https://tools.ietf.org/html/rfc5322 for more info.
code(Code) — the character code to check
(boolean) Whether the character code matches
Check whether a character code is an ASCII control character.
An ASCII control is a character in the inclusive range U+0000 NULL (NUL) to U+001F (US),
or U+007F (DEL).
code(Code) — the character code to check
(boolean) Whether the character code matches
Check whether a character code represents an ASCII digit (0 through 9).
An ASCII digit is a character in the inclusive range U+0030 (0) to U+0039 (9).
code(Code) — the character code to check
(boolean) Whether the character code matches
Check whether a character code represents an ASCII hex digit (a through f, case insensitive, or 0 through 9).
An ASCII hex digit is an ASCII digit (see asciiDigit),
ASCII upper hex digit, or an ASCII lower hex digit.
An ASCII upper hex digit is a character in the inclusive range U+0041 (A) to U+0046 (F).
An ASCII lower hex digit is a character in the inclusive range U+0061 (a) to U+0066 (f).
code(Code) — the character code to check
(boolean) Whether the character code matches
Check whether a character code represents ASCII punctuation.
An ASCII punctuation is a character in the following inclusive ranges:
U+0021EXCLAMATION MARK (!) toU+002FSLASH (/)U+003ACOLON (:) toU+0040AT SIGN (@)U+005BLEFT SQUARE BRACKET ([) toU+0060GRAVE ACCENT (`)U+007BLEFT CURLY BRACE ({) toU+007ETILDE (~)
code(Code) — the character code to check
(boolean) Whether the character code matches
Create a code check, i.e. guard, from a regular expression.
After serializing a character code, the guard will check if the character matches the bound regex.
test(RegExp|string) — the regular expression or regular expression patternserialize(Serialize|null|undefined, optional) — serialize a character code
(CodeCheck) The code check
Check if code is the end-of-stream code.
code(unknown) — the character code to check
(code is typeof codes.eos) true if code is codes.eos, false otherwise
Check if code represents a horizontal tab.
code(unknown) — the character code to check
(code is typeof codes.ht | typeof codes.vht)
true if code is codes.horizontalTab (aka codes.vht) or codes.ht, false otherwise
Check whether a character code can continue an identifier.
code(Code) — the character code to check
(boolean) Whether the character code matches
Check whether a character code can start an identifier.
code(Code) — the character code to check
(boolean) Whether the character code matches
Check if value looks like a character code.
value(unknown) — the thing to check
(value is Code) true if value is a number or null, false otherwise
Check if code represents a line ending or whitespace.
code(unknown) — the character code to check
(code is LineEnding | Whitespace)
true if code is line ending or whitespace code, false otherwise
Check if code represents a line ending.
code(unknown) — the character code to check
(code is LineEnding) true if code is line ending code, false otherwise
Check if code represents space.
code(unknown) — the character code to check
(code is Space) true if code is space code, false otherwise
Check if code represents a stream break.
The stream break code can be written between chunks to signal separation, or a "pause" in the current stream.
code(unknown) — the character code to check
(code is typeof codes.break) true if code is codes.break, false otherwise
Check whether a character code represents Unicode punctuation.
A Unicode punctuation is a character in the following Unicode categories:
Pc(Punctuation, Connector)Pd(Punctuation, Dash)Pe(Punctuation, Close)Pf(Punctuation, Final quote)Pi(Punctuation, Initial quote)Po(Punctuation, Other)Ps(Punctuation, Open)
or an ASCII punctuation (see asciiPunctuation).
See also:
- https://www.fileformat.info/info/unicode/category/Pc/list.htm
- https://www.fileformat.info/info/unicode/category/Pd/list.htm
- https://www.fileformat.info/info/unicode/category/Pe/list.htm
- https://www.fileformat.info/info/unicode/category/Pf/list.htm
- https://www.fileformat.info/info/unicode/category/Pi/list.htm
- https://www.fileformat.info/info/unicode/category/Po/list.htm
- https://www.fileformat.info/info/unicode/category/Ps/list.htm
code(Code) — the character code to check
(boolean) Whether the character code matches
Check whether a character code represents Unicode whitespace.
A Unicode whitespace is a character in the Unicode Zs (Separator, Space) category or one of the following:
U+0009CHARACTER TABULATION (HT)U+000ALINE FEED (LF),U+000CFORM FEED (FF)U+000DCARRIAGE RETURN (CR)
See also:
code(Code) — the character code to check
(boolean) Whether the character code matches
Check if code represents a vertical tab.
code(unknown) — the character code to check
(boolean) true if code is codes.vt, false otherwise
Check if code represents whitespace.
code(unknown) — the character code to check
(code is Whitespace) true if code is whitespace code, false otherwise
This package is fully typed with TypeScript.
Union of codes representing a line ending.
type LineEnding =
| typeof codes.carriageReturn
| typeof codes.carriageReturnLineFeed
| typeof codes.cr
| typeof codes.crlf
| typeof codes.lf
| typeof codes.lineFeed
| typeof codes.ls
| typeof codes.ps
| typeof codes.vcr
| typeof codes.vlfSerialize a character code.
code(Code) — the character code to serialize
(string) The character produced from code
Union of codes representing space.
type Space = typeof codes.space | typeof codes.virtualSpace | typeof codes.vsUnion of codes representing whitespace.
type Whitespace =
| Space
| typeof codes.horizontalTab
| typeof codes.ht
| typeof codes.vhtmark-util-character adheres to semver.
See CONTRIBUTING.md.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
Small primitives power larger systems. Support long-term stability by sponsoring Flex Development.
@flex-development/mark— the specification@flex-development/mark-compiler— finite state machine event compiler@flex-development/mark-parser— finite state machine parser