diff --git a/types/settings/index.d.ts b/types/settings/index.d.ts new file mode 100644 index 0000000000..1c7ec115de --- /dev/null +++ b/types/settings/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for settings 0.1 +// Project: https://github.com/mgutz/node-settings +// Definitions by: Shrey Jain +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +// This wierd looking class definition is necessary since the function that the module +// exposes NEEDS (will throw error otherwise) to be called with the `new` keyword +// BUT returns a random object...not an instance of the class +declare class Settings { + constructor(pathOrModule: Settings.PathOrModule, options?: Settings.Options); + + [setting: string]: any; +} + +declare namespace Settings { + interface Options { + env?: string; + root?: string; + defaults?: any; + } + + type PathOrModule = string | + { + forceEnv?: string, + common: any, // error is thrown if 'common' object is not provided + [envName: string]: any + }; +} +export = Settings; diff --git a/types/settings/settings-tests.ts b/types/settings/settings-tests.ts new file mode 100644 index 0000000000..e872298796 --- /dev/null +++ b/types/settings/settings-tests.ts @@ -0,0 +1,33 @@ +import Settings = require('settings'); + +// works without options +new Settings('foo'); + +// works with path to module containing settings +const settings = new Settings('./path/to/my/config'); +// any prop is accessible on returned value +settings.hello = 'world'; +const foo = settings.bar; + +// works with settings object +const settings2 = new Settings({ + common: {setting: 'mySetting'}, production: { + hello: 'bar' + } +}); +settings2.hello = 'world'; + +// allows for forceEnv in settings object +const settings3 = new Settings({ + common: {}, + forceEnv: 'production' +}); + +// allows options +const settings4 = new Settings('./path/to/my/settings', { + root: 'someRoot', + env: 'development', + defaults: { + someSetting: 'settingValue' + } +}); diff --git a/types/settings/tsconfig.json b/types/settings/tsconfig.json new file mode 100644 index 0000000000..d565388a77 --- /dev/null +++ b/types/settings/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "settings-tests.ts" + ] +} diff --git a/types/settings/tslint.json b/types/settings/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/settings/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}