@sv443-network/userutils 2.0.1 → 4.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.
@@ -3,7 +3,20 @@ export type Stringifiable = string | {
3
3
  toString(): string;
4
4
  };
5
5
  /**
6
- * Automatically appends an `s` to the passed `word`, if `num` is not equal to 1
6
+ * A type that offers autocomplete for the passed union but also allows any arbitrary value of the same type to be passed.
7
+ * Supports unions of strings, numbers and objects.
8
+ */
9
+ 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)));
10
+ /**
11
+ * A type that allows all strings except for empty ones
12
+ * @example
13
+ * function foo<T extends string>(bar: NonEmptyString<T>) {
14
+ * console.log(bar);
15
+ * }
16
+ */
17
+ export type NonEmptyString<TString extends string> = TString extends "" ? never : TString;
18
+ /**
19
+ * Automatically appends an `s` to the passed {@linkcode word}, if {@linkcode num} is not equal to 1
7
20
  * @param word A word in singular form, to auto-convert to plural
8
21
  * @param num If this is an array or NodeList, the amount of items is used
9
22
  */
@@ -11,8 +24,8 @@ export declare function autoPlural(word: Stringifiable, num: number | unknown[]
11
24
  /** Pauses async execution for the specified time in ms */
12
25
  export declare function pauseFor(time: number): Promise<void>;
13
26
  /**
14
- * Calls the passed `func` after the specified `timeout` in ms (defaults to 300).
15
- * Any subsequent calls to this function will reset the timer and discard previous calls.
27
+ * Calls the passed {@linkcode func} after the specified {@linkcode timeout} in ms (defaults to 300).
28
+ * Any subsequent calls to this function will reset the timer and discard all previous calls.
16
29
  */
17
30
  export declare function debounce<TFunc extends (...args: TArgs[]) => void, TArgs = any>(func: TFunc, timeout?: number): (...args: TArgs[]) => void;
18
31
  /** Options for the `fetchAdvanced()` function */
@@ -25,7 +38,15 @@ export declare function fetchAdvanced(url: string, options?: FetchAdvancedOpts):
25
38
  /**
26
39
  * Inserts the passed values into a string at the respective placeholders.
27
40
  * The placeholder format is `%n`, where `n` is the 1-indexed argument number.
28
- * @param str The string to insert the values into
41
+ * @param input The string to insert the values into
29
42
  * @param values The values to insert, in order, starting at `%1`
30
43
  */
31
- export declare function insertValues(str: string, ...values: Stringifiable[]): string;
44
+ export declare function insertValues(input: string, ...values: Stringifiable[]): string;
45
+ /** Compresses a string or an ArrayBuffer using the provided {@linkcode compressionFormat} and returns it as a base64 string */
46
+ export declare function compress(input: string | ArrayBuffer, compressionFormat: CompressionFormat, outputType?: "base64"): Promise<string>;
47
+ /** Compresses a string or an ArrayBuffer using the provided {@linkcode compressionFormat} and returns it as an ArrayBuffer */
48
+ export declare function compress(input: string | ArrayBuffer, compressionFormat: CompressionFormat, outputType: "arrayBuffer"): Promise<ArrayBuffer>;
49
+ /** Decompresses a previously compressed base64 string or ArrayBuffer, with the format passed by {@linkcode compressionFormat}, converted to a string */
50
+ export declare function decompress(input: string | ArrayBuffer, compressionFormat: CompressionFormat, outputType?: "string"): Promise<string>;
51
+ /** Decompresses a previously compressed base64 string or ArrayBuffer, with the format passed by {@linkcode compressionFormat}, converted to an ArrayBuffer */
52
+ export declare function decompress(input: string | ArrayBuffer, compressionFormat: CompressionFormat, outputType: "arrayBuffer"): Promise<ArrayBuffer>;
@@ -1,9 +1,9 @@
1
1
  import { Stringifiable } from "./misc";
2
2
  /**
3
- * Returns the translated text for the specified key in the current language set by `setLanguage()`
3
+ * Returns the translated text for the specified key in the current language set by {@linkcode tr.setLanguage()}
4
4
  * If the key is not found in the previously registered translation, the key itself is returned.
5
5
  *
6
- * ⚠️ Remember to register a language with `tr.addLanguage()` and set it as active with `tr.setLanguage()` before using this function, otherwise it will always return the key itself.
6
+ * ⚠️ Remember to register a language with {@linkcode tr.addLanguage()} and set it as active with {@linkcode tr.setLanguage()} before using this function, otherwise it will always return the key itself.
7
7
  * @param key Key of the translation to return
8
8
  * @param args Optional arguments to be passed to the translated text. They will replace placeholders in the format `%n`, where `n` is the 1-indexed argument number
9
9
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sv443-network/userutils",
3
- "version": "2.0.1",
3
+ "version": "4.0.0",
4
4
  "description": "Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, manage persistent user configurations, modify the DOM more easily and more",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -14,7 +14,10 @@
14
14
  "post-build-global": "npm run node-ts -- ./tools/post-build-global.mts",
15
15
  "dev": "npm run build-common -- --sourcemap --watch --onSuccess \"npm run build-types && echo Finished building.\"",
16
16
  "publish-package": "changeset publish",
17
- "node-ts": "node --no-warnings=ExperimentalWarning --enable-source-maps --loader ts-node/esm"
17
+ "node-ts": "node --no-warnings=ExperimentalWarning --enable-source-maps --loader ts-node/esm",
18
+ "test-serve": "npm run node-ts -- ./test/TestPage/server.mts",
19
+ "test-dev": "cd test/TestScript && npm run dev",
20
+ "test": "concurrently \"npm run test-serve\" \"npm run test-dev\""
18
21
  },
19
22
  "repository": {
20
23
  "type": "git",
@@ -35,14 +38,17 @@
35
38
  "homepage": "https://github.com/Sv443-Network/UserUtils",
36
39
  "devDependencies": {
37
40
  "@changesets/cli": "^2.26.2",
41
+ "@types/express": "^4.17.19",
38
42
  "@types/greasemonkey": "^4.0.4",
39
43
  "@types/node": "^20.5.9",
40
44
  "@typescript-eslint/eslint-plugin": "^6.2.1",
41
45
  "@typescript-eslint/parser": "^6.2.1",
46
+ "concurrently": "^8.2.1",
42
47
  "eslint": "^8.46.0",
48
+ "express": "^4.18.2",
43
49
  "ts-node": "^10.9.1",
44
50
  "tslib": "^2.6.1",
45
- "tsup": "^7.2.0",
51
+ "tsup": "^7.1.0",
46
52
  "typescript": "^5.1.6"
47
53
  },
48
54
  "files": [
@@ -55,4 +61,4 @@
55
61
  "/CHANGELOG.md",
56
62
  "/LICENSE.txt"
57
63
  ]
58
- }
64
+ }
@@ -1,40 +0,0 @@
1
- /** Options for the `onSelector()` function */
2
- export type OnSelectorOpts<TElem extends Element = HTMLElement> = SelectorOptsOne<TElem> | SelectorOptsAll<TElem>;
3
- type SelectorOptsOne<TElem extends Element> = SelectorOptsCommon & {
4
- /** Whether to use `querySelectorAll()` instead - default is false */
5
- all?: false;
6
- /** Gets called whenever the selector was found in the DOM */
7
- listener: (element: TElem) => void;
8
- };
9
- type SelectorOptsAll<TElem extends Element> = SelectorOptsCommon & {
10
- /** Whether to use `querySelectorAll()` instead - default is false */
11
- all: true;
12
- /** Gets called whenever the selector was found in the DOM */
13
- listener: (elements: NodeListOf<TElem>) => void;
14
- };
15
- type SelectorOptsCommon = {
16
- /** Whether to call the listener continuously instead of once - default is false */
17
- continuous?: boolean;
18
- };
19
- /**
20
- * Calls the `listener` as soon as the `selector` exists in the DOM.
21
- * Listeners are deleted when they are called once, unless `options.continuous` is set.
22
- * Multiple listeners with the same selector may be registered.
23
- * @param selector The selector to listen for
24
- * @param options Used for switching to `querySelectorAll()` and for calling the listener continuously
25
- * @template TElem The type of element that the listener will return as its argument (defaults to the generic HTMLElement)
26
- */
27
- export declare function onSelector<TElem extends Element = HTMLElement>(selector: string, options: OnSelectorOpts<TElem>): void;
28
- /**
29
- * Removes all listeners registered in `onSelector()` that have the given selector
30
- * @returns Returns true when all listeners with the associated selector were found and removed, false otherwise
31
- */
32
- export declare function removeOnSelector(selector: string): boolean;
33
- /**
34
- * Initializes a MutationObserver that checks for all registered selectors whenever an element is added to or removed from the `<body>`
35
- * @param options For fine-tuning what triggers the MutationObserver's checking function - `subtree` and `childList` are set to true by default
36
- */
37
- export declare function initOnSelector(options?: MutationObserverInit): void;
38
- /** Returns all currently registered selectors, as a map of selector strings to their associated options */
39
- export declare function getSelectorMap(): Map<string, OnSelectorOpts<HTMLElement>[]>;
40
- export {};