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

@4lch4/schemas

v0.3.0

Published

A package containing all of the JSON Schema assets used across my projects for 4lch4 and 4lch4 Industries, as well as a utility class to perform validation.

Downloads

3

Readme

@4lch4/Schemas

This repository is home to my Schemas package, which was inspired by the Vercel/Schemas package. Basically it's an NPM package that exports schemas for a variety of use-cases and utility classes such as a Schema Validator that uses Ajv/Joi behind the scenes to validate a given object matches a given Schema object.

Schemas

The following table provides information regarding the available schemas that this package exports. The first two columns are self-explanatory but the third column (Parent Project) is a bit special. If the schema was developed for use with a particular open-source project then this column should contain the name of said project and it should also be a hyperlink to the homepage of said project. For example, if the parent project was the Sindri API, then it should link to its git repository hosted on my instance of Gitea.

| Name | Description | Parent Project | | ------------------- | ------------------------------------------------------------------------------------------------------------------- | --------------- | | QuestionnaireSchema | Defines the structure of a questionnaire.json file that is present at the root of a template repository for Sindri. | Sindri-API | | TurboRepoSchema | Defines the structure of a turbo.json file that is present in mono-repos managed by Turbo. | Turbo Repo | | VercelSchemas | Defines the structure of the Vercel Config file present in individual projects and at the global level. | Vercel |

Validator Utility

This library also exports a ValidatorUtil class that uses Ajv under the hood to validate objects match a given Schema, like so:

import { ValidatorUtil, QuestionnaireSchema } from '@4lch4/schemas'

const testObj = {
  alpha: 'string',
  beta: {
    subAlpha: 'Another String.'
  }
}

const validator = new ValidatorUtil()

// Validate the testObj against the QuestionnaireSchema by name.
const namedIsValid = await validator.validate(testObj, 'QuestionnaireSchema')

// Validate the testObj using the QuestionnaireSchema by passing in the QuestionnaireSchema object itself.
const specialIsValid = await validator.validate(testObj, QuestionnaireSchema)

Why?

At first I just wanted a small API that would return the JSON Schema for a particular schema I needed. Once I built that I stumbled upon Vercel's Schema package and realized how useful it would be to have something like that in my tool belt. That aside, the other reasons why I'm making this are the same as what Vercel listed in their README:

  • Keep schemas used across 4lch4/4lch4 Industries projects in sync.
  • We use .js instead of .json because parsing JSON takes longer.

NOTE: A lot of the following text is a copy/paste from the Vercel/Schemas README since what I'm doing with this repository/package is the same as what their package does.

Usage

To get started, pick one of the schemas in this repository and load it:

const { TurboRepoSchema, Validator } = require('@4lch4/schemas')

const isValid = ajv.validate(TurboRepoSchema, <object-to-validate>);

if (!isValid) {
  console.error(`The following entries are wrong: ${JSON.stringify(ajv.errors)}`);
}

Next, set up AJV (the validator) and run the schema through it:

const AJV = require('ajv')

const ajv = new AJV({ allErrors: true })

That is all! :tada:

Contributing

At the moment I am not looking for any external contributions to this repository due to the very nature of the library.