libram 0.8.27 → 0.8.28
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/package.json +9 -8
- package/dist/Clan.d.ts +0 -128
- package/dist/Clan.js +0 -300
- package/dist/Copier.d.ts +0 -9
- package/dist/Copier.js +0 -15
- package/dist/Dungeon.d.ts +0 -45
- package/dist/Dungeon.js +0 -115
- package/dist/Kmail.d.ts +0 -104
- package/dist/Kmail.js +0 -182
- package/dist/actions/ActionSource.d.ts +0 -131
- package/dist/actions/ActionSource.js +0 -177
- package/dist/actions/Banish.d.ts +0 -16
- package/dist/actions/Banish.js +0 -121
- package/dist/actions/FreeKill.d.ts +0 -16
- package/dist/actions/FreeKill.js +0 -94
- package/dist/actions/FreeRun.d.ts +0 -16
- package/dist/actions/FreeRun.js +0 -77
- package/dist/actions/index.d.ts +0 -4
- package/dist/actions/index.js +0 -4
- package/dist/ascend.d.ts +0 -83
- package/dist/ascend.js +0 -268
- package/dist/challengePaths/2014/HeavyRains.d.ts +0 -22
- package/dist/challengePaths/2014/HeavyRains.js +0 -75
- package/dist/challengePaths/2015/CommunityService.d.ts +0 -125
- package/dist/challengePaths/2015/CommunityService.js +0 -334
- package/dist/challengePaths/2016/NuclearAutumn.d.ts +0 -13
- package/dist/challengePaths/2016/NuclearAutumn.js +0 -21
- package/dist/challengePaths/index.d.ts +0 -4
- package/dist/challengePaths/index.js +0 -4
- package/dist/combat.d.ts +0 -414
- package/dist/combat.js +0 -711
- package/dist/console.d.ts +0 -12
- package/dist/console.js +0 -14
- package/dist/counter.d.ts +0 -22
- package/dist/counter.js +0 -37
- package/dist/diet/index.d.ts +0 -80
- package/dist/diet/index.js +0 -662
- package/dist/diet/knapsack.d.ts +0 -8
- package/dist/diet/knapsack.js +0 -128
- package/dist/index.d.ts +0 -29
- package/dist/index.js +0 -26
- package/dist/lib.d.ts +0 -497
- package/dist/lib.js +0 -958
- package/dist/logger.d.ts +0 -35
- package/dist/logger.js +0 -62
- package/dist/maximize.d.ts +0 -121
- package/dist/maximize.js +0 -525
- package/dist/modifier.d.ts +0 -41
- package/dist/modifier.js +0 -160
- package/dist/modifierTypes.d.ts +0 -16
- package/dist/modifierTypes.js +0 -9
- package/dist/mood.d.ts +0 -105
- package/dist/mood.js +0 -349
- package/dist/moonSign.d.ts +0 -13
- package/dist/moonSign.js +0 -25
- package/dist/overlappingNames.d.ts +0 -3
- package/dist/overlappingNames.js +0 -42
- package/dist/property.d.ts +0 -222
- package/dist/property.js +0 -385
- package/dist/propertyTypes.d.ts +0 -19
- package/dist/propertyTypes.js +0 -10
- package/dist/propertyTyping.d.ts +0 -65
- package/dist/propertyTyping.js +0 -91
- package/dist/resources/2007/CandyHearts.d.ts +0 -9
- package/dist/resources/2007/CandyHearts.js +0 -24
- package/dist/resources/2008/DivineFavors.d.ts +0 -9
- package/dist/resources/2008/DivineFavors.js +0 -27
- package/dist/resources/2008/Stickers.d.ts +0 -49
- package/dist/resources/2008/Stickers.js +0 -84
- package/dist/resources/2009/Bandersnatch.d.ts +0 -56
- package/dist/resources/2009/Bandersnatch.js +0 -93
- package/dist/resources/2009/LoveSongs.d.ts +0 -9
- package/dist/resources/2009/LoveSongs.js +0 -24
- package/dist/resources/2009/SpookyPutty.d.ts +0 -31
- package/dist/resources/2009/SpookyPutty.js +0 -49
- package/dist/resources/2010/Brickos.d.ts +0 -9
- package/dist/resources/2010/Brickos.js +0 -21
- package/dist/resources/2010/CrownOfThrones.d.ts +0 -68
- package/dist/resources/2010/CrownOfThrones.js +0 -418
- package/dist/resources/2010/LookingGlass.d.ts +0 -29
- package/dist/resources/2010/LookingGlass.js +0 -89
- package/dist/resources/2011/Gygaxian.d.ts +0 -9
- package/dist/resources/2011/Gygaxian.js +0 -24
- package/dist/resources/2011/ObtuseAngel.d.ts +0 -33
- package/dist/resources/2011/ObtuseAngel.js +0 -51
- package/dist/resources/2011/StompingBoots.d.ts +0 -37
- package/dist/resources/2011/StompingBoots.js +0 -57
- package/dist/resources/2012/RainDoh.d.ts +0 -25
- package/dist/resources/2012/RainDoh.js +0 -37
- package/dist/resources/2012/ReagnimatedGnome.d.ts +0 -31
- package/dist/resources/2012/ReagnimatedGnome.js +0 -46
- package/dist/resources/2012/Resolutions.d.ts +0 -9
- package/dist/resources/2012/Resolutions.js +0 -28
- package/dist/resources/2013/Florist.d.ts +0 -81
- package/dist/resources/2013/Florist.js +0 -245
- package/dist/resources/2013/JungMan.d.ts +0 -33
- package/dist/resources/2013/JungMan.js +0 -69
- package/dist/resources/2013/PulledTaffy.d.ts +0 -9
- package/dist/resources/2013/PulledTaffy.js +0 -33
- package/dist/resources/2014/CrimboShrub.d.ts +0 -42
- package/dist/resources/2014/CrimboShrub.js +0 -89
- package/dist/resources/2014/DNALab.d.ts +0 -56
- package/dist/resources/2014/DNALab.js +0 -162
- package/dist/resources/2014/WinterGarden.d.ts +0 -23
- package/dist/resources/2014/WinterGarden.js +0 -35
- package/dist/resources/2015/BarrelShrine.d.ts +0 -8
- package/dist/resources/2015/BarrelShrine.js +0 -25
- package/dist/resources/2015/ChateauMantegna.d.ts +0 -52
- package/dist/resources/2015/ChateauMantegna.js +0 -99
- package/dist/resources/2015/DeckOfEveryCard.d.ts +0 -29
- package/dist/resources/2015/DeckOfEveryCard.js +0 -122
- package/dist/resources/2015/Dinseylandfill.d.ts +0 -89
- package/dist/resources/2015/Dinseylandfill.js +0 -205
- package/dist/resources/2015/MayoClinic.d.ts +0 -23
- package/dist/resources/2015/MayoClinic.js +0 -49
- package/dist/resources/2016/GingerBread.d.ts +0 -32
- package/dist/resources/2016/GingerBread.js +0 -73
- package/dist/resources/2016/SourceTerminal.d.ts +0 -181
- package/dist/resources/2016/SourceTerminal.js +0 -275
- package/dist/resources/2016/Witchess.d.ts +0 -17
- package/dist/resources/2016/Witchess.js +0 -47
- package/dist/resources/2017/AsdonMartin.d.ts +0 -59
- package/dist/resources/2017/AsdonMartin.js +0 -238
- package/dist/resources/2017/Horsery.d.ts +0 -19
- package/dist/resources/2017/Horsery.js +0 -42
- package/dist/resources/2017/MummingTrunk.d.ts +0 -8
- package/dist/resources/2017/MummingTrunk.js +0 -33
- package/dist/resources/2017/Pantogram.d.ts +0 -92
- package/dist/resources/2017/Pantogram.js +0 -174
- package/dist/resources/2017/Robortender.d.ts +0 -30
- package/dist/resources/2017/Robortender.js +0 -90
- package/dist/resources/2017/Spacegate.d.ts +0 -86
- package/dist/resources/2017/Spacegate.js +0 -178
- package/dist/resources/2017/TunnelOfLove.d.ts +0 -39
- package/dist/resources/2017/TunnelOfLove.js +0 -120
- package/dist/resources/2018/LatteLoversMembersMug.d.ts +0 -392
- package/dist/resources/2018/LatteLoversMembersMug.js +0 -303
- package/dist/resources/2018/SongBoom.d.ts +0 -33
- package/dist/resources/2018/SongBoom.js +0 -55
- package/dist/resources/2019/BeachComb.d.ts +0 -72
- package/dist/resources/2019/BeachComb.js +0 -118
- package/dist/resources/2019/CampAway.d.ts +0 -39
- package/dist/resources/2019/CampAway.js +0 -72
- package/dist/resources/2019/Snapper.d.ts +0 -33
- package/dist/resources/2019/Snapper.js +0 -73
- package/dist/resources/2020/Cartography.d.ts +0 -16
- package/dist/resources/2020/Cartography.js +0 -48
- package/dist/resources/2020/Guzzlr.d.ts +0 -160
- package/dist/resources/2020/Guzzlr.js +0 -275
- package/dist/resources/2020/RetroCape.d.ts +0 -51
- package/dist/resources/2020/RetroCape.js +0 -115
- package/dist/resources/2021/CrystalBall.d.ts +0 -14
- package/dist/resources/2021/CrystalBall.js +0 -39
- package/dist/resources/2021/DaylightShavings.d.ts +0 -40
- package/dist/resources/2021/DaylightShavings.js +0 -74
- package/dist/resources/2022/AutumnAton.d.ts +0 -78
- package/dist/resources/2022/AutumnAton.js +0 -182
- package/dist/resources/2022/CombatLoversLocket.d.ts +0 -44
- package/dist/resources/2022/CombatLoversLocket.js +0 -82
- package/dist/resources/2022/GreyGoose.d.ts +0 -59
- package/dist/resources/2022/GreyGoose.js +0 -90
- package/dist/resources/2022/JuneCleaver.d.ts +0 -47
- package/dist/resources/2022/JuneCleaver.js +0 -69
- package/dist/resources/2022/TrainSet.d.ts +0 -146
- package/dist/resources/2022/TrainSet.js +0 -228
- package/dist/resources/2023/AugustScepter.d.ts +0 -25
- package/dist/resources/2023/AugustScepter.js +0 -40
- package/dist/resources/2023/BurningLeaves.d.ts +0 -25
- package/dist/resources/2023/BurningLeaves.js +0 -74
- package/dist/resources/2023/CinchoDeMayo.d.ts +0 -25
- package/dist/resources/2023/CinchoDeMayo.js +0 -45
- package/dist/resources/2023/ClosedCircuitPayphone.d.ts +0 -80
- package/dist/resources/2023/ClosedCircuitPayphone.js +0 -129
- package/dist/resources/2023/CursedMonkeyPaw.d.ts +0 -46
- package/dist/resources/2023/CursedMonkeyPaw.js +0 -113
- package/dist/resources/2024/AprilingBandHelmet.d.ts +0 -57
- package/dist/resources/2024/AprilingBandHelmet.js +0 -118
- package/dist/resources/2024/ChestMimic.d.ts +0 -35
- package/dist/resources/2024/ChestMimic.js +0 -108
- package/dist/resources/LibramSummon.d.ts +0 -18
- package/dist/resources/LibramSummon.js +0 -74
- package/dist/resources/index.d.ts +0 -54
- package/dist/resources/index.js +0 -54
- package/dist/resources/putty-likes.d.ts +0 -21
- package/dist/resources/putty-likes.js +0 -33
- package/dist/session.d.ts +0 -169
- package/dist/session.js +0 -284
- package/dist/since.d.ts +0 -51
- package/dist/since.js +0 -108
- package/dist/template-string.d.ts +0 -324
- package/dist/template-string.js +0 -265
- package/dist/url.d.ts +0 -35
- package/dist/url.js +0 -67
- package/dist/utils.d.ts +0 -178
- package/dist/utils.js +0 -255
package/dist/utils.d.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guard against null value
|
|
3
|
-
*
|
|
4
|
-
* @param value Value that can be null
|
|
5
|
-
* @returns Whether the value is not null or... not
|
|
6
|
-
*/
|
|
7
|
-
export declare function notNull<T>(value: T | null): value is T;
|
|
8
|
-
/**
|
|
9
|
-
* Parse string to number, stripping commas
|
|
10
|
-
*
|
|
11
|
-
* @param n Numberical string to parse
|
|
12
|
-
* @returns Numerical value of string
|
|
13
|
-
*/
|
|
14
|
-
export declare function parseNumber(n: string): number;
|
|
15
|
-
/**
|
|
16
|
-
* Clamp a number between lower and upper bounds.
|
|
17
|
-
*
|
|
18
|
-
* @param n Number to clamp.
|
|
19
|
-
* @param min Lower bound.
|
|
20
|
-
* @param max Upper bound.
|
|
21
|
-
* @returns Clamped value
|
|
22
|
-
*/
|
|
23
|
-
export declare function clamp(n: number, min: number, max: number): number;
|
|
24
|
-
/**
|
|
25
|
-
* Split an {@param array} into {@param chunkSize} sized chunks
|
|
26
|
-
*
|
|
27
|
-
* @param array Array to split
|
|
28
|
-
* @param chunkSize Size of chunk
|
|
29
|
-
* @returns Split array
|
|
30
|
-
*/
|
|
31
|
-
export declare function chunk<T>(array: T[], chunkSize: number): T[][];
|
|
32
|
-
/**
|
|
33
|
-
* Count distinct values in an array
|
|
34
|
-
*
|
|
35
|
-
* @param array Array of values
|
|
36
|
-
* @returns Map of distinct values to count
|
|
37
|
-
*/
|
|
38
|
-
export declare function arrayToCountedMap<T>(array: T[] | Map<T, number>): Map<T, number>;
|
|
39
|
-
/**
|
|
40
|
-
* Turn map of distinct values to count into array of values
|
|
41
|
-
*
|
|
42
|
-
* @param map Map to turn into array
|
|
43
|
-
* @returns Array of values
|
|
44
|
-
*/
|
|
45
|
-
export declare function countedMapToArray<T>(map: Map<T, number>): T[];
|
|
46
|
-
/**
|
|
47
|
-
* Stringify a counted map
|
|
48
|
-
*
|
|
49
|
-
* @param map Map of counted values
|
|
50
|
-
* @returns String representing map of counted values
|
|
51
|
-
*/
|
|
52
|
-
export declare function countedMapToString<T>(map: Map<T, number>): string;
|
|
53
|
-
/**
|
|
54
|
-
* Sum an array of numbers.
|
|
55
|
-
*
|
|
56
|
-
* @param addends Addends to sum.
|
|
57
|
-
* @param property Property of the elements to be summing
|
|
58
|
-
* @returns Sum of numbers
|
|
59
|
-
*/
|
|
60
|
-
export declare function sum<S extends string | number | symbol, T extends {
|
|
61
|
-
[s in S]: number;
|
|
62
|
-
}>(addends: T[], property: S): number;
|
|
63
|
-
/**
|
|
64
|
-
* Sum an array of numbers.
|
|
65
|
-
*
|
|
66
|
-
* @param addends Addends to sum.
|
|
67
|
-
* @param mappingFunction Mapping function to turn addends into actual numbers.
|
|
68
|
-
* @returns Sum of numbers
|
|
69
|
-
*/
|
|
70
|
-
export declare function sum<T>(addends: T[], mappingFunction: (element: T) => number): number;
|
|
71
|
-
/**
|
|
72
|
-
* Sum array of numbers
|
|
73
|
-
*
|
|
74
|
-
* @param addends Numbers to sum
|
|
75
|
-
* @returns Sum of numbers
|
|
76
|
-
*/
|
|
77
|
-
export declare function sumNumbers(addends: number[]): number;
|
|
78
|
-
/**
|
|
79
|
-
* Checks if a given item is in a readonly array, acting as a typeguard.
|
|
80
|
-
*
|
|
81
|
-
* @param item Needle
|
|
82
|
-
* @param array Readonly array haystack
|
|
83
|
-
* @returns Whether the item is in the array, and narrows the type of the item.
|
|
84
|
-
*/
|
|
85
|
-
export declare function arrayContains<T, A extends T>(item: T, array: ReadonlyArray<A>): item is A;
|
|
86
|
-
/**
|
|
87
|
-
* Checks if two arrays contain the same elements in the same quantity.
|
|
88
|
-
*
|
|
89
|
-
* @param a First array for comparison
|
|
90
|
-
* @param b Second array for comparison
|
|
91
|
-
* @returns Whether the two arrays are equal, irrespective of order.
|
|
92
|
-
*/
|
|
93
|
-
export declare function setEqual<T>(a: T[], b: T[]): boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Reverses keys and values for a given map
|
|
96
|
-
*
|
|
97
|
-
* @param map Map to invert
|
|
98
|
-
* @returns Inverted map
|
|
99
|
-
*/
|
|
100
|
-
export declare function invertMap<T1, T2>(map: Map<T1, T2>): Map<T2, T1>;
|
|
101
|
-
/**
|
|
102
|
-
* Splits a string by commas while also respecting escaping commas with a backslash
|
|
103
|
-
*
|
|
104
|
-
* @param str String to split
|
|
105
|
-
* @returns List of tokens
|
|
106
|
-
*/
|
|
107
|
-
export declare function splitByCommasWithEscapes(str: string): string[];
|
|
108
|
-
export declare function maxBy<T>(array: T[] | readonly T[], optimizer: (element: T) => number, reverse?: boolean): T;
|
|
109
|
-
export declare function maxBy<S extends string | number | symbol, T extends {
|
|
110
|
-
[x in S]: number;
|
|
111
|
-
}>(array: T[] | readonly T[], key: S, reverse?: boolean): T;
|
|
112
|
-
export declare type Tuple<T, N extends number> = N extends N ? number extends N ? T[] : _tupleOf<T, N, []> : never;
|
|
113
|
-
declare type _tupleOf<T, N extends number, R extends unknown[]> = R["length"] extends N ? R : _tupleOf<T, N, [T, ...R]>;
|
|
114
|
-
/**
|
|
115
|
-
* Compare arrays shallowly
|
|
116
|
-
*
|
|
117
|
-
* @param left One array to compare
|
|
118
|
-
* @param right The other array to compare
|
|
119
|
-
* @returns Whether the two arrays are shallowly equal
|
|
120
|
-
*/
|
|
121
|
-
export declare function arrayEquals<T>(left: T[] | readonly T[], right: T[] | readonly T[]): boolean;
|
|
122
|
-
/**
|
|
123
|
-
* Type that extends any non-function entity--like a string, number, or array--into a itself and a no-input function that returns it.
|
|
124
|
-
* Used to interact with objects that could either be functions or static values.
|
|
125
|
-
*/
|
|
126
|
-
export declare type Delayed<T, S extends any[] = never[]> = [T] extends [
|
|
127
|
-
(...args: any) => any
|
|
128
|
-
] ? never : T | ((...args: S) => T);
|
|
129
|
-
/**
|
|
130
|
-
* Used to collapse a Delayed<T, S> object into an entity of type "T" as represented by the object.
|
|
131
|
-
*
|
|
132
|
-
* @param delayedObject Object of type Delayed<T, S> that represents either a value of type T or a function returning a value of type T.
|
|
133
|
-
* @param args The arguments to pass to the delay function
|
|
134
|
-
* @returns The return value of the function, if delayedObject is a function. Otherwise, this returns the original element.
|
|
135
|
-
*/
|
|
136
|
-
export declare function undelay<T, S extends any[] = never[]>(delayedObject: Delayed<T, S>, ...args: S): T;
|
|
137
|
-
/**
|
|
138
|
-
* An object keyed by string type T, with values of S.
|
|
139
|
-
* or contains a 'default' parameter to use as a fallback.
|
|
140
|
-
*/
|
|
141
|
-
export declare type Switch<T extends string, S> = Record<T, S> | (Partial<{
|
|
142
|
-
[x in T]: S;
|
|
143
|
-
}> & {
|
|
144
|
-
default: S;
|
|
145
|
-
});
|
|
146
|
-
/**
|
|
147
|
-
* Makes a byX function, like byStat or byClass
|
|
148
|
-
*
|
|
149
|
-
* @param source A method for finding your stat, or class, or whatever X is in this context
|
|
150
|
-
* @returns A function akin to byStat or byClass; it accepts an object that either is "complete" in the sense that it has a key for every conceivable value, or contains a `default` parameter. If an inappropriate input is provided, returns undefined.
|
|
151
|
-
*/
|
|
152
|
-
export declare function makeByXFunction<T extends string>(source: Delayed<T>): <S>(options: Switch<T, S>) => S;
|
|
153
|
-
/**
|
|
154
|
-
* Flattens an array. Basically replacing Array.prototype.flat for which Rhino doesn't yet have an implementation
|
|
155
|
-
*
|
|
156
|
-
* @param arr Array to flatten
|
|
157
|
-
* @param depth Number of layers to flatten by; Infinity for a fully flat array
|
|
158
|
-
* @returns Flattened array
|
|
159
|
-
*/
|
|
160
|
-
export declare function flat<A extends any[], D extends number = 1>(arr: A, depth?: number): FlatArray<A, D>[];
|
|
161
|
-
/**
|
|
162
|
-
* @param array Array to select from
|
|
163
|
-
* @returns Random item from array
|
|
164
|
-
*/
|
|
165
|
-
export declare function random<T>(array: T[]): T;
|
|
166
|
-
/**
|
|
167
|
-
* Title cases a single word
|
|
168
|
-
*
|
|
169
|
-
* @param word Word to transform
|
|
170
|
-
* @returns Word in title case
|
|
171
|
-
*/
|
|
172
|
-
export declare const tc: (word: string) => string;
|
|
173
|
-
declare type Enumerate<N extends number, A extends number[] = []> = A["length"] extends N ? A[number] : Enumerate<N, [...A, A["length"]]>;
|
|
174
|
-
/**
|
|
175
|
-
* Integers on the interval [A, B).
|
|
176
|
-
*/
|
|
177
|
-
export declare type Range<A extends number, B extends number> = Exclude<Enumerate<B>, Enumerate<A>>;
|
|
178
|
-
export {};
|
package/dist/utils.js
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guard against null value
|
|
3
|
-
*
|
|
4
|
-
* @param value Value that can be null
|
|
5
|
-
* @returns Whether the value is not null or... not
|
|
6
|
-
*/
|
|
7
|
-
export function notNull(value) {
|
|
8
|
-
return value !== null;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Parse string to number, stripping commas
|
|
12
|
-
*
|
|
13
|
-
* @param n Numberical string to parse
|
|
14
|
-
* @returns Numerical value of string
|
|
15
|
-
*/
|
|
16
|
-
export function parseNumber(n) {
|
|
17
|
-
return Number.parseInt(n.replace(/,/g, ""));
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Clamp a number between lower and upper bounds.
|
|
21
|
-
*
|
|
22
|
-
* @param n Number to clamp.
|
|
23
|
-
* @param min Lower bound.
|
|
24
|
-
* @param max Upper bound.
|
|
25
|
-
* @returns Clamped value
|
|
26
|
-
*/
|
|
27
|
-
export function clamp(n, min, max) {
|
|
28
|
-
return Math.max(min, Math.min(max, n));
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Split an {@param array} into {@param chunkSize} sized chunks
|
|
32
|
-
*
|
|
33
|
-
* @param array Array to split
|
|
34
|
-
* @param chunkSize Size of chunk
|
|
35
|
-
* @returns Split array
|
|
36
|
-
*/
|
|
37
|
-
export function chunk(array, chunkSize) {
|
|
38
|
-
const result = [];
|
|
39
|
-
for (let i = 0; i < array.length; i += chunkSize) {
|
|
40
|
-
result.push(array.slice(i, i + chunkSize));
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Count distinct values in an array
|
|
46
|
-
*
|
|
47
|
-
* @param array Array of values
|
|
48
|
-
* @returns Map of distinct values to count
|
|
49
|
-
*/
|
|
50
|
-
export function arrayToCountedMap(array) {
|
|
51
|
-
if (!Array.isArray(array))
|
|
52
|
-
return array;
|
|
53
|
-
const map = new Map();
|
|
54
|
-
array.forEach((item) => {
|
|
55
|
-
map.set(item, (map.get(item) || 0) + 1);
|
|
56
|
-
});
|
|
57
|
-
return map;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Turn map of distinct values to count into array of values
|
|
61
|
-
*
|
|
62
|
-
* @param map Map to turn into array
|
|
63
|
-
* @returns Array of values
|
|
64
|
-
*/
|
|
65
|
-
export function countedMapToArray(map) {
|
|
66
|
-
return [].concat(...[...map].map(([item, quantity]) => Array(quantity).fill(item)));
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Stringify a counted map
|
|
70
|
-
*
|
|
71
|
-
* @param map Map of counted values
|
|
72
|
-
* @returns String representing map of counted values
|
|
73
|
-
*/
|
|
74
|
-
export function countedMapToString(map) {
|
|
75
|
-
return [...map].map(([item, quantity]) => `${quantity} x ${item}`).join(", ");
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Sum an array of numbers.
|
|
79
|
-
*
|
|
80
|
-
* @param addends Addends to sum.
|
|
81
|
-
* @param x Property or mapping function of addends to sum
|
|
82
|
-
* @returns Sum of numbers
|
|
83
|
-
*/
|
|
84
|
-
export function sum(addends, x) {
|
|
85
|
-
return addends.reduce((subtotal, element) => subtotal + (typeof x === "function" ? x(element) : element[x]), 0);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Sum array of numbers
|
|
89
|
-
*
|
|
90
|
-
* @param addends Numbers to sum
|
|
91
|
-
* @returns Sum of numbers
|
|
92
|
-
*/
|
|
93
|
-
export function sumNumbers(addends) {
|
|
94
|
-
return sum(addends, (x) => x);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Checks if a given item is in a readonly array, acting as a typeguard.
|
|
98
|
-
*
|
|
99
|
-
* @param item Needle
|
|
100
|
-
* @param array Readonly array haystack
|
|
101
|
-
* @returns Whether the item is in the array, and narrows the type of the item.
|
|
102
|
-
*/
|
|
103
|
-
export function arrayContains(item, array) {
|
|
104
|
-
return array.includes(item);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Checks if two arrays contain the same elements in the same quantity.
|
|
108
|
-
*
|
|
109
|
-
* @param a First array for comparison
|
|
110
|
-
* @param b Second array for comparison
|
|
111
|
-
* @returns Whether the two arrays are equal, irrespective of order.
|
|
112
|
-
*/
|
|
113
|
-
export function setEqual(a, b) {
|
|
114
|
-
const sortedA = [...a].sort();
|
|
115
|
-
const sortedB = [...b].sort();
|
|
116
|
-
return (a.length === b.length &&
|
|
117
|
-
sortedA.every((item, index) => item === sortedB[index]));
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Reverses keys and values for a given map
|
|
121
|
-
*
|
|
122
|
-
* @param map Map to invert
|
|
123
|
-
* @returns Inverted map
|
|
124
|
-
*/
|
|
125
|
-
export function invertMap(map) {
|
|
126
|
-
const returnValue = new Map();
|
|
127
|
-
for (const [key, value] of map) {
|
|
128
|
-
returnValue.set(value, key);
|
|
129
|
-
}
|
|
130
|
-
return returnValue;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Splits a string by commas while also respecting escaping commas with a backslash
|
|
134
|
-
*
|
|
135
|
-
* @param str String to split
|
|
136
|
-
* @returns List of tokens
|
|
137
|
-
*/
|
|
138
|
-
export function splitByCommasWithEscapes(str) {
|
|
139
|
-
const returnValue = [];
|
|
140
|
-
let ignoreNext = false;
|
|
141
|
-
let currentString = "";
|
|
142
|
-
for (const char of str.split("")) {
|
|
143
|
-
if (char === "\\") {
|
|
144
|
-
ignoreNext = true;
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
if (char == "," && !ignoreNext) {
|
|
148
|
-
returnValue.push(currentString.trim());
|
|
149
|
-
currentString = "";
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
currentString += char;
|
|
153
|
-
}
|
|
154
|
-
ignoreNext = false;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
returnValue.push(currentString.trim());
|
|
158
|
-
return returnValue;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Find the best element of an array, where "best" is defined by some given criteria.
|
|
162
|
-
*
|
|
163
|
-
* @param array The array to traverse and find the best element of.
|
|
164
|
-
* @param optimizer Either a key on the objects we're looking at that corresponds to numerical values, or a function for mapping these objects to numbers. Essentially, some way of assigning value to the elements of the array.
|
|
165
|
-
* @param reverse Make this true to find the worst element of the array, and false to find the best. Defaults to false.
|
|
166
|
-
* @returns Best element by optimizer function
|
|
167
|
-
*/
|
|
168
|
-
export function maxBy(array, optimizer, reverse = false) {
|
|
169
|
-
if (!array.length)
|
|
170
|
-
throw new Error("Cannot call maxBy on an empty array!");
|
|
171
|
-
if (typeof optimizer === "function") {
|
|
172
|
-
return [...array].reduce(({ value, item }, other) => {
|
|
173
|
-
const otherValue = optimizer(other);
|
|
174
|
-
return value >= otherValue !== reverse
|
|
175
|
-
? { value, item }
|
|
176
|
-
: { value: otherValue, item: other };
|
|
177
|
-
}, { item: array[0], value: optimizer(array[0]) }).item;
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
return array.reduce((a, b) => a[optimizer] >= b[optimizer] !== reverse ? a : b);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Compare arrays shallowly
|
|
185
|
-
*
|
|
186
|
-
* @param left One array to compare
|
|
187
|
-
* @param right The other array to compare
|
|
188
|
-
* @returns Whether the two arrays are shallowly equal
|
|
189
|
-
*/
|
|
190
|
-
export function arrayEquals(left, right) {
|
|
191
|
-
if (left.length !== right.length)
|
|
192
|
-
return false;
|
|
193
|
-
return left.every((element, index) => element === right[index]);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Used to collapse a Delayed<T, S> object into an entity of type "T" as represented by the object.
|
|
197
|
-
*
|
|
198
|
-
* @param delayedObject Object of type Delayed<T, S> that represents either a value of type T or a function returning a value of type T.
|
|
199
|
-
* @param args The arguments to pass to the delay function
|
|
200
|
-
* @returns The return value of the function, if delayedObject is a function. Otherwise, this returns the original element.
|
|
201
|
-
*/
|
|
202
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
203
|
-
export function undelay(delayedObject, ...args) {
|
|
204
|
-
return typeof delayedObject === "function"
|
|
205
|
-
? delayedObject(...args)
|
|
206
|
-
: delayedObject;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Makes a byX function, like byStat or byClass
|
|
210
|
-
*
|
|
211
|
-
* @param source A method for finding your stat, or class, or whatever X is in this context
|
|
212
|
-
* @returns A function akin to byStat or byClass; it accepts an object that either is "complete" in the sense that it has a key for every conceivable value, or contains a `default` parameter. If an inappropriate input is provided, returns undefined.
|
|
213
|
-
*/
|
|
214
|
-
export function makeByXFunction(source) {
|
|
215
|
-
return function (options) {
|
|
216
|
-
const val = undelay(source);
|
|
217
|
-
if ("default" in options)
|
|
218
|
-
return options[val] ?? options.default;
|
|
219
|
-
return options[val];
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Flattens an array. Basically replacing Array.prototype.flat for which Rhino doesn't yet have an implementation
|
|
224
|
-
*
|
|
225
|
-
* @param arr Array to flatten
|
|
226
|
-
* @param depth Number of layers to flatten by; Infinity for a fully flat array
|
|
227
|
-
* @returns Flattened array
|
|
228
|
-
*/
|
|
229
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
230
|
-
export function flat(arr, depth = Infinity) {
|
|
231
|
-
let flatArray = [];
|
|
232
|
-
for (const item of arr) {
|
|
233
|
-
if (Array.isArray(item) && depth > 0) {
|
|
234
|
-
flatArray = flatArray.concat(flat(item, depth - 1));
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
flatArray.push(item);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return flatArray;
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* @param array Array to select from
|
|
244
|
-
* @returns Random item from array
|
|
245
|
-
*/
|
|
246
|
-
export function random(array) {
|
|
247
|
-
return array[Math.floor(Math.random() * array.length)];
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Title cases a single word
|
|
251
|
-
*
|
|
252
|
-
* @param word Word to transform
|
|
253
|
-
* @returns Word in title case
|
|
254
|
-
*/
|
|
255
|
-
export const tc = (word) => word.charAt(0).toUpperCase() + word.slice(1);
|