@sv443-network/userutils 9.0.0 → 9.0.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @sv443-network/userutils
2
2
 
3
+ ## 9.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f24f355: Fixed missing return type signatures for JSR
8
+
3
9
  ## 9.0.0
4
10
 
5
11
  ### 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.1
12
12
  // @license MIT
13
13
  // @copyright Sv443 (https://github.com/Sv443)
14
14
 
@@ -50,6 +50,35 @@ export type TransformTuple<TTrKey extends string = string> = [RegExp, TransformF
50
50
  export type TrKeys<TTrObj, P extends string = ""> = {
51
51
  [K in keyof TTrObj]: K extends string | number | boolean | null | undefined ? TTrObj[K] extends object ? TrKeys<TTrObj[K], `${P}${K}.`> : `${P}${K}` : never;
52
52
  }[keyof TTrObj];
53
+ /**
54
+ * Returns the translated text for the specified key in the specified language.
55
+ * If the key is not found in the specified previously registered translation, the key itself is returned.
56
+ *
57
+ * ⚠️ Remember to register a language with {@linkcode tr.addTranslations()} before using this function, otherwise it will always return the key itself.
58
+ * @param language Language code or name to use for the translation
59
+ * @param key Key of the translation to return
60
+ * @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
61
+ */
62
+ declare function trFor<TTrKey extends string = string>(language: string, key: TTrKey, ...args: (Stringifiable | Record<string, Stringifiable>)[]): string;
63
+ /**
64
+ * Prepares a translation function for a specific language.
65
+ * @example ```ts
66
+ * tr.addTranslations("en", {
67
+ * hello: "Hello, %1!",
68
+ * });
69
+ * const t = tr.useTr("en");
70
+ * t("hello", "John"); // "Hello, John!"
71
+ * ```
72
+ */
73
+ declare function useTr<TTrKey extends string = string>(language: string): (key: TTrKey, ...args: (Stringifiable | Record<string, Stringifiable>)[]) => ReturnType<typeof trFor<TTrKey>>;
74
+ /**
75
+ * Checks if a translation exists given its {@linkcode key} in the specified {@linkcode language} or the set fallback language.
76
+ * If the given language was not registered with {@linkcode tr.addTranslations()}, this function will return `false`.
77
+ * @param key Key of the translation to check for
78
+ * @param language Language code or name to check in - defaults to the currently active language (set by {@linkcode tr.setLanguage()})
79
+ * @returns Whether the translation key exists in the specified language - always returns `false` if no language is given and no active language was set
80
+ */
81
+ declare function hasKey<TTrKey extends string = string>(language: string | undefined, key: TTrKey): boolean;
53
82
  /**
54
83
  * Registers a new language and its translations - if the language already exists, it will be overwritten.
55
84
  * The translations are a key-value pair where the key is the translation key and the value is the translated text.
@@ -127,9 +156,9 @@ declare function addTransform<TTrKey extends string = string>(transform: Transfo
127
156
  */
128
157
  declare function deleteTransform(patternOrFn: RegExp | string | TransformFn): boolean;
129
158
  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;
159
+ for: <TTrKey extends string = string>(language: string, key: TTrKey, ...args: (Stringifiable | Record<string, Stringifiable>)[]) => ReturnType<typeof trFor<TTrKey>>;
160
+ use: <TTrKey extends string = string>(language: string) => ReturnType<typeof useTr<TTrKey>>;
161
+ hasKey: <TTrKey extends string = string>(language: string | undefined, key: TTrKey) => ReturnType<typeof hasKey<TTrKey>>;
133
162
  addTranslations: typeof addTranslations;
134
163
  getTranslations: typeof getTranslations;
135
164
  deleteTranslations: (language: string) => boolean;
@@ -138,8 +167,8 @@ declare const tr: {
138
167
  addTransform: typeof addTransform;
139
168
  deleteTransform: typeof deleteTransform;
140
169
  transforms: {
141
- templateLiteral: [RegExp, ({ matches, trArgs, trValue }: TransformFnProps<string>) => string];
142
- percent: [RegExp, ({ matches, trArgs, trValue }: TransformFnProps<string>) => string];
170
+ templateLiteral: TransformTuple<string>;
171
+ percent: TransformTuple<string>;
143
172
  };
144
173
  };
145
174
  export { tr };
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.1",
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",