Supportive Is
A small library of type and shape predicates — isString, isEmpty, isUrl, isPromise, isMobile.*, and friends. Each one is a named export, so bundlers drop the ones you don’t use. Pure predicates run anywhere; DOM-touching predicates read globals lazily so server-side imports stay safe.
Highlighted features
~60 named predicates
One named export per predicate — isString, isEmail, isUrl, isPromise, isPlainObject, dozens more.
Tree-shake to ~80 bytes
sideEffects: false + per-predicate exports. Pull isEmail alone and ship ~80 bytes, not the whole 3KB bag.
Server-safe imports
DOM/browser predicates read navigator / window / document lazily. Safe to import on the server; isFormElement returns false there instead of throwing.
”Smart” emptiness
isEmpty collapses null / undefined / "" / [] / {} / Maps / Sets into one check. 0 and false are deliberately NOT empty.
Install
npm install @mongez/supportive-isyarn add @mongez/supportive-ispnpm add @mongez/supportive-isQuick peek
import { isEmail, isEmpty, isPlainObject, isUrl } from "@mongez/supportive-is";
isEmail("user@example.com"); // trueisEmpty({}); // trueisEmpty(0); // false — zero is a real valueisPlainObject(new Date()); // false — Date is an instance, not a literalisUrl("https://example.com"); // trueTree-shakable predicates — import only what you use.
Mental model
| Concept | What it means |
|---|---|
| Pure predicates | Single-argument functions: take a value, return boolean-ish. No side effects, no allocation. |
Is namespace | A bag of references to the same functions, kept for v1 compatibility. Doesn’t tree-shake — prefer named imports. |
| Environment probes | Touch navigator / window / document at call time. Server-safe to import, server-unsafe to call. |
| ”Smart” emptiness | isEmpty collapses null / undefined / "" / [] / / new Map() / new Set() into one check, with 0 and false deliberately not empty. |
Scope boundaries
| Concern | Lives in | Why |
|---|---|---|
| General object/string/array helpers | @mongez/reinforcements | Different package, different scope |
Schema validation (z.string().email()) | zod, valibot | Predicates are guards, not validators |
| HTML sanitization | DOMPurify | Regex-based stripping is a footgun |
Where to go next
- Primitives —
isString,isNumber,isBoolean,isFunction, etc. - Collections —
isArray,isPlainObject,isMap,isSet,isEmpty - Formats —
isEmail,isUrl,isJson,isIp - Environment —
isBrowser,isMobile,isMac, vendor probes - Misc — edge-case predicates
- Recipes — composition patterns