Skip to content

Latest commit

 

History

History
128 lines (91 loc) · 2.98 KB

File metadata and controls

128 lines (91 loc) · 2.98 KB

🛡️ String Guard

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.


Access the strings utility

import atomix from '@nasriya/atomix';

const stringsGuard = atomix.dataTypes.string.guard;

APIs

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

API Details

isAlpha

Signature: isAlpha(value: unknown): boolean

Checks if a string contains only alphabetic characters.

stringsGuard.isAlpha('HelloWorld'); // true
stringsGuard.isAlpha('Hello123');   // false

🔡 isAlphaNumeric

Signature: isAlphaNumeric(value: unknown): boolean

Checks if the string contains only letters and numbers.

stringsGuard.isAlphaNumeric('abc123');    // true
stringsGuard.isAlphaNumeric('abc 123');   // false

isBlank

Signature: isBlank(value: unknown): boolean

Checks if the string contains only whitespace.

stringsGuard.isBlank('   ');
// true

stringsGuard.isBlank('not blank');
// false

📭 isEmpty

Signature: isEmpty(value: unknown): boolean

Checks if the string is empty.

stringsGuard.isEmpty('');
// true

stringsGuard.isEmpty(' ');
// false

isNotEmpty

Signature: isNotEmpty(value: unknown): boolean

Checks if the string is not empty.

stringsGuard.isNotEmpty('text');
// true

stringsGuard.isNotEmpty('');
// false

🧪 isString

Signature: isString(value: unknown): value is string

Checks if the value is a string.

stringsGuard.isString('hello');
// true

stringsGuard.isString(123);
// false

🔍 isUUID

Signature: 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');
// true

🟩 isValidString

Signature: isValidString(value: unknown): boolean

Checks if the string is non-empty and not just whitespace.

stringsGuard.isValidString('OpenAI');
// true

stringsGuard.isValidString('   ');
// false