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

@ords/obj-schema

v1.2.3

Published

Perform schema validation in typescript

Downloads

15

Readme

This project lets you create schemas for your objects and validate a given dataset against that schema

Using this module

This module exists on npm. To use it run:

npm install @ords/obj-schema --save

The different erros can be found in:

import {errors}            from    '@ords/obj-schema';

Check our tests for expected behavior of this module.

Examples

import {setType, lib}            from    '@ords/obj-schema';

// boolean type
let bool: lib.SingleElementDefinition {
    valueset: { true: true, false: false }, // values allowed
    numValues: 1,                           // required number of values
    maxNumValues: 1                         // maximum number of values
}

// custom type
let myCustom: lib.SingleElementDefinition {
    numValues: 2,                          // required minium one
    maxNumValues: 3                        // maximum length leave empty of unlimited
    customValidator: (data: any) => {
        
            // this validator just lets everything pass
            return data;
        }
}

let CustomGoat = {
    cool: setType(bool)
    coolAndFunny: setType(myCustom)
}

// works with true or 'true' output = true
let schema = setType(bool);
schema.validate('true')

// works with true or 'true' output = ['true', 'true']
let schema = setType(myCustom);
schema.validate(['true', 'true'])

// disables strictmode and thereby required minima is ignored
let schema = setType(bool);
schema.validate(['true'],false)

// this works
let schema = setType(CustomGoat);
schema.validate({coolAndFunny: ['true', 'true'], cool: ['true']})

// this doesnt work
let schema = setType(CustomGoat);
schema.validate({keyDoNotExist: ['true', 'true'], cool: ['true']})

Global dependencies

  • nodejs
  • typescript
  • typings
  • mocha

Getting started

Initially install dependencies by running:

npm run build-env

Whenever you have made changes you can run the following command

npm run build-depoly

Scripts

In order to test the project you can now run:

npm test

To clean the project do:

npm run clean

Contribution

Modules can be created seperatly from this core project. These core modules in thie repo implements proposals from the proposals directory in ords-core. Essentially all kinds of modules can be created, but modules following the proposals will be more interopable. Below are some general rules of code:

  • Use camleCase instead of underscore
  • Document your code with comments
  • Write at least unit tests
  • Follow established directory structure

Ideas for naming to and directory structure to keep consistensy modules/:type/:type.:custom.ts where type is the type of module and custom can be everything. A mongodb db will be modules/database/database.mongo.ts with the class name being DatabaseMongo.

Versioning

We use schemantic versioning. Do no introduce backwards compatible breakable code without upgrading the software version to a major release.