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

object-model-validator

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-model-validator

Validate data models from object.

  • 1.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Simple model validator.

Build Status

Install

npm i object-model-validator

Usage

  'use strict'

  const {types, ObjectModel} = require('object-model-validator')

  const model = await new ObjectModel({
    name: types.string,
    parse: (data) => {
      return `${data.name} is Ok`
    }
  }).validate({
    name: 'Validate object'
  }).then(result => {
    console.log(result)
  })
  // {name: 'Validate Object is Ok'}

### Custom Property

let model = await new ObjectModel({
  name: types.string,
  lastName: types.string,
  fullName: {
    optional: true,
    type: types.string,
    parse: (data) => {
      return `${data.name} ${data.lastName}`
    }
  }
}).validate({name: 'Models', lastName: 'Object'})

console.log(model)
// { name: 'Models', lastName: 'Object', fullName: 'Models Object' }


Types availables

  • Integer types.integer
  • Boolean types.boolean
  • Object types.object
  • String types.string
  • Date types.date
  • Moment types.moment

## Declaration key options

  • type The type of value that the key must contain
  • in Array of available values
  • parse Function with data parameter equal to this and need return correct type value
  • optional If is required or not default false
  • format Only available in types.moment

License

MIT

Keywords

FAQs

Package last updated on 08 Feb 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