@typedly/regexp v1.0.0-beta.4
typedly/regexp
A TypeScript type definitions package for RegExp
.
Table of contents
- Installation
Core Types
Escaped
EscapedArray
EscapedString
EscapedStringFromArray
FromTo
NonCapturingRepetition
Quantifier
Range
RegExpPattern
Repetition
Character
CharacterRange
CharacterRangeRepetition
Flag
AppendFlag
FlagString
IncludeFlag
IncludeFlags
PrependFlag
RegExpFlag
RemoveFlag
Letter Ranges
LetterRange
LetterRangeExclusion
LetterRangeRepetition
LetterRangeRepetitionPattern
LetterRangeTuple
Lowercase Ranges
LowercaseLetterRange
LowercaseLetterRangePattern
Multiple Ranges
MultiLetterRange
MultiLetterRangeRepetition
Uppercase Ranges
UppercaseLetterRange
UppercaseLetterRangePattern
- Support
- Code of Conduct
- Git
- License
Installation
1. Install Peer Dependencies
Before installing the package, ensure that all required peer dependencies are installed:
npm install @typedly/letter --save-peer
2. Install the package
Now, install the package:
npm install @typedly/regexp --save-peer
Api
import {
Escaped,
EscapedArray,
EscapedString,
FromTo,
NonCapturingRepetition,
Quantifier,
Range,
RegExpPattern,
Repetition,
// Character
CharacterRange,
CharacterRangeRepetition,
// Flag
AppendFlag,
FlagString,
IncludeFlag,
IncludeFlags,
PrependFlag,
RegExpFlag,
RemoveFlag,
// LetterRange
LetterRange,
LetterRangeExclusion,
LetterRangeRepetition,
LetterRangeRepetitionPattern,
LetterRangeTuple,
// Lowercase
LowercaseLetterRange,
LowercaseLetterRangePattern,
// MultiLetter
MultiLetterRange,
MultiLetterRangeRepetition,
// UpperLetter
UppercaseLetterRange,
UppercaseLetterRangePattern,
} from '@typedly/regexp';
Escaped
import { Escaped } from '@typedly/regexp';
const valid1: Escaped<'dws'> = '\\d\\w\\s'; // '\\d\\w\\s'
const valid2: Escaped<'*Dws'> = '\\*\\D\\w\\s'; // '\\*\\D\\w\\s'
const valid3: Escaped<'^d+*w$'> = '\\^\\d\\+\\*\\w\\$'; // '\\^\\d\\+\\*\\w\\$'
RegExpFlag
import { RegExpFlags } from '@typedly/regexp';
const g: RegExpFlag = 'g';
const i: RegExpFlag = 'i';
const m: RegExpFlag = 'm';
const u: RegExpFlag = 'u';
const y: RegExpFlag = 'y';
Repetition
import { Repetition } from '@typedly/regexp';
type ZeroOrMore = Repetition<'*'>; // Output: "*"
type OneOrMore = Repetition<'+'>; // Output: "+"
type ZeroOrOne = Repetition<'?'>; // Output: "?"
type ExactlyThree = Repetition<3>; // Output: "{3}"
type TwoToFourTimes = Repetition<2, 4>; // Output: "{2,4}"
type AtLeastFive = Repetition<5, ''>; // Output: "{5,}"
const zeroOrMore: ZeroOrMore = '*';
const oneOrMore: OneOrMore = '+';
const zeroOrOne: ZeroOrOne = '?';
const exactlyThree: ExactlyThree = '{3,}';
const twoToFourTimes: TwoToFourTimes = '{2,4}';
const atLeastFive: AtLeastFive = '{5,}';
LetterRangeExclusion
import { LetterRangeExclusion } from '@typedly/regexp';
type ExcludedLowercase = LetterRangeExclusion; // Resolves to "[^a-z]
type ExcludedVowels = LetterRangeExclusion<'a', 'u'>; // Resolves to "[^a-u]"
// Using the type in a variable
const pattern: ExcludedLowercase = "[^a-z]"; // This matches any character not in a-z
// If you log the pattern or use it in a RegExp, it will exclude lowercase letters:
const regex = new RegExp(pattern);
regex.test("B"); // true, because 'B' is not a lowercase letter
regex.test("b"); // false, because 'b' is a lowercase letter
Contributing
Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.
Support
If you find this package useful and would like to support its and general development, you can contribute through one of the following payment methods. Your support helps maintain the packages and continue adding new.
Support via:
Thanks for your support!
Code of Conduct
By participating in this project, you agree to follow Code of Conduct.
GIT
Commit
Versioning
Given a version number MAJOR.MINOR.PATCH, increment the:
- MAJOR version when you make incompatible API changes,
- MINOR version when you add functionality in a backwards-compatible manner, and
- PATCH version when you make backwards-compatible bug fixes.
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
FAQ How should I deal with revisions in the 0.y.z initial development phase?
The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.
How do I know when to release 1.0.0?
If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0.
License
MIT © typedly (license)
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago