DEV Community

Sandeep Dara
Sandeep Dara

Posted on

πŸš€ Introducing sd-is v1.0.6: A Tiny JavaScript Utility for Type Checking, Smart Validation & Schemas

πŸ” What is sd-is?

sd-is is a zero-dependency, blazing-fast JavaScript utility library for:

  • βœ… Clean runtime type checks
  • 🧠 Smart validation with auto-fix suggestions
  • πŸ“‹ Schema definition + enforcement
  • πŸ”’ Emoji-enhanced developer-friendly errors

It’s like typeof, instanceof, and Array.isArray β€” but smarter and cleaner.


✨ What's New in v2.0+

Feature Description
βœ… assertType() Enforce expected type at runtime
πŸ“‹ defineSchema() Declaratively define reusable schemas
πŸ§ͺ validateAgainst() Validate data against your schema (enums, custom, nested)
🧠 smartCheck Check + explain + suggest fixes in human-readable format
βž• Bonus Checks New utils: isDate, isPromise, isSymbol, isRegExp, listFunctions

πŸ“¦ Installation

npm install sd-is
Enter fullscreen mode Exit fullscreen mode

Supports CommonJS, ESM, and is fully tree-shakable.

βœ… Type Checking Basics

import {
  isString,
  isNumber,
  isBoolean,
  isUndefined,
  isNotUndefined,
  isEmptyObject,
  isEmptyArray,
  isPlainObject
} from 'sd-is';

console.log(isString('hello'));          // true
console.log(isNumber(123));              // true
console.log(isBoolean(false));           // true
console.log(isEmptyArray([]));           // true
console.log(isPlainObject({ a: 1 }));    // true
console.log(isUndefined(undefined));     // true
console.log(isNotUndefined(42));         // true
Enter fullscreen mode Exit fullscreen mode

🧠 smartCheck: Check + Explain + Fix

import { smartCheck } from 'sd-is';

const result = smartCheck.isEmptyObject({ x: 1 });

console.log(result.ok);        // false
console.log(result.verdict);   // ❌ Not empty or not a valid object
console.log(result.reason);    // Found 1 key(s): x
console.log(result.fix());     // {}
Enter fullscreen mode Exit fullscreen mode

πŸ”’ assertType: Catch Mistakes Early

import assertType from 'sd-is/utils/assertType.js';

assertType('hello', 'string');       // βœ…
assertType(42, 'string');            // ❌ Throws: expected 'string', got 'number'
Enter fullscreen mode Exit fullscreen mode

πŸ“‹ defineSchema + validateAgainst

import defineSchema from 'sd-is/utils/defineSchema.js';
import validateAgainst from 'sd-is/utils/validateAgainst.js';

const productSchema = defineSchema({
  id: { type: 'string' },
  price: { type: 'number', default: 0 },
  category: { type: ['string', 'undefined'], optional: true },
  tags: { type: 'array', default: [] },
  status: { enum: ['active', 'inactive'] },
  createdAt: {
    type: 'string',
    custom: (val) =>
      /\d{4}-\d{2}-\d{2}/.test(val) || 'Must be in YYYY-MM-DD format'
  }
});

const product = {
  id: 'p-001',
  price: 89,
  tags: ['electronics', 'sale'],
  status: 'active',
  createdAt: '2025-07-14'
};

const result = validateAgainst(productSchema, product);

console.log(result.ok);      // true
console.log(result.errors);  // []
Enter fullscreen mode Exit fullscreen mode

πŸ“š All Available Utilities

Function Description
isBoolean Check for true/false
isNumber Check if value is number
isString Check if value is string
isUndefined Check if value is undefined
isNotUndefined Opposite of isUndefined
isNull Check if value is null
isFunction Check if value is function
isPlainObject Check if object is a plain {}
isEmptyObject Check if object has no keys
isEmptyArray Check if array is empty
isDate Check if value is a valid Date
isSymbol Check if value is a Symbol
isPromise Check if value is a Promise
isRegExp Check if value is a RegExp
listFunctions List all available util functions

πŸ€” Why Use sd-is?

  • πŸ” No need to write typeof value === 'string' everywhere
  • 🧠 Helpful validation, with built-in defaults and messages
  • ⚑ Extremely fast and tiny (~2KB gzipped)
  • βœ… Perfect for API layers, CLI tools, or raw object validation
  • πŸ“¦ No dependencies, supports modern JS without bloat

πŸ”— Links

πŸ“¦ NPM: sd-is
πŸ’» GitHub: github.com/sandeepdara-sd/sd-is

πŸ™Œ Wrap Up

If you're tired of verbose type checks and want a tiny, reliable, and developer-friendly utility for validating JavaScript structures β€” sd-is is for you.

Let me know what you think or contribute on GitHub! ⭐

Top comments (0)