-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
315 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
export const checkMapName = (name: string, search: string) => { | ||
if (!search) { | ||
return true; | ||
} | ||
|
||
let mapInitial = ''; | ||
let mapNameNoSeparator = ''; | ||
let prevIsUpper = false; | ||
let prevIsSeparator = true; | ||
for (let i = 0; i < name.length; i++) { | ||
const char = name[i]; | ||
const isUpper = !!char.match(/[A-Z]/); | ||
const isLetter = isUpper || char.match(/[a-z]/); | ||
const isSeparator = char == '-' || char == '_' || char == ' '; | ||
const isNumber = char.match(/[0-9]/); | ||
if (isUpper) { | ||
if (!prevIsUpper || prevIsSeparator) { | ||
mapInitial += char; | ||
} | ||
} else if (isLetter) { | ||
if (prevIsSeparator) { | ||
mapInitial += char; | ||
} | ||
} else if (isNumber) { | ||
mapInitial += char; | ||
} | ||
prevIsUpper = isUpper; | ||
prevIsSeparator = isSeparator; | ||
if (!isSeparator) { | ||
mapNameNoSeparator += char; | ||
} | ||
} | ||
|
||
const mapName = name.toLowerCase(); | ||
const searchTextLower = search.toLowerCase(); | ||
return ( | ||
mapInitial.toLowerCase() == searchTextLower || | ||
mapNameNoSeparator.toLowerCase().includes(searchTextLower) || | ||
mapName.includes(searchTextLower) | ||
); | ||
}; | ||
|
||
export const checkMapper = (mapper: string, search: string) => { | ||
if (!search) { | ||
return true; | ||
} | ||
|
||
const mapperString = mapper || '不详'; | ||
|
||
if (search.startsWith('"') && search.endsWith('"')) { | ||
// exact match | ||
const mappers = (mapperString as string) | ||
.split(',') | ||
.flatMap((mapper) => mapper.split('&')) | ||
.map((mapper) => mapper.trim()); | ||
|
||
search = search.slice(1, -1).toLowerCase(); | ||
return mappers.some((mapper) => mapper.toLowerCase() == search); | ||
} | ||
|
||
return mapperString.toLowerCase().includes(search.toLowerCase()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.