Skip to content

Commit b88aa60

Browse files
committed
fix exception when empty text
1 parent b8030a1 commit b88aa60

File tree

11 files changed

+44
-10
lines changed

11 files changed

+44
-10
lines changed

assets/img/browser.png

68 KB
Loading

dist/jsrmvi.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var jsrmvi = (function (exports) {
4646
if (text === void 0) { text = ''; }
4747
if (options === void 0) { options = DefaultOption; }
4848
var _a = options.ignoreCase, ignoreCase = _a === void 0 ? DefaultOption.ignoreCase : _a, _b = options.replaceSpecialCharacters, replaceSpecialCharacters = _b === void 0 ? DefaultOption.replaceSpecialCharacters : _b, _c = options.concatBy, concatBy = _c === void 0 ? DefaultOption.concatBy : _c;
49-
var res = text;
49+
var res = text || '';
5050
if (ignoreCase) {
5151
res = res.toLowerCase();
5252
}

dist/jsrmvi.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ exports.removeVI = function (text, options) {
3535
if (text === void 0) { text = ''; }
3636
if (options === void 0) { options = DefaultOption; }
3737
var _a = options.ignoreCase, ignoreCase = _a === void 0 ? DefaultOption.ignoreCase : _a, _b = options.replaceSpecialCharacters, replaceSpecialCharacters = _b === void 0 ? DefaultOption.replaceSpecialCharacters : _b, _c = options.concatBy, concatBy = _c === void 0 ? DefaultOption.concatBy : _c;
38-
var res = text;
38+
var res = text || '';
3939
if (ignoreCase) {
4040
res = res.toLowerCase();
4141
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsrmvi",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Convert Vietnamese words to Latin alphabet - Use for both Node.JS and Browser.",
55
"author": {
66
"name": "huynhsamha",

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const removeVI = (text: string = '', options: Options = DefaultOption) =>
5050
concatBy = DefaultOption.concatBy,
5151
} = options;
5252

53-
let res = text;
53+
let res = text || '';
5454
if (ignoreCase) {
5555
res = res.toLowerCase();
5656
}

test/browser/script.js

+6
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@
55
console.log('File script.js');
66
console.log(jsrmvi);
77
console.log(DefaultOption);
8+
9+
console.log('Null or empty text:');
10+
console.log('1: ' + removeVI());
11+
console.log('2: ' + removeVI(null));
12+
console.log('3: ' + removeVI(undefined));
13+
console.log('4: ' + removeVI(''));
814
})();

test/node/index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('fs');
22
const path = require('path');
33

4-
const { removeVI, DefaultOption } = require('../../dist/index');
4+
const { removeVI, DefaultOption } = require('../../index');
55

66
console.log(DefaultOption);
77
/*
@@ -12,6 +12,20 @@ console.log(DefaultOption);
1212
}
1313
*/
1414

15+
console.log('Null or empty text:');
16+
console.log('1: ' + removeVI());
17+
console.log('2: ' + removeVI(null));
18+
console.log('3: ' + removeVI(undefined));
19+
console.log('4: ' + removeVI(''));
20+
console.log();
21+
/*
22+
Null or empty text:
23+
1:
24+
2:
25+
3:
26+
4:
27+
*/
28+
1529
const parttern = 'à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ|è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ|ì|í|ị|ỉ|ĩ|ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ|ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ|ỳ|ý|ỵ|ỷ|ỹ|đ';
1630

1731
console.log('Lowercase pattern:');

test/npm/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ console.log(DefaultOption);
99
}
1010
*/
1111

12+
console.log('Null or empty text:');
13+
console.log('1: ' + removeVI());
14+
console.log('2: ' + removeVI(null));
15+
console.log('3: ' + removeVI(undefined));
16+
console.log('4: ' + removeVI(''));
17+
console.log();
18+
/*
19+
Null or empty text:
20+
1:
21+
2:
22+
3:
23+
4:
24+
*/
25+
1226
const parttern = 'à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ|è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ|ì|í|ị|ỉ|ĩ|ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ|ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ|ỳ|ý|ỵ|ỷ|ỹ|đ';
1327

1428
console.log('Lowercase pattern:');

test/npm/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"main": "index.js",
55
"license": "MIT",
66
"dependencies": {
7-
"jsrmvi": "file:jsrmvi-0.0.1.tgz"
7+
"jsrmvi": "file:jsrmvi-0.0.2.tgz"
88
}
99
}

test/npm/yarn.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# yarn lockfile v1
33

44

5-
"jsrmvi@file:jsrmvi-0.0.1.tgz":
6-
version "0.0.1"
7-
resolved "file:jsrmvi-0.0.1.tgz#228f699d23cd1127f69aec59218ae87ab1638327"
5+
"jsrmvi@file:jsrmvi-0.0.2.tgz":
6+
version "0.0.2"
7+
resolved "file:jsrmvi-0.0.2.tgz#272b21ee265e8e9c8091dbe5fb0bbf4b6529b6cd"

0 commit comments

Comments
 (0)