libram 0.8.28 → 0.8.30

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