@openrailuk/common

3.4.0 • Public • Published

country license npm (scoped) status pipeline coverage slack

A package for common files and functions between the various open rail UK packages

info

This repository is hosted on GitLab as common-nodejs. The GitHub repository is a downstream repository where all changes from GitLab are pushed. Please raise any issues or pull requests on the GitLab repository.

usage

To use the common-nodejs package you need to import the required classes and functions in which your application needs, this can be done as follows:

import { Location, Station } from '@openrailuk/common';

or this for everything:

import * as common from '@openrailuk/common');

an example of using the classes:

import { Station } from '@openrailuk/common';

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:

import { Station } from '@openrailuk/common';

const stations = stationArr.map(station => new 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(params) { return 'stuff'; }
  };
};

and this can be applied by calling (re replacing station with the intended class to apply the mixin too:

import * as common from '@openrailuk/common';

common.stationMixer(mixin);

documentation

You might be wondering where to find information about how to use this package, fear not all documentation for open rail packages can be found on the doc site and documentation specific to this package can be found under @openrailuk/common

Package Sidebar

Install

npm i @openrailuk/common

Weekly Downloads

1

Version

3.4.0

License

MIT

Unpacked Size

287 kB

Total Files

34

Last publish

Collaborators

  • carboncollins