ts-regex-builder
Version:
Maintainable regular expressions for TypeScript and JavaScript.
1 lines • 2.64 kB
Source Map (JSON)
{"version":3,"file":"quantifiers.mjs","names":["encodeAtomic","ensureElements","zeroOrMore","sequence","options","elements","precedence","pattern","greedy","oneOrMore","optional"],"sources":["../../../src/constructs/quantifiers.ts"],"sourcesContent":["import { encodeAtomic } from '../encoder';\nimport type { EncodedRegex, RegexSequence } from '../types';\nimport { ensureElements } from '../utils';\n\nexport interface QuantifierOptions {\n greedy?: boolean;\n}\n\n/**\n * Creates a quantifier which matches zero or more of the given elements.\n *\n * @param sequence - Elements to match zero or more of.\n * @param options - Quantifier options.\n */\nexport function zeroOrMore(sequence: RegexSequence, options?: QuantifierOptions): EncodedRegex {\n const elements = ensureElements(sequence);\n return {\n precedence: 'sequence',\n pattern: `${encodeAtomic(elements)}*${options?.greedy === false ? '?' : ''}`,\n };\n}\n\n/**\n * Creates a quantifier which matches one or more of the given elements.\n *\n * @param sequence - Elements to match one or more of.\n * @param options - Quantifier options.\n */\nexport function oneOrMore(sequence: RegexSequence, options?: QuantifierOptions): EncodedRegex {\n const elements = ensureElements(sequence);\n return {\n precedence: 'sequence',\n pattern: `${encodeAtomic(elements)}+${options?.greedy === false ? '?' : ''}`,\n };\n}\n\n/**\n * Creates a quantifier which matches zero or one of the given elements.\n *\n * @param sequence - Elements to match zero or one of.\n * @param options - Quantifier options.\n */\nexport function optional(sequence: RegexSequence, options?: QuantifierOptions): EncodedRegex {\n const elements = ensureElements(sequence);\n return {\n precedence: 'sequence',\n pattern: `${encodeAtomic(elements)}?${options?.greedy === false ? '?' : ''}`,\n };\n}\n"],"mappings":"SAASA,YAAY;AAAA,SAEZC,cAAc;AAYvB,OAAO,SAASC,UAAUA,CAACC,QAAuB,EAAEC,OAA2B,EAAgB;EAC7F,MAAMC,QAAQ,GAAGJ,cAAc,CAACE,QAAQ,CAAC;EACzC,OAAO;IACLG,UAAU,EAAE,UAAU;IACtBC,OAAO,EAAG,GAAEP,YAAY,CAACK,QAAQ,CAAE,IAAGD,OAAO,EAAEI,MAAM,KAAK,KAAK,GAAG,GAAG,GAAG,EAAG;EAC7E,CAAC;AACH;AAQA,OAAO,SAASC,SAASA,CAACN,QAAuB,EAAEC,OAA2B,EAAgB;EAC5F,MAAMC,QAAQ,GAAGJ,cAAc,CAACE,QAAQ,CAAC;EACzC,OAAO;IACLG,UAAU,EAAE,UAAU;IACtBC,OAAO,EAAG,GAAEP,YAAY,CAACK,QAAQ,CAAE,IAAGD,OAAO,EAAEI,MAAM,KAAK,KAAK,GAAG,GAAG,GAAG,EAAG;EAC7E,CAAC;AACH;AAQA,OAAO,SAASE,QAAQA,CAACP,QAAuB,EAAEC,OAA2B,EAAgB;EAC3F,MAAMC,QAAQ,GAAGJ,cAAc,CAACE,QAAQ,CAAC;EACzC,OAAO;IACLG,UAAU,EAAE,UAAU;IACtBC,OAAO,EAAG,GAAEP,YAAY,CAACK,QAAQ,CAAE,IAAGD,OAAO,EAAEI,MAAM,KAAK,KAAK,GAAG,GAAG,GAAG,EAAG;EAC7E,CAAC;AACH","ignoreList":[]}