-
Notifications
You must be signed in to change notification settings - Fork 22
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
3 changed files
with
37 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { removeBlankChars } from './removeBlankChars' | ||
|
||
describe('removeBlankChars', () => { | ||
test('半角空格', () => { | ||
expect(removeBlankChars('o k')).toBe('ok') | ||
}) | ||
|
||
test('全角空格', () => { | ||
expect(removeBlankChars('o k')).toBe('ok') | ||
}) | ||
|
||
test('半角空格+全角空格', () => { | ||
expect(removeBlankChars(' o k ')).toBe('ok') | ||
}) | ||
|
||
test('换行', () => { | ||
expect(removeBlankChars('o\r\nk')).toBe('ok') | ||
}) | ||
|
||
test('特殊', () => { | ||
expect(removeBlankChars('o\u180E\u200Bk')).toBe('ok') | ||
}) | ||
}) |
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,13 @@ | ||
// https://github.com/frandiox/normalize-unicode-text/blob/master/src/index.ts | ||
const re = | ||
/(\s+|[\u180E\u200B-\u200D\u2060\uFEFF]+|[ \u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]+|[\u2420\u2422\u2423]+)/gs | ||
|
||
/** | ||
* 从字符串中移除空白字符。 | ||
* | ||
* @param value 要操作的字符串 | ||
* @returns 返回移除空白字符后的字符串 | ||
*/ | ||
export function removeBlankChars(value: string): string { | ||
return value.replace(re, '') | ||
} |