Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .changeset/silly-foxes-melt.md
Original file line number Diff line number Diff line change
@@ -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.<ext>` files in `dist/` to `UserUtils.<ext>`
- 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.
5 changes: 5 additions & 0 deletions .changeset/ten-otters-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sv443-network/userutils": major
---

Increased library target to ES2018
3 changes: 1 addition & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

<br>
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-and-publish-jsr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
env:
CI: "true"
STORE_PATH: ""
PNPM_VERSION: 9
PNPM_VERSION: 10
RETENTION_DAYS: 2

steps:
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/build-and-publish-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
env:
CI: "true"
STORE_PATH: ""
PNPM_VERSION: 9
PNPM_VERSION: 10
RETENTION_DAYS: 2

steps:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-and-test-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
env:
CI: "true"
STORE_PATH: ""
PNPM_VERSION: 9
PNPM_VERSION: 10
RETENTION_DAYS: 2

steps:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion README-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Shameless plug: I made a [template for userscripts in TypeScript](https://github
<br>

- Then, access the functions on the global variable `UserUtils`:

```ts
UserUtils.addGlobalStyle("body { background-color: red; }");

Expand All @@ -183,6 +184,7 @@ Shameless plug: I made a [template for userscripts in TypeScript](https://github
<br>

- 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");

Expand All @@ -195,7 +197,8 @@ Shameless plug: I made a [template for userscripts in TypeScript](https://github

<br>

- 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"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ Shameless plug: I made a [template for userscripts in TypeScript](https://github

<br>

- 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"
Expand Down
12 changes: 9 additions & 3 deletions docs.md
Original file line number Diff line number Diff line change
@@ -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 `<script>`
The library works in any DOM environment with or without the [GreaseMonkey API](https://wiki.greasespot.net/Greasemonkey_Manual:API), but some features will be unavailable or limited.

You may want to check out my [template for userscripts in TypeScript](https://github.com/Sv443/Userscript.ts) that you can use to get started quickly. It also includes this library by default.
If you like using this library, please consider [supporting the development ❤️](https://github.com/sponsors/Sv443)

<br>

<!-- #region Preamble -->
## Preamble:
This library is written in TypeScript and contains builtin TypeScript declarations, but it will also work in plain JavaScript after removing the `: type` annotations.
This library is written in TypeScript and contains builtin TypeScript declarations, but it will also work in plain JavaScript after removing the `: type` annotations in the example code snippets.

Each feature has example code that can be expanded by clicking on the text "Example - click to view".
Each feature's example code snippet can be expanded by clicking on the text "Example - click to view".
The signatures and examples are written in TypeScript and use ESM import syntax to show you which types need to be provided and will be returned.
The library itself supports importing an ESM, CommonJS or global variable definition bundle, depending on your use case.

Expand Down Expand Up @@ -2329,7 +2335,7 @@ Returns an array of all registered listener functions.

<br>

#### `Debouncer.setTimeout()`
#### `Debouncer.setTimeout()`
Signature: `setTimeout(timeout: number): void`
Changes the timeout for the debouncer.

Expand Down
28 changes: 15 additions & 13 deletions jsr.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
{
"$schema": "https://jsr.io/schema/config-file.v1.json",
"name": "@sv443-network/userutils",
"version": "0.0.1-invalid",
"exports": "./lib/index.ts",
"version": "10.0.0-alpha.0",
"exports": {
".": "./lib/index.ts"
},
"publish": {
"include": [
"lib/**/*.ts",
"dist/index.js",
"dist/index.mjs",
"dist/index.cjs",
"dist/index.global.js",
"dist/index.umd.js",
"dist/lib/*.d.ts",
"package.json",
"README.md",
"CHANGELOG.md",
"LICENSE.txt"
"./dist/index.cjs",
"./dist/index.global.js",
"./dist/index.js",
"./dist/index.mjs",
"./dist/index.umd.js",
"./dist/lib/*.d.ts",
"./lib/**/*.ts",
"./CHANGELOG.md",
"./LICENSE.txt",
"./package.json",
"./README.md"
],
"exclude": [
"**/*.spec.ts"
Expand Down
Loading