-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
382 lines (325 loc) · 9.43 KB
/
index.d.ts
File metadata and controls
382 lines (325 loc) · 9.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
// Type definitions for algorith
// Project: algorith
// Definitions by: MXA.K
export interface SimilarityResult {
levenshtein: number;
jaroWinkler: number;
hamming: number;
trigram: number;
jaccard: number;
jaro: number;
dice: number;
cosine: number;
}
export interface WeightedItem<T = any> {
value: T;
weight: number;
}
/**
* Calculates the normalized Levenshtein distance between two strings
* @param a First string
* @param b Second string
* @returns Similarity score between 0 and 1
*/
export function levenshtein(a: string, b: string): number;
/**
* Calculates the Jaro-Winkler similarity between two strings
* @param a First string
* @param b Second string
* @returns Similarity score between 0 and 1
*/
export function jaroWinkler(a: string, b: string): number;
/**
* Calculates the Jaro similarity between two strings
* @param a First string
* @param b Second string
* @returns Similarity score between 0 and 1
*/
export function jaro(a: string, b: string): number;
/**
* Calculates the normalized Hamming distance between two strings
* @param a First string
* @param b Second string
* @returns Similarity score between 0 and 1
*/
export function hamming(a: string, b: string): number;
/**
* Calculates the Jaccard similarity between two strings
* @param a First string
* @param b Second string
* @returns Similarity score between 0 and 1
*/
export function jaccardSimilarity(a: string, b: string): number;
/**
* Calculates the cosine similarity between two strings
* @param a First string
* @param b Second string
* @returns Similarity score between 0 and 1
*/
export function cosineSimilarity(a: string, b: string): number;
/**
* Calculates the Dice coefficient between two strings
* @param a First string
* @param b Second string
* @returns Similarity score between 0 and 1
*/
export function diceCoefficient(a: string, b: string): number;
/**
* Calculates the trigram score between two strings
* @param a First string
* @param b Second string
* @returns Similarity score between 0 and 1
*/
export function trigramScore(a: string, b: string): number;
/**
* Shuffles an array using the Fisher-Yates algorithm
* @param array Input array
* @param random Optional random generator (default: Math.random)
* @returns New shuffled array
*/
export function fisherYatesShuffle<T>(array: T[], random?: () => number): T[];
/**
* Generates the Soundex code for a string with multilingual support
* @param s Input string
* @param lang Language code ('en' or 'fr', default: 'en')
* @param customMap Custom character mapping (optional)
* @returns 4-character Soundex code
*/
export function soundex(s: string, lang?: string, customMap?: Record<string, string | number>): string;
/**
* Compares two strings using all available similarity algorithms
* @param a First string
* @param b Second string
* @returns Object containing all similarity scores
*/
export function compareAll(a: string, b: string): SimilarityResult;
/**
* Advanced random number generator with multiple distributions and noise functions
*/
export class RandomEngine {
/**
* Current seed value
*/
public seed: number;
/**
* Gradient table for noise generation
*/
public gradients: number[];
/**
* Permutation table for noise generation
*/
public permutation: number[];
/**
* Creates a new RandomEngine instance
* @param seed Optional seed for deterministic generation
*/
constructor(seed?: number);
// Basic random functions
/**
* Generates a uniform random number
* @param min Minimum value (default: 0)
* @param max Maximum value (default: 1)
* @returns Random number between min and max
*/
uniform(min?: number, max?: number): number;
/**
* Generates a random integer
* @param min Minimum value (inclusive)
* @param max Maximum value (inclusive)
* @returns Random integer between min and max
*/
int(min: number, max: number): number;
/**
* Generates a random boolean
* @param prob Probability of returning true (default: 0.5)
* @returns Random boolean value
*/
bool(prob?: number): boolean;
/**
* Picks a random element from an array
* @param array Input array
* @returns Random element from the array
*/
pick<T>(array: T[]): T;
/**
* Shuffles an array (returns a new array)
* @param array Input array
* @returns New shuffled array
*/
shuffle<T>(array: T[]): T[];
// Probability distributions
/**
* Generates a normally distributed random number
* @param mean Mean value (default: 0)
* @param stdDev Standard deviation (default: 1)
* @returns Normally distributed random number
*/
normal(mean?: number, stdDev?: number): number;
/**
* Generates an exponentially distributed random number
* @param lambda Rate parameter (default: 1)
* @returns Exponentially distributed random number
*/
exponential(lambda?: number): number;
/**
* Generates a Poisson distributed random number
* @param lambda Rate parameter (default: 4)
* @returns Poisson distributed random integer
*/
poisson(lambda?: number): number;
/**
* Generates a binomially distributed random number
* @param n Number of trials
* @param p Probability of success
* @returns Binomially distributed random integer
*/
binomial(n: number, p: number): number;
/**
* Generates a geometrically distributed random number
* @param p Probability of success
* @returns Geometrically distributed random integer
*/
geometric(p: number): number;
/**
* Selects a random value based on weights
* @param items Array of weighted items
* @returns Selected value
*/
weighted<T>(items: WeightedItem<T>[]): T;
// Text generation
/**
* Generates a random lowercase character
* @returns Random character a-z
*/
randomChar(): string;
/**
* Generates a random string
* @param length Length of the string (default: 8)
* @returns Random string
*/
randomString(length?: number): string;
/**
* Generates a random pronounceable word
* @returns Random word made of syllables
*/
randomWord(): string;
/**
* Generates a UUID v4
* @returns Valid UUID string
*/
uuid(): string;
// Crypto functions
/**
* Generates a cryptographically secure random integer
* @param min Minimum value (inclusive)
* @param max Maximum value (inclusive)
* @returns Cryptographically secure random integer
*/
static cryptoInt(min: number, max: number): number;
// Noise functions
/**
* Generates noise using the specified type
* @param x Input coordinate
* @param type Noise type: 'perlin', 'value', 'white', or 'pink'
* @returns Noise value
*/
noise(x: number, type?: 'perlin' | 'value' | 'white' | 'pink'): number;
/**
* Generates 1D Perlin noise
* @param x Input coordinate
* @returns Perlin noise value
*/
perlin1D(x: number): number;
/**
* Generates 1D value noise
* @param x Input coordinate
* @returns Value noise value
*/
valueNoise1D(x: number): number;
/**
* Generates white noise
* @returns White noise value between -1 and 1
*/
whiteNoise(): number;
/**
* Generates pink noise
* @param x Input frequency
* @returns Pink noise value
*/
pinkNoise(x: number): number;
// Utility functions
/**
* Applies fade function for smooth interpolation
* @param t Input value between 0 and 1
* @returns Smoothed value
*/
fade(t: number): number;
/**
* Linear interpolation between two values
* @param a First value
* @param b Second value
* @param t Interpolation factor (0-1)
* @returns Interpolated value
*/
lerp(a: number, b: number, t: number): number;
/**
* Generates gradient table for noise functions
* @param size Size of the gradient table (default: 256)
*/
generateGradientTable(size?: number): void;
/**
* Mulberry32 PRNG implementation
* @param seed Seed value
* @returns Random number generator function
*/
mulberry32(seed: number): () => number;
}
export interface AutocompleteOptions {
/** Language for default dictionary ('fr' or 'en') */
language?: 'fr' | 'en' | string;
/** Custom dictionary array or path to dictionary file */
dictionary?: string[] | string | null;
/** Maximum number of suggestions to return */
maxSuggestions?: number;
}
/**
* Advanced autocomplete engine using Trie data structure
*/
export class AutocompleteEngine {
/** Current language setting */
readonly language: string;
/** Maximum number of suggestions */
readonly maxSuggestions: number;
/**
* Creates a new AutocompleteEngine instance
* @param options Configuration options
*/
constructor(options?: AutocompleteOptions);
/**
* Adds a single word to the autocomplete dictionary
* @param word Word to add (will be normalized to lowercase)
*/
addWord(word: string): void;
/**
* Adds multiple words to the autocomplete dictionary
* @param words Array of words to add
*/
addWords(words: string[]): void;
/**
* Gets autocomplete suggestions for a given prefix
* @param prefix Text prefix to search for
* @returns Array of suggested completions
*/
autocomplete(prefix: string): string[];
/**
* Alias for autocomplete method (for compatibility)
* @param prefix Text prefix to search for
* @returns Array of suggested completions
*/
search(prefix: string): string[];
/**
* Returns the total number of words in the dictionary
* @returns Number of words in the dictionary
*/
getWordCount(): number;
}