Type-safe validation helpers for string values.
The guard module provides a collection of runtime checks for determining whether values are valid strings under different conditions. It helps enforce correctness and type narrowing when working with user input, form data, or external sources.
import atomix from '@nasriya/atomix';
const stringsGuard = atomix.dataTypes.string.guard;| API | Description |
|---|---|
| isAlpha | Checks if a string contains only alphabetic characters |
| isAlphaNumeric | Checks if a string contains only alphanumeric characters |
| isBlank | Checks if a string contains only whitespace |
| isEmpty | Checks if a string is empty |
| isNotEmpty | Checks if a string is not empty |
| isString | Checks if a value is a string |
| isUUID | Checks if a string is a valid UUID (v1, v4, or v5) |
| isValidString | Checks if a string is not empty after trimming |
Signature: isAlpha(value: unknown): boolean
Checks if a string contains only alphabetic characters.
stringsGuard.isAlpha('HelloWorld'); // true
stringsGuard.isAlpha('Hello123'); // falseSignature: isAlphaNumeric(value: unknown): boolean
Checks if the string contains only letters and numbers.
stringsGuard.isAlphaNumeric('abc123'); // true
stringsGuard.isAlphaNumeric('abc 123'); // falseSignature: isBlank(value: unknown): boolean
Checks if the string contains only whitespace.
stringsGuard.isBlank(' ');
// true
stringsGuard.isBlank('not blank');
// falseSignature: isEmpty(value: unknown): boolean
Checks if the string is empty.
stringsGuard.isEmpty('');
// true
stringsGuard.isEmpty(' ');
// falseSignature: isNotEmpty(value: unknown): boolean
Checks if the string is not empty.
stringsGuard.isNotEmpty('text');
// true
stringsGuard.isNotEmpty('');
// falseSignature: isString(value: unknown): value is string
Checks if the value is a string.
stringsGuard.isString('hello');
// true
stringsGuard.isString(123);
// falseSignature: isUUID(value: unknown, version?: 'v1' | 'v4' | 'v5'): boolean
Checks if the value is a valid UUID.
stringsGuard.isUUID('550e8400-e29b-41d4-a716-446655440000');
// true (v4)
stringsGuard.isUUID('550e8400-e29b-11d4-a716-446655440000', 'v1');
// trueSignature: isValidString(value: unknown): boolean
Checks if the string is non-empty and not just whitespace.
stringsGuard.isValidString('OpenAI');
// true
stringsGuard.isValidString(' ');
// false