isaacscript-common 84.1.2 → 84.2.1

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 (45) hide show
  1. package/dist/classes/features/callbackLogic/PlayerCollectibleDetection.d.ts.map +1 -1
  2. package/dist/classes/features/callbackLogic/PlayerCollectibleDetection.js +3 -2
  3. package/dist/classes/features/callbackLogic/PlayerCollectibleDetection.lua +4 -2
  4. package/dist/decorators.d.ts.map +1 -1
  5. package/dist/decorators.js +9 -3
  6. package/dist/decorators.lua +9 -2
  7. package/dist/functions/array.d.ts +1 -1
  8. package/dist/functions/array.d.ts.map +1 -1
  9. package/dist/functions/array.js +2 -1
  10. package/dist/functions/array.lua +3 -1
  11. package/dist/functions/decorators.d.ts.map +1 -1
  12. package/dist/functions/decorators.js +10 -6
  13. package/dist/functions/decorators.lua +10 -6
  14. package/dist/functions/enums.d.ts.map +1 -1
  15. package/dist/functions/enums.js +7 -4
  16. package/dist/functions/enums.lua +9 -4
  17. package/dist/functions/logMisc.d.ts +2 -2
  18. package/dist/functions/logMisc.d.ts.map +1 -1
  19. package/dist/functions/logMisc.js +3 -4
  20. package/dist/functions/logMisc.lua +4 -3
  21. package/dist/functions/set.d.ts +3 -3
  22. package/dist/functions/set.d.ts.map +1 -1
  23. package/dist/functions/set.js +2 -1
  24. package/dist/functions/set.lua +3 -1
  25. package/dist/functions/sort.d.ts +2 -1
  26. package/dist/functions/sort.d.ts.map +1 -1
  27. package/dist/functions/sort.js +3 -2
  28. package/dist/functions/sort.lua +6 -6
  29. package/dist/functions/table.js +1 -1
  30. package/dist/functions/types.d.ts.map +1 -1
  31. package/dist/functions/types.js +7 -5
  32. package/dist/functions/types.lua +3 -1
  33. package/dist/index.rollup.d.ts +9 -7
  34. package/dist/isaacscript-common.lua +52 -27
  35. package/package.json +1 -1
  36. package/src/classes/features/callbackLogic/PlayerCollectibleDetection.ts +3 -2
  37. package/src/decorators.ts +18 -9
  38. package/src/functions/array.ts +3 -2
  39. package/src/functions/decorators.ts +12 -13
  40. package/src/functions/enums.ts +7 -6
  41. package/src/functions/logMisc.ts +5 -6
  42. package/src/functions/set.ts +7 -4
  43. package/src/functions/sort.ts +2 -2
  44. package/src/functions/table.ts +1 -1
  45. package/src/functions/types.ts +7 -5
@@ -1,5 +1,6 @@
1
1
  import { ReadonlySet } from "../types/ReadonlySet";
2
2
  import { getArrayCombinations, getRandomArrayElement, sumArray } from "./array";
3
+ import { sortNormal } from "./sort";
3
4
  import { isPrimitive } from "./types";
4
5
 
5
6
  /**
@@ -78,7 +79,7 @@ export function deleteSetsFromSet<T>(
78
79
  * a random seed.
79
80
  * @param exceptions Optional. An array of elements to skip over if selected.
80
81
  */
81
- export function getRandomSetElement<T>(
82
+ export function getRandomSetElement<T extends number | string>(
82
83
  set: ReadonlySet<T>,
83
84
  seedOrRNG: Seed | RNG | undefined,
84
85
  exceptions: readonly T[] = [],
@@ -106,7 +107,7 @@ export function getRandomSetElement<T>(
106
107
  * @param set The set to get the combinations of.
107
108
  * @param includeEmptyArray Whether to include an empty array in the combinations.
108
109
  */
109
- export function getSetCombinations<T>(
110
+ export function getSetCombinations<T extends number | string>(
110
111
  set: ReadonlySet<T>,
111
112
  includeEmptyArray: boolean,
112
113
  ): ReadonlyArray<ReadonlySet<T>> {
@@ -123,7 +124,9 @@ export function getSetCombinations<T>(
123
124
  * the contents is important.
124
125
  */
125
126
  // eslint-disable-next-line isaacscript/no-mutable-return
126
- export function getSortedSetValues<T>(set: ReadonlySet<T>): T[] {
127
+ export function getSortedSetValues<T extends number | string>(
128
+ set: ReadonlySet<T>,
129
+ ): T[] {
127
130
  const values = [...set];
128
131
 
129
132
  // Check for problematic types in order to throw a helpful error message.
@@ -137,7 +140,7 @@ export function getSortedSetValues<T>(set: ReadonlySet<T>): T[] {
137
140
  }
138
141
  }
139
142
 
140
- values.sort();
143
+ values.sort(sortNormal);
141
144
 
142
145
  return values;
143
146
  }
@@ -1,6 +1,6 @@
1
1
  import { isNumber, isString, isTable } from "./types";
2
2
 
3
- function sortNormal(a: unknown, b: unknown): -1 | 0 | 1 {
3
+ export function sortNormal(a: unknown, b: unknown): -1 | 0 | 1 {
4
4
  if (!isNumber(a) && !isString(a)) {
5
5
  error(
6
6
  `Failed to normal sort since the first value was not a number or string and was instead: ${type(
@@ -79,7 +79,7 @@ export function sortObjectArrayByKey(key: string) {
79
79
  *
80
80
  * ```ts
81
81
  * const myArray = [[1, 2], [2, 3], [3, 4]];
82
- * myArray.sort(twoDimensionalSort);
82
+ * myArray.sort(sortTwoDimensionalArray);
83
83
  * ```
84
84
  *
85
85
  * This function also properly handles when the array elements are strings or numbers (instead of
@@ -186,7 +186,7 @@ export function iterateTableInOrder<K extends AnyNotNil, V>(
186
186
  return;
187
187
  }
188
188
 
189
- keys.sort();
189
+ keys.sort(); // eslint-disable-line @typescript-eslint/require-array-sort-compare
190
190
  for (const key of keys) {
191
191
  const keyIndex = key as unknown as K;
192
192
  const value = luaMap.get(keyIndex);
@@ -171,12 +171,12 @@ export function asTrinketType(num: int): TrinketType {
171
171
  }
172
172
 
173
173
  export function isBoolean(variable: unknown): variable is boolean {
174
- return type(variable) === "boolean";
174
+ return typeof variable === "boolean";
175
175
  }
176
176
 
177
177
  // eslint-disable-next-line @typescript-eslint/ban-types
178
178
  export function isFunction(variable: unknown): variable is Function {
179
- return type(variable) === "function";
179
+ return typeof variable === "function";
180
180
  }
181
181
 
182
182
  export function isInteger(variable: unknown): variable is int {
@@ -188,14 +188,14 @@ export function isInteger(variable: unknown): variable is int {
188
188
  }
189
189
 
190
190
  export function isNumber(variable: unknown): variable is number {
191
- return type(variable) === "number";
191
+ return typeof variable === "number";
192
192
  }
193
193
 
194
194
  /** Helper function to detect if a variable is a boolean, number, or string. */
195
195
  export function isPrimitive(
196
196
  variable: unknown,
197
197
  ): variable is boolean | number | string {
198
- const variableType = type(variable);
198
+ const variableType = typeof variable;
199
199
  return (
200
200
  variableType === "boolean" ||
201
201
  variableType === "number" ||
@@ -204,16 +204,18 @@ export function isPrimitive(
204
204
  }
205
205
 
206
206
  export function isString(variable: unknown): variable is string {
207
- return type(variable) === "string";
207
+ return typeof variable === "string";
208
208
  }
209
209
 
210
210
  export function isTable(
211
211
  variable: unknown,
212
212
  ): variable is LuaMap<AnyNotNil, unknown> {
213
+ // We cannot use `typeof` here since "table" is not a JavaScript type.
213
214
  return type(variable) === "table";
214
215
  }
215
216
 
216
217
  export function isUserdata(variable: unknown): variable is LuaUserdata {
218
+ // We cannot use `typeof` here since "userdata" is not a JavaScript type.
217
219
  return type(variable) === "userdata";
218
220
  }
219
221