Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@mironal/validate-ts

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mironal/validate-ts

The object validator for TypeScript.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

validate-{TS}

The object validator for TypeScript.

Install

npm install @mironal/validate-ts

Usage

interface Example {
  n: number
  s: string
  b: boolean
  obj: { [key: string]: string }
  nested: { [key: string]: { [inner: string]: number[] } }
}

const validator = createValidatorFor<Example>({
  n: value => typeof value === "number",
  s: value => typeof value === "string",
  b: value => typeof value === "boolean",
  obj: value => typeof value === "object",
  nested: value => typeof value === "object",
})

const anyVal = {/**/}
try {
    if (validator(anyVal)) {
        // If the verification succeeds, code completion becomes possible.
    }
} catch (e) {
    // Or an exception is thrown.
    console.error(e)
}

We recommend that you use @sindresorhus/is to write validator more easily.

const is = require('@sindresorhus/is')

const validator = createValidatorFor<Example>({
  n: value => is.number,
  s: value => is.string,
  b: value => is.boolean
  obj: value => is.object,
  nested: value => is.object,
})

TODO

  • more test
  • more useful functions
    • compose validator

Keywords

scheme

FAQs

Package last updated on 27 May 2018

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