UNPKG

rivo

Version:

🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.

134 lines (118 loc) • 3.72 kB
import type AppendFn from "./Append"; import type CapitalizeFn from "./Capitalize"; import type ConcatFn from "./Concat"; import type EndsWithFn from "./EndsWith"; import type IsDigitFn from "./IsDigit"; import type LengthFn from "./Length"; import type PrependFn from "./Prepend"; import type RepeatFn from "./Repeat"; import type ReverseFn from "./Reverse"; import type SplitFn from "./Split"; import type StartsWithFn from "./StartsWith"; import type ToCamelCaseFn from "./ToCamelCase"; import type ToCharsFn from "./ToChars"; import type ToLowerFn from "./ToLower"; import type ToSnakeCaseFn from "./ToSnakeCase"; import type ToUpperFn from "./ToUpper"; import type TrimFn from "./Trim"; import type TrimLeftFn from "./TrimLeft"; import type TrimRightFn from "./TrimRight"; import type UncapitalizeFn from "./Uncapitalize"; import type { PartialApply } from "../HKT"; import type { Nat } from "../Num"; /*********** * Methods * ***********/ /** * Methods for `string`. */ export namespace Str { /** * [Fn] Append a string (the 1st argument) to another string (the 2nd argument). * * Sig: `[ext: string](s: string) => string` */ export type Append<Ext extends string> = PartialApply<AppendFn, [Ext]>; /** * [Fn] Prepend a string (the 1st argument) to another string (the 2nd argument). * * Sig: `[prefix: string](s: string) => string` */ export type Prepend<Prefix extends string> = PartialApply<PrependFn, [Prefix]>; /** * [Fn] Concatenate two strings. * * Sig: `(s1: string, s2: string) => string` */ export type Concat = ConcatFn; /** * [Fn] Check if a string is a digit (i.e. 0-9). * * Sig: `(s: string) => boolean` */ export type IsDigit = IsDigitFn; export type StartsWith<Prefix extends string> = PartialApply<StartsWithFn, [Prefix]>; export type EndsWith<Suffix extends string> = PartialApply<EndsWithFn, [Suffix]>; /** * [Fn] Returns a list of characters of a string. * * Sig: `(s: string) => List<string>` */ export type ToChars = ToCharsFn; export type Repeat<N extends Nat> = PartialApply<RepeatFn, [N]>; export type Capitalize = CapitalizeFn; export type Uncapitalize = UncapitalizeFn; /** * [Fn] Convert a string to uppercase. * * Sig: `(s: string) => string` */ export type ToUpper = ToUpperFn; /** * [Fn] Convert a string to lowercase. * * Sig: `(s: string) => string` */ export type ToLower = ToLowerFn; export type ToCamelCase = ToCamelCaseFn; export type ToSnakeCase = ToSnakeCaseFn; export type Trim<C extends string = Str$$BlankChar> = PartialApply<TrimFn, [C]>; export type TrimLeft<C extends string = Str$$BlankChar> = PartialApply<TrimLeftFn, [C]>; export type TrimRight<C extends string = Str$$BlankChar> = PartialApply<TrimRightFn, [C]>; /** * [Fn] Reverse a string. * * Sig: `(s: string) => string` */ export type Reverse = ReverseFn; /** * [Fn] Get the length of a string. The return type is a {@link Nat} (i.e., a natural * number). * * Sig: `(s: string) => Nat` */ export type Length = LengthFn; /** * [Fn] Split a string by a separator. * * Sig: `[sep: string](s: string) => List<string>` */ export type Split<Sep extends string> = PartialApply<SplitFn, [Sep]>; } /****************** * Static members * ******************/ /** * Empty string. */ export type Str$$Empty = ""; /** * A string that contains only whitespace characters. */ export type Str$$BlankChar = " " | "\t" | "\n" | "\r"; /**************** * Type classes * ****************/ export type { Str$$Monoid } from "./Monoid"; export type { Str$$Semigroup } from "./Semigroup"; export type { Str$$Show } from "./Show";