UNPKG

kuvio

Version:

Create string patterns and derive things from them, such as regexes

418 lines (399 loc) 16.5 kB
import { C as Char, A as Atom, a as CharacterClass, P as Pattern, Q as QuantifiedAtom, T as TermSequence, D as Disjunction, b as Term } from './types-b1ba45f9.js'; /** * A pattern of a single, specific character * * @since 0.0.1 */ declare const char: (c: Char) => Atom; /** * A pattern of any single character * * @since 0.0.1 */ declare const anything: Atom; /** * A pattern of a single character that matches a list of characters or ranges. The ranges * can either be charcter to character (e.g. `['A', 'Z']`) or number to number (e.g. * `[0x3040, 0x309F]` which matches the Hiragana range in Unicode.) * * If the first argument (`exclude`) is true, then the pattern is a single character that * is _not_ in the given ranges. * * @since 0.0.1 */ declare const characterClass: (exclude: boolean, ...ranges: ReadonlyArray<readonly [Char, Char] | Char | readonly [number, number]>) => CharacterClass; /** * Turn a `Pattern` into an `Atom`. In regular expression terms, this is wrapping the * pattern in parentheses. * * @since 0.0.1 */ declare const subgroup: (subpattern: Pattern) => Atom; /** * Repeat an `Atom` any number of times (including zero). * * @since 0.0.1 */ declare const anyNumber: (opts?: { greedy: boolean; }) => (atom: Atom) => QuantifiedAtom; /** * Repeat an `Atom` any number of times, but at least once. * * @since 0.0.1 */ declare const atLeastOne: (opts?: { greedy: boolean; }) => (atom: Atom) => QuantifiedAtom; /** * Make an `Atom` optional -- it can occur in the pattern once or not at all. * * @since 0.0.1 */ declare const maybe: (atom: Atom) => QuantifiedAtom; /** * Repeat an `Atom` an exact number of times. (Aliased to `exactly` for better readability * in some situations) * * @since 0.0.1 */ declare const times: (count: number) => (atom: Atom) => QuantifiedAtom; /** * Alias of `times` * * @since 0.0.1 */ declare const exactly: (count: number) => (atom: Atom) => QuantifiedAtom; /** * Repeat an `Atom` at least some number of times. For example, `atLeast(3)(char('a'))` * represents `aaa`, `aaaaaa`, and `aaaaaaaaaaaaaaaaaaaaaaaa` but not `aa` * * @since 0.0.1 */ declare const atLeast: (min: number) => (atom: Atom) => QuantifiedAtom; /** * Repeat an `Atom` some number of times in the given range, inclusive. * * @since 0.0.1 */ declare const between: (min: number, max: number) => (atom: Atom) => QuantifiedAtom; /** * Repeat an `Atom` at most some number of times. For example, `atMost(3)(char('a'))` * represents ``, `a`, and `aaa` but not `aaaa` * * @since 1.1.0 */ declare const atMost: (min: number) => (atom: Atom) => QuantifiedAtom; /** * Create a disjunction of two patterns. In regular expression terms, this corresponds to `|`. * * @since 0.0.1 */ declare const or: (right: TermSequence | Atom | QuantifiedAtom) => (left: Pattern) => Disjunction; /** * Append a term or term sequence onto another. * * @since 0.0.1 */ declare const andThen: (term: Term | TermSequence) => (alt: TermSequence | Term) => TermSequence; /** * Construct an `Atom` for a specific string. * * @since 0.0.1 */ declare const exactString: (s: string) => Atom; /** * Concatenate `Term`s * * @since 0.0.1 */ declare const sequence: (term: Term, ...terms: ReadonlyArray<Term>) => TermSequence; /** * Modify a character class with more ranges, or combine two character classes together. * * @since 0.0.1 */ declare const and: { (...ranges: ReadonlyArray<readonly [Char, Char] | Char | readonly [number, number]>): (cc: CharacterClass) => CharacterClass; (ccb: CharacterClass): (cca: CharacterClass) => CharacterClass; }; /** * Invert a character class * * @since 0.0.1 */ declare const non: (cc: CharacterClass) => CharacterClass; /** * An empty pattern. * * @since 0.0.1 */ declare const empty: Atom; /** * Any upper case letter in ASCII. See [POSIX * equivalent](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions#Character_classes) * * @since 0.0.1 */ declare const upper: CharacterClass; /** * Any lower case letter in ASCII. See [POSIX * equivalent](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions#Character_classes) * * @since 0.0.1 */ declare const lower: CharacterClass; /** * Any upper or lower case letter in ASCII. See [POSIX * equivalent](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions#Character_classes) * * @since 0.0.1 */ declare const alpha: CharacterClass; /** * Any digit character in ASCII. See [POSIX * equivalent](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions#Character_classes) * * @since 0.0.1 */ declare const digit: CharacterClass; /** * Any hexadecimal digit in ASCII. See [POSIX * equivalent](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions#Character_classes) * * @since 0.0.1 */ declare const xdigit: CharacterClass; /** * Alias of `xdigit` * * @since 0.0.1 */ declare const hexDigit: CharacterClass; /** * Any alphanumeric character in ASCII. See [POSIX * equivalent](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions#Character_classes) * * @since 0.0.1 */ declare const alnum: CharacterClass; /** * Any alphanumeric character in ASCII, or an underscore ('_'). See [POSIX * equivalent](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions#Character_classes) * * @since 0.0.1 */ declare const word: CharacterClass; /** * Any punctuation character in ASCII. See [POSIX * equivalent](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions#Character_classes) * * @since 0.0.1 */ declare const punct: CharacterClass; /** * Space or tab. See [POSIX * equivalent](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions#Character_classes) * * @since 0.0.1 */ declare const blank: CharacterClass; /** * Any whitespace character in ASCII. See [POSIX * equivalent](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions#Character_classes) * * @since 0.0.1 */ declare const space: CharacterClass; /** * Any character in ASCII which has a graphical representation (i.e. not control * characters or space). See [POSIX * equivalent](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions#Character_classes) * * @since 0.0.1 */ declare const graph: CharacterClass; /** * Any non-control character in ASCII. See [POSIX * equivalent](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions#Character_classes) * * @since 0.0.1 */ declare const print: CharacterClass; /** * Form a disjunction of multiple terms or term sequences. * * @since 0.0.1 */ declare const oneOf: (pattern: Pattern, ...terms: ReadonlyArray<Term | TermSequence>) => Pattern; /** * Create a pattern that matches integers in a given range. Does not currently handle * negatives (it returns an empty pattern if either number is negative) * * @since 0.0.1 */ declare const integerRange: (min: number, max: number) => Pattern; /** * Construct a regular expression (`RegExp`) from a given `Pattern`. * * @since 1.0.0 */ declare const regexFromPattern: (pattern: Pattern, caseInsensitive?: boolean, global?: boolean, multiline?: boolean) => RegExp; declare const base64Character: CharacterClass; /** * Matches a base64 string, with or without trailing '=' characters. However, if * they are present, they must be correct (i.e. pad out the string so its length * is a multiple of 4) * * @since 1.0.0 * @category Pattern */ declare const base64: Pattern; /** * Matches any * [base64url](https://datatracker.ietf.org/doc/html/rfc4648#section-5) string. * * @since 1.0.0 * @category Pattern */ declare const base64Url: Pattern; /** * @since 1.1.0 * @category Pattern */ declare const creditCard: Pattern; /** * @since 1.1.0 * @category Pattern */ declare const emailAddress: Pattern; /** * Matches a hex color, with or without a leading '#'. Matches both short form * (3-digit) and long form (6-digit) hex colors, and can also match alpha values * (4- or 8-digit). */ declare const hexColor: Pattern; /** * Matches a hexadecimal number, with or without a leading '0x' or '0h', in any * combination of upper or lower case. * * @since 1.0.0 * @category Pattern */ declare const hexadecimal: Pattern; /** * Matches an HSL color in the format `hsl(0, 0%, 0%)`. * * @since 1.0.0 * @category Pattern */ declare const hslColor: TermSequence; /** * Matches a [JSON Web Token](https://datatracker.ietf.org/doc/html/rfc7519). */ declare const jwt: Pattern; /** * @since 1.0.0 * @category Pattern */ declare const latLong: Pattern; /** * Matches an RGB color in the format `rgb(0, 0, 0)`. */ declare const rgbColorDecimal: TermSequence; /** * Matches an RGBA color in the format `rgba(0, 0, 0, 0)`. */ declare const rgbColorWithAlphaDecimal: TermSequence; /** * Matches an RGB color in the format `rgb(0%, 0%, 0%)`. */ declare const rgbColorPercent: TermSequence; /** * Matches an RGBA color in the format `rgba(0%, 0%, 0%, 0)`. */ declare const rgbColorWithAlphaPercent: TermSequence; /** * Matches an RGB color in any of the following formats: * - `rgb(0, 0, 0)` * - `rgba(0, 0, 0, 0)` * - `rgb(0%, 0%, 0%)` * - `rgba(0%, 0%, 0%, 0)` * * @since 1.1.0 * @category Pattern */ declare const rgbColor: Pattern; declare const uuidV1: TermSequence; declare const uuidV2: TermSequence; declare const uuidV3: TermSequence; declare const uuidV4: TermSequence; declare const uuidV5: TermSequence; declare const anyUUID: TermSequence; declare const index_anyUUID: typeof anyUUID; declare const index_base64: typeof base64; declare const index_base64Character: typeof base64Character; declare const index_base64Url: typeof base64Url; declare const index_creditCard: typeof creditCard; declare const index_emailAddress: typeof emailAddress; declare const index_hexColor: typeof hexColor; declare const index_hexadecimal: typeof hexadecimal; declare const index_hslColor: typeof hslColor; declare const index_jwt: typeof jwt; declare const index_latLong: typeof latLong; declare const index_rgbColor: typeof rgbColor; declare const index_rgbColorDecimal: typeof rgbColorDecimal; declare const index_rgbColorPercent: typeof rgbColorPercent; declare const index_rgbColorWithAlphaDecimal: typeof rgbColorWithAlphaDecimal; declare const index_rgbColorWithAlphaPercent: typeof rgbColorWithAlphaPercent; declare const index_uuidV1: typeof uuidV1; declare const index_uuidV2: typeof uuidV2; declare const index_uuidV3: typeof uuidV3; declare const index_uuidV4: typeof uuidV4; declare const index_uuidV5: typeof uuidV5; declare namespace index { export { index_anyUUID as anyUUID, index_base64 as base64, index_base64Character as base64Character, index_base64Url as base64Url, index_creditCard as creditCard, index_emailAddress as emailAddress, index_hexColor as hexColor, index_hexadecimal as hexadecimal, index_hslColor as hslColor, index_jwt as jwt, index_latLong as latLong, index_rgbColor as rgbColor, index_rgbColorDecimal as rgbColorDecimal, index_rgbColorPercent as rgbColorPercent, index_rgbColorWithAlphaDecimal as rgbColorWithAlphaDecimal, index_rgbColorWithAlphaPercent as rgbColorWithAlphaPercent, index_uuidV1 as uuidV1, index_uuidV2 as uuidV2, index_uuidV3 as uuidV3, index_uuidV4 as uuidV4, index_uuidV5 as uuidV5, }; } declare function pipe<A>(a: A): A; declare function pipe<A, B>(a: A, ab: (a: A) => B): B; declare function pipe<A, B, C>(a: A, ab: (a: A) => B, bc: (b: B) => C): C; declare function pipe<A, B, C, D>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D; declare function pipe<A, B, C, D, E>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E): E; declare function pipe<A, B, C, D, E, F>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F): F; declare function pipe<A, B, C, D, E, F, G>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G): G; declare function pipe<A, B, C, D, E, F, G, H>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H): H; declare function pipe<A, B, C, D, E, F, G, H, I>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I): I; declare function pipe<A, B, C, D, E, F, G, H, I, J>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J): J; declare function pipe<A, B, C, D, E, F, G, H, I, J, K>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K): K; declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L): L; declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M): M; declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N): N; declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O): O; declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P): P; declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q): Q; declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R): R; declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S): S; declare function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D, de: (d: D) => E, ef: (e: E) => F, fg: (f: F) => G, gh: (g: G) => H, hi: (h: H) => I, ij: (i: I) => J, jk: (j: J) => K, kl: (k: K) => L, lm: (l: L) => M, mn: (m: M) => N, no: (n: N) => O, op: (o: O) => P, pq: (p: P) => Q, qr: (q: Q) => R, rs: (r: R) => S, st: (s: S) => T): T; export { Atom, Char, CharacterClass, Disjunction, Pattern, QuantifiedAtom, Term, TermSequence, alnum, alpha, and, andThen, anyNumber, anything, atLeast, atLeastOne, atMost, between, blank, char, characterClass, digit, empty, exactString, exactly, graph, hexDigit, integerRange, lower, maybe, non, oneOf, or, index as patterns, pipe, print, punct, regexFromPattern, sequence, space, subgroup, times, upper, word, xdigit };