diff --git a/README.md b/README.md index d34e3ce..2c9e291 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Validate is a standard Deno module for validating string. * [x] isFloat * [x] isFQDN * [x] isFullWidth -* [ ] isHalfWidth +* [x] isHalfWidth * [ ] isHash * [ ] isHexColor * [ ] isHexadecimal diff --git a/src/libs/isHalfWidth.ts b/src/libs/isHalfWidth.ts new file mode 100644 index 0000000..d101f81 --- /dev/null +++ b/src/libs/isHalfWidth.ts @@ -0,0 +1,9 @@ +// @ts-ignore allowing typedoc to build +import assertString from '../utils/assertString.ts'; + +export const halfWidth = /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/; + +export const isHalfWidth = (str: string) => { + assertString(str); + return halfWidth.test(str); +}; diff --git a/src/mod.ts b/src/mod.ts index ebc3d64..189eb27 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -42,3 +42,5 @@ export * from './libs/isFloat.ts'; export * from './libs/isFQDN.ts'; // @ts-ignore allowing typedoc to build export * from './libs/isFullWidth.ts'; +// @ts-ignore allowing typedoc to build +export * from './libs/isHalfWidth.ts';