Skip to main content

patterns

Regular expressions and string patterns used throughout the core package.

This module centralizes all regex patterns and constants to ensure consistency and simplify maintenance when patterns need to be updated.

CONFIG_CONSTANTS​

const CONFIG_CONSTANTS: object;

Defined in: core/src/const/patterns.ts:115

String constants used for configuration parsing and defaults.

Type Declaration​

DEFAULT_GROUP​

readonly DEFAULT_GROUP: "Miscellaneous";

Default fallback group name used when groupByDirective is configured. Items without the grouping directive are assigned to this group.


PATTERNS​

const PATTERNS: object;

Defined in: core/src/const/patterns.ts:20

Central repository of regex patterns used for configuration parsing and string transformation.

Type Declaration​

CASE_TRANSITION​

readonly CASE_TRANSITION: RegExp;

Matches transitions between lowercase/digits and uppercase letters. Used to insert spaces in camelCase strings (e.g., "userId" β†’ "user Id").

Pattern​

([a-z]+|\d+)([A-Z])

Example​
- "userId" matches β†’ insert space between "id" and "U" β†’ "user Id"
- "HTTPServer" does not match (no lowercase/digit before uppercase)
- "get2Users" matches β†’ insert space between "2" and "U" β†’ "get 2 Users"

DIGIT_LETTER_TRANSITION​

readonly DIGIT_LETTER_TRANSITION: RegExp;

Matches transitions from digits to letters. Used to insert spaces between numbers and letters (e.g., "2k" β†’ "2 k").

Pattern​

(\d+)([a-z])

Example​
- "2k" matches β†’ "2 k"
- "123abc" matches β†’ "123 abc"
- "2K" does not match (K is uppercase)

DIRECTIVE_NAME​

readonly DIRECTIVE_NAME: RegExp;

Matches directive names with named capture groups. Captures the directive name after the @ symbol.

Pattern​

^\@(?<directive>\w+)$

Example​
- "@tag" matches β†’ directive: "tag"
- "@myDirective" matches β†’ directive: "myDirective"
- "@" does not match
- "tag" does not match

GROUP_BY_DIRECTIVE​

readonly GROUP_BY_DIRECTIVE: RegExp;

Matches group-by directive format with directive name, field, and optional fallback. Groups: (1) directive name, (2) field name, (3) optional fallback

Pattern​

^\@(\w+)\((\w+)(?:\|=(\w+))?\)$

Example​
- "@tag(name)" matches β†’ ["@tag(name)", "tag", "name", undefined]
- "@category(type|=Other)" matches β†’ ["@category(type|=Other)", "category", "type", "Other"]
- "@tag()" does not match
- "tag(name)" does not match

LETTER_DIGIT_TRANSITION​

readonly LETTER_DIGIT_TRANSITION: RegExp;

Matches transitions from letters to digits. Used to insert spaces between letters and numbers (e.g., "user1" β†’ "user 1").

Pattern​

([a-z]+)(\d)

Example​
- "user1" matches β†’ "user 1"
- "abc123" matches β†’ "abc 123"
- "U1" does not match (U is uppercase)

NUMERIC_PREFIX​

readonly NUMERIC_PREFIX: RegExp;

Matches numeric prefix for sorted categories (e.g., "01-query" β†’ "query"). Used to extract category names from numbered folder names.

Pattern: ^\d{2}-

Example​
- "01-query" matches β†’ remove "01-" β†’ "query"
- "02-mutations" matches β†’ remove "02-" β†’ "mutations"
- "query" does not match
- "1-query" does not match (only 1 digit)

WORD_BOUNDARY​

readonly WORD_BOUNDARY: RegExp;

Matches word boundaries (non-alphanumeric characters) for string splitting. Used globally to split strings on any non-alphanumeric character.

Pattern​

[^0-9A-Za-z]+

Example​
- "hello-world" split β†’ ["hello", "world"]
- "hello_world" split β†’ ["hello", "world"]
- "hello world" split β†’ ["hello", "world"]

Example​

import { PATTERNS } from "@graphql-markdown/core/const/patterns";

const match = PATTERNS.DIRECTIVE_NAME.exec("@myDirective");