mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add typings for settings module.
This commit is contained in:
parent
420e0d5d29
commit
aaafc25a53
30
types/settings/index.d.ts
vendored
Normal file
30
types/settings/index.d.ts
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
// Type definitions for settings 0.1
|
||||
// Project: https://github.com/mgutz/node-settings
|
||||
// Definitions by: Shrey Jain <https://github.com/shreyjain1994>
|
||||
// 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;
|
||||
33
types/settings/settings-tests.ts
Normal file
33
types/settings/settings-tests.ts
Normal file
@ -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'
|
||||
}
|
||||
});
|
||||
23
types/settings/tsconfig.json
Normal file
23
types/settings/tsconfig.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
||||
3
types/settings/tslint.json
Normal file
3
types/settings/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user