diff --git a/.changeset/silly-foxes-melt.md b/.changeset/silly-foxes-melt.md new file mode 100644 index 0000000..7479206 --- /dev/null +++ b/.changeset/silly-foxes-melt.md @@ -0,0 +1,27 @@ +--- +"@sv443-network/userutils": major +--- + +**Moved a majority of the general-purpose code to the `@sv443-network/coreutils` package.** +The features are still accessible on this library in the same way, but some of them needed to be modified so they were more generic and consistent with the new package's codebase. +Refer to [the CoreUtils documentation](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md) for more information. + +**These are all the breaking changes:** +- Renamed `index.` files in `dist/` to `UserUtils.` + - Turned `index.global.js` into an actual UMD bundle at `UserUtils.umd.js` +- Reworked DataStore + - The constructor now needs an `engine` property that is an instance of a [`DataStoreEngine`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#class-datastoreengine) + - Encoding with `deflate-raw` will now be enabled by default. Set `compressionFormat: null` to disable it and restore the previous behavior. + - Added [`DataStoreEngine` class](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#class-datastoreengine) with two implementations available out-of-the-box; [`FileStorageEngine`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#class-filestorageengine) and [`BrowserStorageEngine`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#class-browserstorageengine), for Node/Deno and browser environments respectively. Userscripts need to use [`BrowserStorageEngine`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#class-browserstorageengine) + - Added shorthand property `compressionFormat` as an alternative to the properties `encodeData` and `decodeData` + - The global key `__ds_fmt_ver` will now contain a global version number for DataStore-internal format integrity. + - Renamed `ab2str()` to `abtoa()` and `str2ab()` to `atoab()` to match `btoa()` and `atob()` + - Renamed `purifyObj()` to `pureObj()` + +**These are all new additions:** + - Added [`capitalize()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-capitalize) to capitalize the first letter of a string. + - Added [`setImmediateInterval()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-setimmediateinterval) to set an interval that runs immediately, then again on a fixed *interval.* + - Added [`setImmediateTimeoutLoop()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-setimmediatetimeoutloop) to set a recursive `setTimeout()` loop with a fixed *delay.* + - Added [`takeRandomItemIndex()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-takerandomitemindex), as a mutating counterpart to [`randomItemIndex()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-randomitemindex) + - Added [`truncStr()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-truncstr) to truncate a string to a given length, optionally adding an ellipsis. + - Added [`valsWithin()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-valswithin) to check if two values, rounded at the given decimal, are within a certain range of each other. diff --git a/.changeset/ten-otters-check.md b/.changeset/ten-otters-check.md new file mode 100644 index 0000000..2a5665d --- /dev/null +++ b/.changeset/ten-otters-check.md @@ -0,0 +1,5 @@ +--- +"@sv443-network/userutils": major +--- + +Increased library target to ES2018 diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index cfcbf3b..3de99af 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -14,8 +14,7 @@ Thanks to Matt Pocock for his video on how to set up a modern TypeScript library | Command | Description | | :-- | :-- | | `npm run lint` | Run TSC and ESLint to lint the code | -| `npm run build` | Build the project with tsup, outputting CJS and ESM bundles as well as TypeScript declarations to `dist/` | -| `npm run build-all` | Build the project with tsup, outputting a bundle that exports as CJS, ESM and global declaration bundles (for publishing to GreasyFork and OpenUserJS) to `dist/` | +| `npm run build` | Build the project with tsup, outputting CJS and ESM bundles and global declaration bundles (for publishing to GreasyFork and OpenUserJS), as well as TypeScript declarations to `dist/` | | `npm run dev` | Watch for changes and build the project with sourcemaps |
diff --git a/.github/workflows/build-and-publish-jsr.yml b/.github/workflows/build-and-publish-jsr.yml index ae56a40..e0298d4 100644 --- a/.github/workflows/build-and-publish-jsr.yml +++ b/.github/workflows/build-and-publish-jsr.yml @@ -21,7 +21,7 @@ jobs: env: CI: "true" STORE_PATH: "" - PNPM_VERSION: 9 + PNPM_VERSION: 10 RETENTION_DAYS: 2 steps: @@ -56,7 +56,7 @@ jobs: run: pnpm i - name: Build package - run: pnpm build-all + run: pnpm build - name: Publish on JSR run: pnpm publish-package-jsr diff --git a/.github/workflows/build-and-publish-npm.yml b/.github/workflows/build-and-publish-npm.yml index 8b80d92..1c0bec7 100644 --- a/.github/workflows/build-and-publish-npm.yml +++ b/.github/workflows/build-and-publish-npm.yml @@ -27,7 +27,7 @@ jobs: env: CI: "true" STORE_PATH: "" - PNPM_VERSION: 9 + PNPM_VERSION: 10 RETENTION_DAYS: 2 steps: @@ -62,7 +62,7 @@ jobs: run: pnpm i - name: Build package - run: pnpm build-all + run: pnpm build - name: Create artifact uses: actions/upload-artifact@v4 diff --git a/.github/workflows/lint-and-test-code.yml b/.github/workflows/lint-and-test-code.yml index 3d5a96d..c5287c5 100644 --- a/.github/workflows/lint-and-test-code.yml +++ b/.github/workflows/lint-and-test-code.yml @@ -19,7 +19,7 @@ jobs: env: CI: "true" STORE_PATH: "" - PNPM_VERSION: 9 + PNPM_VERSION: 10 RETENTION_DAYS: 2 steps: diff --git a/LICENSE.txt b/LICENSE.txt index d613d26..ee2b85c 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Sven Fehler (Sv443) +Copyright (c) 2023 Sv443 Network and Sven Fehler (Sv443) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README-summary.md b/README-summary.md index 7125897..7c89b95 100644 --- a/README-summary.md +++ b/README-summary.md @@ -171,6 +171,7 @@ Shameless plug: I made a [template for userscripts in TypeScript](https://github
- Then, access the functions on the global variable `UserUtils`: + ```ts UserUtils.addGlobalStyle("body { background-color: red; }"); @@ -183,6 +184,7 @@ Shameless plug: I made a [template for userscripts in TypeScript](https://github
- If you're using TypeScript and it complains about the missing global variable `UserUtils`, install the library using the package manager of your choice and add the following inside any `.ts` file that is included in the final build: + ```ts declare const UserUtils: typeof import("@sv443-network/userutils"); @@ -195,7 +197,8 @@ Shameless plug: I made a [template for userscripts in TypeScript](https://github
-- If you're using a linter like ESLint, it might complain about the global variable `UserUtils` not being defined. To fix this, add the following to your ESLint configuration file: +- If you're using a linter like ESLint, it might complain about the global variable `UserUtils` not being defined. To fix this, add the following to your ESLint configuration file: + ```json "globals": { "UserUtils": "readonly" diff --git a/README.md b/README.md index 6564216..a8e67f5 100644 --- a/README.md +++ b/README.md @@ -199,7 +199,8 @@ Shameless plug: I made a [template for userscripts in TypeScript](https://github
-- If you're using a linter like ESLint, it might complain about the global variable `UserUtils` not being defined. To fix this, add the following to your ESLint configuration file: +- If you're using a linter like ESLint, it might complain about the global variable `UserUtils` not being defined. To fix this, add the following to your ESLint configuration file: + ```json "globals": { "UserUtils": "readonly" diff --git a/docs.md b/docs.md index 5389476..348121a 100644 --- a/docs.md +++ b/docs.md @@ -1,12 +1,18 @@ # UserUtils Documentation +General purpose DOM/GreaseMonkey library that allows you to register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more. +Contains builtin TypeScript declarations. Supports ESM and CJS imports via a bundler and global declaration via `@require` or `