@sv443-network/userutils 9.0.0 → 9.0.2

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @sv443-network/userutils
2
2
 
3
+ ## 9.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 69c4dd1: Fixed wrong readme being included in JSR package and added `@module` comments
8
+
9
+ ## 9.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - f24f355: Fixed missing return type signatures for JSR
14
+
3
15
  ## 9.0.0
4
16
 
5
17
  ### Major Changes
@@ -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.0
11
+ // @version 9.0.2
12
12
  // @license MIT
13
13
  // @copyright Sv443 (https://github.com/Sv443)
14
14
 
@@ -1,3 +1,7 @@
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";
2
6
  /** Dictionary of format version numbers and the function that migrates to them from the previous whole integer */
3
7
  export type DataMigrationsDict = Record<number, ((oldData: unknown) => unknown | Promise<unknown>)>;
@@ -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 */
@@ -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)
@@ -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} */
@@ -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 */
@@ -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.
@@ -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
  */
@@ -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";
@@ -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;
@@ -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()}
@@ -50,6 +54,35 @@ export type TransformTuple<TTrKey extends string = string> = [RegExp, TransformF
50
54
  export type TrKeys<TTrObj, P extends string = ""> = {
51
55
  [K in keyof TTrObj]: K extends string | number | boolean | null | undefined ? TTrObj[K] extends object ? TrKeys<TTrObj[K], `${P}${K}.`> : `${P}${K}` : never;
52
56
  }[keyof TTrObj];
57
+ /**
58
+ * Returns the translated text for the specified key in the specified language.
59
+ * If the key is not found in the specified previously registered translation, the key itself is returned.
60
+ *
61
+ * ⚠️ Remember to register a language with {@linkcode tr.addTranslations()} before using this function, otherwise it will always return the key itself.
62
+ * @param language Language code or name to use for the translation
63
+ * @param key Key of the translation to return
64
+ * @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
65
+ */
66
+ declare function trFor<TTrKey extends string = string>(language: string, key: TTrKey, ...args: (Stringifiable | Record<string, Stringifiable>)[]): string;
67
+ /**
68
+ * Prepares a translation function for a specific language.
69
+ * @example ```ts
70
+ * tr.addTranslations("en", {
71
+ * hello: "Hello, %1!",
72
+ * });
73
+ * const t = tr.useTr("en");
74
+ * t("hello", "John"); // "Hello, John!"
75
+ * ```
76
+ */
77
+ declare function useTr<TTrKey extends string = string>(language: string): (key: TTrKey, ...args: (Stringifiable | Record<string, Stringifiable>)[]) => ReturnType<typeof trFor<TTrKey>>;
78
+ /**
79
+ * Checks if a translation exists given its {@linkcode key} in the specified {@linkcode language} or the set fallback language.
80
+ * If the given language was not registered with {@linkcode tr.addTranslations()}, this function will return `false`.
81
+ * @param key Key of the translation to check for
82
+ * @param language Language code or name to check in - defaults to the currently active language (set by {@linkcode tr.setLanguage()})
83
+ * @returns Whether the translation key exists in the specified language - always returns `false` if no language is given and no active language was set
84
+ */
85
+ declare function hasKey<TTrKey extends string = string>(language: string | undefined, key: TTrKey): boolean;
53
86
  /**
54
87
  * Registers a new language and its translations - if the language already exists, it will be overwritten.
55
88
  * The translations are a key-value pair where the key is the translation key and the value is the translated text.
@@ -127,9 +160,9 @@ declare function addTransform<TTrKey extends string = string>(transform: Transfo
127
160
  */
128
161
  declare function deleteTransform(patternOrFn: RegExp | string | TransformFn): boolean;
129
162
  declare const tr: {
130
- for: <TTrKey extends string = string>(language: string, key: TTrKey, ...args: (Stringifiable | Record<string, Stringifiable>)[]) => string;
131
- use: <TTrKey extends string = string>(language: string) => (key: TTrKey, ...args: (Stringifiable | Record<string, Stringifiable>)[]) => string;
132
- hasKey: <TTrKey extends string = string>(language: string | undefined, key: TTrKey) => boolean;
163
+ for: <TTrKey extends string = string>(language: string, key: TTrKey, ...args: (Stringifiable | Record<string, Stringifiable>)[]) => ReturnType<typeof trFor<TTrKey>>;
164
+ use: <TTrKey extends string = string>(language: string) => ReturnType<typeof useTr<TTrKey>>;
165
+ hasKey: <TTrKey extends string = string>(language: string | undefined, key: TTrKey) => ReturnType<typeof hasKey<TTrKey>>;
133
166
  addTranslations: typeof addTranslations;
134
167
  getTranslations: typeof getTranslations;
135
168
  deleteTranslations: (language: string) => boolean;
@@ -138,8 +171,8 @@ declare const tr: {
138
171
  addTransform: typeof addTransform;
139
172
  deleteTransform: typeof deleteTransform;
140
173
  transforms: {
141
- templateLiteral: [RegExp, ({ matches, trArgs, trValue }: TransformFnProps<string>) => string];
142
- percent: [RegExp, ({ matches, trArgs, trValue }: TransformFnProps<string>) => string];
174
+ templateLiteral: TransformTuple<string>;
175
+ percent: TransformTuple<string>;
143
176
  };
144
177
  };
145
178
  export { tr };
@@ -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.0",
4
+ "version": "9.0.2",
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",
@@ -79,6 +79,7 @@
79
79
  "update-jsr-version": "node --import tsx ./tools/update-jsr-version.mts",
80
80
  "publish-package": "changeset publish",
81
81
  "publish-package-jsr": "pnpm update-jsr-version && npx jsr publish --allow-dirty",
82
+ "check-jsr": "npx jsr publish --allow-dirty --dry-run",
82
83
  "change": "changeset",
83
84
  "test-serve": "node --import tsx ./test/TestPage/server.mts",
84
85
  "test-dev": "cd test/TestScript && pnpm dev",