@sv443-network/coreutils 0.0.1 → 2.0.0

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,11 +1,40 @@
1
+ # @sv443-network/coreutils
2
+
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 273fa5a: Removed the boolean property `__ds-${id}-enc` from the `DataStore` and `DataStoreEngine` classes.
8
+ Now the key `__ds-${id}-enf` will hold the encoding format identifier string, or `null` if not set (will get created on the next write call).
9
+ This will make it possible to switch the encoding format without compatibility issues.
10
+ This functionality is not officially supported yet, but can be achieved manually by calling the storage API methods of `storeInstance.engine`
11
+
12
+ ### Minor Changes
13
+
14
+ - 29fb048: Added `overflowVal()` to conform a value to an over- & undeflowing range
15
+ - 91cbe9c: Added optional abstract method `DataStoreEngine.deleteStorage()` for deleting the data storage container itself. If implemented in subclasses, it will be called from the method `DataStore.deleteData()`
16
+ - 3cae1cb: Added `dataStoreOptions` constructor prop to the DataStoreEngine subclasses to enable them to be used standalone.
17
+ - f6465b5: Added method `NanoEmitter.onMulti()` to listen to when multiple events have emitted, with fine grained options
18
+
19
+ ## 1.0.0
20
+
21
+ This is the initial release of CoreUtils. Most features have been originally ported from [version 9.4.1 of `@sv443-network/userutils`](https://github.com/Sv443-Network/UserUtils/tree/v9.4.1)
22
+ Parts of the code have been overhauled, and some features have been added:
23
+
1
24
  - Additions:
2
- - array:
3
- - Added `takeRandomItemIndex()`
4
- - BREAKING CHANGES:
5
- - Reworked DataStore
6
- - Encoding with `deflate-raw` will now be enabled by default. Set `compressionFormat: null` to disable it.
7
- - Added `DataStoreEngine` base class to create a persistent storage engine
8
- - Added `FileStorageEngine` for file-based storage in the backend and `BrowserStorageEngine` for browser API based storage
9
- - The global key `__ds_fmt_ver` will now contain a global version number for DataStore-internal format integrity
10
- - crypto:
11
- - renamed `ab2str()` to `abtoa()` and `str2ab()` to `atoab()` to match `btoa()` and `atob()`
25
+ - Added [`capitalize()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-capitalize) to capitalize the first letter of a string.
26
+ - 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._
27
+ - Added [`setImmediateTimeoutLoop()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-setimmediatetimeoutloop) to set a recursive `setTimeout()` loop with a fixed _delay._
28
+ - 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)
29
+ - 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.
30
+ - 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.
31
+ - Added [`scheduleExit()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-scheduleexit) to schedule a Node/Deno process to exit with the given code, after the microtask queue is empty or after the given timeout.
32
+ - **BREAKING CHANGES:**
33
+ - Reworked `DataStore`
34
+ - 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.)
35
+ - Encoding with `deflate-raw` will now be enabled by default. Set `compressionFormat: null` to disable it and restore the previous behavior.
36
+ - 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)
37
+ - Added shorthand property `compressionFormat` as an alternative to the properties `encodeData` and `decodeData`
38
+ - The global key `__ds_fmt_ver` will now contain a global version number for DataStore-internal format integrity.
39
+ - Renamed `ab2str()` to `abtoa()` and `str2ab()` to `atoab()` to match the naming of `atob()` and `btoa()`
40
+ - Renamed `purifyObj()` to `pureObj()`
package/README.md CHANGED
@@ -1,15 +1,10 @@
1
- > [!IMPORTANT]
2
- > This library is not ready to be used yet. Please check back in a couple weeks.
3
-
4
- <br><br>
5
-
6
1
  <div align="center" style="text-align: center;">
7
2
 
8
3
  # CoreUtils
9
4
  Cross-platform, general-purpose, JavaScript core library for Node, Deno and the browser.
10
5
  Intended to be used in conjunction with [`@sv443-network/userutils`](https://github.com/Sv443-Network/UserUtils) and [`@sv443-network/djsutils`](https://github.com/Sv443-Network/DJSUtils), but can be used independently as well.
11
6
 
12
- ### [Documentation](./docs.md#readme) &bull; [Features](#features) &bull; [Installation](#installation) &bull; [License](#license)
7
+ ### [Documentation](./docs.md#readme) &bull; [Features](#features) &bull; [Installation](#installation) &bull; [License](./LICENSE.txt) &bull; [Changelog](./CHANGELOG.md)
13
8
 
14
9
  </div>
15
10
  <br>
@@ -39,12 +34,14 @@ Intended to be used in conjunction with [`@sv443-network/userutils`](https://git
39
34
  - 🟧 [`class DataStore`](./docs.md#class-datastore) - The main class for the data store
40
35
  - 🔷 [`type DataStoreOptions`](./docs.md#type-datastoreoptions) - Options for the data store
41
36
  - 🔷 [`type DataMigrationsDict`](./docs.md#type-datamigrationsdict) - Dictionary of data migration functions
37
+ - 🔷 [`type DataStoreData`](./docs.md#type-datastoredata) - The type of the serializable data
42
38
  - 🟧 [`class DataStoreSerializer`](./docs.md#class-datastoreserializer) - Serializes and deserializes data for multiple DataStore instances
43
39
  - 🔷 [`type DataStoreSerializerOptions`](./docs.md#type-datastoreserializeroptions) - Options for the DataStoreSerializer
44
40
  - 🔷 [`type LoadStoresDataResult`](./docs.md#type-loadstoresdataresult) - Result of calling [`loadStoresData()`](./docs.md#datastoreserializer-loadstoresdata)
45
41
  - 🔷 [`type SerializedDataStore`](./docs.md#type-serializeddatastore) - Meta object and serialized data of a DataStore instance
46
42
  - 🔷 [`type StoreFilter`](./docs.md#type-storefilter) - Filter for selecting data stores
47
43
  - 🟧 [`class DataStoreEngine`](./docs.md#class-datastoreengine) - Base class for DataStore storage engines, which handle the data storage
44
+ - 🔷 [`type DataStoreEngineDSOptions`](./docs.md#type-datastoreenginedsoptions) - Reduced version of [`DataStoreOptions`](./docs.md#type-datastoreoptions)
48
45
  - [Storage Engines:](./docs.md#storage-engines)
49
46
  - 🟧 [`class BrowserStorageEngine`](./docs.md#class-browserstorageengine) - Storage engine for browser environments (localStorage, sessionStorage)
50
47
  - 🔷 [`type BrowserStorageEngineOptions`](./docs.md#browserstorageengineoptions) - Options for the browser storage engine
@@ -68,6 +65,7 @@ Intended to be used in conjunction with [`@sv443-network/userutils`](https://git
68
65
  - 🟣 [`function formatNumber()`](./docs.md#function-formatnumber) - Formats a number to a string using the given locale and format identifier
69
66
  - 🔷 [`type NumberFormat`](./docs.md#type-numberformat) - Number format identifier
70
67
  - 🟣 [`function mapRange()`](./docs.md#function-maprange) - Maps a number from one range to another
68
+ - 🟣 [`function overflowVal()`](./docs.md#function-overflowVal) - Makes sure a number is in a range by over- & underflowing it
71
69
  - 🟣 [`function randRange()`](./docs.md#function-randrange) - Returns a random number in the given range
72
70
  - 🟣 [`function roundFixed()`](./docs.md#function-roundfixed) - Rounds the given number to the given number of decimal places
73
71
  - 🟣 [`function valsWithin()`](./docs.md#function-valswithin) - Checks if the given numbers are within a certain range of each other
@@ -84,6 +82,7 @@ Intended to be used in conjunction with [`@sv443-network/userutils`](https://git
84
82
  - 🟣 [`function pureObj()`](./docs.md#function-pureobj) - Applies an object's props to a null object (object without prototype chain) or just returns a new null object
85
83
  - 🟣 [`function setImmediateInterval()`](./docs.md#function-setimmediateinterval) - Like `setInterval()`, but instantly calls the callback and supports passing an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
86
84
  - 🟣 [`function setImmediateTimeoutLoop()`](./docs.md#function-setimmediatetimeoutloop) - Like a recursive `setTimeout()` loop, but instantly calls the callback and supports passing an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
85
+ - 🟣 [`function scheduleExit()`](./docs.md#function-scheduleexit) - Schedules a process exit after the next event loop tick, to allow operations like IO writes to finish.
87
86
  - [**NanoEmitter:**](./docs.md#nanoemitter)
88
87
  - 🟧 [`class NanoEmitter`](./docs.md#class-nanoemitter) - Simple, lightweight event emitter class that can be used in both FP and OOP, inspired by [`EventEmitter` from `node:events`](https://nodejs.org/api/events.html#class-eventemitter), based on [`nanoevents`](https://npmjs.com/package/nanoevents)
89
88
  - 🔷 [`type NanoEmitterOptions`](./docs.md#type-nanoemitteroptions) - Options for the [`NanoEmitter` class](./docs.md#class-nanoemitter)
@@ -94,7 +93,7 @@ Intended to be used in conjunction with [`@sv443-network/userutils`](https://git
94
93
  - 🟩 [`const defaultPbChars`](./docs.md#const-defaultpbchars) - Default characters for the progress bar
95
94
  - 🔷 [`type ProgressBarChars`](./docs.md#type-progressbarchars) - Type for the progress bar characters object
96
95
  - 🟣 [`function joinArrayReadable()`](./docs.md#function-joinarrayreadable) - Joins the given array into a string, using the given separators and last separator
97
- - 🟣 [`function secsToTimeStr()`](./docs.md#function-sectostimestr) - Turns the given number of seconds into a string in the format `(hh:)mm:ss` with intelligent zero-padding
96
+ - 🟣 [`function secsToTimeStr()`](./docs.md#function-secstotimestr) - Turns the given number of seconds into a string in the format `(hh:)mm:ss` with intelligent zero-padding
98
97
  - 🟣 [`function truncStr()`](./docs.md#function-truncstr) - Truncates the given string to the given length
99
98
  <!-- - *[**TieredCache:**](./docs.md#tieredcache)
100
99
  - 🟧 *[`class TieredCache`](./docs.md#class-tieredcache) - A multi-tier cache that uses multiple storage engines with different expiration times
@@ -126,7 +125,7 @@ Intended to be used in conjunction with [`@sv443-network/userutils`](https://git
126
125
  > 🟣 = function
127
126
  > 🟧 = class
128
127
  > 🔷 = type
129
- > 🔶 = const
128
+ > 🟩 = const
130
129
 
131
130
  <br>
132
131
 
@@ -138,4 +137,48 @@ pnpm i @sv443-network/coreutils
138
137
  yarn add @sv443-network/coreutils
139
138
  npx jsr install @sv443-network/coreutils
140
139
  deno add jsr:@sv443-network/coreutils
141
- ```
140
+ ```
141
+ - If you are in a DOM environment, you can include the UMD bundle using your favorite CDN (after inserting the version number):
142
+ ```html
143
+ <script src="https://cdn.jsdelivr.net/npm/@sv443-network/coreutils@INSERT_VERSION_HERE/dist/CoreUtils.min.umd.js"></script>
144
+ <script src="https://unpkg.com/@sv443-network/coreutils@INSERT_VERSION_HERE/dist/CoreUtils.min.umd.js"></script>
145
+ <script src="https://esm.sh/@sv443-network/coreutils@INSERT_VERSION_HERE/dist/CoreUtils.min.umd.js"></script>
146
+ ```
147
+ - Then, import parts of the library as needed:
148
+ ```ts
149
+ // >> EcmaScript Modules (ESM):
150
+
151
+ // - import parts of the library:
152
+ import { randomItem } from "@sv443-network/coreutils";
153
+ // - or import the full library:
154
+ import * as CoreUtils from "@sv443-network/coreutils";
155
+ // - or import raw TS files, after installing via JSR:
156
+ import { DataStore } from "jsr:@sv443-network/coreutils/lib/DataStore.ts";
157
+
158
+ // >> CommonJS (CJS):
159
+
160
+ // - import parts of the library:
161
+ const { debounce } = require("@sv443-network/coreutils");
162
+ // - or import the full library:
163
+ const CoreUtils = require("@sv443-network/coreutils");
164
+
165
+ // >> Universal Module Definition (UMD):
166
+
167
+ // - to make the global variable `CoreUtils` available, import this file:
168
+ // "@sv443-network/coreutils/dist/CoreUtils.min.umd.js"
169
+ // - or import the library on your HTML page:
170
+ // <script src="https://cdn.jsdelivr.net/npm/@sv443-network/coreutils@INSERT_VERSION_HERE/dist/CoreUtils.min.umd.js"></script>
171
+ // (make sure to insert the version number above. Use 'latest' (not recommended) or a specific version, e.g. '9.4.3')
172
+ ```
173
+
174
+ <br><br>
175
+
176
+ <div align="center" style="text-align: center;">
177
+
178
+ Made with ❤️ by [Sv443](https://github.com/Sv443)
179
+ If you like this userscript, please consider [supporting the development](https://github.com/sponsors/Sv443)
180
+
181
+ © 2025 Sv443 & Sv443 Network
182
+ [MIT license](./LICENSE.txt)
183
+
184
+ </div>