@sv443-network/coreutils
Version:
Cross-platform, general-purpose, JavaScript core library for Node, Deno and the browser. Intended to be used in conjunction with `@sv443-network/userutils` and `@sv443-network/djsutils`, but can be used independently as well.
42 lines (41 loc) • 3.04 kB
TypeScript
import type { ListLike, Prettify, Stringifiable } from "./types.js";
/**
* Automatically pluralizes the given string an `-s` or `-ies` to the passed {@linkcode term}, if {@linkcode num} is not equal to 1.
* By default, words ending in `-y` will have it replaced with `-ies`, and all other words will simply have `-s` appended.
* If {@linkcode num} resolves to NaN or the {@linkcode pluralType} is wrong, it defaults to the {@linkcode pluralType} `auto` and sets {@linkcode num} to 2.
* @param term The term, written in singular form, to auto-convert to plural form
* @param num A number, or list-like value that has either a `length`, `count` or `size` property, like an array, Map or discord.js Collection - does not support iterables, they need to be converted to an array first
* @param pluralType Which plural form to use when auto-pluralizing. Defaults to `"auto"`, which removes the last char and uses `-ies` for words ending in `y` and simply appends `-s` for all other words
*/
export declare function autoPlural(term: Stringifiable, num: number | ListLike, pluralType?: "auto" | "-s" | "-ies"): string;
/** Capitalizes the first letter of a string */
export declare function capitalize(text: string): string;
/** The default progress bar characters used by {@linkcode createProgressBar()} */
export declare const defaultPbChars: {
readonly 100: "█";
readonly 75: "▓";
readonly 50: "▒";
readonly 25: "░";
readonly 0: "─";
};
/** Progress bar characters used by {@linkcode createProgressBar()} */
export type ProgressBarChars = Prettify<Record<keyof typeof defaultPbChars, string>>;
/**
* Generates a progress bar with the given percentage and max length.
* Uses opaque, dithered unicode block characters by default for extra detail.
* Use {@linkcode chars} to override the default characters (for example, use emojis via `<:emoji:ID>` or `😃`)
*/
export declare function createProgressBar(percentage: number, barLength: number, chars?: ProgressBarChars): string;
/**
* Inserts the passed values into a string at the respective placeholders.
* The placeholder format is `%n`, where `n` is the 1-indexed argument number.
* @param input The string to insert the values into
* @param values The values to insert, in order, starting at `%1`
*/
export declare function insertValues(input: string, ...values: Stringifiable[]): string;
/** Joins an array of strings with a separator and a last separator - defaults to `,` & `and` */
export declare function joinArrayReadable(array: unknown[], separators?: string, lastSeparator?: string): string;
/** Converts seconds into the timestamp format `(hh:)mm:ss`, with intelligent zero-padding */
export declare function secsToTimeStr(seconds: number): string;
/** Truncates a string if it exceeds `length` and inserts `endStr` at the end (empty string to disable), so that the final string doesn't exceed the given length */
export declare function truncStr(input: Stringifiable, length: number, endStr?: string): string;