Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions 11 src/chibiScript/functions/stringFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,15 @@ export default {
},

/**
* Converts full-width ASCII characters or number to its half-width character
* Converts full-width characters to half-width character
* @input string
* @form 'NFC' | 'NFD' | 'NFKC' | 'NFKD' - Normalization form (default: 'NFKC')
* @returns Its half-width characters or number
* @example
* $c.string('Hello World 3').toHalfWidth().run(); // returns Hello World 3
* $c.string('Hello World 3').normalize().run(); // returns Hello World 3
*/
toHalfWidth: (ctx: ChibiCtx, input: string) => {
return input
.replace(/[\uFF01-\uFF5E]/g, ch => String.fromCharCode(ch.charCodeAt(0) - 0xfee0))
.replace(/\u3000/g, ' ');
normalize: (ctx: ChibiCtx, input: string, form: 'NFC' | 'NFD' | 'NFKC' | 'NFKD' = 'NFKC') => {
return input.normalize(form);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion 2 src/pages-chibi/implementations/ComicDays/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function multiEpisode($c) {
$c
.getVariable('epList')
.string()
.toHalfWidth()
.normalize()
.regex('(\\d+)', 1)
.ifThen($c => $c.number().run())
.run(),
Expand Down
6 changes: 3 additions & 3 deletions 6 test/src/chibiScript/functions/stringFunctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ describe('String Functions', () => {
});
});

describe('toHalfWidth', () => {
describe('normalize', () => {
it('should converts full-width ASCII characters or number to its half-width character', () => {
const code = $c.string('Hello World 3').toHalfWidth().run();
const code = $c.string('Hello World 3').normalize().run();
expect(generateAndExecute(code).run()).to.equal('Hello World 3');
});

it('should only converts full-width ASCII characters or number to its half-width character', () => {
const code = $c.string('こんにちは ワールド 3s').toHalfWidth().run();
const code = $c.string('こんにちは ワールド 3s').normalize().run();
expect(generateAndExecute(code).run()).to.equal('こんにちは ワールド 3s');
});
});
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.