From e5bec20ac0e62bcc3649d2eb03cf87db6bd773d5 Mon Sep 17 00:00:00 2001 From: ikatyang Date: Mon, 21 Aug 2017 13:12:21 +0800 Subject: [PATCH] feat(require-from-string): initial commit --- types/require-from-string/index.d.ts | 27 +++++++++++++++++++ .../require-from-string-tests.ts | 9 +++++++ types/require-from-string/tsconfig.json | 15 +++++++++++ types/require-from-string/tslint.json | 1 + 4 files changed, 52 insertions(+) create mode 100644 types/require-from-string/index.d.ts create mode 100644 types/require-from-string/require-from-string-tests.ts create mode 100644 types/require-from-string/tsconfig.json create mode 100644 types/require-from-string/tslint.json diff --git a/types/require-from-string/index.d.ts b/types/require-from-string/index.d.ts new file mode 100644 index 0000000000..e694b34931 --- /dev/null +++ b/types/require-from-string/index.d.ts @@ -0,0 +1,27 @@ +// Type definitions for require-from-string 1.2 +// Project: https://github.com/floatdrop/require-from-string +// Definitions by: Ika +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * Load module from string in Node. + */ +declare function requireFromString(code: string, options?: requireFromString.Options): any; +declare function requireFromString(code: string, filename?: string, options?: requireFromString.Options): any; + +declare namespace requireFromString { + interface Options { + /** + * List of `paths`, that will be appended to module `paths`. + * Useful when you want to be able require modules from these paths. + */ + appendPaths?: string[]; + /** + * List of `paths`, that will be preppended to module `paths`. + * Useful when you want to be able require modules from these paths. + */ + prependPaths?: string[]; + } +} + +export = requireFromString; diff --git a/types/require-from-string/require-from-string-tests.ts b/types/require-from-string/require-from-string-tests.ts new file mode 100644 index 0000000000..bb9787c179 --- /dev/null +++ b/types/require-from-string/require-from-string-tests.ts @@ -0,0 +1,9 @@ +import requireFromString = require('require-from-string'); + +const moduleA1 = requireFromString('module.exports = 123'); + +const moduleA2 = requireFromString('module.exports = 123', { appendPaths: ['some-path'] }); + +const moduleB1 = requireFromString('module.exports = { a: 1, b: 2, c: 3 }', 'abc.js'); + +const moduleB2 = requireFromString('module.exports = { a: 1, b: 2, c: 3 }', 'abc.js', { prependPaths: ['some-path'] }); diff --git a/types/require-from-string/tsconfig.json b/types/require-from-string/tsconfig.json new file mode 100644 index 0000000000..cb876e2322 --- /dev/null +++ b/types/require-from-string/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "require-from-string-tests.ts"] +} diff --git a/types/require-from-string/tslint.json b/types/require-from-string/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/require-from-string/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }