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 🙏

© 2024 – Pkg Stats / Ryan Hefner

yncc

v0.0.3

Published

Yncc is a validator and parser inspired by lizod, which in turn was inspired by zod.

Downloads

4

Readme

Yncc

Yncc is a validator and parser inspired by lizod, which in turn was inspired by zod.

Features

  • API similar to zod, but with a different concept.
  • Tree-shakable
  • CommonJS and ES module support
  • All typescript implementations

Installation

npm install -S yncc

Why is it named Yncc?

Yncc is a library that takes one step back from Zod.

Y ← Z
n ← o
c ← d
c ???

Basic usage

Its writing style is similar to zod, and it has been particularly influenced by lizod.

import { $object, $string, $number, Infer } from "yncc";

// Create a schema
const schema = $object({
  name: $string,
  age: $number,
});

// parse a value
schema.parse({ name: "John", age: 42 });
// => ✅ { success: true, value: { name: 'John', age: 42 } }

schema.parse({ name: "John" });
// => ⛔ { success: false, errors: [{ path ['age'], kind: 'required' }] }

// type from schema
type Person = Infer<typeof schema>;

Specify it along with the options.

import { $object, $string, $number } from "yncc";

// Create a schema
const schema = $object({
  name: $string({ nullable: true }),
  age: $number({ default: 0, min: 0, max: 100 }),
});

schema.parse({ name: null, age: 42 });
// => ✅ { success: true, value: {name: null, age: 42} }

schema.parse({ name: null });
// => ✅ { success: true, value: {name: null, age: 0} }

schema.parse({ age: 101 });
// => ⛔ {
//  success: false,
//  errors: [{
//    path: ['name'],
//    kind: 'required',
//  } , {
//    path ['age'],
//    kind: 'optional_validation_failure',
//    option: 'max',
//    optionValue: 100
//  }]}

Yncc is a parser

import { $object, $string, $number } from "yncc";

// Create a schema
const schema = $object({
  name: $string,
  age: $number,
});

// parse a value
schema.parse({ name: 1024, age: "0x20" });
// => ✅ {success: true, value: { name: '1024', age: 32 } }

It has a significantly different concept compared to zod and lizod. Yncc is a library designed with a focus on parsing. It interprets data as numbers if it can be recognized as number and interprets it as string if it can be recognized as string.

Parsing rules

$number

  • If the value is a string, it will attempt to parse it as a number.
    • ✅ "32" => 32
    • ✅ "0x20" => 32
    • ✅ "0o40" => 32
    • ✅ "0b100000" => 32
    • ✅ "32.0" => 32
    • ⛔ "Hello world"
    • ⛔ "32px"
  • Other types will trigger an error.
    • ⛔ true / false

$boolean

  • If the value is a string, it will attempt to parse it as a boolean.
    • ✅ "true" => true
    • ✅ "TRUE" => true
    • ✅ "false" => false
    • ✅ "FALSE" => false
    • ⛔ "on"
    • ⛔ "off"
  • Other types will trigger an error.
    • ⛔ 0
    • ⛔ 1

$string

  • If the value is a number, it will attempt to parse it as a string.
    • ✅ 32 => "32"
    • ✅ 32.0 => "32"
    • ✅ 0x20 => "32"
    • ✅ 0o40 => "32"
    • ✅ 0b100000 => "32"
  • If the value is a boolean, it will attempt to parse it as a string.
    • ✅ true => "true"
    • ✅ false => "false"
  • Other types will trigger an error.
    • ⛔ { a: 1 }
    • ⛔ [0, 1, 2]

$date

  • If the value is a number, it will attempt to parse it as a string. ⚠Warning: Date conversions based on numbers are subject to timezone effects, so please be aware!
    • ✅ 20200101 => "20200101" => Date(2020, 0, 1)
    • ✅ 2020 => "2020" => Date(2020, 0, 1)
    • ⛔ 101 => "101" => malformed value

All schemas

  • $number
  • $string
  • $boolean
  • $object
  • $array
  • $literal
  • $date
  • $optional
  • $union
  • $intersection

Standard provided validators

  • emailValidator