@sv443-network/userutils 9.4.3 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,69 +0,0 @@
1
- /**
2
- * @module lib/misc
3
- * This module contains miscellaneous functions that don't fit in another category - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#misc)
4
- */
5
- import type { ListWithLength, Prettify, Stringifiable } from "./types.js";
6
- /** Which plural form to use when auto-pluralizing */
7
- export type PluralType = "auto" | "-s" | "-ies";
8
- /**
9
- * Automatically pluralizes the given string by adding an `-s` or `-ies` to the passed {@linkcode term}, if {@linkcode num} is not equal to 1.
10
- * By default, words ending in `-y` will have it replaced with `-ies`, and all other words will simply have `-s` appended.
11
- * {@linkcode pluralType} will default to `auto` if invalid and {@linkcode num} is set to 2 if it resolves to `NaN`.
12
- * @param term The term, written in singular form, to auto-convert to plural form
13
- * @param num A number, or list-like value that has either a `length`, `count` or `size` property, like an array, Map or NodeList - does not support iterables, they need to be converted to an array first
14
- * @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
15
- */
16
- export declare function autoPlural(term: Stringifiable, num: number | ListWithLength, pluralType?: PluralType): string;
17
- /**
18
- * Inserts the passed values into a string at the respective placeholders.
19
- * The placeholder format is `%n`, where `n` is the 1-indexed argument number.
20
- * @param input The string to insert the values into
21
- * @param values The values to insert, in order, starting at `%1`
22
- */
23
- export declare function insertValues(input: string, ...values: Stringifiable[]): string;
24
- /**
25
- * Pauses async execution for the specified time in ms.
26
- * If an `AbortSignal` is passed, the pause will be aborted when the signal is triggered.
27
- * By default, this will resolve the promise, but you can set {@linkcode rejectOnAbort} to true to reject it instead.
28
- */
29
- export declare function pauseFor(time: number, signal?: AbortSignal, rejectOnAbort?: boolean): Promise<void>;
30
- /** Options for the `fetchAdvanced()` function */
31
- export type FetchAdvancedOpts = Prettify<Partial<{
32
- /** Timeout in milliseconds after which the fetch call will be canceled with an AbortController signal */
33
- timeout: number;
34
- }> & RequestInit>;
35
- /** Calls the fetch API with special options like a timeout */
36
- export declare function fetchAdvanced(input: string | RequestInfo | URL, options?: FetchAdvancedOpts): Promise<Response>;
37
- /**
38
- * A ValueGen value is either its type, a promise that resolves to its type, or a function that returns its type, either synchronous or asynchronous.
39
- * ValueGen allows for the utmost flexibility when applied to any type, as long as {@linkcode consumeGen()} is used to get the final value.
40
- * @template TValueType The type of the value that the ValueGen should yield
41
- */
42
- export type ValueGen<TValueType> = TValueType | Promise<TValueType> | (() => TValueType | Promise<TValueType>);
43
- /**
44
- * Turns a {@linkcode ValueGen} into its final value.
45
- * @template TValueType The type of the value that the ValueGen should yield
46
- */
47
- export declare function consumeGen<TValueType>(valGen: ValueGen<TValueType>): Promise<TValueType>;
48
- /**
49
- * A StringGen value is either a string, anything that can be converted to a string, or a function that returns one of the previous two, either synchronous or asynchronous, or a promise that returns a string.
50
- * StringGen allows for the utmost flexibility when dealing with strings, as long as {@linkcode consumeStringGen()} is used to get the final string.
51
- */
52
- export type StringGen = ValueGen<Stringifiable>;
53
- /**
54
- * Turns a {@linkcode StringGen} into its final string value.
55
- * @template TStrUnion The union of strings that the StringGen should yield - this allows for finer type control compared to {@linkcode consumeGen()}
56
- */
57
- export declare function consumeStringGen<TStrUnion extends string>(strGen: StringGen): Promise<TStrUnion>;
58
- /**
59
- * Returns the length of the given list-like object (anything with a numeric `length`, `size` or `count` property, like an array, Map or NodeList).
60
- * If the object doesn't have any of these properties, it will return 0 by default.
61
- * Set {@linkcode zeroOnInvalid} to false to return NaN instead of 0 if the object doesn't have any of the properties.
62
- */
63
- export declare function getListLength(obj: ListWithLength, zeroOnInvalid?: boolean): number;
64
- /**
65
- * Turns the passed object into a "pure" object without a prototype chain, meaning it won't have any default properties like `toString`, `__proto__`, `__defineGetter__`, etc.
66
- * This makes the object immune to prototype pollution attacks and allows for cleaner object literals, at the cost of being harder to work with in some cases.
67
- * It also effectively transforms a `Stringifiable` value into one that will throw a TypeError when stringified instead of defaulting to `[object Object]`
68
- */
69
- export declare function purifyObj<TObj extends object>(obj: TObj): TObj;
@@ -1,38 +0,0 @@
1
- /**
2
- * @module lib/types
3
- * This module contains various TS types - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#utility-types)
4
- */
5
- /** Represents any value that is either a string itself or can be converted to one (implicitly and explicitly) because it has a toString() method */
6
- export type Stringifiable = string | {
7
- toString(): string;
8
- } | {
9
- [Symbol.toStringTag]: string;
10
- } | number | boolean | null | undefined;
11
- /**
12
- * A type that offers autocomplete for the passed union but also allows any arbitrary value of the same type to be passed.
13
- * Supports unions of strings, numbers and objects.
14
- */
15
- export type LooseUnion<TUnion extends string | number | object> = (TUnion) | (TUnion extends string ? (string & {}) : (TUnion extends number ? (number & {}) : (TUnion extends Record<keyof any, unknown> ? (object & {}) : never)));
16
- /**
17
- * A type that allows all strings except for empty ones
18
- * @example
19
- * function foo<T extends string>(bar: NonEmptyString<T>) {
20
- * console.log(bar);
21
- * }
22
- */
23
- export type NonEmptyString<TString extends string> = TString extends "" ? never : TString;
24
- /**
25
- * Makes the structure of a type more readable by expanding it.
26
- * This can be useful for debugging or for improving the readability of complex types.
27
- */
28
- export type Prettify<T> = {
29
- [K in keyof T]: T[K];
30
- } & {};
31
- /** Any value that is list-like, i.e. has a numeric length, count or size property */
32
- export type ListWithLength = {
33
- length: number;
34
- } | {
35
- count: number;
36
- } | {
37
- size: number;
38
- };