Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/rimbu/typical/str.ts>RepeatAtMostTimes

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

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

Examples

Example 1

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

Type Parameters

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