1---2name: lodash-es-runtime-guards3description: lodash-es-runtime-guards4---5# lodash-es-runtime-guards67Replace runtime `typeof` checks and ad-hoc empty-string checks with `lodash-es` predicates.89## When to Use1011- You see runtime checks like `typeof value === 'string'`.12- You see object guards like `value && typeof value === 'object'`.13- You see emptiness checks like `value.trim() !== ''` or `value.trim() === ''`.14- You want consistent guard style across app, server, IPC, and tests.1516## Do Not Replace1718- Type-level `typeof` (TypeScript only), for example:19 - `ReturnType<typeof fn>`20 - `keyof typeof CONST_MAP`21 - `z.infer<typeof Schema>`2223These are compile-time types and must remain as-is.2425## Guard Mapping2627- `typeof x === 'string'` -> `isString(x)`28- `typeof x !== 'string'` -> `!isString(x)`29- `typeof x === 'number'` -> `isNumber(x)`30- `typeof x === 'boolean'` -> `isBoolean(x)`31- `typeof x === 'function'` -> `isFunction(x)`32- `typeof x === 'undefined'` -> `isUndefined(x)`33- `x && typeof x === 'object'` -> `isObjectLike(x)`34- `typeof x === 'object' && x !== null` -> `isObjectLike(x)`35- `typeof x === 'object' && !Array.isArray(x)` -> `isObjectLike(x) && !isArray(x)`3637## String Emptiness Pattern3839- Prefer:40 - `isEmpty(value.trim())`41- Instead of:42 - `value.trim() === ''`43 - `value.trim() !== ''`44 - `value.trim().length === 0`4546## Import Style4748- Use named imports from `lodash-es`:4950```ts51import { isString, isNumber, isObjectLike, isEmpty } from 'lodash-es';52```5354- Do not use full-package imports.55- Reuse existing imports in file; avoid duplicate imports.5657## Refactor Checklist58591. Replace runtime checks first, preserving behavior.602. Keep array/object branching semantics unchanged.613. Re-scan:6263```bash64rg -n "typeof\s+[^\n]+(?:===|!==)\s*'" src65```66674. Confirm only type-level `typeof` remains:6869```bash70rg -n "\btypeof\b" src71```72735. Run verification:7475```bash76npm run type-check77```78
Run npx get-skill add draculabo/lodash-es-runtime-guards in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
lodash-es-runtime-guards It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Draculabo (@draculabo) published this skill. Their other Agent Skills are listed on their SkillMD profile.