npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@geeleed/validate-easy

v1.0.0

Published

Simple, async-friendly schema-based data validator for JavaScript and TypeScript

Readme

@geeleed/validate-easy

@geeleed/validate-easy คือไลบรารี JavaScript ขนาดเล็กที่ช่วยตรวจสอบความถูกต้องของข้อมูล (data validation) โดยใช้รูปแบบ schema ที่เข้าใจง่าย รองรับทั้ง synchronous และ asynchronous validation พร้อมรองรับ TypeScript


🚀 Features

  • ✅ รองรับชนิดข้อมูล: string, number, boolean, array, object
  • ✅ รองรับ object ซ้อน และ array
  • ✅ รองรับ custom validation แบบ sync และ async
  • ✅ เขียนง่าย ใช้งานสะดวก ไม่ต้องติดตั้ง dependency อื่น
  • ✅ มี Type Definitions สำหรับ TypeScript

📦 การติดตั้ง

npm install @geeleed/validate-easy

🔰 วิธีใช้งานเบื้องต้น

const { validateData } = require('@geeleed/validate-easy');

const schema = {
  username: {
    type: 'string',
    required: true,
    minLength: 3,
    maxLength: 15
  },
  age: {
    type: 'number',
    required: true,
    custom: (value) => value >= 18 || 'ต้องมีอายุอย่างน้อย 18 ปี'
  },
  email: {
    type: 'string',
    pattern: /^[^\s@]+@[^\s@]+\.[^\s@]+$/
  }
};

const data = {
  username: 'jo',
  age: 16,
  email: 'invalid-email'
};

(async () => {
  const result = await validateData(schema, data);
  console.log(result);
})();

🧾 ผลลัพธ์ที่ได้

{
  "valid": false,
  "errors": {
    "username": "Minimum length is 3",
    "age": "ต้องมีอายุอย่างน้อย 18 ปี",
    "email": "Invalid format"
  }
}

🔍 ตัวอย่างการใช้งานในกรณีต่าง ๆ

✅ Object ซ้อน (Nested Object)

const schema = {
  address: {
    type: 'object',
    required: true,
    properties: {
      city: { type: 'string', required: true },
      zip: { type: 'string', pattern: /^\d{5}$/ }
    }
  }
};

const data = {
  address: {
    city: '',
    zip: 'abc'
  }
};

✅ ผลลัพธ์:

{
  "valid": false,
  "errors": {
    "address.city": "This field is required",
    "address.zip": "Invalid format"
  }
}

✅ Array + Schema สำหรับแต่ละรายการ

const schema = {
  tags: {
    type: 'array',
    required: true,
    items: {
      type: 'string',
      minLength: 2
    }
  }
};

const data = {
  tags: ['ok', 2, 'a']
};

✅ ผลลัพธ์:

{
  "valid": false,
  "errors": {
    "tags[1].item": "Expected type string but got number",
    "tags[2].item": "Minimum length is 2"
  }
}

✅ Custom Validation แบบ Async

async function isEmailTaken(email) {
  const takenEmails = ['[email protected]'];
  return takenEmails.includes(email);
}

const schema = {
  email: {
    type: 'string',
    required: true,
    custom: async (value) => {
      const exists = await isEmailTaken(value);
      return !exists || 'อีเมลนี้ถูกใช้งานแล้ว';
    }
  }
};

const data = {
  email: '[email protected]'
};

✅ ผลลัพธ์:

{
  "valid": false,
  "errors": {
    "email": "อีเมลนี้ถูกใช้งานแล้ว"
  }
}

📘 รายการกฎที่ใช้ได้ใน schema

| กฎ | ประเภท | คำอธิบาย | | ------------ | ------------------------------------------------------------------ | --------------------------- | | type | 'string', 'number', 'boolean', 'array', 'object' | ชนิดข้อมูลที่รับได้ | | required | boolean | กำหนดว่าต้องกรอกหรือไม่ | | minLength | number | ความยาวขั้นต่ำของ string | | maxLength | number | ความยาวสูงสุดของ string | | pattern | RegExp | ตรวจสอบ string ด้วย pattern | | items | SchemaRule | กำหนด schema ของ array item | | properties | object | กำหนด schema ของ object | | custom | (value, data) => boolean \| string \| Promise<boolean \| string> | ฟังก์ชันตรวจสอบแบบกำหนดเอง |

🧑‍💻 TypeScript Support

ใช้งานใน TypeScript ได้ทันที พร้อม auto-complete และ type checking:

import { validateData } from '@geeleed/validate-easy';

const schema = {
  age: {
    type: 'number',
    required: true,
    custom: (value) => value > 0 || 'อายุต้องมากกว่า 0'
  }
};

const result = await validateData(schema, { age: -1 });

if (!result.valid) {
  console.log(result.errors.age); // Type-safe
}

✅ License

MIT License


✨ ผู้เขียน

พัฒนาโดย Surasak Kaewpho (Geeleed) github.com/Geeleed