@sv443-network/coreutils 0.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 ADDED
@@ -0,0 +1,11 @@
1
+ - 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()`
package/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sv443 Network and Sven Fehler (Sv443)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,141 @@
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
+ <div align="center" style="text-align: center;">
7
+
8
+ # CoreUtils
9
+ Cross-platform, general-purpose, JavaScript core library for Node, Deno and the browser.
10
+ 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
+
12
+ ### [Documentation](./docs.md#readme) &bull; [Features](#features) &bull; [Installation](#installation) &bull; [License](#license)
13
+
14
+ </div>
15
+ <br>
16
+
17
+ ## Features
18
+
19
+ - [**Array:**](./docs.md#array)
20
+ - 🟣 [`function randomItem()`](./docs.md#function-randomitem) - Returns a random item from the given array
21
+ - 🟣 [`function randomItemIndex()`](./docs.md#function-randomitemindex) - Returns a random array item and index as a tuple
22
+ - 🟣 [`function randomizeArray()`](./docs.md#function-randomizearray) - Returns a new array with the items in random order
23
+ - 🟣 [`function takeRandomItem()`](./docs.md#function-takerandomitem) - Returns a random array item and mutates the array to remove it
24
+ - 🟣 [`function takeRandomItemIndex()`](./docs.md#function-randomitemindex) - Returns a random array item and index as a tuple and mutates the array to remove it
25
+ - 🔷 [`type NonEmptyArray`](./docs.md#type-nonemptyarray) - Non-empty array type
26
+ - [**Colors:**](./docs.md#colors)
27
+ - 🟣 [`function darkenColor()`](./docs.md#function-darkencolor) - Darkens the given color by the given percentage
28
+ - 🟣 [`function hexToRgb()`](./docs.md#function-hextorgb) - Converts a hex color string to an RGB object
29
+ - 🟣 [`function lightenColor()`](./docs.md#function-lightencolor) - Lightens the given color by the given percentage
30
+ - 🟣 [`function rgbToHex()`](./docs.md#function-rgbtohex) - Converts an RGB object to a hex color string
31
+ - [**Crypto:**](./docs.md#crypto)
32
+ - 🟣 [`function abtoa()`](./docs.md#function-abtoa) - Converts an ArrayBuffer to a string
33
+ - 🟣 [`function atoab()`](./docs.md#function-atoab) - Converts a string to an ArrayBuffer
34
+ - 🟣 [`function compress()`](./docs.md#function-compress) - Compresses the given string using the given algorithm and encoding
35
+ - 🟣 [`function decompress()`](./docs.md#function-decompress) - Decompresses the given string using the given algorithm and encoding
36
+ - 🟣 [`function computeHash()`](./docs.md#function-computehash) - Computes a string's hash using the given algorithm
37
+ - 🟣 [`function randomId()`](./docs.md#function-randomid) - Generates a random ID of the given length
38
+ - [**DataStore:**](./docs.md#datastore) - Cross-platform, general-purpose, sync/async hybrid, JSON-serializable database infrastructure:
39
+ - 🟧 [`class DataStore`](./docs.md#class-datastore) - The main class for the data store
40
+ - 🔷 [`type DataStoreOptions`](./docs.md#type-datastoreoptions) - Options for the data store
41
+ - 🔷 [`type DataMigrationsDict`](./docs.md#type-datamigrationsdict) - Dictionary of data migration functions
42
+ - 🟧 [`class DataStoreSerializer`](./docs.md#class-datastoreserializer) - Serializes and deserializes data for multiple DataStore instances
43
+ - 🔷 [`type DataStoreSerializerOptions`](./docs.md#type-datastoreserializeroptions) - Options for the DataStoreSerializer
44
+ - 🔷 [`type LoadStoresDataResult`](./docs.md#type-loadstoresdataresult) - Result of calling [`loadStoresData()`](./docs.md#datastoreserializer-loadstoresdata)
45
+ - 🔷 [`type SerializedDataStore`](./docs.md#type-serializeddatastore) - Meta object and serialized data of a DataStore instance
46
+ - 🔷 [`type StoreFilter`](./docs.md#type-storefilter) - Filter for selecting data stores
47
+ - 🟧 [`class DataStoreEngine`](./docs.md#class-datastoreengine) - Base class for DataStore storage engines, which handle the data storage
48
+ - [Storage Engines:](./docs.md#storage-engines)
49
+ - 🟧 [`class BrowserStorageEngine`](./docs.md#class-browserstorageengine) - Storage engine for browser environments (localStorage, sessionStorage)
50
+ - 🔷 [`type BrowserStorageEngineOptions`](./docs.md#browserstorageengineoptions) - Options for the browser storage engine
51
+ - 🟧 [`class FileStorageEngine`](./docs.md#class-FileStorageEngine) - File-based storage engine for Node.js and Deno
52
+ - 🔷 [`type FileStorageEngineOptions`](./docs.md#FileStorageEngineoptions) - Options for the file storage engine
53
+ - [**Debouncer:**](./docs.md#debouncer)
54
+ - 🟣 [`function debounce()`](./docs.md#function-debounce) - Function wrapper for the [`Debouncer` class](./docs.md#class-debouncer)
55
+ - 🟧 [`class Debouncer`](./docs.md#class-debouncer) - Class that manages listeners whose calls are rate-limited
56
+ - 🔷 [`type DebouncerType`](./docs.md#type-debouncertype) - The triggering type for the debouncer
57
+ - 🔷 [`type DebouncedFunction`](./docs.md#type-debouncedfunction) - Function type that is returned by the [`debounce()` function](./docs.md#function-debounce)
58
+ - 🔷 [`type DebouncerEventMap`](./docs.md#type-debouncereventmap) - Event map type for the [`Debouncer` class](./docs.md#class-debouncer)
59
+ - [**Errors:**](./docs.md#errors)
60
+ - 🟧 [`class DatedError`](./docs.md#class-datederror) - Base error class with a `date` property
61
+ - 🟧 [`class ChecksumMismatchError`](./docs.md#class-checksummismatcherror) - Error thrown when two checksums don't match
62
+ - 🟧 [`class MigrationError`](./docs.md#class-migrationerror) - Error thrown in a failed data migration
63
+ - 🟧 [`class ValidationError`](./docs.md#class-validationerror) - Error while validating data
64
+ - [**Math:**](./docs.md#math)
65
+ - 🟣 [`function bitSetHas()`](./docs.md#function-bitsethas) - Checks if a bit is set in a bitset
66
+ - 🟣 [`function clamp()`](./docs.md#function-clamp) - Clamps a number between a given range
67
+ - 🟣 [`function digitCount()`](./docs.md#function-digitcount) - Returns the number of digits in a number
68
+ - 🟣 [`function formatNumber()`](./docs.md#function-formatnumber) - Formats a number to a string using the given locale and format identifier
69
+ - 🔷 [`type NumberFormat`](./docs.md#type-numberformat) - Number format identifier
70
+ - 🟣 [`function mapRange()`](./docs.md#function-maprange) - Maps a number from one range to another
71
+ - 🟣 [`function randRange()`](./docs.md#function-randrange) - Returns a random number in the given range
72
+ - 🟣 [`function roundFixed()`](./docs.md#function-roundfixed) - Rounds the given number to the given number of decimal places
73
+ - 🟣 [`function valsWithin()`](./docs.md#function-valswithin) - Checks if the given numbers are within a certain range of each other
74
+ - [**Misc:**](./docs.md#misc)
75
+ - 🟣 [`function consumeGen()`](./docs.md#function-consumegen) - Consumes a [`ValueGen` object](./docs.md#type-valuegen)
76
+ - 🔷 [`type ValueGen`](./docs.md#type-valuegen) - A value that can be either type T, or a sync or async function that returns T
77
+ - 🟣 [`function consumeStringGen()`](./docs.md#function-consumestringgen) - Consumes a [`StringGen` object](./docs.md#type-stringgen)
78
+ - 🔷 [`type StringGen`](./docs.md#type-stringgen) - A value that can be either of type string, or a sync or async function that returns a string
79
+ - 🟣 [`function fetchAdvanced()`](./docs.md#function-fetchadvanced) - Wrapper around [`fetch()`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) with options like a timeout
80
+ - 🔷 [`type FetchAdvancedOpts`](./docs.md#type-fetchadvancedopts) - Options for the [`fetchAdvanced()` function](./docs.md#function-fetchadvanced)
81
+ - 🟣 [`function getListLength()`](./docs.md#function-getlistlength) - Returns the length of a [`ListLike` object](./docs.md#type-listlike)
82
+ - 🔷 [`type ListLike`](./docs.md#type-listlike) - Any value with a quantifiable `length`, `count` or `size` property
83
+ - 🟣 [`function pauseFor()`](./docs.md#function-pausefor) - Pauses async execution for the given amount of time
84
+ - 🟣 [`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
+ - 🟣 [`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
+ - 🟣 [`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)
87
+ - [**NanoEmitter:**](./docs.md#nanoemitter)
88
+ - 🟧 [`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
+ - 🔷 [`type NanoEmitterOptions`](./docs.md#type-nanoemitteroptions) - Options for the [`NanoEmitter` class](./docs.md#class-nanoemitter)
90
+ - [**Text:**](./docs.md#text)
91
+ - 🟣 [`function autoPlural()`](./docs.md#function-autoplural) - Turns the given term into its plural form, depending on the given number or list length
92
+ - 🟣 [`function capitalize()`](./docs.md#function-capitalize) - Capitalizes the first letter of the given string
93
+ - 🟣 [`function createProgressBar()`](./docs.md#function-createprogressbar) - Creates a progress bar string with the given percentage and length
94
+ - 🟩 [`const defaultPbChars`](./docs.md#const-defaultpbchars) - Default characters for the progress bar
95
+ - 🔷 [`type ProgressBarChars`](./docs.md#type-progressbarchars) - Type for the progress bar characters object
96
+ - 🟣 [`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
98
+ - 🟣 [`function truncStr()`](./docs.md#function-truncstr) - Truncates the given string to the given length
99
+ <!-- - *[**TieredCache:**](./docs.md#tieredcache)
100
+ - 🟧 *[`class TieredCache`](./docs.md#class-tieredcache) - A multi-tier cache that uses multiple storage engines with different expiration times
101
+ - 🔷 *[`type TieredCacheOptions`](./docs.md#type-tieredcacheoptions) - Options for the [`TieredCache` class](./docs.md#class-tieredcache)
102
+ - 🔷 *[`type TieredCachePropagateTierOptions`](./docs.md#type-tieredcachestaleoptions) - Entry propagation options for each tier
103
+ - 🔷 *[`type TieredCacheStaleOptions`](./docs.md#type-tieredcachepropagatetieroptions) - Entry staleness options for each tier
104
+ - 🔷 *[`type TieredCacheTierOptions`](./docs.md#type-tieredcachetieroptions) - Options for each tier of a [`TieredCache` instance](./docs.md#class-tieredcache)
105
+ - *[**Translate:**](./docs.md#translate)
106
+ - 🟧 *[`class Translate`](./docs.md#class-translate) - JSON-based translation system supporting transformation hooks, value injection, nested objects, etc.
107
+ - 🔷 *[`type TransformFn`](./docs.md#type-transformfn) - The type of the transformation hook functions
108
+ - 🔷 *[`type TransformFnProps`](./docs.md#type-transformfnprops) - The properties passed to the transformation functions
109
+ - 🔷 *[`type TranslateOptions`](./docs.md#type-translateoptions) - The options for the [`Translate` class](./docs.md#class-translate)
110
+ - 🔷 *[`type TrKeys`](./docs.md#type-trkeys) - Generic type that gives you a union of keys from the passed [`TrObject` object](./docs.md#type-trobject)
111
+ - 🔷 *[`type TrObject`](./docs.md#type-trobject) - The translation object for a specific language -->
112
+ - [**Misc. Types:**](./docs.md#types)
113
+ - 🔷 [`type LooseUnion`](./docs.md#type-looseunion) - A union type that allows for autocomplete suggestions as well as substitutions of the same type
114
+ - 🔷 [`type ListLike`](./docs.md#type-listlike) - Any value with a quantifiable `length`, `count` or `size` property
115
+ - 🔷 [`type Newable`](./docs.md#type-newable) - Any class reference that can be instantiated with `new`
116
+ - 🔷 [`type NonEmptyArray`](./docs.md#type-nonemptyarray) - Non-empty array type
117
+ - 🔷 [`type NonEmptyString`](./docs.md#type-nonemptystring) - String type with at least one character
118
+ - 🔷 [`type NumberFormat`](./docs.md#type-numberformat) - Number format identifier
119
+ - 🔷 [`type Prettify`](./docs.md#type-prettify) - Makes the structure of a type more readable by fully expanding it (recursively)
120
+ - 🔷 [`type SerializableVal`](./docs.md#type-serializableval) - Any value that can be serialized to JSON
121
+ - 🔷 [`type StringGen`](./docs.md#type-stringgen) - A value that can be either of type string, or a sync or async function that returns a string
122
+ - 🔷 [`type ValueGen`](./docs.md#type-valuegen) - A value that can be either the generic type T, or a sync or async function that returns T
123
+ - 🔷 [`type Stringifiable`](./docs.md#type-stringifiable) - Any value that can be implicitly converted to a string
124
+
125
+ > [!NOTE]
126
+ > 🟣 = function
127
+ > 🟧 = class
128
+ > 🔷 = type
129
+ > 🔶 = const
130
+
131
+ <br>
132
+
133
+ ## Installation
134
+ - If you are using Node.js or Deno, install the package from NPM or JSR via your favorite package manager:
135
+ ```bash
136
+ npm i @sv443-network/coreutils
137
+ pnpm i @sv443-network/coreutils
138
+ yarn add @sv443-network/coreutils
139
+ npx jsr install @sv443-network/coreutils
140
+ deno add jsr:@sv443-network/coreutils
141
+ ```