umt 2.6.0 → 2.8.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/README.md +25 -0
- package/module/Crypto/decodeBase32.d.ts +7 -0
- package/module/Crypto/decodeBase32.js +27 -0
- package/module/Crypto/decodeBase32.js.map +1 -0
- package/module/Crypto/decodeBase32ToString.d.ts +7 -0
- package/module/Crypto/decodeBase32ToString.js +11 -0
- package/module/Crypto/decodeBase32ToString.js.map +1 -0
- package/module/Crypto/decodeBase58.d.ts +7 -0
- package/module/Crypto/decodeBase58.js +34 -0
- package/module/Crypto/decodeBase58.js.map +1 -0
- package/module/Crypto/decodeBase58ToString.d.ts +7 -0
- package/module/Crypto/decodeBase58ToString.js +11 -0
- package/module/Crypto/decodeBase58ToString.js.map +1 -0
- package/module/Crypto/encodeBase32.d.ts +7 -0
- package/module/Crypto/encodeBase32.js +28 -0
- package/module/Crypto/encodeBase32.js.map +1 -0
- package/module/Crypto/encodeBase58.d.ts +7 -0
- package/module/Crypto/encodeBase58.js +29 -0
- package/module/Crypto/encodeBase58.js.map +1 -0
- package/module/Crypto/index.d.ts +6 -0
- package/module/Crypto/index.js +7 -0
- package/module/Crypto/index.js.map +1 -0
- package/module/DataStructure/index.d.ts +1 -0
- package/module/DataStructure/index.js +2 -0
- package/module/DataStructure/index.js.map +1 -0
- package/module/DataStructure/priorityQueue.d.ts +241 -0
- package/module/DataStructure/priorityQueue.js +327 -0
- package/module/DataStructure/priorityQueue.js.map +1 -0
- package/module/Math/correlationCoefficient.d.ts +11 -0
- package/module/Math/correlationCoefficient.js +40 -0
- package/module/Math/correlationCoefficient.js.map +1 -0
- package/module/Math/index.d.ts +3 -0
- package/module/Math/index.js +3 -0
- package/module/Math/index.js.map +1 -1
- package/module/Math/mode.d.ts +10 -0
- package/module/Math/mode.js +31 -0
- package/module/Math/mode.js.map +1 -0
- package/module/Math/percentile.d.ts +11 -0
- package/module/Math/percentile.js +31 -0
- package/module/Math/percentile.js.map +1 -0
- package/module/Math/solveEquation.js +1 -1
- package/module/Math/solveEquation.js.map +1 -1
- package/module/String/fuzzySearch.d.ts +14 -0
- package/module/String/fuzzySearch.js +27 -0
- package/module/String/fuzzySearch.js.map +1 -0
- package/module/String/index.d.ts +4 -0
- package/module/String/index.js +4 -0
- package/module/String/index.js.map +1 -1
- package/module/String/reverseString.js +1 -1
- package/module/String/reverseString.js.map +1 -1
- package/module/String/slugify.d.ts +10 -0
- package/module/String/slugify.js +21 -0
- package/module/String/slugify.js.map +1 -0
- package/module/String/truncate.d.ts +12 -0
- package/module/String/truncate.js +21 -0
- package/module/String/truncate.js.map +1 -0
- package/module/String/unescapeHtml.d.ts +17 -0
- package/module/String/unescapeHtml.js +45 -0
- package/module/String/unescapeHtml.js.map +1 -0
- package/module/Validate/index.d.ts +1 -0
- package/module/Validate/index.js +1 -0
- package/module/Validate/index.js.map +1 -1
- package/module/Validate/isDeepEqual.d.ts +28 -0
- package/module/Validate/isDeepEqual.js +148 -0
- package/module/Validate/isDeepEqual.js.map +1 -0
- package/module/Validate/isNode.js +3 -2
- package/module/Validate/isNode.js.map +1 -1
- package/module/Validate/string/email.js +8 -0
- package/module/Validate/string/email.js.map +1 -1
- package/module/es5/Crypto/decodeBase32.d.ts +7 -0
- package/module/es5/Crypto/decodeBase32.js +44 -0
- package/module/es5/Crypto/decodeBase32ToString.d.ts +7 -0
- package/module/es5/Crypto/decodeBase32ToString.js +16 -0
- package/module/es5/Crypto/decodeBase58.d.ts +7 -0
- package/module/es5/Crypto/decodeBase58.js +63 -0
- package/module/es5/Crypto/decodeBase58ToString.d.ts +7 -0
- package/module/es5/Crypto/decodeBase58ToString.js +16 -0
- package/module/es5/Crypto/encodeBase32.d.ts +7 -0
- package/module/es5/Crypto/encodeBase32.js +45 -0
- package/module/es5/Crypto/encodeBase58.d.ts +7 -0
- package/module/es5/Crypto/encodeBase58.js +55 -0
- package/module/es5/Crypto/index.d.ts +6 -0
- package/module/es5/Crypto/index.js +71 -0
- package/module/es5/DataStructure/index.d.ts +1 -0
- package/module/es5/DataStructure/index.js +16 -0
- package/module/es5/DataStructure/priorityQueue.d.ts +241 -0
- package/module/es5/DataStructure/priorityQueue.js +405 -0
- package/module/es5/Error/retry.js +2 -2
- package/module/es5/Math/correlationCoefficient.d.ts +11 -0
- package/module/es5/Math/correlationCoefficient.js +63 -0
- package/module/es5/Math/index.d.ts +3 -0
- package/module/es5/Math/index.js +33 -0
- package/module/es5/Math/mode.d.ts +10 -0
- package/module/es5/Math/mode.js +67 -0
- package/module/es5/Math/percentile.d.ts +11 -0
- package/module/es5/Math/percentile.js +42 -0
- package/module/es5/Math/solveEquation.js +1 -1
- package/module/es5/String/fuzzySearch.d.ts +14 -0
- package/module/es5/String/fuzzySearch.js +50 -0
- package/module/es5/String/index.d.ts +4 -0
- package/module/es5/String/index.js +44 -0
- package/module/es5/String/reverseString.js +1 -1
- package/module/es5/String/slugify.d.ts +10 -0
- package/module/es5/String/slugify.js +18 -0
- package/module/es5/String/truncate.d.ts +12 -0
- package/module/es5/String/truncate.js +27 -0
- package/module/es5/String/unescapeHtml.d.ts +17 -0
- package/module/es5/String/unescapeHtml.js +51 -0
- package/module/es5/Validate/index.d.ts +1 -0
- package/module/es5/Validate/index.js +11 -0
- package/module/es5/Validate/isDeepEqual.d.ts +28 -0
- package/module/es5/Validate/isDeepEqual.js +232 -0
- package/module/es5/Validate/isNode.js +5 -2
- package/module/es5/Validate/string/email.js +10 -0
- package/module/es5/index.d.ts +2 -0
- package/module/es5/index.js +22 -0
- package/module/es5/tsconfig.tsbuildinfo +1 -1
- package/module/index.d.ts +2 -0
- package/module/index.js +2 -0
- package/module/index.js.map +1 -1
- package/package.json +31 -31
package/README.md
CHANGED
|
@@ -60,6 +60,12 @@ bun add umt
|
|
|
60
60
|
| zip | `<T extends unknown[][]>(...arrays: T) => ZipArrayType<T>` | Creates a new array by combining elements from multiple arrays at corresponding positions | `zip([1, 2], ['a', 'b']); // [[1, 'a'], [2, 'b']]` |
|
|
61
61
|
| zipLongest | `<T extends unknown[][]>(...arrays: T) => ZipArrayType<T>` | Combines arrays of different lengths by padding shorter arrays with undefined values | `zipLongest([1, 2], ['a']); // [[1, 'a'], [2, undefined]]` |
|
|
62
62
|
|
|
63
|
+
### DataStructure
|
|
64
|
+
|
|
65
|
+
| name | type | description | example |
|
|
66
|
+
|------|------|-------------|---------|
|
|
67
|
+
| PriorityQueue | `class PriorityQueue<T>` | A priority queue implementation using a binary heap. Higher priority values are dequeued first. | `const queue = new PriorityQueue<string>(); queue.enqueue("low", 1); queue.enqueue("high", 3); queue.enqueueBack("back"); queue.dequeue(); // "high"` |
|
|
68
|
+
|
|
63
69
|
### Color
|
|
64
70
|
|
|
65
71
|
| name | type | description | example |
|
|
@@ -71,6 +77,17 @@ bun add umt
|
|
|
71
77
|
| rgbaToHexA | `(rgba: { r: number; g: number; b: number; a?: number }) => string` | Convert RGBA color to hexadecimal color code | `rgbaToHexA({ r: 0, g: 0, b: 0, a: 1 }); // "#000000ff"` |
|
|
72
78
|
| rgbaToHsla | `(rgba: { r: number; g: number; b: number; a?: number }) => { h: number; s: number; l: number; a: number }` | Convert RGBA color values to HSLA color space | `rgbaToHsla({ r: 100, g: 100, b: 100, a: 1 }); // { h: 0, s: 0, l: 39.22, a: 1 }` |
|
|
73
79
|
|
|
80
|
+
### Crypto
|
|
81
|
+
|
|
82
|
+
| name | type | description | example |
|
|
83
|
+
|------|------|-------------|---------|
|
|
84
|
+
| decodeBase32 | `(input: string) => Uint8Array` | Decodes an uppercase Base32 string to Uint8Array. Does not validate padding placement. | `decodeBase32("JBSWY3DP"); // Uint8Array for "Hello"` |
|
|
85
|
+
| decodeBase32ToString | `(input: string) => string` | Decodes an uppercase Base32 string to a UTF-8 string. Does not validate padding placement. | `decodeBase32ToString("JBSWY3DP"); // "Hello"` |
|
|
86
|
+
| decodeBase58 | `(input: string) => Uint8Array` | Decodes a Base58 string to Uint8Array | `decodeBase58("9Ajdvzr"); // Uint8Array for "Hello"` |
|
|
87
|
+
| decodeBase58ToString | `(input: string) => string` | Decodes a Base58 string to a UTF-8 string | `decodeBase58ToString("9Ajdvzr"); // "Hello"` |
|
|
88
|
+
| encodeBase32 | `(input: string \| Uint8Array) => string` | Encodes a string or Uint8Array to Base32 format | `encodeBase32("Hello"); // "JBSWY3DP"` |
|
|
89
|
+
| encodeBase58 | `(input: string \| Uint8Array) => string` | Encodes a string or Uint8Array to Base58 format | `encodeBase58("Hello"); // "9Ajdvzr"` |
|
|
90
|
+
|
|
74
91
|
### Date
|
|
75
92
|
|
|
76
93
|
| name | type | description | example |
|
|
@@ -119,6 +136,7 @@ bun add umt
|
|
|
119
136
|
|------|------|-------------|---------|
|
|
120
137
|
| addition | `(...numbers: number[]) => number` | Addition without floating point errors | `addition(0.1, 0.2); // 0.3` |
|
|
121
138
|
| average | `(numbers: number[]) => number` | Calculates the arithmetic mean of an array of numbers | `average([1, 2, 3]); // 2` |
|
|
139
|
+
| correlationCoefficient | `(x: number[], y: number[]) => number` | Calculate the Pearson correlation coefficient between two arrays | `correlationCoefficient([1, 2, 3, 4, 5], [2, 4, 6, 8, 10]); // 1` |
|
|
122
140
|
| bitwise | `(x: number, k: number, direction?: "left" \| "right") => number` | Performs bit rotation on a number | `bitwise(0x12345678, 8); // 0x34567812` |
|
|
123
141
|
| calculator | `<T extends Record<string, string \| number>>(expression: string, exchange?: T) => string` | Calculator function that handles mathematical expressions and simple equations | `calculator("1+2"); // "3"` |
|
|
124
142
|
| calculatorInitialization | `<T extends { [key: string]: string \| number }>(exchange: T) => (x: string) => string` | Initializes a calculator function with exchange rates | `calculatorInitialization({ $: 100 })("$1"); // "100"` |
|
|
@@ -139,11 +157,13 @@ bun add umt
|
|
|
139
157
|
| max | `(...number_: number[]) => number` | Returns the maximum value from the input numbers | `max(1, 2, 3); // 3` |
|
|
140
158
|
| median | `(array: number[]) => number` | Calculate the median of an array of numbers | `median([1, 3, 3, 6, 7, 8, 9]); // 6` |
|
|
141
159
|
| min | `(...number_: number[]) => number` | Returns the minimum value from the input numbers | `min(1, 2, 3); // 1` |
|
|
160
|
+
| mode | `(array: number[]) => number[]` | Finds the most frequently occurring value(s) in an array | `mode([1, 2, 2, 3, 3, 3]); // [3]` |
|
|
142
161
|
| multiples | `(x: number, n: number) => number[]` | Generate an array of multiples of a number | `multiples(2, 5); // [2, 4, 6, 8, 10]` |
|
|
143
162
|
| multiplication | `(...numbers: number[]) => number` | Performs multiplication without floating point errors for any number of arguments | `multiplication(0.1, 0.2, 0.3); // 0.006` |
|
|
144
163
|
| nCr | `(n: number, r: number) => number` | Calculates combinations (nCr) - number of ways to choose r items from n items | `nCr(5, 2); // 10` |
|
|
145
164
|
| nHr | `(n: number, r: number) => number` | Calculates combinations with repetition (nHr) | `nHr(5, 2); // 15` |
|
|
146
165
|
| nPr | `(n: number, r: number) => number` | Calculates permutations (nPr) - number of ways to arrange r items from n items | `nPr(5, 2); // 20` |
|
|
166
|
+
| percentile | `(array: number[], percentile: number) => number` | Calculate the nth percentile of values in an array | `percentile([1, 2, 3, 4, 5], 50); // 3` |
|
|
147
167
|
| primeFactorization | `(x: number) => Array<{number: number; count: number}>` | Performs prime factorization of a number | `primeFactorization(12); // [{number: 2, count: 2}, {number: 3, count: 1}]` |
|
|
148
168
|
| quotient | `(x: number, y: number) => number[]` | Computes quotient and remainder of division | `quotient(5, 2); // [2, 1]` |
|
|
149
169
|
| radToDeg | `(x: number) => number` | Converts radians to degrees | `radToDeg(Math.PI); // 180` |
|
|
@@ -192,6 +212,7 @@ bun add umt
|
|
|
192
212
|
| deleteSpaces | `(string_: string) => string` | Removes all whitespace characters from a string | `deleteSpaces("Hello World"); // "HelloWorld"` |
|
|
193
213
|
| escapeHtml | `(str: string) => string` | Escapes HTML special characters in a string | `escapeHtml("<script>alert('XSS')</script>"); // "<script>alert('XSS')</script>"` |
|
|
194
214
|
| formatString | `(template: string, ...values: unknown[]) => string` | Replaces placeholders in a template string with specified values | `formatString("Hello, {0}!", "World"); // "Hello, World!"` |
|
|
215
|
+
| fuzzySearch | `(query: string, items: string[], threshold?: number) => Array<{ item: string; score: number }>` | Perform fuzzy string matching on an array of strings | `fuzzySearch("hello", ["hello", "world", "helo", "help"]); // [{ item: "hello", score: 1 }, { item: "helo", score: 0.8 }, { item: "help", score: 0.6 }]` |
|
|
195
216
|
| fromBase64 | `(base64String: string) => string` | Converts Base64 to string | `fromBase64("SGVsbG8="); // "Hello"` |
|
|
196
217
|
| hasNoLetters | `(text: string) => boolean` | Checks if the string contains no letters (contains only emojis, numbers, or special characters) | `hasNoLetters("123"); // true` |
|
|
197
218
|
| kebabCase | `(str: string) => string` | Converts a string to kebab-case | `kebabCase("helloWorld"); // "hello-world"` |
|
|
@@ -201,12 +222,15 @@ bun add umt
|
|
|
201
222
|
| randomString | `(size?: number, char?: string) => string` | Generates a random string | `randomString(8); // "aB3dEf9h"` |
|
|
202
223
|
| randomStringInitialization | `(char?: string) => (size: number) => string` | Initializes a function that generates random strings | `const gen = randomStringInitialization("ABC"); gen(5); // "ABCAB"` |
|
|
203
224
|
| reverseString | `(char: string) => string` | Reverses a string | `reverseString("Hello"); // "olleH"` |
|
|
225
|
+
| slugify | `(str: string) => string` | Convert a string to a URL-friendly slug | `slugify("Hello World!"); // "hello-world"` |
|
|
204
226
|
| stringSimilarity | `(string1: string, string2: string) => number` | Calculates the similarity between two strings as a percentage (0-1) using Levenshtein distance | `stringSimilarity("hello", "hallo"); // 0.8` |
|
|
205
227
|
| toBase64 | `(char: string) => string` | Convert string to Base64 | `toBase64("Hello"); // "SGVsbG8="` |
|
|
206
228
|
| toHalfWidth | `(str: string) => string` | Convert full-width characters to half-width characters | `toHalfWidth("123ABC"); // "123ABC"` |
|
|
207
229
|
| trimCharacters | `(string_: string, chars: string) => string` | Removes specified characters from both ends of a string | `trimCharacters("!!!hello!!!", "!"); // "hello"` |
|
|
208
230
|
| trimEndCharacters | `(string_: string, chars: string) => string` | Removes specified characters from the end of a string | `trimEndCharacters("hello!!!", "!"); // "hello"` |
|
|
209
231
|
| trimStartCharacters | `(string_: string, chars: string) => string` | Removes specified characters from the start of a string | `trimStartCharacters("!!!hello", "!"); // "hello"` |
|
|
232
|
+
| truncate | `(str: string, length: number, suffix?: string) => string` | Truncate a string to a specified length | `truncate("Hello World", 5); // "Hello..."` |
|
|
233
|
+
| unescapeHtml | `(str: string) => string` | Unescapes HTML entities in a string | `unescapeHtml("<script>alert("Hello");</script>"); // "<script>alert("Hello");</script>"` |
|
|
210
234
|
|
|
211
235
|
### Time
|
|
212
236
|
|
|
@@ -250,6 +274,7 @@ bun add umt
|
|
|
250
274
|
| isArray | `<T>(array: unknown) => array is T[]` | Determines if the value is an array | `isArray([1, 2, 3]); // true` |
|
|
251
275
|
| isBrowser | `() => boolean` | Determines if the current environment is a browser | `isBrowser(); // true in browser` |
|
|
252
276
|
| isBun | `() => boolean` | Determines if the current environment is Bun runtime | `isBun(); // true in Bun` |
|
|
277
|
+
| isDeepEqual | `(a: unknown, b: unknown, options?: IsDeepEqualOptions) => boolean` | Performs deep equality comparison between two values with support for nested objects, arrays, Sets, Maps, and circular references | `isDeepEqual({ a: 1, b: [2, 3] }, { b: [2, 3], a: 1 }); // true` |
|
|
253
278
|
| isDictionaryObject | `<T extends { [key: string]: unknown }>(object: unknown) => object is T` | Determines if the value is a dictionary-type object | `isDictionaryObject({}); // true` |
|
|
254
279
|
| isDouble | `<T extends boolean = true>(x: unknown, loose?: T) => x is T extends true ? number \| string : number` | Determines if the value is a decimal number | `isDouble(0.1); // true` |
|
|
255
280
|
| isEqual | `(a: unknown, b: unknown) => boolean` | Evaluates true strict equality | `isEqual(1, 1); // true` |
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a Base32 string to Uint8Array
|
|
3
|
+
* @param {string} input - Base32 encoded string
|
|
4
|
+
* @returns {Uint8Array} Decoded bytes
|
|
5
|
+
* @example decodeBase32("JBSWY3DP"); // Uint8Array for "Hello"
|
|
6
|
+
*/
|
|
7
|
+
export declare const decodeBase32: (input: string) => Uint8Array;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a Base32 string to Uint8Array
|
|
3
|
+
* @param {string} input - Base32 encoded string
|
|
4
|
+
* @returns {Uint8Array} Decoded bytes
|
|
5
|
+
* @example decodeBase32("JBSWY3DP"); // Uint8Array for "Hello"
|
|
6
|
+
*/
|
|
7
|
+
export const decodeBase32 = (input) => {
|
|
8
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
9
|
+
const cleanedInput = input.replaceAll("=", "");
|
|
10
|
+
const result = [];
|
|
11
|
+
let buffer = 0;
|
|
12
|
+
let bufferLength = 0;
|
|
13
|
+
for (const char of cleanedInput) {
|
|
14
|
+
const value = alphabet.indexOf(char);
|
|
15
|
+
if (value === -1) {
|
|
16
|
+
throw new Error(`Invalid base32 character: ${char}`);
|
|
17
|
+
}
|
|
18
|
+
buffer = (buffer << 5) | value;
|
|
19
|
+
bufferLength += 5;
|
|
20
|
+
if (bufferLength >= 8) {
|
|
21
|
+
bufferLength -= 8;
|
|
22
|
+
result.push((buffer >> bufferLength) & 0xff);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return new Uint8Array(result);
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=decodeBase32.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeBase32.js","sourceRoot":"","sources":["../../src/Crypto/decodeBase32.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAa,EAAc,EAAE;IACxD,MAAM,QAAQ,GAAG,kCAAkC,CAAC;IACpD,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,EAAE,CAAC,CAAC;QACvD,CAAC;QAED,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC;QAC/B,YAAY,IAAI,CAAC,CAAC;QAElB,IAAI,YAAY,IAAI,CAAC,EAAE,CAAC;YACtB,YAAY,IAAI,CAAC,CAAC;YAClB,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a Base32 string to a UTF-8 string
|
|
3
|
+
* @param {string} input - Base32 encoded string
|
|
4
|
+
* @returns {string} Decoded string
|
|
5
|
+
* @example decodeBase32ToString("JBSWY3DP"); // "Hello"
|
|
6
|
+
*/
|
|
7
|
+
export declare const decodeBase32ToString: (input: string) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { decodeBase32 } from "./decodeBase32";
|
|
2
|
+
/**
|
|
3
|
+
* Decodes a Base32 string to a UTF-8 string
|
|
4
|
+
* @param {string} input - Base32 encoded string
|
|
5
|
+
* @returns {string} Decoded string
|
|
6
|
+
* @example decodeBase32ToString("JBSWY3DP"); // "Hello"
|
|
7
|
+
*/
|
|
8
|
+
export const decodeBase32ToString = (input) => {
|
|
9
|
+
return new TextDecoder().decode(decodeBase32(input));
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=decodeBase32ToString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeBase32ToString.js","sourceRoot":"","sources":["../../src/Crypto/decodeBase32ToString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAU,EAAE;IAC5D,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a Base58 string to Uint8Array
|
|
3
|
+
* @param {string} input - Base58 encoded string
|
|
4
|
+
* @returns {Uint8Array} Decoded bytes
|
|
5
|
+
* @example decodeBase58("9Ajdvzr"); // Uint8Array for "Hello"
|
|
6
|
+
*/
|
|
7
|
+
export declare const decodeBase58: (input: string) => Uint8Array;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a Base58 string to Uint8Array
|
|
3
|
+
* @param {string} input - Base58 encoded string
|
|
4
|
+
* @returns {Uint8Array} Decoded bytes
|
|
5
|
+
* @example decodeBase58("9Ajdvzr"); // Uint8Array for "Hello"
|
|
6
|
+
*/
|
|
7
|
+
export const decodeBase58 = (input) => {
|
|
8
|
+
const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
9
|
+
let bigNumber = BigInt(0);
|
|
10
|
+
for (const char of input) {
|
|
11
|
+
const value = alphabet.indexOf(char);
|
|
12
|
+
if (value === -1) {
|
|
13
|
+
throw new Error(`Invalid base58 character: ${char}`);
|
|
14
|
+
}
|
|
15
|
+
bigNumber = bigNumber * BigInt(58) + BigInt(value);
|
|
16
|
+
}
|
|
17
|
+
const bytes = [];
|
|
18
|
+
while (bigNumber > 0) {
|
|
19
|
+
bytes.unshift(Number(bigNumber % BigInt(256)));
|
|
20
|
+
bigNumber /= BigInt(256);
|
|
21
|
+
}
|
|
22
|
+
let leadingOnes = 0;
|
|
23
|
+
for (const char of input) {
|
|
24
|
+
if (char !== "1") {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
leadingOnes++;
|
|
28
|
+
}
|
|
29
|
+
return new Uint8Array([
|
|
30
|
+
...Array.from({ length: leadingOnes }).fill(0),
|
|
31
|
+
...bytes,
|
|
32
|
+
]);
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=decodeBase58.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeBase58.js","sourceRoot":"","sources":["../../src/Crypto/decodeBase58.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAa,EAAc,EAAE;IACxD,MAAM,QAAQ,GAAG,4DAA4D,CAAC;IAC9E,IAAI,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAE1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,EAAE,CAAC,CAAC;QACvD,CAAC;QACD,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,OAAO,SAAS,GAAG,CAAC,EAAE,CAAC;QACrB,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/C,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,MAAM;QACR,CAAC;QACD,WAAW,EAAE,CAAC;IAChB,CAAC;IAED,OAAO,IAAI,UAAU,CAAC;QACpB,GAAI,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAc;QAC5D,GAAG,KAAK;KACT,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a Base58 string to a UTF-8 string
|
|
3
|
+
* @param {string} input - Base58 encoded string
|
|
4
|
+
* @returns {string} Decoded string
|
|
5
|
+
* @example decodeBase58ToString("9Ajdvzr"); // "Hello"
|
|
6
|
+
*/
|
|
7
|
+
export declare const decodeBase58ToString: (input: string) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { decodeBase58 } from "./decodeBase58";
|
|
2
|
+
/**
|
|
3
|
+
* Decodes a Base58 string to a UTF-8 string
|
|
4
|
+
* @param {string} input - Base58 encoded string
|
|
5
|
+
* @returns {string} Decoded string
|
|
6
|
+
* @example decodeBase58ToString("9Ajdvzr"); // "Hello"
|
|
7
|
+
*/
|
|
8
|
+
export const decodeBase58ToString = (input) => {
|
|
9
|
+
return new TextDecoder().decode(decodeBase58(input));
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=decodeBase58ToString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeBase58ToString.js","sourceRoot":"","sources":["../../src/Crypto/decodeBase58ToString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAU,EAAE;IAC5D,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a string or Uint8Array to Base32 format
|
|
3
|
+
* @param {string | Uint8Array} input - The input to encode
|
|
4
|
+
* @returns {string} Base32 encoded string
|
|
5
|
+
* @example encodeBase32("Hello"); // "JBSWY3DP"
|
|
6
|
+
*/
|
|
7
|
+
export declare const encodeBase32: (input: string | Uint8Array) => string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a string or Uint8Array to Base32 format
|
|
3
|
+
* @param {string | Uint8Array} input - The input to encode
|
|
4
|
+
* @returns {string} Base32 encoded string
|
|
5
|
+
* @example encodeBase32("Hello"); // "JBSWY3DP"
|
|
6
|
+
*/
|
|
7
|
+
export const encodeBase32 = (input) => {
|
|
8
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
9
|
+
const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
|
|
10
|
+
let result = "";
|
|
11
|
+
let buffer = 0;
|
|
12
|
+
let bufferLength = 0;
|
|
13
|
+
for (const byte of bytes) {
|
|
14
|
+
buffer = (buffer << 8) | byte;
|
|
15
|
+
bufferLength += 8;
|
|
16
|
+
while (bufferLength >= 5) {
|
|
17
|
+
bufferLength -= 5;
|
|
18
|
+
result += alphabet[(buffer >> bufferLength) & 0x1f];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (bufferLength > 0) {
|
|
22
|
+
result += alphabet[(buffer << (5 - bufferLength)) & 0x1f];
|
|
23
|
+
}
|
|
24
|
+
const paddingLength = (8 - (result.length % 8)) % 8;
|
|
25
|
+
result += "=".repeat(paddingLength);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=encodeBase32.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encodeBase32.js","sourceRoot":"","sources":["../../src/Crypto/encodeBase32.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAA0B,EAAU,EAAE;IACjE,MAAM,QAAQ,GAAG,kCAAkC,CAAC;IACpD,MAAM,KAAK,GACT,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAEtE,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;QAC9B,YAAY,IAAI,CAAC,CAAC;QAElB,OAAO,YAAY,IAAI,CAAC,EAAE,CAAC;YACzB,YAAY,IAAI,CAAC,CAAC;YAClB,MAAM,IAAI,QAAQ,CAAC,CAAC,MAAM,IAAI,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,QAAQ,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,aAAa,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACpD,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAEpC,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a string or Uint8Array to Base58 format
|
|
3
|
+
* @param {string | Uint8Array} input - The input to encode
|
|
4
|
+
* @returns {string} Base58 encoded string
|
|
5
|
+
* @example encodeBase58("Hello"); // "9Ajdvzr"
|
|
6
|
+
*/
|
|
7
|
+
export declare const encodeBase58: (input: string | Uint8Array) => string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a string or Uint8Array to Base58 format
|
|
3
|
+
* @param {string | Uint8Array} input - The input to encode
|
|
4
|
+
* @returns {string} Base58 encoded string
|
|
5
|
+
* @example encodeBase58("Hello"); // "9Ajdvzr"
|
|
6
|
+
*/
|
|
7
|
+
export const encodeBase58 = (input) => {
|
|
8
|
+
const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
9
|
+
const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
|
|
10
|
+
let encoded = "";
|
|
11
|
+
let bigNumber = BigInt(0);
|
|
12
|
+
for (const byte of bytes) {
|
|
13
|
+
bigNumber = bigNumber * BigInt(256) + BigInt(byte);
|
|
14
|
+
}
|
|
15
|
+
while (bigNumber > 0) {
|
|
16
|
+
const remainder = Number(bigNumber % BigInt(58));
|
|
17
|
+
encoded = alphabet[remainder] + encoded;
|
|
18
|
+
bigNumber /= BigInt(58);
|
|
19
|
+
}
|
|
20
|
+
let leadingZeros = 0;
|
|
21
|
+
for (const byte of bytes) {
|
|
22
|
+
if (byte !== 0) {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
leadingZeros++;
|
|
26
|
+
}
|
|
27
|
+
return "1".repeat(leadingZeros) + encoded;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=encodeBase58.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encodeBase58.js","sourceRoot":"","sources":["../../src/Crypto/encodeBase58.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAA0B,EAAU,EAAE;IACjE,MAAM,QAAQ,GAAG,4DAA4D,CAAC;IAC9E,MAAM,KAAK,GACT,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAEtE,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAE1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,SAAS,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QACjD,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;QACxC,SAAS,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IAED,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;YACf,MAAM;QACR,CAAC;QACD,YAAY,EAAE,CAAC;IACjB,CAAC;IAED,OAAO,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC;AAC5C,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Crypto/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./priorityQueue";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/DataStructure/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A priority queue implementation using a binary heap.
|
|
3
|
+
* Higher priority values are dequeued first.
|
|
4
|
+
*
|
|
5
|
+
* ## Features
|
|
6
|
+
* - **enqueue(value, priority)**: Add element with priority
|
|
7
|
+
* - **enqueueBack(value)**: Add element to the back with lowest priority
|
|
8
|
+
* - **dequeue()**: Remove and return highest priority element
|
|
9
|
+
* - **peek()**: View highest priority element without removing
|
|
10
|
+
* - **peekPriority()**: View highest priority value
|
|
11
|
+
* - **size**: Get number of elements
|
|
12
|
+
* - **isEmpty**: Check if queue is empty
|
|
13
|
+
* - **clear()**: Remove all elements
|
|
14
|
+
* - **toArray()**: Get all elements as array
|
|
15
|
+
* - **toArrayWithPriorities()**: Get all elements with priorities
|
|
16
|
+
*
|
|
17
|
+
* ## Time Complexity
|
|
18
|
+
* - enqueue: O(log n)
|
|
19
|
+
* - enqueueBack: O(log n)
|
|
20
|
+
* - dequeue: O(log n)
|
|
21
|
+
* - peek: O(1)
|
|
22
|
+
* - peekPriority: O(1)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const queue = new PriorityQueue<string>();
|
|
27
|
+
* queue.enqueue("low", 1);
|
|
28
|
+
* queue.enqueue("high", 3);
|
|
29
|
+
* queue.enqueue("medium", 2);
|
|
30
|
+
*
|
|
31
|
+
* console.log(queue.dequeue()); // "high"
|
|
32
|
+
* console.log(queue.dequeue()); // "medium"
|
|
33
|
+
* console.log(queue.dequeue()); // "low"
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Initialize with elements
|
|
39
|
+
* const queue = new PriorityQueue([
|
|
40
|
+
* { value: "task1", priority: 1 },
|
|
41
|
+
* { value: "task2", priority: 3 },
|
|
42
|
+
* { value: "task3", priority: 2 }
|
|
43
|
+
* ]);
|
|
44
|
+
*
|
|
45
|
+
* console.log(queue.peek()); // "task2"
|
|
46
|
+
* console.log(queue.peekPriority()); // 3
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @template T - The type of elements stored in the queue
|
|
50
|
+
*/
|
|
51
|
+
export declare class PriorityQueue<T> {
|
|
52
|
+
private heap;
|
|
53
|
+
private minPriority;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new PriorityQueue instance.
|
|
56
|
+
* @param initialElements - Optional array of initial elements with priorities
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const queue = new PriorityQueue<string>();
|
|
60
|
+
* // or
|
|
61
|
+
* const queue = new PriorityQueue([
|
|
62
|
+
* { value: "item1", priority: 10 },
|
|
63
|
+
* { value: "item2", priority: 5 }
|
|
64
|
+
* ]);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
constructor(initialElements?: Array<{
|
|
68
|
+
value: T;
|
|
69
|
+
priority: number;
|
|
70
|
+
}>);
|
|
71
|
+
/**
|
|
72
|
+
* Returns the number of elements in the queue.
|
|
73
|
+
* @returns The number of elements in the queue
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const queue = new PriorityQueue<string>();
|
|
77
|
+
* queue.enqueue("item", 1);
|
|
78
|
+
* console.log(queue.size); // 1
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
get size(): number;
|
|
82
|
+
/**
|
|
83
|
+
* Checks if the queue is empty.
|
|
84
|
+
* @returns True if the queue is empty, false otherwise
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const queue = new PriorityQueue<string>();
|
|
88
|
+
* console.log(queue.isEmpty); // true
|
|
89
|
+
* queue.enqueue("item", 1);
|
|
90
|
+
* console.log(queue.isEmpty); // false
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
get isEmpty(): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Adds an element to the queue with a specified priority.
|
|
96
|
+
* Higher priority values are dequeued first.
|
|
97
|
+
* @param value - The value to add
|
|
98
|
+
* @param priority - The priority value (higher values have higher priority)
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const queue = new PriorityQueue<string>();
|
|
102
|
+
* queue.enqueue("low", 1);
|
|
103
|
+
* queue.enqueue("high", 10);
|
|
104
|
+
* queue.enqueue("medium", 5);
|
|
105
|
+
* console.log(queue.dequeue()); // "high"
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
enqueue(value: T, priority: number): void;
|
|
109
|
+
/**
|
|
110
|
+
* Adds an element to the end of the queue with lowest priority.
|
|
111
|
+
* This element will be dequeued last (FIFO for equal lowest priority).
|
|
112
|
+
*
|
|
113
|
+
* @param value - The value to add
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const queue = new PriorityQueue<string>();
|
|
117
|
+
* queue.enqueue("high", 10);
|
|
118
|
+
* queue.enqueue("medium", 5);
|
|
119
|
+
* queue.enqueueBack("back1");
|
|
120
|
+
* queue.enqueueBack("back2");
|
|
121
|
+
* console.log(queue.dequeue()); // "high"
|
|
122
|
+
* console.log(queue.dequeue()); // "medium"
|
|
123
|
+
* console.log(queue.dequeue()); // "back1"
|
|
124
|
+
* console.log(queue.dequeue()); // "back2"
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
enqueueBack(value: T): void;
|
|
128
|
+
/**
|
|
129
|
+
* Removes and returns the element with the highest priority.
|
|
130
|
+
* @returns The element with highest priority, or undefined if queue is empty
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const queue = new PriorityQueue<string>();
|
|
134
|
+
* queue.enqueue("low", 1);
|
|
135
|
+
* queue.enqueue("high", 10);
|
|
136
|
+
* console.log(queue.dequeue()); // "high"
|
|
137
|
+
* console.log(queue.dequeue()); // "low"
|
|
138
|
+
* console.log(queue.dequeue()); // undefined
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
dequeue(): T | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* Returns the element with the highest priority without removing it.
|
|
144
|
+
* @returns The element with highest priority, or undefined if queue is empty
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const queue = new PriorityQueue<string>();
|
|
148
|
+
* queue.enqueue("low", 1);
|
|
149
|
+
* queue.enqueue("high", 10);
|
|
150
|
+
* console.log(queue.peek()); // "high"
|
|
151
|
+
* console.log(queue.size); // 2 (element not removed)
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
peek(): T | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Returns the priority of the element with the highest priority.
|
|
157
|
+
* @returns The highest priority value, or undefined if queue is empty
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const queue = new PriorityQueue<string>();
|
|
161
|
+
* queue.enqueue("low", 1);
|
|
162
|
+
* queue.enqueue("high", 10);
|
|
163
|
+
* console.log(queue.peekPriority()); // 10
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
peekPriority(): number | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* Removes all elements from the queue.
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const queue = new PriorityQueue<string>();
|
|
172
|
+
* queue.enqueue("item1", 1);
|
|
173
|
+
* queue.enqueue("item2", 2);
|
|
174
|
+
* console.log(queue.size); // 2
|
|
175
|
+
* queue.clear();
|
|
176
|
+
* console.log(queue.size); // 0
|
|
177
|
+
* console.log(queue.isEmpty); // true
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
clear(): void;
|
|
181
|
+
/**
|
|
182
|
+
* Returns an array of all elements in the queue (without removing them).
|
|
183
|
+
* The order is not guaranteed to be sorted by priority.
|
|
184
|
+
* @returns Array of all elements in the queue
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const queue = new PriorityQueue<string>();
|
|
188
|
+
* queue.enqueue("low", 1);
|
|
189
|
+
* queue.enqueue("high", 10);
|
|
190
|
+
* queue.enqueue("medium", 5);
|
|
191
|
+
* console.log(queue.toArray()); // ["high", "medium", "low"] (order may vary)
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
toArray(): T[];
|
|
195
|
+
/**
|
|
196
|
+
* Returns an array of all elements with their priorities.
|
|
197
|
+
* The order is not guaranteed to be sorted by priority.
|
|
198
|
+
* @returns Array of all elements with their priorities
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const queue = new PriorityQueue<string>();
|
|
202
|
+
* queue.enqueue("low", 1);
|
|
203
|
+
* queue.enqueue("high", 10);
|
|
204
|
+
* console.log(queue.toArrayWithPriorities());
|
|
205
|
+
* // [{ value: "high", priority: 10 }, { value: "low", priority: 1 }] (order may vary)
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
toArrayWithPriorities(): Array<{
|
|
209
|
+
value: T;
|
|
210
|
+
priority: number;
|
|
211
|
+
}>;
|
|
212
|
+
/**
|
|
213
|
+
* Updates the minimum priority when adding elements.
|
|
214
|
+
* @param priority - The priority being added
|
|
215
|
+
*/
|
|
216
|
+
private updateMinPriorityOnAdd;
|
|
217
|
+
/**
|
|
218
|
+
* Updates the minimum priority from all elements (used in constructor).
|
|
219
|
+
*/
|
|
220
|
+
private updateMinPriority;
|
|
221
|
+
/**
|
|
222
|
+
* Builds a max heap from the current heap array.
|
|
223
|
+
*/
|
|
224
|
+
private buildHeap;
|
|
225
|
+
/**
|
|
226
|
+
* Moves an element up the heap to maintain heap property.
|
|
227
|
+
* @param index - The index of the element to move up
|
|
228
|
+
*/
|
|
229
|
+
private heapifyUp;
|
|
230
|
+
/**
|
|
231
|
+
* Moves an element down the heap to maintain heap property.
|
|
232
|
+
* @param index - The index of the element to move down
|
|
233
|
+
*/
|
|
234
|
+
private heapifyDown;
|
|
235
|
+
/**
|
|
236
|
+
* Swaps two elements in the heap.
|
|
237
|
+
* @param i - First index
|
|
238
|
+
* @param j - Second index
|
|
239
|
+
*/
|
|
240
|
+
private swap;
|
|
241
|
+
}
|