Skip to content

Commit

Permalink
fix: ignore numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Oct 19, 2019
1 parent a95edfe commit 352a84c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/_helpers/lang-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const isContain: { [key in Languages]: (text: string) => boolean } = {
}

const matcherPunct = /[/[\]{}$^*+|?.\-~!@#%&()_='";:><,。?!,、;:“”﹃﹄「」﹁﹂‘’『』()—[]〔〕【】…-~·‧《》〈〉﹏_]/
const matchAllPunct = new RegExp(`^${matcherPunct.source}+$`)
const matchAllMeaningless = new RegExp(`^(\\d|\\s|${matcherPunct.source})+$`)

const matcherCJK = new RegExp(
`${matchers.chinese.source}|${matchers.japanese.source}|${matchers.korean.source}`
Expand Down Expand Up @@ -103,7 +103,7 @@ export function checkSupportedLangs(
}

if (langs.matchAll) {
if (matchAllPunct.test(text)) {
if (matchAllMeaningless.test(text)) {
return false
}

Expand Down Expand Up @@ -149,7 +149,7 @@ export function checkSupportedLangs(
return true
}

if (!langs.others || matchAllPunct.test(text)) {
if (!langs.others || matchAllMeaningless.test(text)) {
return false
}

Expand Down
10 changes: 8 additions & 2 deletions test/specs/_helpers/lang-check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ describe('Language Check', () => {
describe('with matchAll on', () => {
const tl = tlHelper(true)

it('should return false with all punctuation', () => {
it('should return false with all meaningless characters', () => {
expect(tl('。「')).toBe(false)
expect(tl('。「', 'chinese')).toBe(false)
expect(tl('。「', 'english')).toBe(false)
expect(tl('。「', 'others')).toBe(false)
expect(tl('1234')).toBe(false)
expect(tl('1234', 'chinese')).toBe(false)
expect(tl('1234', 'others')).toBe(false)
})

it('should work with CJK', () => {
Expand Down Expand Up @@ -96,11 +99,14 @@ describe('Language Check', () => {
describe('with matchAll off', () => {
const tl = tlHelper(false)

it('should return false with all punctuation', () => {
it('should return false with all meaningless characters', () => {
expect(tl('。「')).toBe(false)
expect(tl('。「', 'chinese')).toBe(false)
expect(tl('。「', 'english')).toBe(false)
expect(tl('。「', 'others')).toBe(false)
expect(tl('1')).toBe(false)
expect(tl('1', 'english')).toBe(false)
expect(tl('1', 'others')).toBe(false)
})

it('should work with CJK', () => {
Expand Down

0 comments on commit 352a84c

Please sign in to comment.