Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
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

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

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