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
Install
npm:
npm install micromark-util-classify-character
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 following identifiers: classifyCharacter
.
There is no default export.
classifyCharacter(code)
Classify whether a
character 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 that eof (null
) is seen as whitespace.
Returns
constants.characterGroupWhitespace
, constants.characterGroupPunctuation
,
or undefined.
Security
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