isaacscript-common 8.1.0 → 8.2.0
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.
- package/dist/functions/map.d.ts.map +1 -1
- package/dist/functions/map.lua +4 -17
- package/dist/functions/string.d.ts +17 -0
- package/dist/functions/string.d.ts.map +1 -1
- package/dist/functions/string.lua +31 -1
- package/dist/functions/utils.d.ts +2 -2
- package/dist/functions/utils.lua +2 -2
- package/dist/index.d.ts +20 -2
- package/package.json +1 -1
- package/src/functions/map.ts +5 -11
- package/src/functions/string.ts +33 -0
- package/src/functions/utils.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/functions/map.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/functions/map.ts"],"names":[],"mappings":"AAGA,mGAAmG;AACnG,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAO1D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,GAC1B,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,CAgBzB;AAED,4DAA4D;AAC5D,wBAAgB,MAAM,CACpB,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,GACvD,MAAM,CAGR"}
|
package/dist/functions/map.lua
CHANGED
|
@@ -3,13 +3,11 @@ local Map = ____lualib.Map
|
|
|
3
3
|
local __TS__New = ____lualib.__TS__New
|
|
4
4
|
local __TS__Iterator = ____lualib.__TS__Iterator
|
|
5
5
|
local __TS__Spread = ____lualib.__TS__Spread
|
|
6
|
-
local __TS__ArraySort = ____lualib.__TS__ArraySort
|
|
7
|
-
local __TS__StringReplaceAll = ____lualib.__TS__StringReplaceAll
|
|
8
|
-
local __TS__StringStartsWith = ____lualib.__TS__StringStartsWith
|
|
9
|
-
local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
|
|
10
6
|
local ____exports = {}
|
|
11
7
|
local ____array = require("functions.array")
|
|
12
8
|
local sumArray = ____array.sumArray
|
|
9
|
+
local ____string = require("functions.string")
|
|
10
|
+
local getPartialMatch = ____string.getPartialMatch
|
|
13
11
|
--- Helper function to copy a map. (You can also use a Map constructor to accomplish this task.)
|
|
14
12
|
function ____exports.copyMap(self, oldMap)
|
|
15
13
|
local newMap = __TS__New(Map)
|
|
@@ -39,24 +37,13 @@ end
|
|
|
39
37
|
-- ```
|
|
40
38
|
function ____exports.getMapPartialMatch(self, searchText, map)
|
|
41
39
|
local keys = {__TS__Spread(map:keys())}
|
|
42
|
-
|
|
43
|
-
searchText = string.lower(searchText)
|
|
44
|
-
searchText = __TS__StringReplaceAll(searchText, " ", "")
|
|
45
|
-
local matchingKeys = __TS__ArrayFilter(
|
|
46
|
-
keys,
|
|
47
|
-
function(____, key) return __TS__StringStartsWith(
|
|
48
|
-
string.lower(key),
|
|
49
|
-
searchText
|
|
50
|
-
) end
|
|
51
|
-
)
|
|
52
|
-
__TS__ArraySort(matchingKeys)
|
|
53
|
-
local matchingKey = matchingKeys[1]
|
|
40
|
+
local matchingKey = getPartialMatch(nil, searchText, keys)
|
|
54
41
|
if matchingKey == nil then
|
|
55
42
|
return nil
|
|
56
43
|
end
|
|
57
44
|
local value = map:get(matchingKey)
|
|
58
45
|
if value == nil then
|
|
59
|
-
|
|
46
|
+
error("Failed to get the map value corresponding to the partial match of: " .. matchingKey)
|
|
60
47
|
end
|
|
61
48
|
return {matchingKey, value}
|
|
62
49
|
end
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
export declare function capitalizeFirstLetter(string: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* 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.
|
|
6
|
+
*
|
|
7
|
+
* For example:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const array = ["foo", "bar"];
|
|
11
|
+
* const searchText = "f";
|
|
12
|
+
* const match = getPartialMatch(array, searchText); // match is now equal to "foo"
|
|
13
|
+
*
|
|
14
|
+
* @returns If a match was found, returns the array element. If a match was not
|
|
15
|
+
* found, returns undefined.
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function getPartialMatch(searchText: string, array: string[]): string | undefined;
|
|
2
19
|
export declare function removeAllCharacters(string: string, character: string): string;
|
|
3
20
|
/**
|
|
4
21
|
* Helper function to remove all of the characters in a string before a given substring. Returns the
|
|
@@ -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,CAM5D;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;;;;;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
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/functions/string.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAM5D;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;;;;;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,7 +1,9 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__ArraySort = ____lualib.__TS__ArraySort
|
|
2
3
|
local __TS__StringReplaceAll = ____lualib.__TS__StringReplaceAll
|
|
3
|
-
local __TS__StringSlice = ____lualib.__TS__StringSlice
|
|
4
4
|
local __TS__StringStartsWith = ____lualib.__TS__StringStartsWith
|
|
5
|
+
local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
|
|
6
|
+
local __TS__StringSlice = ____lualib.__TS__StringSlice
|
|
5
7
|
local __TS__StringEndsWith = ____lualib.__TS__StringEndsWith
|
|
6
8
|
local ____exports = {}
|
|
7
9
|
function ____exports.capitalizeFirstLetter(self, ____string)
|
|
@@ -10,6 +12,34 @@ function ____exports.capitalizeFirstLetter(self, ____string)
|
|
|
10
12
|
local restOfString = string.sub(____string, 2)
|
|
11
13
|
return capitalizedFirstLetter .. restOfString
|
|
12
14
|
end
|
|
15
|
+
--- Helper function to get the closest value from an array of strings based on partial search text.
|
|
16
|
+
-- For the purposes of this function, both search text and the array are converted to lowercase
|
|
17
|
+
-- before attempting to find a match.
|
|
18
|
+
--
|
|
19
|
+
-- For example:
|
|
20
|
+
--
|
|
21
|
+
-- ```ts
|
|
22
|
+
-- const array = ["foo", "bar"];
|
|
23
|
+
-- const searchText = "f";
|
|
24
|
+
-- const match = getPartialMatch(array, searchText); // match is now equal to "foo"
|
|
25
|
+
--
|
|
26
|
+
-- @returns If a match was found, returns the array element. If a match was not
|
|
27
|
+
-- found, returns undefined.
|
|
28
|
+
-- ```
|
|
29
|
+
function ____exports.getPartialMatch(self, searchText, array)
|
|
30
|
+
__TS__ArraySort(array)
|
|
31
|
+
searchText = string.lower(searchText)
|
|
32
|
+
searchText = __TS__StringReplaceAll(searchText, " ", "")
|
|
33
|
+
local matchingElements = __TS__ArrayFilter(
|
|
34
|
+
array,
|
|
35
|
+
function(____, element) return __TS__StringStartsWith(
|
|
36
|
+
string.lower(element),
|
|
37
|
+
searchText
|
|
38
|
+
) end
|
|
39
|
+
)
|
|
40
|
+
__TS__ArraySort(matchingElements)
|
|
41
|
+
return matchingElements[1]
|
|
42
|
+
end
|
|
13
43
|
function ____exports.removeAllCharacters(self, ____string, character)
|
|
14
44
|
return __TS__StringReplaceAll(____string, character, "")
|
|
15
45
|
end
|
|
@@ -80,13 +80,13 @@ export declare function repeat(n: int, func: (i: int) => void): void;
|
|
|
80
80
|
/**
|
|
81
81
|
* Helper function to signify that the enclosing code block is not yet complete. Using this function
|
|
82
82
|
* is similar to writing a "TODO" comment, but it has the benefit of preventing ESLint errors due to
|
|
83
|
-
* early returns.
|
|
83
|
+
* unused variables or early returns.
|
|
84
84
|
*
|
|
85
85
|
* When you see this function, it simply means that the programmer intends to add in more code to
|
|
86
86
|
* this spot later.
|
|
87
87
|
*
|
|
88
88
|
* This function is variadic, meaning that you can pass as many arguments as you want. (This is
|
|
89
|
-
* useful as a means to prevent
|
|
89
|
+
* useful as a means to prevent unused variables.)
|
|
90
90
|
*
|
|
91
91
|
* This function does not actually do anything. (It is an "empty" function.)
|
|
92
92
|
*/
|
package/dist/functions/utils.lua
CHANGED
|
@@ -153,13 +153,13 @@ ____exports["repeat"] = function(self, n, func)
|
|
|
153
153
|
end
|
|
154
154
|
--- Helper function to signify that the enclosing code block is not yet complete. Using this function
|
|
155
155
|
-- is similar to writing a "TODO" comment, but it has the benefit of preventing ESLint errors due to
|
|
156
|
-
-- early returns.
|
|
156
|
+
-- unused variables or early returns.
|
|
157
157
|
--
|
|
158
158
|
-- When you see this function, it simply means that the programmer intends to add in more code to
|
|
159
159
|
-- this spot later.
|
|
160
160
|
--
|
|
161
161
|
-- This function is variadic, meaning that you can pass as many arguments as you want. (This is
|
|
162
|
-
-- useful as a means to prevent
|
|
162
|
+
-- useful as a means to prevent unused variables.)
|
|
163
163
|
--
|
|
164
164
|
-- This function does not actually do anything. (It is an "empty" function.)
|
|
165
165
|
function ____exports.todo(self, ...)
|
package/dist/index.d.ts
CHANGED
|
@@ -3790,6 +3790,24 @@ export declare function getOppositeDoorSlot(doorSlot: DoorSlot): DoorSlot | unde
|
|
|
3790
3790
|
*/
|
|
3791
3791
|
export declare function getOtherPlayers(player: EntityPlayer): EntityPlayer[];
|
|
3792
3792
|
|
|
3793
|
+
/**
|
|
3794
|
+
* Helper function to get the closest value from an array of strings based on partial search text.
|
|
3795
|
+
* For the purposes of this function, both search text and the array are converted to lowercase
|
|
3796
|
+
* before attempting to find a match.
|
|
3797
|
+
*
|
|
3798
|
+
* For example:
|
|
3799
|
+
*
|
|
3800
|
+
* ```ts
|
|
3801
|
+
* const array = ["foo", "bar"];
|
|
3802
|
+
* const searchText = "f";
|
|
3803
|
+
* const match = getPartialMatch(array, searchText); // match is now equal to "foo"
|
|
3804
|
+
*
|
|
3805
|
+
* @returns If a match was found, returns the array element. If a match was not
|
|
3806
|
+
* found, returns undefined.
|
|
3807
|
+
* ```
|
|
3808
|
+
*/
|
|
3809
|
+
export declare function getPartialMatch(searchText: string, array: string[]): string | undefined;
|
|
3810
|
+
|
|
3793
3811
|
/**
|
|
3794
3812
|
* Helper function to get the associated pill effect after PHD is acquired. If a pill effect is not
|
|
3795
3813
|
* altered by PHD, then the same pill effect will be returned.
|
|
@@ -11212,13 +11230,13 @@ export declare function texelEquals(sprite1: Sprite, sprite2: Sprite, position:
|
|
|
11212
11230
|
/**
|
|
11213
11231
|
* Helper function to signify that the enclosing code block is not yet complete. Using this function
|
|
11214
11232
|
* is similar to writing a "TODO" comment, but it has the benefit of preventing ESLint errors due to
|
|
11215
|
-
* early returns.
|
|
11233
|
+
* unused variables or early returns.
|
|
11216
11234
|
*
|
|
11217
11235
|
* When you see this function, it simply means that the programmer intends to add in more code to
|
|
11218
11236
|
* this spot later.
|
|
11219
11237
|
*
|
|
11220
11238
|
* This function is variadic, meaning that you can pass as many arguments as you want. (This is
|
|
11221
|
-
* useful as a means to prevent
|
|
11239
|
+
* useful as a means to prevent unused variables.)
|
|
11222
11240
|
*
|
|
11223
11241
|
* This function does not actually do anything. (It is an "empty" function.)
|
|
11224
11242
|
*/
|
package/package.json
CHANGED
package/src/functions/map.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { sumArray } from "./array";
|
|
2
|
+
import { getPartialMatch } from "./string";
|
|
2
3
|
|
|
3
4
|
/** Helper function to copy a map. (You can also use a Map constructor to accomplish this task.) */
|
|
4
5
|
export function copyMap<K, V>(oldMap: Map<K, V>): Map<K, V> {
|
|
@@ -34,24 +35,17 @@ export function getMapPartialMatch<T>(
|
|
|
34
35
|
map: ReadonlyMap<string, T>,
|
|
35
36
|
): [string, T] | undefined {
|
|
36
37
|
const keys = [...map.keys()];
|
|
37
|
-
keys.sort();
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
searchText = searchText.replaceAll(" ", "");
|
|
41
|
-
|
|
42
|
-
const matchingKeys = keys.filter((key) =>
|
|
43
|
-
key.toLowerCase().startsWith(searchText),
|
|
44
|
-
);
|
|
45
|
-
matchingKeys.sort();
|
|
46
|
-
|
|
47
|
-
const matchingKey = matchingKeys[0];
|
|
39
|
+
const matchingKey = getPartialMatch(searchText, keys);
|
|
48
40
|
if (matchingKey === undefined) {
|
|
49
41
|
return undefined;
|
|
50
42
|
}
|
|
51
43
|
|
|
52
44
|
const value = map.get(matchingKey);
|
|
53
45
|
if (value === undefined) {
|
|
54
|
-
|
|
46
|
+
error(
|
|
47
|
+
`Failed to get the map value corresponding to the partial match of: ${matchingKey}`,
|
|
48
|
+
);
|
|
55
49
|
}
|
|
56
50
|
|
|
57
51
|
return [matchingKey, value];
|
package/src/functions/string.ts
CHANGED
|
@@ -6,6 +6,39 @@ export function capitalizeFirstLetter(string: string): string {
|
|
|
6
6
|
return `${capitalizedFirstLetter}${restOfString}`;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Helper function to get the closest value from an array of strings based on partial search text.
|
|
11
|
+
* For the purposes of this function, both search text and the array are converted to lowercase
|
|
12
|
+
* before attempting to find a match.
|
|
13
|
+
*
|
|
14
|
+
* For example:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* const array = ["foo", "bar"];
|
|
18
|
+
* const searchText = "f";
|
|
19
|
+
* const match = getPartialMatch(array, searchText); // match is now equal to "foo"
|
|
20
|
+
*
|
|
21
|
+
* @returns If a match was found, returns the array element. If a match was not
|
|
22
|
+
* found, returns undefined.
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export function getPartialMatch(
|
|
26
|
+
searchText: string,
|
|
27
|
+
array: string[],
|
|
28
|
+
): string | undefined {
|
|
29
|
+
array.sort();
|
|
30
|
+
|
|
31
|
+
searchText = searchText.toLowerCase();
|
|
32
|
+
searchText = searchText.replaceAll(" ", "");
|
|
33
|
+
|
|
34
|
+
const matchingElements = array.filter((element) =>
|
|
35
|
+
element.toLowerCase().startsWith(searchText),
|
|
36
|
+
);
|
|
37
|
+
matchingElements.sort();
|
|
38
|
+
|
|
39
|
+
return matchingElements[0];
|
|
40
|
+
}
|
|
41
|
+
|
|
9
42
|
export function removeAllCharacters(string: string, character: string): string {
|
|
10
43
|
return string.replaceAll(character, "");
|
|
11
44
|
}
|
package/src/functions/utils.ts
CHANGED
|
@@ -182,13 +182,13 @@ export function repeat(n: int, func: (i: int) => void): void {
|
|
|
182
182
|
/**
|
|
183
183
|
* Helper function to signify that the enclosing code block is not yet complete. Using this function
|
|
184
184
|
* is similar to writing a "TODO" comment, but it has the benefit of preventing ESLint errors due to
|
|
185
|
-
* early returns.
|
|
185
|
+
* unused variables or early returns.
|
|
186
186
|
*
|
|
187
187
|
* When you see this function, it simply means that the programmer intends to add in more code to
|
|
188
188
|
* this spot later.
|
|
189
189
|
*
|
|
190
190
|
* This function is variadic, meaning that you can pass as many arguments as you want. (This is
|
|
191
|
-
* useful as a means to prevent
|
|
191
|
+
* useful as a means to prevent unused variables.)
|
|
192
192
|
*
|
|
193
193
|
* This function does not actually do anything. (It is an "empty" function.)
|
|
194
194
|
*/
|