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

postkit-validation-library

v1.0.2

Published

Validation helpers for PostKit post data

Downloads

19

Readme

PostKit Validation Library

Validate post data before saving or publishing.

Installation

npm i postkit-validation-library

API

validateTitle

Validate a post title.

Takes in a title string and returns a validation result indicating whether the title is acceptable.

validateTitle(title: string, options?: ValidationOptions): ValidationResult

validateBody

Validate post body text.

Takes in a body string and returns a validation result indicating whether the content body is acceptable.

validateBody(body: string, options?: ValidationOptions): ValidationResult

validateStatus

Validate post status.

Takes in a status string and returns a validation result indicating whether the status is one of the allowed values.

validateStatus(status: string): ValidationResult

validatePost

Validate a full post object.

Takes in a Post object and returns a validation result indicating whether the post is valid as a whole.

validatePost(post: Post, options?: ValidationOptions): ValidationResult

isPostValid

Quick check for full-post validity.

Takes in a Post object and returns a boolean.

isPostValid(post: Post, options?: ValidationOptions): boolean

getPostValidationErrors

Return only validation issues for display.

Takes in a Post object and returns a list of validation issues.

getPostValidationErrors(post: Post, options?: ValidationOptions): ValidationIssue[]

Types

interface Post {
  id: string
  title: string
  body: string
  author: string
  tags: string[]
  category: string
  status: string
  createdAt: string
  updatedAt: string
}

interface ValidationIssue {
  field: 'title' | 'body' | 'status' | 'post'
  code: 'REQUIRED' | 'TOO_SHORT' | 'TOO_LONG' | 'INVALID_STATUS' | 'INVALID_TYPE'
  message: string
}

interface ValidationResult {
  valid: boolean
  issues: ValidationIssue[]
}

type PostStatus = 'draft' | 'review' | 'published'

Example Usage

import {
  validateTitle,
  validateBody,
  validateStatus,
  validatePost,
} from 'postkit-validation-library'

const post = {
  id: 'p1',
  title: 'Hello World',
  body: 'Some content for the post body with enough length.',
  author: 'Author',
  tags: ['writing'],
  category: 'General',
  status: 'published',
  createdAt: new Date().toISOString(),
  updatedAt: new Date().toISOString(),
}

validateTitle('My First Post')
// -> { valid: true, issues: [] }

validateTitle('')
// -> { valid: false, issues: [{ field: 'title', code: 'REQUIRED', message: 'title is required' }] }

validateBody('Some content for the post body.')
// -> { valid: true, issues: [] }

validateStatus('draft')
// -> { valid: true, issues: [] }

validateStatus('pending')
// -> { valid: false, issues: [{ field: 'status', code: 'INVALID_STATUS', message: 'status must be one of: draft, review, published' }] }

validatePost(post)
// -> { valid: true, issues: [] }

validatePost({ ...post, title: '', body: '', status: 'bad' as any })
// -> { valid: false, issues: [{...}, {...}, {...}] }

Edge Cases

  • Empty or whitespace-only title should fail.
  • Body text that is empty or too short should fail.
  • Invalid status values (including wrong casing like "Draft") should fail.
  • Missing fields in partially filled form data should return issues, not crash.
  • Leading/trailing whitespace should be handled consistently by validation rules.
  • Non-object inputs to validatePost (for example null or []) return INVALID_TYPE.
  • Type mismatches (non-string title/body/status) return INVALID_TYPE.

Design Notes

  • Main validators return a consistent ValidationResult shape for predictable app integration.
  • Convenience helpers are included for common UI flows: boolean checks and field error rendering.
  • validatePost aggregates title, body, and status checks so rules stay consistent in one place.
  • Validators return structured issues instead of throwing on common invalid input.