-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add validators utilities to utils package
- Loading branch information
Showing
9 changed files
with
50 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 0 additions & 130 deletions
130
packages/suite/src/utils/suite/__tests__/validators.test.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const URL_REGEX = | ||
/^(http|ws)s?:\/\/[a-z0-9]([a-z0-9.-]+)?(:[0-9]{1,5})?((\/)?(([a-z0-9-_])+(\/)?)+)$/i; | ||
|
||
export const UPPERCASE_RE = new RegExp('^(.*[A-Z].*)$'); | ||
|
||
export const isUrl = (value: string): boolean => URL_REGEX.test(value); | ||
|
||
export function isASCII(value?: string): boolean { | ||
if (!value) return true; | ||
return /^[\x00-\x7F]*$/.test(value); // eslint-disable-line | ||
} | ||
|
||
export const hasUppercase = (value: string) => UPPERCASE_RE.test(value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { isASCII, hasUppercase } from '../src/validators'; | ||
|
||
describe('utils/suite/validators', () => { | ||
describe('isASCII', () => { | ||
it('should return true for ASCII only string', () => { | ||
expect(isASCII('this is only ascii')).toEqual(true); | ||
}); | ||
|
||
it('should return true when called without parameter', () => { | ||
expect(isASCII()).toEqual(true); | ||
}); | ||
|
||
it('should return false strings with non ASCII chars', () => { | ||
const fooStrings = ['¥', 'železniční přejezd']; | ||
fooStrings.forEach(str => { | ||
expect(isASCII(str)).toEqual(false); | ||
}); | ||
}); | ||
}); | ||
|
||
it('hasUppercase', () => { | ||
expect(hasUppercase('0')).toBe(false); | ||
expect(hasUppercase('abc')).toBe(false); | ||
expect(hasUppercase('abcD')).toBe(true); | ||
expect(hasUppercase('Abcd')).toBe(true); | ||
expect(hasUppercase('aBcd')).toBe(true); | ||
expect(hasUppercase('123abc123')).toBe(false); | ||
expect(hasUppercase('0x123abc456')).toBe(false); | ||
expect(hasUppercase('0x123aBc456')).toBe(true); | ||
}); | ||
}); |