mongez-supportive-is-primitives

Document six primitive and numeric type predicates for JavaScript and TypeScript.

12|3|Updated Nov 29, 2017
One-click install
npx skills add https://github.com/hassanzohdy/supportive-is --skill mongez-supportive-is-primitives
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mongez-supportive-is-primitives
Source: https://github.com/hassanzohdy/supportive-is/tree/main/skills/primitives
Command: npx skills add https://github.com/hassanzohdy/supportive-is --skill mongez-supportive-is-primitives

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Documents the six primitive and numeric predicates isString, isNumeric, isInt, isFloat, isPrimitive, and isScalar including their semantics, edge cases, and known bugs to help developers reason about type checks without relying on ad-hoc typeof checks.

Core Features & Use Cases

  • Clear semantics for each predicate: isString, isNumeric, isInt, isFloat, isPrimitive, isScalar.
  • Explanations of edge cases (wrapper objects, numeric strings, NaN/Infinity, symbols, null, undefined) and practical pitfalls when validating data in JavaScript/TypeScript.
  • Guidance for type narrowing and input validation across dynamic and statically-typed codebases.

Quick Start

Import the predicates from @mongez/supportive-is and apply them to validate common values in your codebase.

Frequently Asked Questions about mongez-supportive-is-primitives

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

FAQPage Schema
How do I reliably check primitive types in JavaScript and handle edge cases like NaN?

Primitive type checking in JavaScript requires precise predicates to handle edge cases like NaN, Infinity, and wrapper objects. This Skill provides deterministic O(1) checks using isString, isNumeric, isInt, isFloat, isPrimitive, and isScalar to validate inputs and narrow types.

What is the best way to validate numeric strings versus actual numbers in TypeScript?

Validating numeric strings against actual numbers in TypeScript is handled by the isNumeric predicate, which distinguishes between values like "123" and 123. The Skill documents these semantics thoroughly to help developers reason about type checks without relying on ad-hoc typeof checks.

How do I set up primitive type predicates using @mongez/supportive-is?

To set up primitive type predicates, import isString, isNumeric, isInt, isFloat, isPrimitive, or isScalar directly from @mongez/supportive-is in your JavaScript or TypeScript project, then apply them to validate common values and narrow types across your codebase.

Does this primitive type checking approach work with both JavaScript and TypeScript projects?

Yes, primitive type checking with these predicates works with both JavaScript and TypeScript projects. The Skill provides guidance for type narrowing and input validation across dynamic and statically-typed codebases, ensuring consistent semantics regardless of the environment.

Why does typeof return unexpected results for wrapper objects and how do predicates fix this?

Typeof returns unexpected results for wrapper objects because it identifies them as objects rather than primitives. Predicates like isPrimitive and isScalar bypass this by applying deterministic checks that account for wrapper objects, symbols, null, and undefined edge cases.

What are the limitations of using ad-hoc typeof checks compared to dedicated type predicates?

Ad-hoc typeof checks lack clear semantics for numeric strings, NaN, Infinity, and wrapper objects. Dedicated type predicates solve this by offering documented edge case handling and deterministic O(1) checks, preventing practical pitfalls when validating dynamic data.