Added ns-api typings

This commit is contained in:
Sander Koenders 2017-01-28 22:56:51 +01:00
parent 14db63a765
commit 65131e2649
No known key found for this signature in database
GPG Key ID: 4C8D166407DF5DD7
4 changed files with 143 additions and 0 deletions

66
ns-api/index.d.ts vendored Normal file
View File

@ -0,0 +1,66 @@
// Type definitions for ns-api 2.0
// Project: https://github.com/fvdm/nodejs-ns-api#readme
// Definitions by: Sander Koenders <https://github.com/Archcry>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = nsApi;
declare function nsApi(conf: nsApi.Configuration): nsApi;
interface nsApi {
/**
* Vertrektijden - departure times
*
* @callback callback
* @param station {string} - Station ID
* @param callback {function} - `function (err, data) {}`
* @returns {void}
*/
vertrektijden(station: string, callback: (err: string, data: {}) => void): void;
/**
* Reisadvies - travel advise
*
* @callback callback
* @param params {object} - Parameters
* @param callback {function} - `function (err, data) {}`
* @returns {void}
*/
reisadvies(params: {}, callback: (err: string, data: {}) => void): void;
/**
* Prijzen - tariffs
*
* @callback callback
* @param params {object} - Parameters
* @param callback {function} - `function (err, data) {}`
* @returns {void}
*/
prijzen(params: {}, callback: (err: any, data: {}) => void): void;
/**
* List available stations
*
* @callback callback
* @param [treeKey] {string} - Group by this key
* @param callback {function} - `function (err, data) {}`
*/
stations(treeKey: string, callback: (err: string, data: {}) => void): void;
stations(callback: (err: string, data: {}) => void): void;
/**
* List disruptions
*
* @callback callback
* @param params {object} - Parameters
* @param callback {function} - `function (err, data) {}`
*/
storingen(params: {}, callback: (err: string, data: {}) => void): void;
}
declare namespace nsApi {
interface Configuration {
username: string;
password: string;
timeout?: number;
}
}

56
ns-api/ns-api-tests.ts Normal file
View File

@ -0,0 +1,56 @@
import * as NsApi from "ns-api";
let ns: NsApi = NsApi({
username: "",
password: "",
timeout: 1500
});
ns.vertrektijden("", (err: any, data: Object) => {
if(err) {
console.log(err);
} else {
console.log(data);
}
});
// Get travel advise
ns.reisadvies ({}, (err: any, data: Object) => {
if(err) {
console.log(err);
} else {
console.log(data);
}
});
ns.prijzen({}, (err: any, data: Object) => {
if(err) {
console.log(err);
} else {
console.log(data);
}
});
ns.stations("code", (err: any, data: Object) => {
if(err) {
console.log(err);
} else {
console.log(data);
}
});
ns.stations((err: any, data: Object) => {
if(err) {
console.log(err);
} else {
console.log(data);
}
});
ns.storingen({}, (err: any, data: Object) => {
if(err) {
console.log(err);
} else {
console.log(data);
}
});

20
ns-api/tsconfig.json Normal file
View File

@ -0,0 +1,20 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ns-api-tests.ts"
]
}

1
ns-api/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "../tslint.json" }