Skip to content

flex-development/mark-util-character

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mark-util-character

github release npm npm downloads install size minified bundle size tree shaking suppport codecov module type: esm license conventional commits typescript vitest yarn

mark utility to handle character codes.

Contents

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-character
See 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>

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)) // true

API

This package exports the following identifiers:

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+0023 NUMBER SIGN (#) to U+0027 APOSTROPHE (')
  • U+002A ASTERISK (*)
  • U+002B PLUS SIGN (+)
  • U+002D DASH (-)
  • U+002F SLASH (/)
  • U+003D EQUALS TO (=)
  • U+003F QUESTION MARK (?)
  • U+005E CARET (^) to U+0060 GRAVE ACCENT (`)
  • U+007B LEFT CURLY BRACE ({) to U+007E TILDE (~)

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+0021 EXCLAMATION MARK (!) to U+002F SLASH (/)
  • U+003A COLON (:) to U+0040 AT SIGN (@)
  • U+005B LEFT SQUARE BRACKET ([) to U+0060 GRAVE ACCENT (`)
  • U+007B LEFT CURLY BRACE ({) to U+007E TILDE (~)

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 pattern
  • serialize (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:

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+0009 CHARACTER TABULATION (HT)
  • U+000A LINE FEED (LF),
  • U+000C FORM FEED (FF)
  • U+000D CARRIAGE 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.vlf

Serialize

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.vs

Whitespace

Union of codes representing whitespace.

type Whitespace =
  | Space
  | typeof codes.horizontalTab
  | typeof codes.ht
  | typeof codes.vht

Project

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

About

mark utility to handle character codes

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors

Languages