Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

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

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

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, "">