Skip to content

Commit 0c7bec7

Browse files
committed
feat: expose flags as literal types
1 parent 80beebd commit 0c7bec7

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/core/flags.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
export type Flag = 'd' | 'g' | 'i' | 'm' | 's' | 'u' | 'y'
44

55
/** Generate indices for substring matches */
6-
export const withIndices: Flag = 'd'
6+
export const withIndices = 'd'
77

88
/** Case-insensitive search */
9-
export const caseInsensitive: Flag = 'i'
9+
export const caseInsensitive = 'i'
1010

1111
/** Global search */
12-
export const global: Flag = 'g'
12+
export const global = 'g'
1313

1414
/** Multi-line search */
15-
export const multiline: Flag = 'm'
15+
export const multiline = 'm'
1616

1717
/** Allows `.` to match newline characters */
18-
export const dotAll: Flag = 's'
18+
export const dotAll = 's'
1919

2020
/** Treat a pattern as a sequence of unicode code points */
21-
export const unicode: Flag = 'u'
21+
export const unicode = 'u'
2222

2323
/** Perform a "sticky" search that matches starting at the current position in the target string */
24-
export const sticky: Flag = 'y'
24+
export const sticky = 'y'

test/flags.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { it, describe } from 'vitest'
2+
import { expectTypeOf } from 'expect-type'
3+
import * as flags from '../src/core/flags'
4+
import type { Flag } from '../src/core/flags'
5+
6+
type ValueOf<T> = T[keyof T]
7+
8+
describe('flags', () => {
9+
it('are all present', () => {
10+
expectTypeOf<Flag>().toMatchTypeOf<ValueOf<typeof flags>>()
11+
})
12+
})

0 commit comments

Comments
 (0)