Skip to content

Commit 6fbf967

Browse files
committed
docs: add jsdocs for inputs
1 parent 095ed0a commit 6fbf967

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/core/inputs.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
import { createInput } from './internal'
22

33
export interface Input<T extends string = never> {
4+
/** this adds a new pattern to the current input */
45
and: <X extends string = never>(input: string | Input<X>) => Input<T | X>
6+
/** this provides an alternative to the current input */
57
or: <X extends string = never>(input: string | Input<X>) => Input<T | X>
8+
/** this is a positive lookbehind. Make sure to check [browser support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#browser_compatibility) as not all browsers support lookbehinds (notably Safari) */
69
after: (input: string | Input) => Input<T>
10+
/** this is a positive lookahead */
711
before: (input: string | Input) => Input<T>
12+
/** these is a negative lookbehind. Make sure to check [browser support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#browser_compatibility) as not all browsers support lookbehinds (notably Safari) */
813
notAfter: (input: string | Input) => Input<T>
14+
/** this is a negative lookahead */
915
notBefore: (input: string | Input) => Input<T>
1016
times: {
17+
/** repeat the previous pattern an exact number of times */
1118
(number: number): Input<T>
19+
/** specify a range of times to repeat the previous pattern */
1220
between: (min: number, max: number) => Input<T>
1321
}
22+
/** this defines the entire input so far as a named capture group. You will get type safety when using the resulting RegExp with `String.match()` */
1423
as: <K extends string>(key: K) => Input<T | K>
24+
/** this allows you to match beginning/ends of lines with `at.lineStart()` and `at.lineEnd()` */
1525
at: {
1626
lineStart: () => Input<T>
1727
lineEnd: () => Input<T>
1828
}
1929
toString: () => string
2030
}
2131

32+
/** This matches any character in the string provided */
2233
export const charIn = (chars: string) => createInput(`[${chars.replace(/[-\\^\]]/g, '\\$&')}]`)
34+
/** This matches any character that is not in the string provided */
2335
export const charNotIn = (chars: string) => createInput(`[^${chars.replace(/[-\\^\]]/g, '\\$&')}]`)
36+
/** This takes an array of inputs and matches any of them. */
2437
export const anyOf = <T extends string = never>(...args: Array<string | Input<T>>) =>
2538
createInput<T>(`(${args.map(a => exactly(a)).join('|')})`)
2639

@@ -43,6 +56,8 @@ export const not = {
4356
carriageReturn: createInput('[^\\r]'),
4457
}
4558

59+
/** Equivalent to `?` - this marks the input as optional */
4660
export const maybe = (str: string | Input) => createInput(`(${exactly(str)})?`)
61+
/** This escapes a string input to match it exactly */
4762
export const exactly = (str: string | Input) =>
4863
typeof str === 'string' ? createInput(str.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&')) : str

0 commit comments

Comments
 (0)