New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@divine/judgement-cli

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@divine/judgement-cli

The Divine Judgement: Schema/Code generator CLI

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

The Divine Judgement

Divine Judgement is a simple, yet powerful tool for enforcing TypeScript types at runtime. It:

  1. Reads and parses interfaces, enums and other types directly from your TypeScript source files.
  2. Generates a single file that contains a JSON schema, a type map and two utility functions, as and is. You should include this file in your project.
  3. You may then use those utilities to validate untrusted data at runtime, according to the TypeScript types defined in your project.

Installation

Add @divine/judgement to dependencies and @divine/judgement-cli to devDependencies:

npm install @divine/judgement
npm install --save-dev @divine/judgement-cli

Usage

Generate the schema and validation utilities:

npm exec -- judgement-cli -p 'types/*.ts' -o schema.ts

Then, in your code:

import { as, is } from './schema';
import { readFileSync } from 'fs';

const configName = './config.json';
const configFile = as('MyConfigFile',
                      JSON.parse(readFileSync(configName, 'utf8')),
                      configName);

// configFile is typed as MyConfigFile and is guaranteed to be valid,
// or else a SchemaError would have been thrown.

const config: unknown = configFile;

if (is('MyConfigFile', config)) {
    // config is now typed as MyConfigFile and guaranteed to be valid.
}

Acknowledgements

This project is based on ts-json-schema-generator and uses Ajv for validation.

FAQs

Package last updated on 07 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc