Skip to content

Commit

Permalink
fix: decrease type complexity somewhat
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jun 4, 2024
1 parent e57b322 commit fc3e203
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Input } from './internal'
import type { CharInput, Input } from './internal'
import { createInput } from './internal'
import type { EscapeChar } from './types/escape'
import type { Join } from './types/join'
Expand All @@ -14,7 +14,7 @@ function createCharInput <T extends string>(raw: T) {
const input = createInput(`[${raw}]`)
const from = <From extends string, To extends string>(charFrom: From, charTo: To) => createCharInput(`${raw}${escapeCharInput(charFrom)}-${escapeCharInput(charTo)}`)
const orChar = Object.assign((<T extends string>(chars: T) => createCharInput(`${raw}${escapeCharInput(chars)}`)), { from })
return Object.assign(input, { orChar, from })
return Object.assign(input, { orChar, from }) as CharInput<T>
}

function escapeCharInput <T extends string>(raw: T) {
Expand Down
6 changes: 6 additions & 0 deletions src/core/internal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { exactly } from './inputs'
import { EscapeChar } from './types/escape'
import type { Join } from './types/join'
import type { InputSource, MapToCapturedGroupsArr, MapToGroups, MapToValues } from './types/sources'
import type { IfUnwrapped } from './wrap'
Expand Down Expand Up @@ -134,6 +135,11 @@ export interface Input<
toString: () => string
}

export interface CharInput<T extends string> extends Input<`[${T}]`> {
orChar: (<Or extends string>(chars: Or) => CharInput<`${T}${EscapeChar<Or>}`>) & CharInput<T>
from: <From extends string, To extends string>(charFrom: From, charTo: To) => CharInput<`${T}${EscapeChar<From>}-${EscapeChar<To>}`>
}

export function createInput<
Value extends string,
Groups extends string = never,
Expand Down

0 comments on commit fc3e203

Please sign in to comment.