ret-extended

An extension of ret (regular expression tokenizer) which adds extra details to tokens

Usage no npm install needed!

<script type="module">
  import retExtended from 'https://cdn.skypack.dev/ret-extended';
</script>

README

ret-extended

GitHub license npm version build Dependabot semantic-release

Overview

This adds details to the tokens produced by the ret package. Namely it adds the following properties.

For all tokens the following properties are given:

/**
 * Details that are added to every ret.js token
 */
export interface Detailed<T extends Tokens> {
  /**
   * Minimum number of characters required to 'satisfy' the regex component
   */
  minChar: number;
  /**
   * Maximum number of characters required to 'satisfy' the regex component
   */
  maxChar: number;
  /**
   * Whether the '^' positional is applied or not;
   */
  leftEnd: boolean;
  /**
   * Whether the '

 positional is applied or not;
   */
  rightEnd: boolean;
  /**
   * The original tokens
   */
  token: T
  /**
   * Regular expression (Regex Object with flags) that the token is representing
   */
  regex: RegExp;
  /**
   * Generator for possible values of regular expression
   */
  pattern?: string[];
  /**
   * Whether this token has a 'fixed solution', e.g `(hello)`,
   * or many solutions, e.g. `[0-9]`.
   */
  fixed: boolean;
}

In addition, remembered capturing groups are given a reference entry which is the value that backreferences should use to refer to that group.

Usage

import { regexDetailTokenizer } from '../lib';

regexDetailTokenizer(/a-z/i) // Outputs detailed tokens

License

©2021–present Jesse Wright, MIT License.