diff --git a/types/r-script/index.d.ts b/types/r-script/index.d.ts new file mode 100644 index 0000000000..36e611d98a --- /dev/null +++ b/types/r-script/index.d.ts @@ -0,0 +1,32 @@ +// Type definitions for r-script 0.0 +// Project: https://github.com/joshkatz/r-script +// Definitions by: Adrian Leonhard +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +interface R { + data(...args: any[]): this; + call(callback: (err: any, d: any) => void): void; + call(options: R.Options, callback: (err: any, d: any) => void): void; + callSync(options?: R.Options): any; +} +declare namespace R { + interface Options { + dataframe?: "rows" | "colums" | "values"; + matrix?: "rowmajor" | "columnmajor"; + Date?: "ISO8601" | "epoch"; + POSIXt?: "string" | "ISO8601" | "epoch" | "mongo"; + factor?: "string" | "integer"; + complex?: "string" | "list"; + raw?: "base64" | "hex" | "mongo"; + null?: "list" | "null"; + na?: "null" | "string"; + auto_unbox?: boolean; + digits?: number; + pretty?: boolean; + force?: boolean; + [key: string]: any; + } +} +declare function R(scriptPath: string): R; +export = R; diff --git a/types/r-script/r-script-tests.ts b/types/r-script/r-script-tests.ts new file mode 100644 index 0000000000..91ad055c73 --- /dev/null +++ b/types/r-script/r-script-tests.ts @@ -0,0 +1,22 @@ +import R = require('r-script'); + +function RPromise(r: R): Promise { + return new Promise((resolve, reject) => { + r.call((err, d) => { + if (err) { + reject(err); + } else { + resolve(d); + } + }); + }); +} + +const options: R.Options = { + dataframe: "rows", + anotherRandomOption: true +}; +const result1 = R("foo.R").data("string data param", "another one").callSync(); +const result2 = R("foo.R").data("string data param", "another one").callSync(options); +R("foo.R").data("string data param", "another one").call(options, (err, d) => d); +R("foo.R").data("string data param", "another one").call((err, d) => d); diff --git a/types/r-script/tsconfig.json b/types/r-script/tsconfig.json new file mode 100644 index 0000000000..55f03cb8d9 --- /dev/null +++ b/types/r-script/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "r-script-tests.ts" + ] +} diff --git a/types/r-script/tslint.json b/types/r-script/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/r-script/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }