What is micromark-util-classify-character?
The micromark-util-classify-character package is a utility for classifying characters in the context of micromark, a markdown parser. It helps in identifying character types such as whitespace, punctuation, and more, which is essential for parsing and tokenizing markdown content.
What are micromark-util-classify-character's main functionalities?
Whitespace Classification
This feature allows you to check if a character is a whitespace character. It returns true for spaces, newlines, and other whitespace characters, and false otherwise.
const { isWhitespace } = require('micromark-util-classify-character');
console.log(isWhitespace(' ')); // true
console.log(isWhitespace('\n')); // true
console.log(isWhitespace('a')); // false
Punctuation Classification
This feature allows you to check if a character is a punctuation character. It returns true for characters like periods, commas, and other punctuation marks, and false otherwise.
const { isPunctuation } = require('micromark-util-classify-character');
console.log(isPunctuation('.')); // true
console.log(isPunctuation(',')); // true
console.log(isPunctuation('a')); // false
Identifier Classification
This feature allows you to check if a character can start or continue an identifier. It returns true for valid identifier start characters (like letters and underscores) and valid identifier continuation characters (like letters, digits, and underscores).
const { isIdentifierStart, isIdentifierContinue } = require('micromark-util-classify-character');
console.log(isIdentifierStart('a')); // true
console.log(isIdentifierStart('_')); // true
console.log(isIdentifierStart('1')); // false
console.log(isIdentifierContinue('1')); // true
console.log(isIdentifierContinue('-')); // false
Other packages similar to micromark-util-classify-character
is-whitespace
The is-whitespace package provides a simple utility to check if a character is a whitespace character. It is more focused and less comprehensive compared to micromark-util-classify-character, which offers a broader range of character classification utilities.
is-punctuation
The is-punctuation package allows you to check if a character is a punctuation mark. Similar to is-whitespace, it is more specialized and does not offer the wide range of character classifications that micromark-util-classify-character does.
char-regex
The char-regex package provides regular expressions for different character classes, such as whitespace, punctuation, and identifiers. While it offers similar functionality, it uses regular expressions rather than direct utility functions, which might be less convenient for some use cases.
micromark-util-classify-character
micromark utility to classify whether a character is whitespace or
punctuation.
Contents
What is this?
This package exposes an algorithm to classify characters into 3 categories.
When should I use this?
This package might be useful when you are making your own micromark extensions.
Install
This package is ESM only.
In Node.js (version 16+), install with npm:
npm install micromark-util-classify-character
In Deno with esm.sh
:
import {classifyCharacter} from 'https://esm.sh/micromark-util-classify-character@1'
In browsers with esm.sh
:
<script type="module">
import {classifyCharacter} from 'https://esm.sh/micromark-util-classify-character@1?bundle'
</script>
Use
function tokenizeAttention(effects, ok) {
return start
function sequence(code) {
if (code === marker) {
}
const token = effects.exit('attentionSequence')
const after = classifyCharacter(code)
const open =
!after || (after === constants.characterGroupPunctuation && before)
const close =
!before || (before === constants.characterGroupPunctuation && after)
}
}
API
This module exports the identifier
classifyCharacter
.
There is no default export.
classifyCharacter(code)
Classify whether a code represents whitespace, punctuation, or something
else.
Used for attention (emphasis, strong), whose sequences can open or close
based on the class of surrounding characters.
👉 Note: eof (null
) is seen as whitespace.
Parameters
Returns
Group (constants.characterGroupWhitespace
,
constants.characterGroupPunctuation
, or undefined
).
Types
This package is fully typed with TypeScript.
It exports no additional types.
Compatibility
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
micromark-util-classify-character@2
, compatible with Node.js 16.
This package works with micromark@3
.
Security
This package is safe.
See security.md
in micromark/.github
for how to
submit a security report.
Contribute
See contributing.md
in micromark/.github
for ways
to get started.
See support.md
for ways to get help.
This project has a code of conduct.
By interacting with this repository, organisation, or community you agree to
abide by its terms.
License
MIT © Titus Wormer