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

commonform-validate

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commonform-validate

validate Common Forms

  • 0.6.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-37.5%
Maintainers
1
Weekly downloads
 
Created
Source
var valid = require('commonform-validate')

Forms

Simple Example

var assert = require('assert')

assert(valid.form({content: ['A'], conspicuous: 'yes'}))

No Additional Properties

assert(!valid.form({content: ['A'], extra: false}))

Plain Objects

var invalidForm = function () {}
invalidForm.content = ['A']
assert(!valid.form(invalidForm))

Content

assert(!valid.form({content: 'A'}))

assert(!valid.form({content: []}))

Form content arrays cannot contain contiguous strings:

assert(
  !valid.form({content: ['a', 'b']}),
  'forms cannot contain contiguous strings'
)

Or contiguous blanks:

assert(
  !valid.form({content: [{blank: ''}, {blank: ''}]}),
  'forms cannot contain contiguous blanks'
)

Nor can they contain empty strings:

assert(
  !valid.form({content: ['']}),
  'forms cannot contain empty strings'
)

If the first element of content is a string, it can't start with space:

assert(!valid.form({content: [' a']}))

Nor can a final string element end with space:

assert(!valid.form({content: ['a ']}))

Conspicuous

Forms that must be typeset conspicuously have a conspicuous property:

assert(
  valid.form({
    content: ['A'],
    conspicuous: 'yes'}),
  'form "conspicuous" properties can be "yes"'
)

That property must have the string value "yes". No other falsey values allowed:

assert(!valid.form({content: ['B'], conspicuous: true}))

assert(!valid.form({content: ['A'], conspicuous: null}))

Form Content Objects

Form content arrays can contain a variety of objects:

assert(
  valid.form({
    content: [
      'Any dispute or controversy arising under or in connection ' +
      'with this ', {use: 'Agreement'}, ' shall be settled ' +
      'exclusively by arbitration in the ',
      {blank: ''}, ', in accordance with the ' +
      'applicable rules of the American Arbitration Association ' +
      'then in effect.'
    ]
  }),
  'valid forms include the real-world example'
)

Blanks

assert(valid.blank({blank: ''}))

Definitions

assert(valid.definition({definition: 'A'}))

References

assert(valid.reference({reference: 'A'}))

Uses

assert(valid.use({use: 'A'}))

Children

Children allow forms to contain other forms, with optional headings:

assert(valid.child({form: {content: ['A']}}))

assert(valid.child({heading: 'A', form: {content: ['B']}}))

var invalidChild = function () {}
invalidChild.form = {content: ['A']}
assert(!valid.child(invalidChild))

Any text surrounding a child form can't run up to it with space:

assert(
  !valid.form({
    content: [
      'this is a space -> ',
      {form: {content: ['A']}}
    ]
  })
)

assert(
  !valid.form({
    content: [
      {form: {content: ['A']}},
      ' <- that was a space'
    ]
  })
)

Keywords

FAQs

Package last updated on 09 Aug 2016

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