lodash-es-runtime-guards

Replaces runtime typeof checks and string emptiness checks with lodash-es predicate functions.

2.1k|262|Updated Nov 29, 2025
One-click install
npx skills add https://github.com/Draculabo/AntigravityManager --skill lodash-es-runtime-guards
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: lodash-es-runtime-guards
Source: https://github.com/Draculabo/AntigravityManager/tree/main/.agents/skills/lodash-es-runtime-guards
Command: npx skills add https://github.com/Draculabo/AntigravityManager --skill lodash-es-runtime-guards

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires lodash-es.

What problem does it solve?

Codebases accumulate inconsistent runtime type guards like typeof x === 'string' and ad-hoc emptiness checks like value.trim() !== '', making TypeScript code harder to read and maintain across app, server, IPC, and test layers.

Core Features & Use Cases

  • Guard Mapping: Converts runtime typeof comparisons for strings, numbers, booleans, functions, undefined, and objects into lodash-es predicates such as isString, isNumber, and isObjectLike.
  • String Emptiness Normalization: Replaces value.trim() === '' style checks with isEmpty(value.trim()) for consistent emptiness handling.
  • Type-Level Safety: Explicitly preserves compile-time TypeScript typeof usages like ReturnType<typeof fn> and z.infer<typeof Schema>.
  • Use Case: While refactoring an Electron app's IPC handlers, you find dozens of typeof payload === 'string' checks; apply this Skill to convert them to named lodash-es imports and verify with ripgrep and npm run type-check.

Quick Start

Refactor the runtime typeof and string emptiness checks in the src directory to use lodash-es predicates, then verify only type-level typeof remains.

Frequently Asked Questions about lodash-es-runtime-guards

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace typeof checks with lodash-es in TypeScript?

Map each runtime check to its predicate: `typeof x === 'string'` becomes `isString(x)`, `typeof x === 'number'` becomes `isNumber(x)`, and negations use the `!` prefix. Import only the named functions you need from lodash-es.

How to check for empty strings consistently in JavaScript?

Use `isEmpty(value.trim())` from lodash-es instead of `value.trim() === ''` or `value.trim().length === 0`. This gives one consistent emptiness pattern across the codebase.

Does lodash-es support tree-shaking with named imports?

Yes, lodash-es is the ES module build of lodash, so named imports like `import { isString } from 'lodash-es'` allow bundlers to tree-shake unused code. Avoid full-package imports to keep bundle size down.

When should I not replace typeof with lodash predicates?

Never replace type-level typeof used only at compile time, such as `ReturnType<typeof fn>`, `keyof typeof CONST_MAP`, or `z.infer<typeof Schema>`. These are TypeScript type constructs, not runtime checks, and must remain unchanged.

How do I verify all runtime typeof checks were refactored?

Run `rg -n "typeof\s+[^\n]+(?:===|!==)\s*'" src` to find remaining runtime comparisons, then `rg -n "\btypeof\b" src` to confirm only type-level usages remain. Finish with `npm run type-check`.