Code Monkey home page Code Monkey logo

validate-fptf's Introduction

validate-fptf

Validate data in the Friendly Public Transport Format. Currently validates against Friendly Public Transport Format (FPTF) 1.2.1.

npm version build status ISC-licensed chat on gitter

Installing

npm install validate-fptf

Usage

const createValidate = require('validate-fptf')

const validate = createValidate() // you may pass in custom validators here

validate({
  type: 'journey',
  id: '12345',
  legs: [{
    origin: {
      type: 'station',
      id: '12345678',
      name: 'Foo'
    },
    destination: {
      type: 'station',
      id: '87654321',
      name: 'Bar'
    },
    departure: '2017-03-16T20:00:00+01:00',
    departurePlatform: '4-1',
    arrival: '2017-03-17T15:00:00+02:00',
    arrivalPlatform: '9',
    schedule: '1234',
    mode: 'walking',
    public: true,
    operator: 'sncf'
  }],
  price: {
    amount: 19.95,
    currency: 'EUR'
  }
})

validate({
  type: 'station',
  id: '123',
  name: 'foo',
  location: {
    type: 'location',
    latitude: 1,
    longitude: 2
  }
}, ['station', 'stop'])

API

const validate = createValidate(customValidators = {})

You may provide an object customValidators, where each key is an FPTF type, and the corresponding function validates an FPTF object of this type.

validate(item, types = allTypes, name = 'item')

validate recursively validates item. Throws an AssertionError if something is not valid FPTF 1.2.1.

To validate against one or more specific FPTF types, provide a string or an array of strings via the types parameter.

To get more meaningful assertion errors, provide the name of your item via the name parameter.

Contributing

If you have a question or have difficulties using validate-fptf, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.

validate-fptf's People

Contributors

derhuerst avatar ialokim avatar juliuste avatar snyk-bot avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

ialokim

validate-fptf's Issues

make it easy to validate against specific FPTF type(s)

Not sure if this is already possible, but I would like to have a way to make sure an object is e.g. a valid station object. Perhaps a second argument to createValidate listing the type(s) to validate against could do it.

error when validating station with regions key

Validating this station

{
	type: 'station',
	id: '123456',
	name: 'Hauptbahnhof',
	location: {
		type: 'location',
		latitude: 45,
		longitude: 13
	},
	regions: ['1234']
}

Fails with

AssertionError [ERR_ASSERTION]: objregions[1] must be a string
    at validateReference (/node_modules/validate-fptf/lib/reference.js:9:5)
    at recurse (/node_modules/validate-fptf/index.js:45:7)
    at validateStation (/node_modules/validate-fptf/station.js:32:7)
    at recurse (/node_modules/validate-fptf/index.js:43:7)
    at validate (/node_modules/validate-fptf/index.js:53:10)
    at Object.<anonymous> (/test.js:21:1)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)

Same thing happens for regions with stations key.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.