Skip to content

Commit

Permalink
Add new test
Browse files Browse the repository at this point in the history
  • Loading branch information
ymzEmre committed Jan 30, 2024
1 parent 13820ff commit b5d14a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/patterns/isAscii.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const pattern = new RegExp(/^[\x00-\x7F]*$/)

const isAscii = (value:string) => {
const isAscii = (value:string | number) => {
if (value === null || pattern === new RegExp('/(?:)/')) return
return pattern.test(value)
return pattern.test(value.toString())
}

export default isAscii
12 changes: 12 additions & 0 deletions test/isAscii.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@ it('should return true for valid ascii strings', () => {
expect(isAscii('abc')).toBe(true)
expect(isAscii('abc123')).toBe(true)
expect(isAscii('abc123!@#')).toBe(true)
expect(isAscii(1)).toBe(true)
expect(isAscii('√∑→←Ω♫😊🌍букваحرف')).toBe(false)
expect(isAscii('a√')).toBe(false)
expect(isAscii('a∑')).toBe(false)
expect(isAscii('a→')).toBe(false)
expect(isAscii('a←')).toBe(false)
expect(isAscii('aΩ')).toBe(false)
expect(isAscii('a♫')).toBe(false)
expect(isAscii('a😊')).toBe(false)
expect(isAscii('a🌍')).toBe(false)
expect(isAscii('aбуква')).toBe(false)
expect(isAscii('aحرف')).toBe(false)
})

0 comments on commit b5d14a8

Please sign in to comment.