-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: rename and enhance string validation functions - Renamed `isSafeString` to `isStrictSafeString` and updated its implementation to enforce stricter validation criteria for strings. - Renamed `genSafeString` to `genStrictSafeString` to reflect the stricter generation of safe strings. - Updated corresponding unit tests to match the new function names and ensure they validate the expected behavior for strict safety checks. * feat: enhance isStrictSafeString validation and add test cases - Updated the isStrictSafeString function to use a regular expression for improved string validation, ensuring only alphanumeric characters are accepted. - Added new test cases to validate the function against various inputs, including numeric strings and disallowed characters. - This change enhances the robustness of string validation in the codebase. * feat: enhance string type definitions and documentation - Added detailed JSDoc comments for the StrictSafeString type and isStrictSafeString function, including descriptions in both English and Chinese. - Improved the documentation for the fromUnicodeStr and textWithBOM functions, clarifying parameter types and return values. - Enhanced overall code readability and maintainability through better documentation practices. * refactor: move isStrictSafeString function and tests to appropriate files - Removed the isStrictSafeString function and its tests from str.ts and str.test.ts, respectively. - Added the isStrictSafeString function and its corresponding test cases to string.ts and string.test.ts for better organization and clarity. - This change improves the structure of the codebase by ensuring that string validation functions and tests are located together.
- Loading branch information
Showing
4 changed files
with
53 additions
and
53 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
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 |
---|---|---|
|
@@ -10,6 +10,25 @@ export type JWTString = string; | |
/** 手机号码 */ | ||
export type PhoneNum = string; | ||
|
||
/** | ||
* [Type] Strict safe string (only contains a-z, A-Z, 0-9) | ||
* [类型] 严格安全的字符串 (仅包含 a-z, A-Z, 0-9) | ||
* | ||
* @author iugo <[email protected]> | ||
*/ | ||
export type StrictSafeString = string; | ||
|
||
/** | ||
* Check if a string is strictly safe (only contains a-z, A-Z, 0-9) | ||
* 检查字符串是否为严格安全的字符串 (仅包含 a-z, A-Z, 0-9) | ||
* | ||
* @param str String to check | ||
* @returns Whether the string is strictly safe | ||
*/ | ||
export function isStrictSafeString(str: string): str is StrictSafeString { | ||
return /^[a-zA-Z0-9]+$/.test(str); | ||
} | ||
|
||
/** | ||
* [类型] 不包含英文特殊字符 (ASCII 范围内除了字母, 数字, 下划线和空格以外的字符) | ||
* @author iugo <[email protected]> | ||
|