Explorar o código

feat: update userutils & implement stringgen

Sv443 hai 4 meses
pai
achega
be70bd4773
Modificáronse 5 ficheiros con 16 adicións e 28 borrados
  1. 1 1
      package.json
  2. 12 6
      pnpm-lock.yaml
  3. 1 2
      src/components/MarkdownDialog.ts
  4. 1 7
      src/types.ts
  5. 1 12
      src/utils/misc.ts

+ 1 - 1
package.json

@@ -63,7 +63,7 @@
     "openuserjs": "https://openuserjs.org/scripts/Sv443/BetterYTM"
   },
   "dependencies": {
-    "@sv443-network/userutils": "^8.3.3",
+    "@sv443-network/userutils": "^8.4.0",
     "compare-versions": "^6.1.0",
     "dompurify": "^3.1.6",
     "marked": "^12.0.2",

+ 12 - 6
pnpm-lock.yaml

@@ -9,8 +9,8 @@ importers:
   .:
     dependencies:
       '@sv443-network/userutils':
-        specifier: ^8.3.3
-        version: 8.3.3
+        specifier: ^8.4.0
+        version: 8.4.0
       compare-versions:
         specifier: ^6.1.0
         version: 6.1.0
@@ -1822,8 +1822,8 @@ packages:
   '@storybook/[email protected]':
     resolution: {integrity: sha512-UJ97iqI+0Mk13I6ayd3TaBfSFBkWnEauwTnFMQe1dN/L3wTh8laOBaLa0Vr3utRSnt2b5hpcw/nq7azB/Gx4Yw==}
 
-  '@sv443-network/userutils@8.3.3':
-    resolution: {integrity: sha512-m/iUruQo5gb3AxyimQOLd9M0NLORQIRNOdMYxjn+bN8eySfWQ0GNa3pCr27Xm7joTAUESKaw2VWHb3vyzKc4NA==}
+  '@sv443-network/userutils@8.4.0':
+    resolution: {integrity: sha512-DgMxcpq25IIwupOl3hTLCCmjU4oXrzOyajNoApVsTg2wPI02ZxPcx1YAmpoE19awxApJS+hJQseYdKWE3hFkCA==}
 
   '@testing-library/[email protected]':
     resolution: {integrity: sha512-FlS4ZWlp97iiNWig0Muq8p+3rVDjRiYE+YKGbAqXOu9nwJFFOdL00kFpz42M+4huzYi86vAK1sOOfyOG45muIQ==}
@@ -3577,6 +3577,10 @@ packages:
     resolution: {integrity: sha512-X8pU7IOpgKXVLPxYUI55ymXc8XuBE+uypfEyEFBtHkD1EX9KavYTVc+vXZHFyHKzA1TaZoVDqklLdQBBrxIuAw==}
     engines: {node: ^18.0.0 || >=20.0.0}
 
+  [email protected]:
+    resolution: {integrity: sha512-Jd0fILWG44a9luj8v5kED4WI+zfkkgwKyRQKItTtlPfEsh7Lznfi1kr8/iZ+XAIss4Qq5GqRB0qtWbaz9ceO/A==}
+    engines: {node: ^18.0.0 || >=20.0.0}
+
   [email protected]:
     resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==}
     engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
@@ -6795,9 +6799,9 @@ snapshots:
       '@types/express': 4.17.21
       file-system-cache: 2.3.0
 
-  '@sv443-network/userutils@8.3.3':
+  '@sv443-network/userutils@8.4.0':
     dependencies:
-      nanoevents: 9.0.0
+      nanoevents: 9.1.0
 
   '@testing-library/[email protected]':
     dependencies:
@@ -8672,6 +8676,8 @@ snapshots:
 
   [email protected]: {}
 
+  [email protected]: {}
+
   [email protected]: {}
 
   [email protected]: {}

+ 1 - 2
src/components/MarkdownDialog.ts

@@ -1,8 +1,7 @@
 import { marked } from "marked";
 import { setInnerHtml } from "../utils/dom.js";
-import { consumeStringGen } from "../utils/misc.js";
 import { BytmDialog, type BytmDialogOptions } from "./BytmDialog.js";
-import type { StringGen } from "../types.js";
+import { consumeStringGen, type StringGen } from "@sv443-network/userutils";
 
 /** Options for the MarkdownDialog - a `body` prop is required instead of `renderBody` */
 type MarkdownDialogOptions = Omit<BytmDialogOptions, "renderBody"> & {

+ 1 - 7
src/types.ts

@@ -1,4 +1,4 @@
-import type { NanoEmitter, Stringifiable } from "@sv443-network/userutils";
+import type { NanoEmitter } from "@sv443-network/userutils";
 import type * as consts from "./constants.js";
 import type { scriptInfo } from "./constants.js";
 import type { addSelectorListener } from "./observers.js";
@@ -14,12 +14,6 @@ import locales from "../assets/locales.json" with { type: "json" }; // eslint-di
 
 //#region other
 
-/**
- * Value that is either a string (or stringifiable value) or a sync or async function that returns a string (or a stringifiable value)  
- * Use `await consumeStringGen(strGen)` to get the actual string value from this type
- */
-export type StringGen = Stringifiable | (() => Stringifiable | Promise<Stringifiable>);
-
 /** Custom CLI args passed to rollup */
 export type RollupArgs = Partial<{
   "config-mode": "development" | "production";

+ 1 - 12
src/utils/misc.ts

@@ -1,7 +1,7 @@
 import { compress, decompress, fetchAdvanced, getUnsafeWindow, openInNewTab, pauseFor, randomId, randRange, type Prettify } from "@sv443-network/userutils";
 import { marked } from "marked";
 import { buildNumber, changelogUrl, compressionFormat, repo, sessionStorageAvailable } from "../constants.js";
-import { type Domain, type NumberLengthFormat, type ResourceKey, type StringGen } from "../types.js";
+import { type Domain, type NumberLengthFormat, type ResourceKey } from "../types.js";
 import { error, type TrLocale, warn, sendRequest, getLocale, log, getVideoElement, getVideoTime } from "./index.js";
 import { enableDiscardBeforeUnload } from "../features/behavior.js";
 import { getFeature } from "../config.js";
@@ -194,17 +194,6 @@ export function getOS() {
   return "other";
 }
 
-/** Turns the passed StringGen (either a string, stringifiable object or a sync or async function returning a string or stringifiable object) into a string */
-export async function consumeStringGen(strGen: StringGen): Promise<string> {
-  return typeof strGen === "string"
-    ? strGen
-    : String(
-      typeof strGen === "function"
-        ? await strGen()
-        : strGen
-    );
-}
-
 /** Formats a number based on the config or the passed {@linkcode notation} */
 export function formatNumber(num: number, notation?: NumberLengthFormat): string {
   return num.toLocaleString(