@ptolemy2002/rgx
v13.3.2
Published
A library for easy construction and validation of regular expressions in TypeScript. You can use `rgx` to concatenate various types of tokens into a valid regular expression string, with type safety and validation. You can also use a combination of `RGXWa
Downloads
4,016
Readme
RGX
A library for easy construction and validation of regular expressions in TypeScript. You can use rgx to concatenate various types of tokens into a valid regular expression string, with type safety and validation. You can also use a combination of RGXWalker, RGXPart, and plain tokens to create powerful matchers that can validate partial matches and transform captured values with custom logic.
All public components are exported at the main module entry point.
Note: This library is tested with nearly 100% coverage, but any override of RGXClassToken.clone() does not have the depth parameter fully tested, as that is ultimately part of @ptolemy2002/immutability-utils, which is tested, and setting up tests for that functionality is exceedingly complex.
Table of Contents
Because there is so much to document, it has been broken up into multiple files. The following is a list of the documentation files for this library:
- type-reference - A reference for all public types used in the library.
- general - General utilities of the library, including tagged template functions for creating regular expressions and walkers.
- type-guards - Type guards for validating various types of tokens and string values.
- ExtRegExp - The
ExtRegExpclass, which extends the built-inRegExpclass with the ability to create custom flags that transform the source string of the regular expression before it is compiled. - constants - Constants provided by the library, such as predefined character classes and tokens.
util- A directory containing documentation for various utility functions provided by the library.- clone - The
cloneRGXTokenfunction, which creates a clone of a given RGX token to a specified depth. - escapeRegex - The
escapeRegexfunction, which escapes special regex characters in a given string and assures you that the result is valid Regex. - regexMatchAtPosition - The
regexMatchAtPositionfunction and related functions, which attempt to match a given regular expression at a specific position in a string. - regexMatchAfterPosition - The
regexMatchAfterPositionfunction and related functions, which search for a regular expression match at or after a specific position in a string. - regexWithFlags - The
regexWithFlagsfunction, which creates a new regular expression with the same source as a given regular expression but with different flags. - createRegex - The
createRegexfunction, which safely constructs aRegExporExtRegExpfrom a pattern string, convertingSyntaxErrorintoRGXInvalidRegexStringError. - createRGXClassGuardFunction - The
createRGXClassGuardFunctionandcreateAssertRGXClassGuardFunctionutilities for creating type guard and assertion functions for class instances. - createRGXBounds - The
createRGXBoundsfunction, which creates a pair of zero-width boundary tokens representing the start and end of a region delimited by two patterns.
- clone - The
class- A directory containing documentation for all classes in the library.- collection - The
RGXTokenCollectionclass, which is a collection of tokens. - RGXError - Details on all custom error classes and the base
RGXErrorclass. - walker - Details on both
RGXWalkerandRGXPart, which are used for creating custom matchers that can validate partial matches and transform captured values with custom logic. - lexer - Details on
RGXLexer, which tokenizes a source string into structured lexemes using named lexeme definitions grouped by mode. token- A directory containing documentation for all token classes in the library, which are classes that represent specific types of tokens that can be used in regular expressions.- base - The
RGXClassTokenclass, which is the base class for all token classes in the library. - group - The
RGXGroupTokenclass, which represents a group of tokens that can be treated as a single unit in a regular expression. - repeat - The
RGXRepeatTokenclass, which represents a token that can be repeated a range of times in a regular expression. This also covers optional syntax. - union - The
RGXClassUnionTokenclass, which represents a union of tokens that can match any one of the tokens in the union. - subpattern - The
RGXSubpatternTokenclass, which re-matching the content of a previous capturing group. - wrapper - The
RGXClassWrapperTokenclass, which represents a class token that can wrap any arbitrary token (even non-class), giving you the benefit of the class API for any token. - exclusion - The
RGXExclusionTokenclass, which matches a token while excluding specific alternatives using lookahead-based subtraction. - to - A utility for converting any token into a class token. Most tokens just get wrapped in a
RGXClassWrapperToken, but some do not. lookaround- A directory containing documentation for lookahead and lookbehind tokens.- base - The
RGXLookaroundTokenclass, which is the base class for lookahead and lookbehind tokens. - lookahead - The
RGXLookaheadTokenclass, which represents a lookahead assertion in a regular expression. - lookbehind - The
RGXLookbehindTokenclass, which represents a lookbehind assertion in a regular expression.
- base - The
- base - The
- collection - The
Peer Dependencies
N/A
Commands
The following commands exist in the project:
npm run uninstall- Uninstalls all dependencies for the librarynpm run reinstall- Uninstalls and then Reinstalls all dependencies for the librarynpm run build- Builds the librarynpm run release- Publishes the library to npm without changing the versionnpm run release-patch- Publishes the library to npm with a patch version bumpnpm run release-minor- Publishes the library to npm with a minor version bumpnpm run release-major- Publishes the library to npm with a major version bumpnpm run test- Runs the tests for the librarynpm run test:watch- Runs the tests for the library in watch modenpm run test:coverage- Runs the tests for the library and generates a coverage report
