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

@linktic/validator

v1.0.0

Published

Framework-agnostic TypeScript validation library with fluent API and configurable Spanish default messages

Readme

@linktic/validator

Libreria de validacion TypeScript con API fluida, zero dependencias y mensajes en espanol configurables.

Instalacion

# pnpm
pnpm add @linktic/validator

# npm
npm install @linktic/validator

# yarn
yarn add @linktic/validator

Uso basico

import { validate, ValidationError } from '@linktic/validator'

const data = { name: '', email: 'bad', age: 15 }
const v = validate(data)

v.field('name', 'Nombre').required().string()
v.field('email', 'Correo').required().email()
v.field('age', 'Edad').required().number().min(18)

// Opcion A: lanzar error
try {
  v.validate()
} catch (e) {
  if (e instanceof ValidationError) {
    console.log(e.errors) // ValidationFieldError[]
  }
}

// Opcion B: inspeccionar resultado
const result = v.getResult()
if (!result.isValid) {
  console.log(result.errors)
}

Validacion por schema

const v = validate(data)

v.schema({
  name: { required: true, type: 'string', label: 'Nombre', minLength: 2, maxLength: 100 },
  email: { required: true, type: 'email', label: 'Correo' },
  age: { required: true, type: 'number', label: 'Edad', min: 18, max: 120 },
  role: { required: true, label: 'Rol', enum: ['admin', 'user', 'viewer'] },
  notes: { required: false, type: 'string', label: 'Notas', maxLength: 500 },
})

v.validate()

Campos anidados

const v = validate({ office: { name: 'HQ', classId: '001' } })

v.field('office.name', 'Nombre oficina').required().string()
v.field('office.classId', 'Clase de oficina').required().string()

Validadores personalizados

v.field('username', 'Usuario').custom((value) => {
  if ((value as string).includes(' ')) return 'No puede contener espacios'
  return true
})

Configuracion de mensajes

Por defecto los mensajes vienen en espanol. Puedes personalizarlos:

Sobrescribir mensajes especificos

import { configure } from '@linktic/validator'

configure({
  required: (field) => `${field} is required`,
  email: () => 'Please enter a valid email',
})

Reemplazar todos los mensajes (cambio de idioma)

import { setMessages, spanishMessages } from '@linktic/validator'
import type { ValidationMessageMap } from '@linktic/validator'

const english: ValidationMessageMap = {
  required: (field) => `${field} is required. Please fill it in.`,
  pattern: (field, example) => `${field} format is invalid. Expected: ${example}`,
  maxLength: (field, max, actual) => `${field} exceeds ${max} characters (${actual} entered).`,
  minLength: (field, min) => `${field} requires at least ${min} characters.`,
  range: (field, min, max) => `${field} must be between ${min} and ${max}.`,
  date: (field) => `${field} is not a valid date.`,
  allowedChars: (field, allowed) => `${field} contains invalid characters. Only: ${allowed}`,
  email: () => 'The email entered is not valid',
  string: (field) => `${field} must be text`,
  number: (field) => `${field} must be a number`,
  boolean: (field) => `${field} must be true or false`,
  array: (field) => `${field} must be a list`,
  object: (field) => `${field} must be an object`,
  uuid: (field) => `${field} must be a valid identifier`,
  enum: (field, values) => `${field} must be one of: ${values.join(', ')}`,
  custom: (field) => `${field} is not valid`,
}

setMessages(english)

Restaurar mensajes por defecto

import { resetMessages } from '@linktic/validator'

resetMessages() // Vuelve a espanol

API de FieldValidator

| Metodo | Descripcion | |--------|-------------| | required(msg?) | Campo obligatorio | | optional() | Campo opcional (salta validaciones si esta vacio) | | nullable() | Alias de optional() | | string(msg?) | Debe ser string | | number(msg?) | Debe ser number | | boolean(msg?) | Debe ser boolean | | array(msg?) | Debe ser array | | object(msg?) | Debe ser objeto (no array) | | date(msg?) | Debe ser fecha valida | | email(msg?) | Debe ser email valido | | uuid(msg?) | Debe ser UUID valido | | type(type, msg?) | Validar por tipo (ValidationType) | | minLength(min, msg?) | Longitud minima (string/array) | | maxLength(max, msg?) | Longitud maxima (string/array) | | min(value, msg?) | Valor minimo (number) | | max(value, msg?) | Valor maximo (number) | | range(min, max, msg?) | Rango numerico | | pattern(regex, example?, msg?) | Validar contra regex | | enum(values, msg?) | Debe ser uno de los valores | | allowedChars(chars, msg?) | Solo caracteres permitidos | | custom(fn, msg?) | Validador personalizado |

API de Validator

| Metodo | Descripcion | |--------|-------------| | field(name, label?) | Iniciar validacion de un campo | | schema(config) | Validar con configuracion de schema | | validate() | Lanzar ValidationError si hay errores | | getResult() | Obtener { isValid, errors } | | getErrors() | Obtener array de errores | | isValid() | true si no hay errores | | hasErrors() | true si hay errores | | reset() | Limpiar errores |

Opciones

const v = validate(data, {
  stopOnFirstError: true,  // Detener en el primer error por campo
  throwOnError: true,      // Lanzar inmediatamente al encontrar error (con stopOnFirstError)
})