Runtime type and value predicates (is*) — part of the @goodnight-dev utility
suite. Not limited to one input type: a predicate's name and signature say what
it checks (isAsciiString, and more to come).
Strict, modern, ESM-only TypeScript. Fully typed, tree-shakable, zero runtime dependencies.
# via pnpm
pnpm add @goodnight-dev/predicate
# or via npm
npm install @goodnight-dev/predicate
import { isAsciiString } from '@goodnight-dev/predicate';
isAsciiString('hello'); // => true
isAsciiString('café'); // => false
The same utilities are available through the umbrella package, if you'd rather depend on one thing:
import { isAsciiString } from '@goodnight-dev/utils/predicate';
import { isAsciiString } from '@goodnight-dev/utils';
isAsciiString(value: string): booleanReturns true if every character in the string is ASCII (U+0000–U+007F),
false otherwise (and true for an empty string). See the
implementation notes
for the alternatives considered and why this approach was chosen.
isIterable(value: unknown): booleanReturns true if the value implements the iterable protocol (a callable
Symbol.iterator), so it can drive a for...of loop or the spread operator —
true for arrays, strings, Map, Set, and generator objects; false for
plain objects, null, and undefined. See the
implementation notes
for the alternatives considered and why this approach was chosen.
MIT © Ian Goodnight