libram 0.7.11 → 0.7.13

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 (147) hide show
  1. package/dist/Clan.d.ts +34 -6
  2. package/dist/Clan.js +33 -6
  3. package/dist/Copier.d.ts +5 -5
  4. package/dist/Dungeon.d.ts +45 -0
  5. package/dist/Dungeon.js +115 -0
  6. package/dist/Kmail.d.ts +8 -5
  7. package/dist/Kmail.js +8 -5
  8. package/dist/actions/ActionSource.d.ts +5 -0
  9. package/dist/actions/ActionSource.js +20 -1
  10. package/dist/actions/FreeKill.d.ts +2 -0
  11. package/dist/actions/FreeKill.js +2 -0
  12. package/dist/actions/FreeRun.d.ts +2 -0
  13. package/dist/actions/FreeRun.js +2 -0
  14. package/dist/ascend.d.ts +20 -4
  15. package/dist/ascend.js +32 -4
  16. package/dist/challengePaths/2015/CommunityService.d.ts +7 -0
  17. package/dist/challengePaths/2015/CommunityService.js +12 -1
  18. package/dist/combat.d.ts +55 -0
  19. package/dist/combat.js +85 -0
  20. package/dist/counter.d.ts +3 -0
  21. package/dist/counter.js +3 -0
  22. package/dist/diet/index.d.ts +2 -0
  23. package/dist/diet/index.js +27 -8
  24. package/dist/diet/knapsack.d.ts +1 -0
  25. package/dist/diet/knapsack.js +11 -3
  26. package/dist/index.d.ts +2 -4
  27. package/dist/index.js +1 -3
  28. package/dist/lib.d.ts +101 -34
  29. package/dist/lib.js +133 -42
  30. package/dist/logger.d.ts +24 -11
  31. package/dist/logger.js +38 -12
  32. package/dist/maximize.d.ts +20 -1
  33. package/dist/maximize.js +30 -3
  34. package/dist/modifier.d.ts +1 -1
  35. package/dist/modifier.js +9 -1
  36. package/dist/mood.d.ts +15 -1
  37. package/dist/mood.js +15 -1
  38. package/dist/property.d.ts +52 -17
  39. package/dist/property.js +64 -7
  40. package/dist/propertyTypes.d.ts +5 -5
  41. package/dist/propertyTypes.js +5 -5
  42. package/dist/propertyTyping.d.ts +54 -0
  43. package/dist/propertyTyping.js +54 -0
  44. package/dist/resources/2008/Stickers.d.ts +28 -0
  45. package/dist/resources/2008/Stickers.js +28 -0
  46. package/dist/resources/2009/Bandersnatch.d.ts +17 -7
  47. package/dist/resources/2009/Bandersnatch.js +17 -7
  48. package/dist/resources/2009/SpookyPutty.d.ts +25 -0
  49. package/dist/resources/2009/SpookyPutty.js +25 -0
  50. package/dist/resources/2010/CrownOfThrones.d.ts +23 -0
  51. package/dist/resources/2010/CrownOfThrones.js +31 -15
  52. package/dist/resources/2010/LookingGlass.d.ts +4 -0
  53. package/dist/resources/2010/LookingGlass.js +5 -0
  54. package/dist/resources/2011/ObtuseAngel.d.ts +8 -6
  55. package/dist/resources/2011/ObtuseAngel.js +8 -6
  56. package/dist/resources/2011/StompingBoots.d.ts +9 -15
  57. package/dist/resources/2011/StompingBoots.js +9 -15
  58. package/dist/resources/2012/RainDoh.d.ts +20 -0
  59. package/dist/resources/2012/RainDoh.js +20 -0
  60. package/dist/resources/2012/ReagnimatedGnome.d.ts +18 -0
  61. package/dist/resources/2012/ReagnimatedGnome.js +18 -0
  62. package/dist/resources/2012/Resolutions.d.ts +2 -2
  63. package/dist/resources/2012/Resolutions.js +2 -2
  64. package/dist/resources/2013/Florist.d.ts +15 -0
  65. package/dist/resources/2013/Florist.js +21 -0
  66. package/dist/resources/2014/CrimboShrub.d.ts +12 -0
  67. package/dist/resources/2014/CrimboShrub.js +22 -1
  68. package/dist/resources/2014/DNALab.d.ts +10 -2
  69. package/dist/resources/2014/DNALab.js +10 -2
  70. package/dist/resources/2014/WinterGarden.d.ts +15 -0
  71. package/dist/resources/2014/WinterGarden.js +15 -0
  72. package/dist/resources/2015/BarrelShrine.d.ts +6 -0
  73. package/dist/resources/2015/BarrelShrine.js +6 -0
  74. package/dist/resources/2015/ChateauMantegna.d.ts +35 -0
  75. package/dist/resources/2015/ChateauMantegna.js +35 -0
  76. package/dist/resources/2015/DeckOfEveryCard.d.ts +23 -1
  77. package/dist/resources/2015/DeckOfEveryCard.js +24 -0
  78. package/dist/resources/2015/Dinseylandfill.d.ts +1 -0
  79. package/dist/resources/2015/Dinseylandfill.js +2 -0
  80. package/dist/resources/2015/MayoClinic.d.ts +8 -1
  81. package/dist/resources/2015/MayoClinic.js +8 -1
  82. package/dist/resources/2016/SourceTerminal.d.ts +42 -21
  83. package/dist/resources/2016/SourceTerminal.js +42 -21
  84. package/dist/resources/2016/Witchess.d.ts +12 -0
  85. package/dist/resources/2016/Witchess.js +12 -0
  86. package/dist/resources/2017/AsdonMartin.d.ts +11 -3
  87. package/dist/resources/2017/AsdonMartin.js +44 -7
  88. package/dist/resources/2017/MummingTrunk.d.ts +1 -0
  89. package/dist/resources/2017/MummingTrunk.js +8 -1
  90. package/dist/resources/2017/Pantogram.d.ts +9 -0
  91. package/dist/resources/2017/Pantogram.js +33 -0
  92. package/dist/resources/2017/Robortender.d.ts +1 -0
  93. package/dist/resources/2017/Robortender.js +1 -0
  94. package/dist/resources/2017/Spacegate.js +1 -0
  95. package/dist/resources/2017/TunnelOfLove.d.ts +19 -0
  96. package/dist/resources/2017/TunnelOfLove.js +37 -0
  97. package/dist/resources/2018/LatteLoversMembersMug.d.ts +9 -0
  98. package/dist/resources/2018/LatteLoversMembersMug.js +9 -0
  99. package/dist/resources/2018/SongBoom.d.ts +9 -4
  100. package/dist/resources/2018/SongBoom.js +9 -4
  101. package/dist/resources/2019/BeachComb.d.ts +38 -1
  102. package/dist/resources/2019/BeachComb.js +39 -2
  103. package/dist/resources/2019/Snapper.d.ts +4 -0
  104. package/dist/resources/2019/Snapper.js +4 -0
  105. package/dist/resources/2020/Cartography.d.ts +13 -0
  106. package/dist/resources/2020/Cartography.js +13 -0
  107. package/dist/resources/2020/Guzzlr.d.ts +89 -23
  108. package/dist/resources/2020/Guzzlr.js +100 -29
  109. package/dist/resources/2020/RetroCape.d.ts +4 -0
  110. package/dist/resources/2020/RetroCape.js +4 -0
  111. package/dist/resources/2021/CrystalBall.d.ts +6 -0
  112. package/dist/resources/2021/CrystalBall.js +13 -1
  113. package/dist/resources/2021/DaylightShavings.d.ts +6 -0
  114. package/dist/resources/2021/DaylightShavings.js +6 -0
  115. package/dist/resources/2022/AutumnAton.d.ts +15 -0
  116. package/dist/resources/2022/AutumnAton.js +21 -0
  117. package/dist/resources/2022/CombatLoversLocket.d.ts +9 -0
  118. package/dist/resources/2022/CombatLoversLocket.js +10 -2
  119. package/dist/resources/2022/GreyGoose.d.ts +46 -0
  120. package/dist/resources/2022/GreyGoose.js +47 -1
  121. package/dist/resources/2022/JuneCleaver.d.ts +20 -0
  122. package/dist/resources/2022/JuneCleaver.js +20 -0
  123. package/dist/resources/2022/TrainSet.d.ts +48 -0
  124. package/dist/resources/2022/TrainSet.js +54 -0
  125. package/dist/resources/2023/ClosedCircuitPayphone.d.ts +75 -0
  126. package/dist/resources/2023/ClosedCircuitPayphone.js +117 -0
  127. package/dist/resources/LibramSummon.d.ts +5 -0
  128. package/dist/resources/LibramSummon.js +5 -0
  129. package/dist/resources/index.d.ts +2 -1
  130. package/dist/resources/index.js +2 -1
  131. package/dist/resources/putty-likes.d.ts +15 -0
  132. package/dist/resources/putty-likes.js +15 -0
  133. package/dist/session.d.ts +12 -0
  134. package/dist/session.js +20 -17
  135. package/dist/since.d.ts +3 -2
  136. package/dist/since.js +4 -2
  137. package/dist/utils.d.ts +82 -6
  138. package/dist/utils.js +88 -0
  139. package/package.json +6 -4
  140. package/dist/dungeons/Dreadsylvania.d.ts +0 -5
  141. package/dist/dungeons/Dreadsylvania.js +0 -14
  142. package/dist/dungeons/Dungeon.d.ts +0 -29
  143. package/dist/dungeons/Dungeon.js +0 -99
  144. package/dist/dungeons/Hobopolis.d.ts +0 -5
  145. package/dist/dungeons/Hobopolis.js +0 -14
  146. package/dist/dungeons/SlimeTube.d.ts +0 -5
  147. package/dist/dungeons/SlimeTube.js +0 -14
package/dist/session.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { todayToString, myName, bufferToFile, fileToBuffer, mySessionItems, mySessionMeat, toItem, } from "kolmafia";
2
2
  import { getFoldGroup } from "./lib";
3
3
  import { $item, $items } from "./template-string";
4
- import { sumNumbers } from "./utils";
4
+ import { sum } from "./utils";
5
5
  /**
6
6
  * Return a mapping of the session items, mapping foldable items to a single of their forms
7
+ *
7
8
  * @returns the item session results, with foldables mapped to a single of their folding forms
8
9
  */
9
10
  function mySessionItemsWrapper() {
@@ -44,26 +45,18 @@ function mySessionItemsWrapper() {
44
45
  return inventory;
45
46
  }
46
47
  /**
47
- * Performa a binary element-wise operation on two inventories
48
+ * Perform a binary element-wise operation on two inventories
49
+ *
48
50
  * @param a The LHS inventory to perform the operation on
49
51
  * @param b The RHS inventory to perform the operation on
50
52
  * @param op an operator to compute between the sets
51
- * @param commutative if true use the value of b for any items not in a. if false, ignore values not in a
52
53
  * @returns a new map representing the combined inventories
53
54
  */
54
- function inventoryOperation(a, b, op, commutative) {
55
+ function inventoryOperation(a, b, op) {
55
56
  // return every entry that is in a and not in b
56
57
  const difference = new Map();
57
- for (const [item, quantity] of a.entries()) {
58
- const combinedQuantity = op(quantity, b.get(item) ?? 0);
59
- difference.set(item, combinedQuantity);
60
- }
61
- if (commutative) {
62
- for (const [item, quantity] of b.entries()) {
63
- if (!a.has(item)) {
64
- difference.set(item, quantity);
65
- }
66
- }
58
+ for (const item of new Set([...a.keys(), ...b.keys()])) {
59
+ difference.set(item, op(a.get(item) ?? 0, b.get(item) ?? 0));
67
60
  }
68
61
  const diffEntries = [...difference.entries()];
69
62
  return new Map(diffEntries.filter((value) => value[1] !== 0));
@@ -72,6 +65,7 @@ function inventoryOperation(a, b, op, commutative) {
72
65
  * A wrapper around tracking items and meat gained from this session
73
66
  * Smartly handles foldables being added/removed based on their state
74
67
  * Provides operations to add sessions and subtract Sessions so you can isolate the value of each Session using a baseline
68
+ *
75
69
  * @member meat the raw meat associated with this Session
76
70
  * @member items a map representing the items gained/lost during this Session
77
71
  */
@@ -80,6 +74,7 @@ export class Session {
80
74
  items;
81
75
  /**
82
76
  * Construct a new session
77
+ *
83
78
  * @param meat the amount of meat associated with this session
84
79
  * @param items the items associated with this session
85
80
  */
@@ -89,6 +84,7 @@ export class Session {
89
84
  }
90
85
  /**
91
86
  * Register session results that do not get tracked natively
87
+ *
92
88
  * @param target either the Item or a string saying "meat" of what quantity to modify
93
89
  * @param quantity How much to modify the tracked amount by
94
90
  */
@@ -102,6 +98,7 @@ export class Session {
102
98
  }
103
99
  /**
104
100
  * Value this session
101
+ *
105
102
  * @param itemValue a function that, when given an item, will give a meat value of the item
106
103
  * @returns ItemResult with the full value of this session given the input function
107
104
  */
@@ -111,21 +108,23 @@ export class Session {
111
108
  const itemDetails = [...this.items.entries()].map(([item, quantity]) => {
112
109
  return { item, quantity, value: itemValue(item) * quantity };
113
110
  });
114
- const items = Math.floor(sumNumbers(itemDetails.map((detail) => detail.value)));
111
+ const items = Math.floor(sum(itemDetails, "value"));
115
112
  return { meat, items, total: meat + items, itemDetails };
116
113
  }
117
114
  /**
118
115
  * Subtract the contents of another session from this one, removing any items that have a resulting quantity of 0
119
116
  * (this will ignore elements in b but not in a)
117
+ *
120
118
  * @param other the session from which to pull values to remove from this session
121
119
  * @returns a new session representing the difference between this session and the other session
122
120
  */
123
121
  diff(other) {
124
- return new Session(this.meat - other.meat, inventoryOperation(this.items, other.items, (a, b) => a - b, false));
122
+ return new Session(this.meat - other.meat, inventoryOperation(this.items, other.items, (a, b) => a - b));
125
123
  }
126
124
  /**
127
125
  * Subtract the contents of snasphot b from session a, removing any items that have a resulting quantity of 0
128
126
  * (this will ignore elements in b but not in a)
127
+ *
129
128
  * @param a the session from which to subtract elements
130
129
  * @param b the session from which to add elements
131
130
  * @returns a new session representing the difference between a and b
@@ -135,14 +134,16 @@ export class Session {
135
134
  }
136
135
  /**
137
136
  * Generate a new session combining multiple sessions together
137
+ *
138
138
  * @param other the session from which to add elements to this set
139
139
  * @returns a new session representing the addition of other to this
140
140
  */
141
141
  add(other) {
142
- return new Session(this.meat + other.meat, inventoryOperation(this.items, other.items, (a, b) => a + b, true));
142
+ return new Session(this.meat + other.meat, inventoryOperation(this.items, other.items, (a, b) => a + b));
143
143
  }
144
144
  /**
145
145
  * Combine the contents of sessions
146
+ *
146
147
  * @param sessions the set of sessions to combine together
147
148
  * @returns a new session representing the difference between a and b
148
149
  */
@@ -156,6 +157,7 @@ export class Session {
156
157
  }
157
158
  /**
158
159
  * Export this session to a file in the data/ directory. Conventionally this file should end in ".json"
160
+ *
159
161
  * @param filename The file into which to export
160
162
  */
161
163
  toFile(filename) {
@@ -167,6 +169,7 @@ export class Session {
167
169
  }
168
170
  /**
169
171
  * Import a session from a file in the data/ directory. Conventionally the file should end in ".json"
172
+ *
170
173
  * @param filename The file from which to import
171
174
  * @returns the session represented by the file
172
175
  */
package/dist/since.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Provides functions for checking KoLmafia's version and revision.
3
+ *
3
4
  * @packageDocumentation
4
5
  */
5
6
  /**
@@ -14,11 +15,11 @@ export declare class KolmafiaVersionError extends Error {
14
15
  * Otherwise, does nothing.
15
16
  *
16
17
  * This behaves like the `since rXXX;` statement in ASH.
18
+ *
17
19
  * @param revision Revision number
18
20
  * @throws {KolmafiaVersionError}
19
21
  * If KoLmafia's revision number is less than `revision`.
20
22
  * @throws {TypeError} If `revision` is not an integer
21
- *
22
23
  * @example
23
24
  * ```ts
24
25
  * // Throws if KoLmafia revision is less than r20500
@@ -32,6 +33,7 @@ export declare function sinceKolmafiaRevision(revision: number): void;
32
33
  * Otherwise, does nothing.
33
34
  *
34
35
  * This behaves like the `since X.Y;` statement in ASH.
36
+ *
35
37
  * @param majorVersion Major version number
36
38
  * @param minorVersion Minor version number
37
39
  * @deprecated Point versions are no longer released by KoLmafia
@@ -40,7 +42,6 @@ export declare function sinceKolmafiaRevision(revision: number): void;
40
42
  * versions are equal but the minor version is less than `minorVersion`
41
43
  * @throws {TypeError}
42
44
  * If either `majorVersion` or `minorVersion` are not integers
43
- *
44
45
  * @example
45
46
  * ```ts
46
47
  * // Throws if KoLmafia version is less than 20.7
package/dist/since.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Provides functions for checking KoLmafia's version and revision.
3
+ *
3
4
  * @packageDocumentation
4
5
  */
5
6
  import { getRevision, getVersion } from "kolmafia";
@@ -22,6 +23,7 @@ KolmafiaVersionError.prototype.name = "KolmafiaVersionError";
22
23
  /**
23
24
  * Returns the currently executing script name, suitable for embedding in an
24
25
  * error message.
26
+ *
25
27
  * @returns Path of the main script wrapped in single-quotes, or `"This script"`
26
28
  * if the path cannot be determined
27
29
  */
@@ -35,11 +37,11 @@ function getScriptName() {
35
37
  * Otherwise, does nothing.
36
38
  *
37
39
  * This behaves like the `since rXXX;` statement in ASH.
40
+ *
38
41
  * @param revision Revision number
39
42
  * @throws {KolmafiaVersionError}
40
43
  * If KoLmafia's revision number is less than `revision`.
41
44
  * @throws {TypeError} If `revision` is not an integer
42
- *
43
45
  * @example
44
46
  * ```ts
45
47
  * // Throws if KoLmafia revision is less than r20500
@@ -62,6 +64,7 @@ export function sinceKolmafiaRevision(revision) {
62
64
  * Otherwise, does nothing.
63
65
  *
64
66
  * This behaves like the `since X.Y;` statement in ASH.
67
+ *
65
68
  * @param majorVersion Major version number
66
69
  * @param minorVersion Minor version number
67
70
  * @deprecated Point versions are no longer released by KoLmafia
@@ -70,7 +73,6 @@ export function sinceKolmafiaRevision(revision) {
70
73
  * versions are equal but the minor version is less than `minorVersion`
71
74
  * @throws {TypeError}
72
75
  * If either `majorVersion` or `minorVersion` are not integers
73
- *
74
76
  * @example
75
77
  * ```ts
76
78
  * // Throws if KoLmafia version is less than 20.7
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,16 @@
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
+ */
1
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
+ */
2
14
  export declare function parseNumber(n: string): number;
3
15
  /**
4
16
  * Clamp a number between lower and upper bounds.
@@ -6,6 +18,7 @@ export declare function parseNumber(n: string): number;
6
18
  * @param n Number to clamp.
7
19
  * @param min Lower bound.
8
20
  * @param max Upper bound.
21
+ * @returns Clamped value
9
22
  */
10
23
  export declare function clamp(n: number, min: number, max: number): number;
11
24
  /**
@@ -13,28 +26,58 @@ export declare function clamp(n: number, min: number, max: number): number;
13
26
  *
14
27
  * @param array Array to split
15
28
  * @param chunkSize Size of chunk
29
+ * @returns Split array
16
30
  */
17
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
+ */
18
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
+ */
19
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
+ */
20
52
  export declare function countedMapToString<T>(map: Map<T, number>): string;
21
53
  /**
22
54
  * Sum an array of numbers.
55
+ *
23
56
  * @param addends Addends to sum.
24
57
  * @param property Property of the elements to be summing
58
+ * @returns Sum of numbers
25
59
  */
26
60
  export declare function sum<S extends string | number | symbol, T extends {
27
61
  [s in S]: number;
28
62
  }>(addends: T[], property: S): number;
29
63
  /**
30
64
  * Sum an array of numbers.
65
+ *
31
66
  * @param addends Addends to sum.
32
67
  * @param mappingFunction Mapping function to turn addends into actual numbers.
68
+ * @returns Sum of numbers
33
69
  */
34
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
+ */
35
77
  export declare function sumNumbers(addends: number[]): number;
36
78
  /**
37
79
  * Checks if a given item is in a readonly array, acting as a typeguard.
80
+ *
38
81
  * @param item Needle
39
82
  * @param array Readonly array haystack
40
83
  * @returns Whether the item is in the array, and narrows the type of the item.
@@ -42,6 +85,7 @@ export declare function sumNumbers(addends: number[]): number;
42
85
  export declare function arrayContains<T, A extends T>(item: T, array: ReadonlyArray<A>): item is A;
43
86
  /**
44
87
  * Checks if two arrays contain the same elements in the same quantity.
88
+ *
45
89
  * @param a First array for comparison
46
90
  * @param b Second array for comparison
47
91
  * @returns Whether the two arrays are equal, irrespective of order.
@@ -49,26 +93,58 @@ export declare function arrayContains<T, A extends T>(item: T, array: ReadonlyAr
49
93
  export declare function setEqual<T>(a: T[], b: T[]): boolean;
50
94
  /**
51
95
  * Reverses keys and values for a given map
96
+ *
52
97
  * @param map Map to invert
98
+ * @returns Inverted map
53
99
  */
54
100
  export declare function invertMap<T1, T2>(map: Map<T1, T2>): Map<T2, T1>;
55
101
  /**
56
102
  * Splits a string by commas while also respecting escaping commas with a backslash
103
+ *
57
104
  * @param str String to split
58
105
  * @returns List of tokens
59
106
  */
60
107
  export declare function splitByCommasWithEscapes(str: string): string[];
61
- /**
62
- * Find the best element of an array, where "best" is defined by some given criteria.
63
- * @param array The array to traverse and find the best element of.
64
- * @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.
65
- * @param reverse Make this true to find the worst element of the array, and false to find the best. Defaults to false.
66
- */
67
108
  export declare function maxBy<T>(array: T[] | readonly T[], optimizer: (element: T) => number, reverse?: boolean): T;
68
109
  export declare function maxBy<S extends string | number | symbol, T extends {
69
110
  [x in S]: number;
70
111
  }>(array: T[] | readonly T[], key: S, reverse?: boolean): T;
71
112
  export declare type Tuple<T, N extends number> = N extends N ? number extends N ? T[] : _tupleOf<T, N, []> : never;
72
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
+ */
73
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> = [T] extends [(...args: any) => any] ? never : T | (() => T);
127
+ /**
128
+ * Used to collapse a Delayed<T> object into an entity of type "T" as represented by the object.
129
+ *
130
+ * @param delayedObject Object of type Delayed<T> that represents either a value of type T or a function returning a value of type T.
131
+ * @returns The return value of the function, if delayedObject is a function. Otherwise, this returns the original element.
132
+ */
133
+ export declare function undelay<T>(delayedObject: Delayed<T>): T;
134
+ /**
135
+ * An object keyed by string type T, with values of S.
136
+ * or contains a 'default' parameter to use as a fallback.
137
+ */
138
+ export declare type Switch<T extends string, S> = Record<T, S> | (Partial<{
139
+ [x in T]: S;
140
+ }> & {
141
+ default: S;
142
+ });
143
+ /**
144
+ * Makes a byX function, like byStat or byClass
145
+ *
146
+ * @param source A method for finding your stat, or class, or whatever X is in this context
147
+ * @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.
148
+ */
149
+ export declare function makeByXFunction<T extends string>(source: Delayed<T>): <S>(options: Switch<T, S>) => S;
74
150
  export {};
package/dist/utils.js CHANGED
@@ -1,6 +1,18 @@
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
+ */
1
7
  export function notNull(value) {
2
8
  return value !== null;
3
9
  }
10
+ /**
11
+ * Parse string to number, stripping commas
12
+ *
13
+ * @param n Numberical string to parse
14
+ * @returns Numerical value of string
15
+ */
4
16
  export function parseNumber(n) {
5
17
  return Number.parseInt(n.replace(/,/g, ""));
6
18
  }
@@ -10,6 +22,7 @@ export function parseNumber(n) {
10
22
  * @param n Number to clamp.
11
23
  * @param min Lower bound.
12
24
  * @param max Upper bound.
25
+ * @returns Clamped value
13
26
  */
14
27
  export function clamp(n, min, max) {
15
28
  return Math.max(min, Math.min(max, n));
@@ -19,6 +32,7 @@ export function clamp(n, min, max) {
19
32
  *
20
33
  * @param array Array to split
21
34
  * @param chunkSize Size of chunk
35
+ * @returns Split array
22
36
  */
23
37
  export function chunk(array, chunkSize) {
24
38
  const result = [];
@@ -27,6 +41,12 @@ export function chunk(array, chunkSize) {
27
41
  }
28
42
  return result;
29
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
+ */
30
50
  export function arrayToCountedMap(array) {
31
51
  if (!Array.isArray(array))
32
52
  return array;
@@ -36,20 +56,46 @@ export function arrayToCountedMap(array) {
36
56
  });
37
57
  return map;
38
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
+ */
39
65
  export function countedMapToArray(map) {
40
66
  return [].concat(...[...map].map(([item, quantity]) => Array(quantity).fill(item)));
41
67
  }
68
+ /**
69
+ * Stringify a counted map
70
+ *
71
+ * @param map Map of counted values
72
+ * @returns String representing map of counted values
73
+ */
42
74
  export function countedMapToString(map) {
43
75
  return [...map].map(([item, quantity]) => `${quantity} x ${item}`).join(", ");
44
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
+ */
45
84
  export function sum(addends, x) {
46
85
  return addends.reduce((subtotal, element) => subtotal + (typeof x === "function" ? x(element) : element[x]), 0);
47
86
  }
87
+ /**
88
+ * Sum array of numbers
89
+ *
90
+ * @param addends Numbers to sum
91
+ * @returns Sum of numbers
92
+ */
48
93
  export function sumNumbers(addends) {
49
94
  return sum(addends, (x) => x);
50
95
  }
51
96
  /**
52
97
  * Checks if a given item is in a readonly array, acting as a typeguard.
98
+ *
53
99
  * @param item Needle
54
100
  * @param array Readonly array haystack
55
101
  * @returns Whether the item is in the array, and narrows the type of the item.
@@ -59,6 +105,7 @@ export function arrayContains(item, array) {
59
105
  }
60
106
  /**
61
107
  * Checks if two arrays contain the same elements in the same quantity.
108
+ *
62
109
  * @param a First array for comparison
63
110
  * @param b Second array for comparison
64
111
  * @returns Whether the two arrays are equal, irrespective of order.
@@ -71,7 +118,9 @@ export function setEqual(a, b) {
71
118
  }
72
119
  /**
73
120
  * Reverses keys and values for a given map
121
+ *
74
122
  * @param map Map to invert
123
+ * @returns Inverted map
75
124
  */
76
125
  export function invertMap(map) {
77
126
  const returnValue = new Map();
@@ -82,6 +131,7 @@ export function invertMap(map) {
82
131
  }
83
132
  /**
84
133
  * Splits a string by commas while also respecting escaping commas with a backslash
134
+ *
85
135
  * @param str String to split
86
136
  * @returns List of tokens
87
137
  */
@@ -107,6 +157,14 @@ export function splitByCommasWithEscapes(str) {
107
157
  returnValue.push(currentString.trim());
108
158
  return returnValue;
109
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
+ */
110
168
  export function maxBy(array, optimizer, reverse = false) {
111
169
  if (!array.length)
112
170
  throw new Error("Cannot call maxBy on an empty array!");
@@ -122,8 +180,38 @@ export function maxBy(array, optimizer, reverse = false) {
122
180
  return array.reduce((a, b) => a[optimizer] >= b[optimizer] !== reverse ? a : b);
123
181
  }
124
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
+ */
125
190
  export function arrayEquals(left, right) {
126
191
  if (left.length !== right.length)
127
192
  return false;
128
193
  return left.every((element, index) => element === right[index]);
129
194
  }
195
+ /**
196
+ * Used to collapse a Delayed<T> object into an entity of type "T" as represented by the object.
197
+ *
198
+ * @param delayedObject Object of type Delayed<T> that represents either a value of type T or a function returning a value of type T.
199
+ * @returns The return value of the function, if delayedObject is a function. Otherwise, this returns the original element.
200
+ */
201
+ export function undelay(delayedObject) {
202
+ return typeof delayedObject === "function" ? delayedObject() : delayedObject;
203
+ }
204
+ /**
205
+ * Makes a byX function, like byStat or byClass
206
+ *
207
+ * @param source A method for finding your stat, or class, or whatever X is in this context
208
+ * @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.
209
+ */
210
+ export function makeByXFunction(source) {
211
+ return function (options) {
212
+ const val = undelay(source);
213
+ if ("default" in options)
214
+ return options[val] ?? options.default;
215
+ return options[val];
216
+ };
217
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libram",
3
- "version": "0.7.11",
3
+ "version": "0.7.13",
4
4
  "description": "JavaScript helper library for KoLmafia",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,6 +31,7 @@
31
31
  "@babel/preset-env": "^7.16.11",
32
32
  "@babel/preset-typescript": "^7.15.0",
33
33
  "@tsconfig/node16": "^1.0.2",
34
+ "@types/array.prototype.flat": "^1.2.1",
34
35
  "@types/jest": "^27.0.1",
35
36
  "@types/lodash-es": "^4.17.4",
36
37
  "@types/node": "^16.11.11",
@@ -45,11 +46,12 @@
45
46
  "eslint-import-resolver-typescript": "^2.5.0",
46
47
  "eslint-plugin-import": "^2.25.4",
47
48
  "eslint-plugin-jest": "^25.2.3",
48
- "eslint-plugin-libram": "^0.2.25",
49
+ "eslint-plugin-jsdoc": "^40.0.1",
50
+ "eslint-plugin-libram": "^0.2.29",
49
51
  "husky": "^4.3.6",
50
52
  "java-parser": "^1.4.0",
51
53
  "jest": "^27.1.0",
52
- "kolmafia": "^5.27075.0",
54
+ "kolmafia": "^5.27260.0",
53
55
  "lint-staged": ">=10",
54
56
  "node-fetch": "^2.6.1",
55
57
  "prettier": "^2.1.2",
@@ -60,7 +62,7 @@
60
62
  },
61
63
  "dependencies": {
62
64
  "@babel/runtime-corejs3": "^7.17.2",
63
- "core-js": "^3.21.0"
65
+ "array.prototype.flat": "^1.3.1"
64
66
  },
65
67
  "peerDependencies": {
66
68
  "kolmafia": "^5.26781.0"
@@ -1,5 +0,0 @@
1
- import { Item } from "kolmafia";
2
- export declare function close(): boolean;
3
- export declare function open(paymentPolicy?: "None" | "All" | "Difference"): boolean;
4
- export declare function distribute(idOrName?: number | string, loot?: Item | Item[] | Map<Item, number>, distributeAllOfAGivenItem?: boolean): void;
5
- export declare function findLoot(): Map<Item, number>;
@@ -1,14 +0,0 @@
1
- import { myId } from "kolmafia";
2
- import { close as closeDungeon, distribute as distributeDungeon, Dreadsylvania, findLoot as findLootDungeon, open as openDungeon, } from "./Dungeon";
3
- export function close() {
4
- return closeDungeon(Dreadsylvania);
5
- }
6
- export function open(paymentPolicy = "Difference") {
7
- return openDungeon(Dreadsylvania, paymentPolicy);
8
- }
9
- export function distribute(idOrName = myId(), loot = Dreadsylvania.loot, distributeAllOfAGivenItem = true) {
10
- distributeDungeon(Dreadsylvania, idOrName, loot, distributeAllOfAGivenItem);
11
- }
12
- export function findLoot() {
13
- return findLootDungeon(Dreadsylvania);
14
- }
@@ -1,29 +0,0 @@
1
- import { Item } from "kolmafia";
2
- export declare type Dungeon = {
3
- name: string;
4
- loot: Item[];
5
- openAction: string;
6
- closeAction: string;
7
- openCost: number;
8
- openImage: string;
9
- closedImage: string;
10
- };
11
- /**
12
- * Distributes loot from given dungeon
13
- * @param dungeon The dungeon to distribute loot from
14
- * @param idOrName The player you're trying to distribute to, either as a username or a player ID. Defaults to self.
15
- * @param loot The loot you're looking to distribute, specific to this dungeon
16
- * @param distributeAllOfAGivenItem For items that you can get multiple of in a dungeon. When true, this will give everything of that ilk to your chosen player.
17
- */
18
- export declare function distribute(dungeon: Dungeon, idOrName?: number | string, loot?: Item | Item[] | Map<Item, number>, distributeAllOfAGivenItem?: boolean): void;
19
- export declare function close(dungeon: Dungeon): boolean;
20
- /**
21
- * Opens clan dungeon and, if relevant, pays meat to do so
22
- * @param dungeon The Dungeon to open
23
- * @param paymentPolicy "None", "All", or "Difference". Difference pays into the stash the exact amount needed to open the dungeon.
24
- */
25
- export declare function open(dungeon: Dungeon, paymentPolicy?: "None" | "All" | "Difference"): boolean;
26
- export declare const Dreadsylvania: Dungeon;
27
- export declare const Hobopolis: Dungeon;
28
- export declare const SlimeTube: Dungeon;
29
- export declare function findLoot(dungeon: Dungeon): Map<Item, number>;