import { Call, ComposeLeft, Fn, PartialApply, unset, _ } from "../core/Core"; import { Std } from "../std/Std"; import { Tuples } from "../tuples/Tuples"; import * as H from "../helpers"; import * as Impl from "./impl/strings"; export declare namespace Strings { export type Stringifiable = string | number | boolean | bigint | null | undefined; /** * Get the length of a string. * @param args[0] - The string to get the length of. * @returns The length of the string. * @warning - 🔥 does not work with emojis since they are multiple characters 🔥 * @example * ```ts * type T0 = Call; // 3 * ``` */ export type Length = PartialApply; /** * Get the length of a string. * @param args[0] - The string to get the length of. * @returns The length of the string. * @warning - 🔥 does not work with emojis since they are multiple characters 🔥 * @example * ```ts * type T0 = Call; // 3 * ``` */ export interface LengthFn extends Fn { return: this["arg0"] extends string ? Impl.Length : never; } /** * Trim the left side of a string. * @param args[0] - The string to trim. * @param Sep - The separator to trim. * @returns The trimmed string. * @example * ```ts * type T0 = Call; // "abc" * ``` */ export type TrimLeft = PartialApply; interface TrimLeftFn extends Fn { return: this["args"] extends [ infer Sep extends string, infer Str extends string, ...any ] ? Impl.TrimLeft : never; } /** * Trim the right side of a string. * @param args[0] - The string to trim. * @param Sep - The separator to trim. * @returns The trimmed string. * @example * ```ts * type T0 = Call; // "abc" * ``` */ export type TrimRight = PartialApply; interface TrimRightFn extends Fn { return: this["args"] extends [ infer Sep extends string, infer Str extends string, ...any ] ? Impl.TrimRight : never; } /** * Trim a string. * @param args[0] - The string to trim. * @param Sep - The separator to trim. * @returns The trimmed string. * @example * ```ts * type T0 = Call; // "abc" * ``` */ export type Trim = PartialApply; interface TrimFn extends Fn { return: this["args"] extends [ infer Sep extends string, infer Str extends string, ...any ] ? Impl.Trim : never; } /** * Replace all instances of a substring in a string. * @param args[0] - The string to replace. * @param from - The substring to replace. * @param to - The substring to replace with. * @returns The replaced string. * @example * ```ts * type T0 = Call,"a.b.c.d">; // "a/b/c/d" */ export type Replace = PartialApply; interface ReplaceFn extends Fn { return: this["args"] extends [ infer From extends string, infer To extends string, infer Str, ...any ] ? Call, Str>, H.UnionToTuple> : never; } /** * Cut a slice of a string out from a start index to an end index. * @param args[0] - The string to slice. * @param start - The start index. * @param end - The end index. * @returns The sliced string. * @warning - 🔥 does not work with emojis since they are multiple characters 🔥 * @example * ```ts * type T0 = Call,"1234567890">; // "23456789" */ export type Slice = ComposeLeft<[ Strings.Split<"">, Tuples.Take, Tuples.Drop, Tuples.Join<""> ]>; /** * Split a string into a tuple of strings. * @param args[0] - The string to split. * @param sep - The separator to split the string with. * @returns The split string. * @warning - 🔥 using an empty sep with emojis in the string will destroy the emoji 🔥 * @example * ```ts * type T0 = Call,"a,b,c">; // ["a","b","c"] * ``` */ export type Split = PartialApply; export interface SplitFn extends Fn { return: this["args"] extends [infer Sep extends string, infer Str, ...any] ? Impl.Split : never; } /** * Repeat a string a number of times. * @param args[0] - The string to repeat. * @param times - The number of times to repeat the string. * @returns The repeated string. * @example * ```ts * type T0 = Call,"Hello! ">; // "Hello! Hello! Hello! " * ``` */ export type Repeat = PartialApply; interface RepeatFn extends Fn { return: this["args"] extends [ infer Times extends number, infer Str extends string ] ? Impl.Repeat : never; } /** * Check if a string starts with a substring. * @param args[0] - The string to check. * @param str - The substring to check for. * @returns Whether the string starts with the substring. * @example * ```ts * type T0 = Call,"abcdef">; // true * type T1 = Call,"defabc">; // false * ``` */ export type StartsWith = PartialApply; interface StartsWithFn extends Fn { return: this["args"] extends [infer Start extends string, infer Str] ? Str extends `${Start}${string}` ? true : false : never; } /** * Check if a string ends with a substring. * @param args[0] - The string to check. * @param str - The substring to check for. * @returns Whether the string ends with the substring. * @example * ```ts * type T0 = Call,"abcdef">; // false * type T1 = Call,"defabc">; // true * ``` */ export type EndsWith = PartialApply; interface EndsWithFn extends Fn { return: this["args"] extends [infer End extends string, infer Str] ? Str extends `${string}${End}` ? true : false : never; } /** * Split a string into a tuple of each character. * @param args[0] - The string to split. * @returns The splited string. * @warning - 🔥 does not work with emojis since they are multiple characters 🔥 * @example * ```ts * type T0 = Call; // ["a","b","c"] * ``` */ export interface ToTuple extends Fn { return: Impl.StringToTuple; } /** * Convert a string to a number or bigint. * @param args[0] - The string to convert. * @returns The converted number or bigint. * @example * ```ts * type T0 = Call; // 123 * type T1 = Call; // 12367543547677078675456656790n * ``` */ export interface ToNumber extends Fn { return: this["arg0"] extends `${infer n extends number | bigint}` ? n : never; } /** * Convert a stringifiable literal to a string. * @param args[0] - The stringifiable literal to convert. * @returns The converted string. * @example * ```ts * type T0 = Call; // "123" * type T1 = Call; // "true" * type T2 = Call; // "null" * ``` */ export interface ToString extends Fn { return: `${Extract}`; } /** * Prepend a string to another string. * @param args[0] - The string to be prepended to. * @param str - The string to prepend. * @returns The prepended string. * @example * ```ts * type T0 = Call,"def">; // "abcdef" * ``` */ export type Prepend = PartialApply; interface PrependFn extends Fn { return: `${Extract}${Extract}`; } /** * Append a string to another string. * @param args[0] - The string to be appended to. * @param str - The string to append. * @returns The appended string. * @example * ```ts * type T0 = Call,"def">; // "defabc" * ``` */ export type Append = PartialApply; interface AppendFn extends Fn { return: `${Extract}${Extract}`; } /** * Transform a string to uppercase. * @param args[0] - The string to transform. * @returns The transformed string. * @example * ```ts * type T0 = Call; // "ABC" * ``` */ export interface Uppercase extends Fn { return: Std._Uppercase>; } /** * Transform a string to lowercase. * @param args[0] - The string to transform. * @returns The transformed string. * @example * ```ts * type T0 = Call; // "abc" * ``` */ export interface Lowercase extends Fn { return: Std._Lowercase>; } /** * Capitalize a string. * @param args[0] - The string to capitalize. * @returns The capitalized string. * @example * ```ts * type T0 = Call; // "Abc" * ``` */ export interface Capitalize extends Fn { return: Std._Capitalize>; } /** * Uncapitalize a string. * @param args[0] - The string to uncapitalize. * @returns The uncapitalized string. * @example * ```ts * type T0 = Call; // "addTop" * ``` */ export interface Uncapitalize extends Fn { return: Std._Uncapitalize>; } /** * Convert a string to snake case. * @param args[0] - The string to convert. * @returns The converted string. * @example * ```ts * type T0 = Call; // "add_top" * ``` */ export interface SnakeCase extends Fn { return: H.SnakeCase; } /** * Convert a string to camel case. * @param args[0] - The string to convert. * @returns The converted string. * @example * ```ts * type T0 = Call; // "addTop" * ``` */ export interface CamelCase extends Fn { return: H.CamelCase; } /** * Convert a string to kebab case. * @param args[0] - The string to convert. * @returns The converted string. * @example * ```ts * type T0 = Call; // "add-top" * type T1 = Call; // "add-top" * type T2 = Call; // "add-top" * ``` */ export interface KebabCase extends Fn { return: H.KebabCase; } /** * Compare two strings. (only works with ascii extended characters) * @param args[0] - The first string to compare. * @param args[1] - The second string to compare. * @n1 - The first string to compare or _. * @n2 - The second string to compare or _. * @returns The result of the comparison. * @example * ```ts * type T0 = Call; // -1 * type T1 = Call; // 1 * type T2 = Call; // 0 * ``` */ export type Compare = PartialApply; interface CompareFn extends Fn { return: this["args"] extends [ infer a extends string, infer b extends string, ...any ] ? Impl.Compare : never; } /** * Check if a string is lexically less than another string. (only works with ascii extended characters) * @param args[0] - The first string to compare. * @param args[1] - The second string to compare. * @n1 - The first string to compare or _. * @n2 - The second string to compare or _. * @returns True if the first string is lexically less than the second string, false otherwise. * @example * ```ts * type T0 = Call; // true * type T1 = Call; // false * type T2 = Call; // false * ``` */ export type LessThan = PartialApply; interface LessThanFn extends Fn { return: this["args"] extends [ infer a extends string, infer b extends string, ...any ] ? Impl.LessThan : never; } /** * Check if a string is lexically less than or equal to another string. (only works with ascii extended characters) * @param args[0] - The first string to compare. * @param args[1] - The second string to compare. * @n1 - The first string to compare or _. * @n2 - The second string to compare or _. * @returns True if the first string is lexically less than or equal to the second string, false otherwise. * @example * ```ts * type T0 = Call; // true * type T1 = Call; // false * type T2 = Call; // true */ export type LessThanOrEqual = PartialApply; interface LessThanOrEqualFn extends Fn { return: this["args"] extends [ infer a extends string, infer b extends string, ...any ] ? Impl.LessThanOrEqual : never; } /** * Check if a string is lexically greater than another string. (only works with ascii extended characters) * @param args[0] - The first string to compare. * @param args[1] - The second string to compare. * @n1 - The first string to compare or _. * @n2 - The second string to compare or _. * @returns True if the first string is lexically greater than the second string, false otherwise. * @example * ```ts * type T0 = Call; // false * type T1 = Call; // true * type T2 = Call; // false * ``` */ export type GreaterThan = PartialApply; interface GreaterThanFn extends Fn { return: this["args"] extends [ infer a extends string, infer b extends string, ...any ] ? Impl.GreaterThan : never; } /** * Check if a string is lexically greater than or equal to another string. (only works with ascii extended characters) * @param args[0] - The first string to compare. * @param args[1] - The second string to compare. * @n1 - The first string to compare or _. * @n2 - The second string to compare or _. * @returns True if the first string is lexically greater than or equal to the second string, false otherwise. * @example * ```ts * type T0 = Call; // false * type T1 = Call; // true * type T2 = Call; // true * ``` */ export type GreaterThanOrEqual = PartialApply; interface GreaterThanOrEqualFn extends Fn { return: this["args"] extends [ infer a extends string, infer b extends string, ...any ] ? Impl.GreaterThanOrEqual : never; } export {}; }