isaacscript-common 39.4.3 → 39.4.6

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.
@@ -5773,9 +5773,13 @@ export declare function getLowestArrayElement(array: number[]): number | undefin
5773
5773
  export declare function getLowestEnumValue<T>(transpiledEnum: T): T[keyof T];
5774
5774
 
5775
5775
  /**
5776
- * Helper function to get the closest value from a map based on partial search text. For the
5777
- * purposes of this function, both search text and map keys are converted to lowercase before
5778
- * attempting to find a match.
5776
+ * Helper function to get the closest key from a map based on partial search text. (It only searches
5777
+ * through the keys, not the values.)
5778
+ *
5779
+ * Note that:
5780
+ * - Spaces are automatically removed from the search text.
5781
+ * - Both the search text and the strings to search through are converted to lowercase before
5782
+ * attempting to find a match.
5779
5783
  *
5780
5784
  * For example:
5781
5785
  *
@@ -5977,6 +5981,31 @@ export declare function getNumBitsOfN(n: int): int;
5977
5981
  */
5978
5982
  export declare function getNumRooms(): int;
5979
5983
 
5984
+ /**
5985
+ * Helper function to get the closest key from an object based on partial search text. (It only
5986
+ * searches through the keys, not the values.)
5987
+ *
5988
+ * Note that:
5989
+ * - Spaces are automatically removed from the search text.
5990
+ * - Both the search text and the strings to search through are converted to lowercase before
5991
+ * attempting to find a match.
5992
+ *
5993
+ * For example:
5994
+ *
5995
+ * ```ts
5996
+ * const object = {
5997
+ * foo: 123,
5998
+ * bar: 456,
5999
+ * };
6000
+ * const searchText = "f";
6001
+ * const match = getObjectPartialMatch(object, searchText); // match is now equal to ["foo", 123]
6002
+ * ```
6003
+ *
6004
+ * @returns If a match was found, returns a tuple of the map key and value. If a match was not
6005
+ * found, returns undefined.
6006
+ */
6007
+ export declare function getObjectPartialMatch<T>(searchText: string, object: Record<string, T>): [string, T] | undefined;
6008
+
5980
6009
  /**
5981
6010
  * Returns the slot number corresponding to where a trinket can be safely inserted.
5982
6011
  *
@@ -6015,8 +6044,11 @@ export declare function getParentFunctionDescription(this: void, levels?: number
6015
6044
 
6016
6045
  /**
6017
6046
  * Helper function to get the closest value from an array of strings based on partial search text.
6018
- * For the purposes of this function, both search text and the array are converted to lowercase
6019
- * before attempting to find a match.
6047
+ *
6048
+ * Note that:
6049
+ * - Spaces are automatically removed from the search text.
6050
+ * - Both the search text and the strings to search through are converted to lowercase before
6051
+ * attempting to find a match.
6020
6052
  *
6021
6053
  * For example:
6022
6054
  *
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 39.4.3
3
+ isaacscript-common 39.4.6
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -16369,6 +16369,8 @@ return ____exports
16369
16369
  end,
16370
16370
  ["src.functions.string"] = function(...)
16371
16371
  local ____lualib = require("lualib_bundle")
16372
+ local __TS__Spread = ____lualib.__TS__Spread
16373
+ local __TS__ObjectKeys = ____lualib.__TS__ObjectKeys
16372
16374
  local __TS__ArraySort = ____lualib.__TS__ArraySort
16373
16375
  local __TS__StringReplaceAll = ____lualib.__TS__StringReplaceAll
16374
16376
  local __TS__StringStartsWith = ____lualib.__TS__StringStartsWith
@@ -16376,15 +16378,8 @@ local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
16376
16378
  local __TS__StringSlice = ____lualib.__TS__StringSlice
16377
16379
  local __TS__StringEndsWith = ____lualib.__TS__StringEndsWith
16378
16380
  local ____exports = {}
16379
- function ____exports.capitalizeFirstLetter(self, ____string)
16380
- if ____string == "" then
16381
- return ____string
16382
- end
16383
- local firstCharacter = string.sub(____string, 1, 1)
16384
- local capitalizedFirstLetter = string.upper(firstCharacter)
16385
- local restOfString = string.sub(____string, 2)
16386
- return capitalizedFirstLetter .. restOfString
16387
- end
16381
+ local ____utils = require("src.functions.utils")
16382
+ local assertDefined = ____utils.assertDefined
16388
16383
  function ____exports.getPartialMatch(self, searchText, array)
16389
16384
  __TS__ArraySort(array)
16390
16385
  searchText = string.lower(searchText)
@@ -16399,6 +16394,35 @@ function ____exports.getPartialMatch(self, searchText, array)
16399
16394
  __TS__ArraySort(matchingElements)
16400
16395
  return matchingElements[1]
16401
16396
  end
16397
+ function ____exports.capitalizeFirstLetter(self, ____string)
16398
+ if ____string == "" then
16399
+ return ____string
16400
+ end
16401
+ local firstCharacter = string.sub(____string, 1, 1)
16402
+ local capitalizedFirstLetter = string.upper(firstCharacter)
16403
+ local restOfString = string.sub(____string, 2)
16404
+ return capitalizedFirstLetter .. restOfString
16405
+ end
16406
+ function ____exports.getMapPartialMatch(self, searchText, map)
16407
+ local keys = {__TS__Spread(map:keys())}
16408
+ local matchingKey = ____exports.getPartialMatch(nil, searchText, keys)
16409
+ if matchingKey == nil then
16410
+ return nil
16411
+ end
16412
+ local value = map:get(matchingKey)
16413
+ assertDefined(nil, value, "Failed to get the map value corresponding to the partial match of: " .. matchingKey)
16414
+ return {matchingKey, value}
16415
+ end
16416
+ function ____exports.getObjectPartialMatch(self, searchText, object)
16417
+ local keys = __TS__ObjectKeys(object)
16418
+ local matchingKey = ____exports.getPartialMatch(nil, searchText, keys)
16419
+ if matchingKey == nil then
16420
+ return nil
16421
+ end
16422
+ local value = object[matchingKey]
16423
+ assertDefined(nil, value, "Failed to get the object value corresponding to the partial match of: " .. matchingKey)
16424
+ return {matchingKey, value}
16425
+ end
16402
16426
  function ____exports.removeAllCharacters(self, ____string, character)
16403
16427
  return __TS__StringReplaceAll(____string, character, "")
16404
16428
  end
@@ -40434,10 +40458,6 @@ local __TS__Spread = ____lualib.__TS__Spread
40434
40458
  local ____exports = {}
40435
40459
  local ____array = require("src.functions.array")
40436
40460
  local sumArray = ____array.sumArray
40437
- local ____string = require("src.functions.string")
40438
- local getPartialMatch = ____string.getPartialMatch
40439
- local ____utils = require("src.functions.utils")
40440
- local assertDefined = ____utils.assertDefined
40441
40461
  function ____exports.mapSetHash(self, map, entity, value)
40442
40462
  local hash = GetPtrHash(entity)
40443
40463
  map:set(hash, value)
@@ -40458,16 +40478,6 @@ end
40458
40478
  function ____exports.defaultMapSetHash(self, map, entity, value)
40459
40479
  ____exports.mapSetHash(nil, map, entity, value)
40460
40480
  end
40461
- function ____exports.getMapPartialMatch(self, searchText, map)
40462
- local keys = {__TS__Spread(map:keys())}
40463
- local matchingKey = getPartialMatch(nil, searchText, keys)
40464
- if matchingKey == nil then
40465
- return nil
40466
- end
40467
- local value = map:get(matchingKey)
40468
- assertDefined(nil, value, "Failed to get the map value corresponding to the partial match of: " .. matchingKey)
40469
- return {matchingKey, value}
40470
- end
40471
40481
  function ____exports.getReversedMap(self, map)
40472
40482
  local reverseMap = __TS__New(Map)
40473
40483
  for ____, ____value in __TS__Iterator(map) do
@@ -49674,8 +49684,6 @@ local logPlayerEffects = ____logMisc.logPlayerEffects
49674
49684
  local logRoom = ____logMisc.logRoom
49675
49685
  local logSeedEffects = ____logMisc.logSeedEffects
49676
49686
  local logSounds = ____logMisc.logSounds
49677
- local ____map = require("src.functions.map")
49678
- local getMapPartialMatch = ____map.getMapPartialMatch
49679
49687
  local ____mergeTests = require("src.functions.mergeTests")
49680
49688
  local runMergeTests = ____mergeTests.runMergeTests
49681
49689
  local ____pickupsSpecific = require("src.functions.pickupsSpecific")
@@ -49705,6 +49713,8 @@ local ____spawnCollectible = require("src.functions.spawnCollectible")
49705
49713
  local spawnCollectibleUnsafe = ____spawnCollectible.spawnCollectibleUnsafe
49706
49714
  local ____stage = require("src.functions.stage")
49707
49715
  local setStage = ____stage.setStage
49716
+ local ____string = require("src.functions.string")
49717
+ local getMapPartialMatch = ____string.getMapPartialMatch
49708
49718
  local ____trinkets = require("src.functions.trinkets")
49709
49719
  local getGoldenTrinketType = ____trinkets.getGoldenTrinketType
49710
49720
  local ____types = require("src.functions.types")
@@ -50786,8 +50796,8 @@ local isVanillaConsoleCommand = ____console.isVanillaConsoleCommand
50786
50796
  local ____flag = require("src.functions.flag")
50787
50797
  local addFlag = ____flag.addFlag
50788
50798
  local bitFlags = ____flag.bitFlags
50789
- local ____map = require("src.functions.map")
50790
- local getMapPartialMatch = ____map.getMapPartialMatch
50799
+ local ____string = require("src.functions.string")
50800
+ local getMapPartialMatch = ____string.getMapPartialMatch
50791
50801
  local ____utils = require("src.functions.utils")
50792
50802
  local assertDefined = ____utils.assertDefined
50793
50803
  local ____Feature = require("src.classes.private.Feature")
@@ -21,8 +21,8 @@ local isVanillaConsoleCommand = ____console.isVanillaConsoleCommand
21
21
  local ____flag = require("src.functions.flag")
22
22
  local addFlag = ____flag.addFlag
23
23
  local bitFlags = ____flag.bitFlags
24
- local ____map = require("src.functions.map")
25
- local getMapPartialMatch = ____map.getMapPartialMatch
24
+ local ____string = require("src.functions.string")
25
+ local getMapPartialMatch = ____string.getMapPartialMatch
26
26
  local ____utils = require("src.functions.utils")
27
27
  local assertDefined = ____utils.assertDefined
28
28
  local ____Feature = require("src.classes.private.Feature")
@@ -68,8 +68,6 @@ local logPlayerEffects = ____logMisc.logPlayerEffects
68
68
  local logRoom = ____logMisc.logRoom
69
69
  local logSeedEffects = ____logMisc.logSeedEffects
70
70
  local logSounds = ____logMisc.logSounds
71
- local ____map = require("src.functions.map")
72
- local getMapPartialMatch = ____map.getMapPartialMatch
73
71
  local ____mergeTests = require("src.functions.mergeTests")
74
72
  local runMergeTests = ____mergeTests.runMergeTests
75
73
  local ____pickupsSpecific = require("src.functions.pickupsSpecific")
@@ -99,6 +97,8 @@ local ____spawnCollectible = require("src.functions.spawnCollectible")
99
97
  local spawnCollectibleUnsafe = ____spawnCollectible.spawnCollectibleUnsafe
100
98
  local ____stage = require("src.functions.stage")
101
99
  local setStage = ____stage.setStage
100
+ local ____string = require("src.functions.string")
101
+ local getMapPartialMatch = ____string.getMapPartialMatch
102
102
  local ____trinkets = require("src.functions.trinkets")
103
103
  local getGoldenTrinketType = ____trinkets.getGoldenTrinketType
104
104
  local ____types = require("src.functions.types")
@@ -16,26 +16,6 @@ export declare function defaultMapGetHash<V, A extends unknown[]>(map: DefaultMa
16
16
  * `mapSetHash` helper function.
17
17
  */
18
18
  export declare function defaultMapSetHash<V>(map: Map<PtrHash, V>, entity: Entity, value: V): void;
19
- /**
20
- * Helper function to get the closest value from a map based on partial search text. For the
21
- * purposes of this function, both search text and map keys are converted to lowercase before
22
- * attempting to find a match.
23
- *
24
- * For example:
25
- *
26
- * ```ts
27
- * const map = new <string, number>Map([
28
- * ["foo", 123],
29
- * ["bar", 456],
30
- * ]);
31
- * const searchText = "f";
32
- * const match = getMapPartialMatch(map, searchText); // match is now equal to ["foo", 123]
33
- * ```
34
- *
35
- * @returns If a match was found, returns a tuple of the map key and value. If a match was not
36
- * found, returns undefined.
37
- */
38
- export declare function getMapPartialMatch<T>(searchText: string, map: ReadonlyMap<string, T>): [string, T] | undefined;
39
19
  /**
40
20
  * Helper function to get a copy of a map with the keys and the values reversed.
41
21
  *
@@ -1 +1 @@
1
- {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../../src/functions/map.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAKxD,mGAAmG;AACnG,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAC1B,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GACpC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAOX;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EACtD,GAAG,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9B,MAAM,EAAE,MAAM,EACd,GAAG,SAAS,EAAE,CAAC,GACd,CAAC,CAGH;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,CAAC,GACP,IAAI,CAEN;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAg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AU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9B,MAAM,EAAE,MAAM,EACd,GAAG,SAAS,EAAE,CAAC,GACd,CAAC,CAGH;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,CAAC,GACP,IAAI,CAEN;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAChE,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAahF;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,CAAC,GACP,IAAI,CAGN;AAED,4DAA4D;AAC5D,wBAAgB,MAAM,CACpB,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,GACvD,MAAM,CAGR"}
@@ -6,10 +6,6 @@ local __TS__Spread = ____lualib.__TS__Spread
6
6
  local ____exports = {}
7
7
  local ____array = require("src.functions.array")
8
8
  local sumArray = ____array.sumArray
9
- local ____string = require("src.functions.string")
10
- local getPartialMatch = ____string.getPartialMatch
11
- local ____utils = require("src.functions.utils")
12
- local assertDefined = ____utils.assertDefined
13
9
  --- Helper function to set a value for a `DefaultMap` that corresponds to an entity, assuming that
14
10
  -- the map uses `PtrHash` as an index.
15
11
  function ____exports.mapSetHash(self, map, entity, value)
@@ -40,33 +36,6 @@ end
40
36
  function ____exports.defaultMapSetHash(self, map, entity, value)
41
37
  ____exports.mapSetHash(nil, map, entity, value)
42
38
  end
43
- --- Helper function to get the closest value from a map based on partial search text. For the
44
- -- purposes of this function, both search text and map keys are converted to lowercase before
45
- -- attempting to find a match.
46
- --
47
- -- For example:
48
- --
49
- -- ```ts
50
- -- const map = new <string, number>Map([
51
- -- ["foo", 123],
52
- -- ["bar", 456],
53
- -- ]);
54
- -- const searchText = "f";
55
- -- const match = getMapPartialMatch(map, searchText); // match is now equal to ["foo", 123]
56
- -- ```
57
- --
58
- -- @returns If a match was found, returns a tuple of the map key and value. If a match was not
59
- -- found, returns undefined.
60
- function ____exports.getMapPartialMatch(self, searchText, map)
61
- local keys = {__TS__Spread(map:keys())}
62
- local matchingKey = getPartialMatch(nil, searchText, keys)
63
- if matchingKey == nil then
64
- return nil
65
- end
66
- local value = map:get(matchingKey)
67
- assertDefined(nil, value, "Failed to get the map value corresponding to the partial match of: " .. matchingKey)
68
- return {matchingKey, value}
69
- end
70
39
  --- Helper function to get a copy of a map with the keys and the values reversed.
71
40
  --
72
41
  -- For example:
@@ -1,8 +1,59 @@
1
1
  export declare function capitalizeFirstLetter(string: string): string;
2
+ /**
3
+ * Helper function to get the closest key from a map based on partial search text. (It only searches
4
+ * through the keys, not the values.)
5
+ *
6
+ * Note that:
7
+ * - Spaces are automatically removed from the search text.
8
+ * - Both the search text and the strings to search through are converted to lowercase before
9
+ * attempting to find a match.
10
+ *
11
+ * For example:
12
+ *
13
+ * ```ts
14
+ * const map = new <string, number>Map([
15
+ * ["foo", 123],
16
+ * ["bar", 456],
17
+ * ]);
18
+ * const searchText = "f";
19
+ * const match = getMapPartialMatch(map, searchText); // match is now equal to ["foo", 123]
20
+ * ```
21
+ *
22
+ * @returns If a match was found, returns a tuple of the map key and value. If a match was not
23
+ * found, returns undefined.
24
+ */
25
+ export declare function getMapPartialMatch<T>(searchText: string, map: ReadonlyMap<string, T>): [string, T] | undefined;
26
+ /**
27
+ * Helper function to get the closest key from an object based on partial search text. (It only
28
+ * searches through the keys, not the values.)
29
+ *
30
+ * Note that:
31
+ * - Spaces are automatically removed from the search text.
32
+ * - Both the search text and the strings to search through are converted to lowercase before
33
+ * attempting to find a match.
34
+ *
35
+ * For example:
36
+ *
37
+ * ```ts
38
+ * const object = {
39
+ * foo: 123,
40
+ * bar: 456,
41
+ * };
42
+ * const searchText = "f";
43
+ * const match = getObjectPartialMatch(object, searchText); // match is now equal to ["foo", 123]
44
+ * ```
45
+ *
46
+ * @returns If a match was found, returns a tuple of the map key and value. If a match was not
47
+ * found, returns undefined.
48
+ */
49
+ export declare function getObjectPartialMatch<T>(searchText: string, object: Record<string, T>): [string, T] | undefined;
2
50
  /**
3
51
  * Helper function to get the closest value from an array of strings based on partial search text.
4
- * For the purposes of this function, both search text and the array are converted to lowercase
5
- * before attempting to find a match.
52
+ *
53
+ * Note that:
54
+ * - Spaces are automatically removed from the search text.
55
+ * - Both the search text and the strings to search through are converted to lowercase before
56
+ * attempting to find a match.
6
57
  *
7
58
  * For example:
8
59
  *
@@ -1 +1 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../src/functions/string.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAU5D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EAAE,GACd,MAAM,GAAG,SAAS,CAYpB;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAE7E;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,MAAM,CAGR;AAED,8FAA8F;AAC9F,wBAAgB,+BAA+B,CAAC,GAAG,EAAE,MAAM,GA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B,+BAA+B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,GAAG,UAAU,EAAE,MAAM,EAAE,GACtB,MAAM,CAMR;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAMjE;AAED,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAOjE"}
@@ -1,4 +1,6 @@
1
1
  local ____lualib = require("lualib_bundle")
2
+ local __TS__Spread = ____lualib.__TS__Spread
3
+ local __TS__ObjectKeys = ____lualib.__TS__ObjectKeys
2
4
  local __TS__ArraySort = ____lualib.__TS__ArraySort
3
5
  local __TS__StringReplaceAll = ____lualib.__TS__StringReplaceAll
4
6
  local __TS__StringStartsWith = ____lualib.__TS__StringStartsWith
@@ -6,18 +8,14 @@ local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
6
8
  local __TS__StringSlice = ____lualib.__TS__StringSlice
7
9
  local __TS__StringEndsWith = ____lualib.__TS__StringEndsWith
8
10
  local ____exports = {}
9
- function ____exports.capitalizeFirstLetter(self, ____string)
10
- if ____string == "" then
11
- return ____string
12
- end
13
- local firstCharacter = string.sub(____string, 1, 1)
14
- local capitalizedFirstLetter = string.upper(firstCharacter)
15
- local restOfString = string.sub(____string, 2)
16
- return capitalizedFirstLetter .. restOfString
17
- end
11
+ local ____utils = require("src.functions.utils")
12
+ local assertDefined = ____utils.assertDefined
18
13
  --- Helper function to get the closest value from an array of strings based on partial search text.
19
- -- For the purposes of this function, both search text and the array are converted to lowercase
20
- -- before attempting to find a match.
14
+ --
15
+ -- Note that:
16
+ -- - Spaces are automatically removed from the search text.
17
+ -- - Both the search text and the strings to search through are converted to lowercase before
18
+ -- attempting to find a match.
21
19
  --
22
20
  -- For example:
23
21
  --
@@ -43,6 +41,77 @@ function ____exports.getPartialMatch(self, searchText, array)
43
41
  __TS__ArraySort(matchingElements)
44
42
  return matchingElements[1]
45
43
  end
44
+ function ____exports.capitalizeFirstLetter(self, ____string)
45
+ if ____string == "" then
46
+ return ____string
47
+ end
48
+ local firstCharacter = string.sub(____string, 1, 1)
49
+ local capitalizedFirstLetter = string.upper(firstCharacter)
50
+ local restOfString = string.sub(____string, 2)
51
+ return capitalizedFirstLetter .. restOfString
52
+ end
53
+ --- Helper function to get the closest key from a map based on partial search text. (It only searches
54
+ -- through the keys, not the values.)
55
+ --
56
+ -- Note that:
57
+ -- - Spaces are automatically removed from the search text.
58
+ -- - Both the search text and the strings to search through are converted to lowercase before
59
+ -- attempting to find a match.
60
+ --
61
+ -- For example:
62
+ --
63
+ -- ```ts
64
+ -- const map = new <string, number>Map([
65
+ -- ["foo", 123],
66
+ -- ["bar", 456],
67
+ -- ]);
68
+ -- const searchText = "f";
69
+ -- const match = getMapPartialMatch(map, searchText); // match is now equal to ["foo", 123]
70
+ -- ```
71
+ --
72
+ -- @returns If a match was found, returns a tuple of the map key and value. If a match was not
73
+ -- found, returns undefined.
74
+ function ____exports.getMapPartialMatch(self, searchText, map)
75
+ local keys = {__TS__Spread(map:keys())}
76
+ local matchingKey = ____exports.getPartialMatch(nil, searchText, keys)
77
+ if matchingKey == nil then
78
+ return nil
79
+ end
80
+ local value = map:get(matchingKey)
81
+ assertDefined(nil, value, "Failed to get the map value corresponding to the partial match of: " .. matchingKey)
82
+ return {matchingKey, value}
83
+ end
84
+ --- Helper function to get the closest key from an object based on partial search text. (It only
85
+ -- searches through the keys, not the values.)
86
+ --
87
+ -- Note that:
88
+ -- - Spaces are automatically removed from the search text.
89
+ -- - Both the search text and the strings to search through are converted to lowercase before
90
+ -- attempting to find a match.
91
+ --
92
+ -- For example:
93
+ --
94
+ -- ```ts
95
+ -- const object = {
96
+ -- foo: 123,
97
+ -- bar: 456,
98
+ -- };
99
+ -- const searchText = "f";
100
+ -- const match = getObjectPartialMatch(object, searchText); // match is now equal to ["foo", 123]
101
+ -- ```
102
+ --
103
+ -- @returns If a match was found, returns a tuple of the map key and value. If a match was not
104
+ -- found, returns undefined.
105
+ function ____exports.getObjectPartialMatch(self, searchText, object)
106
+ local keys = __TS__ObjectKeys(object)
107
+ local matchingKey = ____exports.getPartialMatch(nil, searchText, keys)
108
+ if matchingKey == nil then
109
+ return nil
110
+ end
111
+ local value = object[matchingKey]
112
+ assertDefined(nil, value, "Failed to get the object value corresponding to the partial match of: " .. matchingKey)
113
+ return {matchingKey, value}
114
+ end
46
115
  function ____exports.removeAllCharacters(self, ____string, character)
47
116
  return __TS__StringReplaceAll(____string, character, "")
48
117
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "39.4.3",
3
+ "version": "39.4.6",
4
4
  "description": "Helper functions and features for IsaacScript mods.",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,6 +25,6 @@
25
25
  "main": "dist/src/index",
26
26
  "types": "dist/index.rollup.d.ts",
27
27
  "dependencies": {
28
- "isaac-typescript-definitions": "^17.0.3"
28
+ "isaac-typescript-definitions": "^17.0.4"
29
29
  }
30
30
  }
@@ -10,7 +10,7 @@ import { Exported } from "../../../decorators";
10
10
  import { ModCallbackCustom } from "../../../enums/ModCallbackCustom";
11
11
  import { isVanillaConsoleCommand } from "../../../functions/console";
12
12
  import { addFlag, bitFlags } from "../../../functions/flag";
13
- import { getMapPartialMatch } from "../../../functions/map";
13
+ import { getMapPartialMatch } from "../../../functions/string";
14
14
  import { assertDefined } from "../../../functions/utils";
15
15
  import { Feature } from "../../private/Feature";
16
16
  import * as commands from "./extraConsoleCommands/commands";
@@ -100,7 +100,6 @@ import {
100
100
  logSeedEffects,
101
101
  logSounds,
102
102
  } from "../../../../functions/logMisc";
103
- import { getMapPartialMatch } from "../../../../functions/map";
104
103
  import { runMergeTests } from "../../../../functions/mergeTests";
105
104
  import {
106
105
  spawnCard,
@@ -121,6 +120,7 @@ import { changeRoom } from "../../../../functions/rooms";
121
120
  import { onSetSeed, restart, setUnseeded } from "../../../../functions/run";
122
121
  import { spawnCollectibleUnsafe } from "../../../../functions/spawnCollectible";
123
122
  import { setStage } from "../../../../functions/stage";
123
+ import { getMapPartialMatch } from "../../../../functions/string";
124
124
  import { getGoldenTrinketType } from "../../../../functions/trinkets";
125
125
  import {
126
126
  asCardType,
@@ -1,7 +1,5 @@
1
1
  import type { DefaultMap } from "../classes/DefaultMap";
2
2
  import { sumArray } from "./array";
3
- import { getPartialMatch } from "./string";
4
- import { assertDefined } from "./utils";
5
3
 
6
4
  /** Helper function to copy a map. (You can also use a Map constructor to accomplish this task.) */
7
5
  export function copyMap<K, V>(
@@ -43,45 +41,6 @@ export function defaultMapSetHash<V>(
43
41
  mapSetHash(map, entity, value);
44
42
  }
45
43
 
46
- /**
47
- * Helper function to get the closest value from a map based on partial search text. For the
48
- * purposes of this function, both search text and map keys are converted to lowercase before
49
- * attempting to find a match.
50
- *
51
- * For example:
52
- *
53
- * ```ts
54
- * const map = new <string, number>Map([
55
- * ["foo", 123],
56
- * ["bar", 456],
57
- * ]);
58
- * const searchText = "f";
59
- * const match = getMapPartialMatch(map, searchText); // match is now equal to ["foo", 123]
60
- * ```
61
- *
62
- * @returns If a match was found, returns a tuple of the map key and value. If a match was not
63
- * found, returns undefined.
64
- */
65
- export function getMapPartialMatch<T>(
66
- searchText: string,
67
- map: ReadonlyMap<string, T>,
68
- ): [string, T] | undefined {
69
- const keys = [...map.keys()];
70
-
71
- const matchingKey = getPartialMatch(searchText, keys);
72
- if (matchingKey === undefined) {
73
- return undefined;
74
- }
75
-
76
- const value = map.get(matchingKey);
77
- assertDefined(
78
- value,
79
- `Failed to get the map value corresponding to the partial match of: ${matchingKey}`,
80
- );
81
-
82
- return [matchingKey, value];
83
- }
84
-
85
44
  /**
86
45
  * Helper function to get a copy of a map with the keys and the values reversed.
87
46
  *