Skip to main content
Module

x/rimbu/typical/mod.ts>Str.RepeatExactTimes

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
type alias Str.RepeatExactTimes
import { type Str } from "https://deno.land/x/rimbu@0.12.3/typical/mod.ts";
const { RepeatExactTimes } = Str;

Returns a tuple containing the matched part and the rest of the given string if the string start repeats the given Sub exactly N times.

Examples

Example 1

RepeatExactTimes<'aabc', 'a', 0> => false
RepeatExactTimes<'aabc', 'a', 1> => false
RepeatExactTimes<'aabc', 'a', 2> => ['aa', 'bc']
RepeatExactTimes<'aabc', 'a', 3> => false
RepeatExactTimes<'aabc', 'a' | 'b', 3> => ['aab', 'c']

Type Parameters

S extends string
Sub extends string & NonEmptyString<Sub>
N extends number
definition: RepeatExactTimesHelper<S, Sub, N, "">