@sv443-network/userutils 9.0.1 → 9.0.3
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 +13 -0
- package/dist/index.global.js +1 -1
- package/dist/lib/DataStore.d.ts +8 -1
- package/dist/lib/DataStoreSerializer.d.ts +4 -0
- package/dist/lib/Debouncer.d.ts +19 -12
- package/dist/lib/Dialog.d.ts +4 -0
- package/dist/lib/NanoEmitter.d.ts +4 -0
- package/dist/lib/SelectorObserver.d.ts +4 -0
- package/dist/lib/array.d.ts +4 -0
- package/dist/lib/colors.d.ts +4 -0
- package/dist/lib/crypto.d.ts +4 -0
- package/dist/lib/dom.d.ts +4 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/math.d.ts +4 -0
- package/dist/lib/misc.d.ts +4 -0
- package/dist/lib/translation.d.ts +4 -0
- package/dist/lib/types.d.ts +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @sv443-network/userutils
|
|
2
2
|
|
|
3
|
+
## 9.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e3f1e6a: Fixed `Debouncer` TS types as to not break backwards compat
|
|
8
|
+
- 5861bb4: Fixed broken ambiguity of DataStore's migration function type
|
|
9
|
+
|
|
10
|
+
## 9.0.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 69c4dd1: Fixed wrong readme being included in JSR package and added `@module` comments
|
|
15
|
+
|
|
3
16
|
## 9.0.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.global.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// ==UserLibrary==
|
|
9
9
|
// @name UserUtils
|
|
10
10
|
// @description Lightweight library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more
|
|
11
|
-
// @version 9.0.
|
|
11
|
+
// @version 9.0.3
|
|
12
12
|
// @license MIT
|
|
13
13
|
// @copyright Sv443 (https://github.com/Sv443)
|
|
14
14
|
|
package/dist/lib/DataStore.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/DataStore
|
|
3
|
+
* This module contains the DataStore class, which is a general purpose, sync and async persistent JSON database - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#datastore)
|
|
4
|
+
*/
|
|
1
5
|
import type { Prettify } from "./types.js";
|
|
6
|
+
/** Function that takes the data in the old format and returns the data in the new format. Also supports an asynchronous migration. */
|
|
7
|
+
type MigrationFunc = (oldData: any) => any | Promise<any>;
|
|
2
8
|
/** Dictionary of format version numbers and the function that migrates to them from the previous whole integer */
|
|
3
|
-
export type DataMigrationsDict = Record<number,
|
|
9
|
+
export type DataMigrationsDict = Record<number, MigrationFunc>;
|
|
4
10
|
/** Options for the DataStore instance */
|
|
5
11
|
export type DataStoreOptions<TData> = Prettify<{
|
|
6
12
|
/**
|
|
@@ -155,3 +161,4 @@ export declare class DataStore<TData extends object = object> {
|
|
|
155
161
|
/** Deletes a value from persistent storage - can be overwritten in a subclass if you want to use something other than the default storage methods */
|
|
156
162
|
protected deleteValue(name: string): Promise<void>;
|
|
157
163
|
}
|
|
164
|
+
export {};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/DataStoreSerializer
|
|
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
|
+
*/
|
|
1
5
|
import { type DataStore } from "./index.js";
|
|
2
6
|
export type DataStoreSerializerOptions = {
|
|
3
7
|
/** Whether to add a checksum to the exported data */
|
package/dist/lib/Debouncer.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/Debouncer
|
|
3
|
+
* This module contains the Debouncer class and debounce function that allow you to reduce the amount of calls in rapidly firing event listeners and such - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#debouncer)
|
|
4
|
+
*/
|
|
1
5
|
import { NanoEmitter } from "./NanoEmitter.js";
|
|
2
6
|
/**
|
|
3
7
|
* The type of edge to use for the debouncer - [see the docs for a diagram and explanation.](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#debouncer)
|
|
@@ -14,11 +18,15 @@ import { NanoEmitter } from "./NanoEmitter.js";
|
|
|
14
18
|
* - Calls could get stuck in the queue indefinitely if there is no downtime between calls that is greater than the `timeoutDuration`
|
|
15
19
|
*/
|
|
16
20
|
export type DebouncerType = "immediate" | "idle";
|
|
17
|
-
|
|
21
|
+
type AnyFunc = (...args: any) => any;
|
|
22
|
+
/** The debounced function type that is returned by the {@linkcode debounce} function */
|
|
23
|
+
export type DebouncedFunction<TFunc extends AnyFunc> = ((...args: Parameters<TFunc>) => ReturnType<TFunc>) & {
|
|
24
|
+
debouncer: Debouncer<TFunc>;
|
|
25
|
+
};
|
|
18
26
|
/** Event map for the {@linkcode Debouncer} */
|
|
19
|
-
export type DebouncerEventMap<
|
|
27
|
+
export type DebouncerEventMap<TFunc extends AnyFunc> = {
|
|
20
28
|
/** Emitted when the debouncer calls all registered listeners, as a pub-sub alternative */
|
|
21
|
-
call:
|
|
29
|
+
call: TFunc;
|
|
22
30
|
/** Emitted when the timeout or edge type is changed after the instance was created */
|
|
23
31
|
change: (timeout: number, type: DebouncerType) => void;
|
|
24
32
|
};
|
|
@@ -31,15 +39,15 @@ export type DebouncerEventMap<TArgs> = {
|
|
|
31
39
|
* - `call` - emitted when the debouncer calls all listeners - use this as a pub-sub alternative to the default callback-style listeners
|
|
32
40
|
* - `change` - emitted when the timeout or edge type is changed after the instance was created
|
|
33
41
|
*/
|
|
34
|
-
export declare class Debouncer<
|
|
42
|
+
export declare class Debouncer<TFunc extends AnyFunc> extends NanoEmitter<DebouncerEventMap<TFunc>> {
|
|
35
43
|
protected timeout: number;
|
|
36
44
|
protected type: DebouncerType;
|
|
37
45
|
/** All registered listener functions and the time they were attached */
|
|
38
|
-
protected listeners:
|
|
46
|
+
protected listeners: TFunc[];
|
|
39
47
|
/** The currently active timeout */
|
|
40
48
|
protected activeTimeout: ReturnType<typeof setTimeout> | undefined;
|
|
41
49
|
/** The latest queued call */
|
|
42
|
-
protected queuedCall:
|
|
50
|
+
protected queuedCall: (() => void) | undefined;
|
|
43
51
|
/**
|
|
44
52
|
* Creates a new debouncer with the specified timeout and edge type.
|
|
45
53
|
* @param timeout Timeout in milliseconds between letting through calls - defaults to 200
|
|
@@ -47,9 +55,9 @@ export declare class Debouncer<TArgs> extends NanoEmitter<DebouncerEventMap<TArg
|
|
|
47
55
|
*/
|
|
48
56
|
constructor(timeout?: number, type?: DebouncerType);
|
|
49
57
|
/** Adds a listener function that will be called on timeout */
|
|
50
|
-
addListener(fn:
|
|
58
|
+
addListener(fn: TFunc): void;
|
|
51
59
|
/** Removes the listener with the specified function reference */
|
|
52
|
-
removeListener(fn:
|
|
60
|
+
removeListener(fn: TFunc): void;
|
|
53
61
|
/** Removes all listeners */
|
|
54
62
|
removeAllListeners(): void;
|
|
55
63
|
/** Sets the timeout for the debouncer */
|
|
@@ -63,7 +71,7 @@ export declare class Debouncer<TArgs> extends NanoEmitter<DebouncerEventMap<TArg
|
|
|
63
71
|
/** Returns the current edge type */
|
|
64
72
|
getType(): DebouncerType;
|
|
65
73
|
/** Use this to call the debouncer with the specified arguments that will be passed to all listener functions registered with {@linkcode addListener()} */
|
|
66
|
-
call(...args:
|
|
74
|
+
call(...args: Parameters<TFunc>): void;
|
|
67
75
|
}
|
|
68
76
|
/**
|
|
69
77
|
* Creates a {@linkcode Debouncer} instance with the specified timeout and edge type and attaches the passed function as a listener.
|
|
@@ -72,6 +80,5 @@ export declare class Debouncer<TArgs> extends NanoEmitter<DebouncerEventMap<TArg
|
|
|
72
80
|
*
|
|
73
81
|
* Refer to the {@linkcode Debouncer} class definition or the [Debouncer documentation](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#debouncer) for more information.
|
|
74
82
|
*/
|
|
75
|
-
export declare function debounce<TFunc extends
|
|
76
|
-
|
|
77
|
-
};
|
|
83
|
+
export declare function debounce<TFunc extends (...args: any[]) => any>(fn: TFunc, timeout?: number, type?: DebouncerType): DebouncedFunction<TFunc>;
|
|
84
|
+
export {};
|
package/dist/lib/Dialog.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/Dialog
|
|
3
|
+
* This module contains the Dialog class, which allows you to quickly and easily create modal dialogs - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#dialog)
|
|
4
|
+
*/
|
|
1
5
|
import { NanoEmitter } from "./NanoEmitter.js";
|
|
2
6
|
export declare const defaultDialogCss: string;
|
|
3
7
|
/** ID of the last opened (top-most) dialog */
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/NanoEmitter
|
|
3
|
+
* This module contains the NanoEmitter class, which is a tiny event emitter powered by [nanoevents](https://www.npmjs.com/package/nanoevents) - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#nanoemitter)
|
|
4
|
+
*/
|
|
1
5
|
import { type DefaultEvents, type Emitter, type EventsMap, type Unsubscribe } from "nanoevents";
|
|
2
6
|
export interface NanoEmitterOptions {
|
|
3
7
|
/** If set to true, allows emitting events through the public method emit() */
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/SelectorObserver
|
|
3
|
+
* This module contains the SelectorObserver class, allowing you to register listeners that get called whenever the element(s) behind a selector exist in the DOM - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#selectorobserver)
|
|
4
|
+
*/
|
|
1
5
|
import { type DebouncerType } from "./Debouncer.js";
|
|
2
6
|
import type { Prettify } from "./types.js";
|
|
3
7
|
/** Options for the `onSelector()` method of {@linkcode SelectorObserver} */
|
package/dist/lib/array.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/array
|
|
3
|
+
* This module contains various functions for working with arrays - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#arrays)
|
|
4
|
+
*/
|
|
1
5
|
/** Describes an array with at least one item */
|
|
2
6
|
export type NonEmptyArray<TArray = unknown> = [TArray, ...TArray[]];
|
|
3
7
|
/** Returns a random item from the passed array */
|
package/dist/lib/colors.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/colors
|
|
3
|
+
* This module contains various functions for working with colors - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#colors)
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* Converts a hex color string in the format `#RRGGBB`, `#RRGGBBAA` (or even `RRGGBB` and `RGB`) to a tuple.
|
|
3
7
|
* @returns Returns a tuple array where R, G and B are an integer from 0-255 and alpha is a float from 0 to 1, or undefined if no alpha channel exists.
|
package/dist/lib/crypto.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/crypto
|
|
3
|
+
* This module contains various cryptographic functions using the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#table-of-contents)
|
|
4
|
+
*/
|
|
1
5
|
/** Compresses a string or an ArrayBuffer using the provided {@linkcode compressionFormat} and returns it as a base64 string */
|
|
2
6
|
export declare function compress(input: string | ArrayBuffer, compressionFormat: CompressionFormat, outputType?: "string"): Promise<string>;
|
|
3
7
|
/** Compresses a string or an ArrayBuffer using the provided {@linkcode compressionFormat} and returns it as an ArrayBuffer */
|
package/dist/lib/dom.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/dom
|
|
3
|
+
* This module contains various functions for working with the DOM - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#dom)
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* Returns `unsafeWindow` if the `@grant unsafeWindow` is given, otherwise falls back to the regular `window`
|
|
3
7
|
*/
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module UserUtils
|
|
3
|
+
* UserUtils is a lightweight library with various utilities for userscripts, allowing you to register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more
|
|
4
|
+
*/
|
|
1
5
|
export * from "./array.js";
|
|
2
6
|
export * from "./colors.js";
|
|
3
7
|
export * from "./crypto.js";
|
package/dist/lib/math.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/math
|
|
3
|
+
* This module contains various math functions - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#math)
|
|
4
|
+
*/
|
|
1
5
|
import type { Stringifiable } from "./types.js";
|
|
2
6
|
/** Ensures the passed {@linkcode value} always stays between {@linkcode min} and {@linkcode max} */
|
|
3
7
|
export declare function clamp(value: number, min: number, max: number): number;
|
package/dist/lib/misc.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
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
|
+
*/
|
|
1
5
|
import type { Prettify, Stringifiable } from "./types.js";
|
|
2
6
|
/**
|
|
3
7
|
* Automatically appends an `s` to the passed {@linkcode word}, if {@linkcode num} is not equal to 1
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lib/translation
|
|
3
|
+
* This module contains a translation system that supports flat and nested JSON objects and value transformation functions - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#translation)
|
|
4
|
+
*/
|
|
1
5
|
import type { Stringifiable } from "./types.js";
|
|
2
6
|
/**
|
|
3
7
|
* Translation object to pass to {@linkcode tr.addTranslations()}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
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
|
+
*/
|
|
1
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 */
|
|
2
6
|
export type Stringifiable = string | {
|
|
3
7
|
toString(): string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sv443-network/userutils",
|
|
3
3
|
"libName": "UserUtils",
|
|
4
|
-
"version": "9.0.
|
|
4
|
+
"version": "9.0.3",
|
|
5
5
|
"description": "Lightweight library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|