@sv443-network/coreutils 3.4.0 → 3.5.1
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.
- package/CHANGELOG.md +16 -0
- package/README.md +11 -4
- package/dist/CoreUtils.cjs +170 -0
- package/dist/CoreUtils.min.cjs +4 -3
- package/dist/CoreUtils.min.mjs +4 -3
- package/dist/CoreUtils.min.umd.js +4 -3
- package/dist/CoreUtils.mjs +170 -0
- package/dist/CoreUtils.umd.js +751 -461
- package/dist/lib/DataStoreSerializer.d.ts +4 -4
- package/dist/lib/text.d.ts +65 -0
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @module DataStoreSerializer
|
|
3
3
|
* This module contains the DataStoreSerializer class, which allows you to import and export serialized DataStore data - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#datastoreserializer)
|
|
4
4
|
*/
|
|
5
|
-
import type { DataStore
|
|
5
|
+
import type { DataStore } from "./DataStore.ts";
|
|
6
6
|
/** Options for the DataStoreSerializer class */
|
|
7
7
|
export type DataStoreSerializerOptions = {
|
|
8
8
|
/** Whether to add a checksum to the exported data. Defaults to `true` */
|
|
@@ -44,9 +44,9 @@ export type StoreFilter = string[] | ((id: string) => boolean);
|
|
|
44
44
|
* - ⚠️ Needs to run in a secure context (HTTPS) due to the use of the SubtleCrypto API if checksumming is enabled.
|
|
45
45
|
*/
|
|
46
46
|
export declare class DataStoreSerializer {
|
|
47
|
-
protected stores: DataStore<
|
|
47
|
+
protected stores: DataStore<any, boolean>[];
|
|
48
48
|
protected options: Required<DataStoreSerializerOptions>;
|
|
49
|
-
constructor(stores: DataStore<
|
|
49
|
+
constructor(stores: DataStore<any, boolean>[], options?: DataStoreSerializerOptions);
|
|
50
50
|
/**
|
|
51
51
|
* Calculates the checksum of a string. Uses {@linkcode computeHash()} with SHA-256 and digests as a hex string by default.
|
|
52
52
|
* Override this in a subclass if a custom checksum method is needed.
|
|
@@ -118,5 +118,5 @@ export declare class DataStoreSerializer {
|
|
|
118
118
|
/** Checks if a given value is a SerializedDataStore object */
|
|
119
119
|
static isSerializedDataStoreObj(obj: unknown): obj is SerializedDataStore;
|
|
120
120
|
/** Returns the DataStore instances whose IDs match the provided array or function */
|
|
121
|
-
protected getStoresFiltered(stores?: StoreFilter): DataStore<
|
|
121
|
+
protected getStoresFiltered(stores?: StoreFilter): DataStore<any, boolean>[];
|
|
122
122
|
}
|
package/dist/lib/text.d.ts
CHANGED
|
@@ -39,3 +39,68 @@ export declare function joinArrayReadable(array: unknown[], separators?: string,
|
|
|
39
39
|
export declare function secsToTimeStr(seconds: number): string;
|
|
40
40
|
/** 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 */
|
|
41
41
|
export declare function truncStr(input: Stringifiable, length: number, endStr?: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Border styles for the `lineStyle` option of the {@linkcode createTable} function.
|
|
44
|
+
*
|
|
45
|
+
* | Style | Example |
|
|
46
|
+
* | :-- | :-- |
|
|
47
|
+
* | `single` | `┌──────┬──────┐` |
|
|
48
|
+
* | `double` | `╔══════╦══════╗` |
|
|
49
|
+
* | `none` | |
|
|
50
|
+
*/
|
|
51
|
+
export type TableLineStyle = "single" | "double" | "none";
|
|
52
|
+
/**
|
|
53
|
+
* How to align cell content in a column for the `columnAlign` option of the {@linkcode createTable} function.
|
|
54
|
+
*
|
|
55
|
+
* | Alignment | Example | Description |
|
|
56
|
+
* | :-- | :-- | :-- |
|
|
57
|
+
* | `left` | `│.Text....│` | Hugs the left border, with padding determined by `minPadding`. |
|
|
58
|
+
* | `centerLeft` | `│..Text...│` | In the center, but if the padding is uneven, favors the left side. |
|
|
59
|
+
* | `centerRight` | `│...Text..│` | In the center, but if the padding is uneven, favors the right side. |
|
|
60
|
+
* | `right` | `│....Text.│` | Hugs the right border, with padding determined by `minPadding`. |
|
|
61
|
+
*/
|
|
62
|
+
export type TableColumnAlign = "left" | "centerLeft" | "centerRight" | "right";
|
|
63
|
+
/** Options for the {@linkcode createTable} function. */
|
|
64
|
+
export type TableOptions = {
|
|
65
|
+
/** Alignment for each column, either a single value to apply to all columns or an array of values for each column. Defaults to `left`. */
|
|
66
|
+
columnAlign?: TableColumnAlign | TableColumnAlign[];
|
|
67
|
+
/** If set, cell content that exceeds this width will be truncated with the value of `truncEndStr` (defaults to `…`) so that the final cell content doesn't exceed this width. */
|
|
68
|
+
truncateAbove?: number;
|
|
69
|
+
/** The string to append to truncated cell content if `truncateAbove` is set. Defaults to `…`. */
|
|
70
|
+
truncEndStr?: string;
|
|
71
|
+
/** Minimum padding to add to the left and right of cell content, regardless of alignment settings. Defaults to 1, set to 0 to disable. */
|
|
72
|
+
minPadding?: number;
|
|
73
|
+
/** Which kind of line characters to use for the border of the table. Defaults to `single` (`┌──────┬──────┐`). */
|
|
74
|
+
lineStyle?: TableLineStyle;
|
|
75
|
+
/** Can be used to change the characters used for the lines dividing cells in the table. If not set, {@linkcode defaultTableLineCharset} will be used. */
|
|
76
|
+
lineCharset?: TableLineCharset;
|
|
77
|
+
/**
|
|
78
|
+
* Can be used to add custom values like ANSI color codes to the lines dividing cells.
|
|
79
|
+
* Function gets passed the row index (i) and column index (j) of the character being rendered.
|
|
80
|
+
* Note that each row renders three rows of characters, so the row index (i) is not the same as the index of the row in the input array, but can be used to determine it with `Math.floor(i / 3)`.
|
|
81
|
+
* The first value of the returned tuple will be added before the line character and the second value will be added after.
|
|
82
|
+
* Return an empty array to not apply any custom styling.
|
|
83
|
+
*/
|
|
84
|
+
applyLineStyle?: (i: number, j: number) => [before?: string, after?: string] | void;
|
|
85
|
+
/**
|
|
86
|
+
* Can be used to add custom values like ANSI color codes to the cell content.
|
|
87
|
+
* Function gets passed the row index (i) and column index (j) of the cell being rendered.
|
|
88
|
+
* Note: cell width is calculated before applying this style, so characters with non-zero width will mess up the alignment and border placement.
|
|
89
|
+
* The first value of the returned tuple will be added before the cell content and the second value will be added after.
|
|
90
|
+
* Return an empty array to not apply any custom styling.
|
|
91
|
+
*/
|
|
92
|
+
applyCellStyle?: (i: number, j: number) => [before?: string, after?: string] | void;
|
|
93
|
+
};
|
|
94
|
+
/** Characters to use for the lines dividing cells in the table generated by {@linkcode createTable}, based on the `lineStyle` option. */
|
|
95
|
+
export type TableLineStyleChars = Record<"horizontal" | "vertical" | `${"top" | "bottom"}${"Left" | "Right"}` | `${"left" | "right" | "top" | "bottom"}T` | "cross", string>;
|
|
96
|
+
/** The characters to use for the lines dividing cells in the table generated by {@linkcode createTable}, based on the `lineStyle` option. */
|
|
97
|
+
export type TableLineCharset = Record<TableLineStyle, TableLineStyleChars>;
|
|
98
|
+
/** The default characters to use for the lines dividing cells in the table generated by {@linkcode createTable}, based on the `lineStyle` option. */
|
|
99
|
+
export declare const defaultTableLineCharset: TableLineCharset;
|
|
100
|
+
/**
|
|
101
|
+
* Creates an ASCII table string from the given rows and options.
|
|
102
|
+
* Supports ANSI color codes in cell content: they are ignored for width calculation, included in the final output, and handled correctly during truncation (escape sequences are never split; any open color code is closed with a reset).
|
|
103
|
+
* @param rows Array of tuples, where each tuple represents a row and its values. The first tuple is used to determine the column count.
|
|
104
|
+
* @param options Object with options for customizing the table output, such as column alignment, truncation, padding and line styles.
|
|
105
|
+
*/
|
|
106
|
+
export declare function createTable<TRow extends [...Stringifiable[]]>(rows: TRow[], options?: TableOptions): string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sv443-network/coreutils",
|
|
3
3
|
"libName": "@sv443-network/coreutils",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.5.1",
|
|
5
5
|
"description": "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.",
|
|
6
6
|
"main": "dist/CoreUtils.cjs",
|
|
7
7
|
"module": "dist/CoreUtils.mjs",
|