1.1.4 • Published 7 years ago

tape-schema v1.1.4

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

logo

tape-schema Build Status

Schema validation for node.js inside tape test harness.

  • compare javascript object to a schema
  • combine schemas to make testing more consistent
  • pinpoint error, even in deeply nested objects
  • powerful any function provides flexibility
  • validate missing schema definition, error if an object contains more data than schema

install

npm install --save-dev tape-schema

example

const test = require('tape')
const schema = require('tape-schema')

const schemaObject = {
	id: schema.number,
	name: schema.string,
	age: schema.any([null, schema.naturalNumber]),
	friendList: [
		{
			id: schema.number,
			name: schema.string
		}
	]
}

const object = {
	id: 1,
	name: 'Edgars',
	age: null,
	friendList: [
		{
			id: 2,
			name: 'Joe'
		},
		{
			id: 3,
			name: 'Kate'
		}
	]
}

test('Readme test', t => {
	schema.test(t, schemaObject, object)
	t.end()
})

shot

API

schema.test(tape, schema, object)

Validate schema agains given object

string

Specifies that the input is an typeof string.

const schemaObject = {
 	name: schema.string
}

number

Specifies that the input is number.

const schemaObject = {
 	discount: schema.number
}

naturalNumber

Specifies that the input is natural number. (including 0)

const schemaObject = {
 	age: schema.naturalNumber
}

boolean

Specifies that the input is boolean.

const schemaObject = {
 	isOnline: schema.boolean
}

any(values)

Specifies that the input is any value in array.

const schemaObject = {
 	task: schema.any([null, schema.string, 'assigned'])
}

latitude

Specifies that the input is latitude.

const schemaObject = {
 	latitude: schema.latitude
}

longitude

Specifies that the input is longitude.

const schemaObject = {
 	longitude: schema.longitude
}

func

Specifies that the input is typeof function.

const schemaObject = {
 	foo: schema.func
}

regexTest

Specifies that the input shoud be validated by regex test

const schemaObject = {
 	string: schema.regexTest(/^Edgars$/)
}

undef

Specifies that the input shoud be typeof undefined

const schemaObject = {
 	string: schema.undef
}
1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.5

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago