Validation
import {
isEmpty, isBlank, isString, isAlpha,
isNumeric, isAlphaNumeric, isUpperCase, isLowerCase,
} from '@ppabari/strio/str';
These predicates never throw. Except for isString, they accept unknown and return false for non-string input.
isString
isString(value: unknown): value is string
isString('a'); // โ true
isString(42); // โ false
isEmpty
isEmpty(value: unknown): boolean
true for zero-length strings (and non-strings).
isEmpty(''); // โ true
isEmpty(' '); // โ false
isEmpty(null); // โ true
isBlank
isBlank(value: unknown): boolean
true for empty or whitespace-only strings.
isBlank(' '); // โ true
isBlank('a'); // โ false
isAlpha
isAlpha(value: unknown): boolean
Only ASCII letters, non-empty.
isAlpha('Hello'); // โ true
isAlpha('Hi5'); // โ false
isNumeric
isNumeric(value: unknown): boolean
Only ASCII digits, non-empty. Checks the character class, not numeric parseability โ '007' is numeric, '-1' and '1.5' are not.
isNumeric('12345'); // โ true
isNumeric('1.5'); // โ false
isAlphaNumeric
isAlphaNumeric(value: unknown): boolean
Only ASCII letters and digits, non-empty.
isAlphaNumeric('abc123'); // โ true
isAlphaNumeric('abc 12'); // โ false
isUpperCase / isLowerCase
isUpperCase(value: unknown): boolean
isLowerCase(value: unknown): boolean
Must contain at least one cased letter and be unchanged by toUpperCase() / toLowerCase().
isUpperCase('HELLO'); // โ true
isUpperCase('Hello'); // โ false
isUpperCase('123'); // โ false (no cased letters)
isLowerCase('hello'); // โ true