Skip to content

Commit 013fe8f

Browse files
authored
fix: iciba throw error when fy ant love (#130)
1 parent 54381da commit 013fe8f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/print.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ exports.iciba = (data, options = {}) => {
2424
}
2525

2626
// phonetic symbol
27-
data.ps?.forEach((item, i) => {
27+
data.ps?.forEach?.((item, i) => {
2828
firstLine += chalk.magenta(` ${i === 0 ? '英' : '美'}[ ${item} ] `);
2929
});
3030

@@ -35,7 +35,7 @@ exports.iciba = (data, options = {}) => {
3535
}
3636

3737
// pos & acceptation
38-
data.pos?.forEach((item, i) => {
38+
data.pos?.forEach?.((item, i) => {
3939
if (typeof data.pos[i] !== 'string' || !data.pos[i]) {
4040
return;
4141
}
@@ -48,7 +48,7 @@ exports.iciba = (data, options = {}) => {
4848
log();
4949
}
5050

51-
data.sent?.forEach((item, i) => {
51+
data.sent?.forEach?.((item, i) => {
5252
if (typeof item.orig !== 'string' && item.orig[0]) {
5353
item.orig = item.orig[0].trim();
5454
}

tests/index.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,9 @@ describe('fanyi CLI', () => {
7171
const { stdout } = await runScript(['list']);
7272
expect(stdout).toContain('fanyi history:');
7373
});
74+
75+
it('should not print error when translate "ant love"', async () => {
76+
const { stderr } = await runScript(['ant love']);
77+
expect(stderr).not.toContain('访问 iciba 失败');
78+
});
7479
});

0 commit comments

Comments
 (0)