
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
micromark-util-classify-character
Advanced tools
micromark utility to classify whether a character is whitespace or punctuation
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.
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
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.
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.
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 utility to classify whether a character is whitespace or punctuation.
This package exposes an algorithm to classify characters into 3 categories.
This package might be useful when you are making your own micromark extensions.
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>
/**
* @this {TokenizeContext}
* Context.
* @type {Tokenizer}
*/
function tokenizeAttention(effects, ok) {
return start
// …
/** @type {State} */
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)
// …
}
// …
}
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.
code
(Code
)
— codeGroup (constants.characterGroupWhitespace
,
constants.characterGroupPunctuation
, or undefined
).
This package is fully typed with TypeScript. It exports no additional types.
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
.
This package is safe.
See security.md
in micromark/.github
for how to
submit a security report.
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.
FAQs
micromark utility to classify whether a character is whitespace or punctuation
The npm package micromark-util-classify-character receives a total of 7,990,563 weekly downloads. As such, micromark-util-classify-character popularity was classified as popular.
We found that micromark-util-classify-character demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.