@flex-development/mark-util-character
v1.1.0
Published
mark utility to handle character codes
Maintainers
Readme
mark-util-character
mark utility to handle character codes.
Contents
- 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
What is this?
This package exposes algorithms for checking whether character codes match certain groups.
When should I use this?
This package is useful when creating your own your own mark extensions and utilities.
Install
This package is ESM only.
In Node.js with yarn:
yarn add @flex-development/mark-util-characterIn 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>Use
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)) // trueAPI
This package exports the following identifiers:
asciiAlphaasciiAlphanumericasciiAtextasciiControlasciiDigitasciiHexDigitasciiPunctuationcheckereoshtabidContinueidStartisCodelineEndingOrWhitespacelineEndingspacestreamBreakunicodePunctuationunicodeWhitespacevtabwhitespace
There is no default export.
asciiAlpha(code)
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).
Parameters
code(Code) — the character code to check
Returns
(boolean) Whether the character code matches
asciiAlphanumeric(code)
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).
Parameters
code(Code) — the character code to check
Returns
(boolean) Whether the character code matches
asciiAtext(code)
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.
Parameters
code(Code) — the character code to check
Returns
(boolean) Whether the character code matches
asciiControl(code)
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).
Parameters
code(Code) — the character code to check
Returns
(boolean) Whether the character code matches
asciiDigit(code)
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).
Parameters
code(Code) — the character code to check
Returns
(boolean) Whether the character code matches
asciiHexDigit(code)
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).
Parameters
code(Code) — the character code to check
Returns
(boolean) Whether the character code matches
asciiPunctuation(code)
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 (~)
Parameters
code(Code) — the character code to check
Returns
(boolean) Whether the character code matches
checker(test[, serialize])
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.
Parameters
test(RegExp|string) — the regular expression or regular expression patternserialize(Serialize|null|undefined, optional) — serialize a character code
Returns
(CodeCheck) The code check
eos(code)
Check if code is the end-of-stream code.
Parameters
code(unknown) — the character code to check
Returns
(code is typeof codes.eos) true if code is codes.eos, false otherwise
htab(code)
Check if code represents a horizontal tab.
Parameters
code(unknown) — the character code to check
Returns
(code is typeof codes.ht | typeof codes.vht)
true if code is codes.horizontalTab (aka codes.vht) or codes.ht, false otherwise
idContinue(code)
Check whether a character code can continue an identifier.
Parameters
code(Code) — the character code to check
Returns
(boolean) Whether the character code matches
idStart(code)
Check whether a character code can start an identifier.
Parameters
code(Code) — the character code to check
Returns
(boolean) Whether the character code matches
isCode(value)
Check if value looks like a character code.
Parameters
value(unknown) — the thing to check
Returns
(value is Code) true if value is a number or null, false otherwise
lineEndingOrWhitespace(code)
Check if code represents a line ending or whitespace.
Parameters
code(unknown) — the character code to check
Returns
(code is LineEnding | Whitespace)
true if code is line ending or whitespace code, false otherwise
lineEnding(code)
Check if code represents a line ending.
Parameters
code(unknown) — the character code to check
Returns
(code is LineEnding) true if code is line ending code, false otherwise
space(code)
Check if code represents space.
Parameters
code(unknown) — the character code to check
Returns
(code is Space) true if code is space code, false otherwise
streamBreak(code)
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.
Parameters
code(unknown) — the character code to check
Returns
(code is typeof codes.break) true if code is codes.break, false otherwise
unicodePunctuation(code)
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
Parameters
code(Code) — the character code to check
Returns
(boolean) Whether the character code matches
unicodeWhitespace(code)
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:
Parameters
code(Code) — the character code to check
Returns
(boolean) Whether the character code matches
vtab(code)
Check if code represents a vertical tab.
Parameters
code(unknown) — the character code to check
Returns
(boolean) true if code is codes.vt, false otherwise
whitespace(code)
Check if code represents whitespace.
Parameters
code(unknown) — the character code to check
Returns
(code is Whitespace) true if code is whitespace code, false otherwise
Types
This package is fully typed with TypeScript.
LineEnding
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
Serialize a character code.
Parameters
code(Code) — the character code to serialize
Returns
(string) The character produced from code
Space
Union of codes representing space.
type Space = typeof codes.space | typeof codes.virtualSpace | typeof codes.vsWhitespace
Union of codes representing whitespace.
type Whitespace =
| Space
| typeof codes.horizontalTab
| typeof codes.ht
| typeof codes.vhtProject
Version
mark-util-character adheres to semver.
Contribute
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.
Sponsor
Small primitives power larger systems. Support long-term stability by sponsoring Flex Development.
Related
@flex-development/mark— the specification@flex-development/mark-compiler— finite state machine event compiler@flex-development/mark-parser— finite state machine parser
