openraildata-common v2.1.2
openraildata-common
A package for common files and functions between the various openraildata packages
usage
To use the openraildata-common package you need to import the required classes and functions in which your application needs, this can be done as follows:
const { Location, Station } = require('openraildata-common');
or this for everything:
const common = require('openraildata-common');
the currently available classes that can be used are listed below
an example of using the classes are:
const station = new Station(stationRefDataJSON);
console.log(station.plannedTimeOfArrival);
or if you want to convert a large array of stations 'stationArr' into there respective Station class:
const stations = stationArr.map(station => new common.Station(station));
Mixins can be applied to all of the base models that this package provides. A sample mixin would be as follows:
const mixin = (SuperClass) => {
return class StationMix extends SuperClass {
constructor(payload) { super(payload); }
newFunction(parms) { return 'stuff'; }
};
};
and this can be applied by calling (re replacing station with the intended class to apply the mixin too:
const common = require('openraildata-common);
common.stationMixer(mixin);
all the functions for this are documented in the API docs
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago