isaacscript-common 84.2.2 → 84.2.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"bitwise.d.ts","sourceRoot":"","sources":["../../src/functions/bitwise.ts"],"names":[],"mappings":";;;;AAGA,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,UAAU,EAC5D,KAAK,EAAE,SAAS,CAAC,EAAE,GAClB,QAAQ,CAAC,CAAC,CAAC,CAOb;AAED,mFAAmF;AACnF,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,GAAG,MAAM,CAGnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,GAAG,GACd,SAAS,GAAG,EAAE,CAqBhB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAS1C;AAED,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,GAAG,CAE9C;AAED,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,GAAG,GAAG,CAQzC;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,GAAG,UAAU,EAC1D,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAClB,QAAQ,CAAC,CAAC,CAAC,CAOb"}
1
+ {"version":3,"file":"bitwise.d.ts","sourceRoot":"","sources":["../../src/functions/bitwise.ts"],"names":[],"mappings":";;;;AAIA,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,CAAC,SAAS,OAAO,GAAG,UAAU,EAC5D,KAAK,EAAE,SAAS,CAAC,EAAE,GAClB,QAAQ,CAAC,CAAC,CAAC,CAOb;AAED,mFAAmF;AACnF,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,GAAG,MAAM,CAGnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,GAAG,GACd,SAAS,GAAG,EAAE,CAqBhB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAS1C;AAED,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,GAAG,GAAG,CAE9C;AAED,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,GAAG,GAAG,CAQzC;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,GAAG,UAAU,EAC1D,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAClB,QAAQ,CAAC,CAAC,CAAC,CAOb"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setToBitFlags = exports.getNumBitsOfN = exports.getKBitOfN = exports.countSetBits = exports.convertDecimalToBinary = exports.convertBinaryToDecimal = exports.arrayToBitFlags = void 0;
4
4
  const flag_1 = require("./flag");
5
+ const types_1 = require("./types");
5
6
  const utils_1 = require("./utils");
6
7
  /** Helper function to convert a set of flags to a single `BitFlags` object. */
7
8
  function arrayToBitFlags(array) {
@@ -31,7 +32,7 @@ function convertDecimalToBinary(num, minLength) {
31
32
  const bits = [];
32
33
  const bitsString = num.toString(2);
33
34
  for (const bitString of bitsString) {
34
- const bit = tonumber(bitString);
35
+ const bit = (0, types_1.parseIntSafe)(bitString);
35
36
  (0, utils_1.assertDefined)(bit, `Failed to convert the following number to binary: ${num}`);
36
37
  bits.push(bit);
37
38
  }
@@ -6,6 +6,8 @@ local __TS__ArrayUnshift = ____lualib.__TS__ArrayUnshift
6
6
  local ____exports = {}
7
7
  local ____flag = require("functions.flag")
8
8
  local addFlag = ____flag.addFlag
9
+ local ____types = require("functions.types")
10
+ local parseIntSafe = ____types.parseIntSafe
9
11
  local ____utils = require("functions.utils")
10
12
  local assertDefined = ____utils.assertDefined
11
13
  --- Helper function to convert a set of flags to a single `BitFlags` object.
@@ -32,7 +34,7 @@ function ____exports.convertDecimalToBinary(self, num, minLength)
32
34
  local bits = {}
33
35
  local bitsString = __TS__NumberToString(num, 2)
34
36
  for ____, bitString in __TS__Iterator(bitsString) do
35
- local bit = tonumber(bitString)
37
+ local bit = parseIntSafe(nil, bitString)
36
38
  assertDefined(
37
39
  nil,
38
40
  bit,
@@ -28,11 +28,11 @@ function getEnumEntries(transpiledEnum) {
28
28
  const entries = Object.entries(transpiledEnum);
29
29
  const numberEntries = entries.filter(([_key, value]) => typeof value === "number");
30
30
  // If there are no number values, then this must be a string enum, and no filtration is required.
31
- const valuesToReturn = numberEntries.length > 0 ? numberEntries : entries;
31
+ const entriesToReturn = numberEntries.length > 0 ? numberEntries : entries;
32
32
  // The enums will be in a random order (because of "pairs"), so sort them based on the values.
33
33
  // https://stackoverflow.com/questions/5199901/how-to-sort-an-associative-array-by-its-values-in-javascript
34
- valuesToReturn.sort(([_key1, value1], [_key2, value2]) => value1 < value2 ? -1 : value1 > value2 ? 1 : 0);
35
- return valuesToReturn;
34
+ entriesToReturn.sort(([_key1, value1], [_key2, value2]) => value1 < value2 ? -1 : value1 > value2 ? 1 : 0);
35
+ return entriesToReturn;
36
36
  }
37
37
  exports.getEnumEntries = getEnumEntries;
38
38
  /**
@@ -47,9 +47,9 @@ function ____exports.getEnumEntries(self, transpiledEnum)
47
47
  return type(value) == "number"
48
48
  end
49
49
  )
50
- local valuesToReturn = #numberEntries > 0 and numberEntries or entries
50
+ local entriesToReturn = #numberEntries > 0 and numberEntries or entries
51
51
  __TS__ArraySort(
52
- valuesToReturn,
52
+ entriesToReturn,
53
53
  function(____, ____bindingPattern0, ____bindingPattern1)
54
54
  local value1
55
55
  local _key1 = ____bindingPattern0[1]
@@ -60,7 +60,7 @@ function ____exports.getEnumEntries(self, transpiledEnum)
60
60
  return value1 < value2 and -1 or (value1 > value2 and 1 or 0)
61
61
  end
62
62
  )
63
- return valuesToReturn
63
+ return entriesToReturn
64
64
  end
65
65
  --- TypeScriptToLua will transpile TypeScript number enums to Lua tables that have a double mapping.
66
66
  -- Thus, when you iterate over them, you will get both the names of the enums and the values of the
@@ -1 +1 @@
1
- {"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../src/functions/math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAGzD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,CAEvD;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,KAAK,CAGtE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,GAAG,EACd,WAAW,SAAI,EACf,WAAW,SAAI,EACf,gBAAgB,YAAe,GAC9B,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAajC;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAClB,OAAO,CAOT;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,KAAK,EACnB,gBAAgB,EAAE,MAAM,EACxB,oBAAoB,EAAE,MAAM,GAC3B,OAAO,CAgBT;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAGxC;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAGvC;AAED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;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAClB,OAAO,CAOT;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,KAAK,EACnB,gBAAgB,EAAE,MAAM,EACxB,oBAAoB,EAAE,MAAM,GAC3B,OAAO,CAgBT;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAGxC;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAGvC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,MAAM,CAE7D;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,KAAK,GACb,MAAM,CAER;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,gBAAgB,SAAI,GAAG,KAAK,CAI7D;AAED,wEAAwE;AACxE,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAUnC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,GAAG,EACT,WAAW,UAAQ,GAClB,aAAa,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAuB9C;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtC"}
@@ -95,7 +95,8 @@ exports.lerpAngleDegrees = lerpAngleDegrees;
95
95
  * @param numDecimalPlaces Optional. Default is 0.
96
96
  */
97
97
  function round(num, numDecimalPlaces = 0) {
98
- const roundedNum = tonumber(string.format(`%.${numDecimalPlaces}f`, num));
98
+ const roundedString = string.format(`%.${numDecimalPlaces}f`, num);
99
+ const roundedNum = tonumber(roundedString);
99
100
  return roundedNum ?? 0;
100
101
  }
101
102
  exports.round = round;
@@ -96,10 +96,11 @@ function ____exports.round(self, num, numDecimalPlaces)
96
96
  if numDecimalPlaces == nil then
97
97
  numDecimalPlaces = 0
98
98
  end
99
- local roundedNum = tonumber(string.format(
99
+ local roundedString = string.format(
100
100
  ("%." .. tostring(numDecimalPlaces)) .. "f",
101
101
  num
102
- ))
102
+ )
103
+ local roundedNum = tonumber(roundedString)
103
104
  return roundedNum or 0
104
105
  end
105
106
  ---
@@ -221,7 +221,7 @@ function parseIntSafe(string) {
221
221
  if (number === undefined) {
222
222
  return undefined;
223
223
  }
224
- const flooredNumber = math.floor(number);
224
+ const flooredNumber = Math.floor(number);
225
225
  return number === flooredNumber ? flooredNumber : undefined;
226
226
  }
227
227
  exports.parseIntSafe = parseIntSafe;
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 84.2.1
3
+ isaacscript-common 84.2.2
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -19110,9 +19110,9 @@ function ____exports.getEnumEntries(self, transpiledEnum)
19110
19110
  return type(value) == "number"
19111
19111
  end
19112
19112
  )
19113
- local valuesToReturn = #numberEntries > 0 and numberEntries or entries
19113
+ local entriesToReturn = #numberEntries > 0 and numberEntries or entries
19114
19114
  __TS__ArraySort(
19115
- valuesToReturn,
19115
+ entriesToReturn,
19116
19116
  function(____, ____bindingPattern0, ____bindingPattern1)
19117
19117
  local value1
19118
19118
  local _key1 = ____bindingPattern0[1]
@@ -19123,7 +19123,7 @@ function ____exports.getEnumEntries(self, transpiledEnum)
19123
19123
  return value1 < value2 and -1 or (value1 > value2 and 1 or 0)
19124
19124
  end
19125
19125
  )
19126
- return valuesToReturn
19126
+ return entriesToReturn
19127
19127
  end
19128
19128
  --- TypeScriptToLua will transpile TypeScript number enums to Lua tables that have a double mapping.
19129
19129
  -- Thus, when you iterate over them, you will get both the names of the enums and the values of the
@@ -23108,10 +23108,11 @@ function ____exports.round(self, num, numDecimalPlaces)
23108
23108
  if numDecimalPlaces == nil then
23109
23109
  numDecimalPlaces = 0
23110
23110
  end
23111
- local roundedNum = tonumber(string.format(
23111
+ local roundedString = string.format(
23112
23112
  ("%." .. tostring(numDecimalPlaces)) .. "f",
23113
23113
  num
23114
- ))
23114
+ )
23115
+ local roundedNum = tonumber(roundedString)
23115
23116
  return roundedNum or 0
23116
23117
  end
23117
23118
  ---
@@ -23434,6 +23435,8 @@ local __TS__ArrayUnshift = ____lualib.__TS__ArrayUnshift
23434
23435
  local ____exports = {}
23435
23436
  local ____flag = require("functions.flag")
23436
23437
  local addFlag = ____flag.addFlag
23438
+ local ____types = require("functions.types")
23439
+ local parseIntSafe = ____types.parseIntSafe
23437
23440
  local ____utils = require("functions.utils")
23438
23441
  local assertDefined = ____utils.assertDefined
23439
23442
  --- Helper function to convert a set of flags to a single `BitFlags` object.
@@ -23460,7 +23463,7 @@ function ____exports.convertDecimalToBinary(self, num, minLength)
23460
23463
  local bits = {}
23461
23464
  local bitsString = __TS__NumberToString(num, 2)
23462
23465
  for ____, bitString in __TS__Iterator(bitsString) do
23463
- local bit = tonumber(bitString)
23466
+ local bit = parseIntSafe(nil, bitString)
23464
23467
  assertDefined(
23465
23468
  nil,
23466
23469
  bit,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "84.2.2",
3
+ "version": "84.2.3",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -1,4 +1,5 @@
1
1
  import { addFlag } from "./flag";
2
+ import { parseIntSafe } from "./types";
2
3
  import { assertDefined } from "./utils";
3
4
 
4
5
  /** Helper function to convert a set of flags to a single `BitFlags` object. */
@@ -36,7 +37,7 @@ export function convertDecimalToBinary(
36
37
 
37
38
  const bitsString = num.toString(2);
38
39
  for (const bitString of bitsString) {
39
- const bit = tonumber(bitString);
40
+ const bit = parseIntSafe(bitString);
40
41
  assertDefined(
41
42
  bit,
42
43
  `Failed to convert the following number to binary: ${num}`,
@@ -40,16 +40,16 @@ export function getEnumEntries<T extends TranspiledEnum>(
40
40
  );
41
41
 
42
42
  // If there are no number values, then this must be a string enum, and no filtration is required.
43
- const valuesToReturn = numberEntries.length > 0 ? numberEntries : entries;
43
+ const entriesToReturn = numberEntries.length > 0 ? numberEntries : entries;
44
44
 
45
45
  // The enums will be in a random order (because of "pairs"), so sort them based on the values.
46
46
  // https://stackoverflow.com/questions/5199901/how-to-sort-an-associative-array-by-its-values-in-javascript
47
- valuesToReturn.sort(
47
+ entriesToReturn.sort(
48
48
  ([_key1, value1], [_key2, value2]) =>
49
49
  value1 < value2 ? -1 : value1 > value2 ? 1 : 0, // eslint-disable-line no-nested-ternary
50
50
  );
51
51
 
52
- return valuesToReturn as never;
52
+ return entriesToReturn as never;
53
53
  }
54
54
 
55
55
  /**
@@ -126,7 +126,8 @@ export function lerpAngleDegrees(
126
126
  * @param numDecimalPlaces Optional. Default is 0.
127
127
  */
128
128
  export function round(num: float, numDecimalPlaces = 0): float {
129
- const roundedNum = tonumber(string.format(`%.${numDecimalPlaces}f`, num));
129
+ const roundedString = string.format(`%.${numDecimalPlaces}f`, num);
130
+ const roundedNum = tonumber(roundedString);
130
131
  return roundedNum ?? 0;
131
132
  }
132
133
 
@@ -240,6 +240,6 @@ export function parseIntSafe(string: string): int | undefined {
240
240
  return undefined;
241
241
  }
242
242
 
243
- const flooredNumber = math.floor(number);
243
+ const flooredNumber = Math.floor(number);
244
244
  return number === flooredNumber ? flooredNumber : undefined;
245
245
  }