Skip to content

Commit

Permalink
feat: expose flags as literal types
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jul 18, 2022
1 parent 80beebd commit 0c7bec7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/core/flags.ts
Expand Up @@ -3,22 +3,22 @@
export type Flag = 'd' | 'g' | 'i' | 'm' | 's' | 'u' | 'y'

/** Generate indices for substring matches */
export const withIndices: Flag = 'd'
export const withIndices = 'd'

/** Case-insensitive search */
export const caseInsensitive: Flag = 'i'
export const caseInsensitive = 'i'

/** Global search */
export const global: Flag = 'g'
export const global = 'g'

/** Multi-line search */
export const multiline: Flag = 'm'
export const multiline = 'm'

/** Allows `.` to match newline characters */
export const dotAll: Flag = 's'
export const dotAll = 's'

/** Treat a pattern as a sequence of unicode code points */
export const unicode: Flag = 'u'
export const unicode = 'u'

/** Perform a "sticky" search that matches starting at the current position in the target string */
export const sticky: Flag = 'y'
export const sticky = 'y'
12 changes: 12 additions & 0 deletions test/flags.test.ts
@@ -0,0 +1,12 @@
import { it, describe } from 'vitest'
import { expectTypeOf } from 'expect-type'
import * as flags from '../src/core/flags'
import type { Flag } from '../src/core/flags'

type ValueOf<T> = T[keyof T]

describe('flags', () => {
it('are all present', () => {
expectTypeOf<Flag>().toMatchTypeOf<ValueOf<typeof flags>>()
})
})

0 comments on commit 0c7bec7

Please sign in to comment.