From 69e21d0760b694962fc4240e6d7b18b344aa2036 Mon Sep 17 00:00:00 2001 From: Roman Date: Sun, 13 Sep 2015 15:39:10 +0300 Subject: [PATCH 1/3] node-config support --- node-config/node-config-tests.ts | 28 ++++++++++++++++++++++++++ node-config/node-config.d.ts | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 node-config/node-config-tests.ts create mode 100644 node-config/node-config.d.ts diff --git a/node-config/node-config-tests.ts b/node-config/node-config-tests.ts new file mode 100644 index 000000000..9883a8a21 --- /dev/null +++ b/node-config/node-config-tests.ts @@ -0,0 +1,28 @@ +/// + +import config = require('config'); + +var value: string = config.get(""); +var has: boolean = config.has(""); + +// util tests: +var extended1: any = config.util.extendDeep({}, {}); +var extended2: any = config.util.extendDeep({}, {}, 20); + +var clone1: any = config.util.cloneDeep({}); +var clone2: any = config.util.cloneDeep({}, 20); + +var equals1: boolean = config.util.equalsDeep({}, {}); +var equals2: boolean = config.util.equalsDeep({}, {}, 20); + +var diff1: any = config.util.diffDeep({}, {}); +var diff2: any = config.util.diffDeep({}, {}, 20); + +var immutable1: any = config.util.makeImmutable({}); +var immutable2: any = config.util.makeImmutable({}, ""); +var immutable3: any = config.util.makeImmutable({}, "", ""); + +var hidden1: any = config.util.makeHidden({}, ""); +var hidden2: any = config.util.makeHidden({}, "", ""); + +var env: string = config.util.getEnv(""); diff --git a/node-config/node-config.d.ts b/node-config/node-config.d.ts new file mode 100644 index 000000000..3db296850 --- /dev/null +++ b/node-config/node-config.d.ts @@ -0,0 +1,34 @@ +// Type definitions for node-config +// Project: https://github.com/lorenwest/node-config +// Definitions by: Roman Korneev +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +// see https://github.com/lorenwest/node-config/wiki/Using-Config-Utilities +interface IUtil { + // Extend an object (and any object it contains) with one or more objects (and objects contained in them). + extendDeep(mergeInto: any, mergeFrom: any, depth?: number): any; + + // Return a deep copy of the specified object. + cloneDeep(copyFrom: any, depth?: number): any; + + // Return true if two objects have equal contents. + equalsDeep(object1: any, object2: any, dept?: number): boolean; + + // Returns an object containing all elements that differ between two objects. + diffDeep(object1: any, object2: any, depth?: number): any; + + // Make a javascript object property immutable (assuring it cannot be changed from the current value). + makeImmutable(object: any, propertyName?: string, propertyValue?: string): any; + + // Make an object property hidden so it doesn't appear when enumerating elements of the object. + makeHidden(object: any, propertyName: string, propertyValue?: string): any; + + // Get the current value of a config environment variable + getEnv(varName: string): string; +} + +declare module "config" { + export function get(setting: string): any; + export function has(setting: string): boolean; + export var util: IUtil; +} From d4b7e07fa6de575777a0b979b210aad23dd8bec5 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 14 Sep 2015 11:43:48 +0300 Subject: [PATCH 2/3] 1. Use generic for the config.get method. 2. Include IUtil definition in the module scope. --- node-config/node-config-tests.ts | 4 ++- node-config/node-config.d.ts | 50 ++++++++++++++++---------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/node-config/node-config-tests.ts b/node-config/node-config-tests.ts index 9883a8a21..f20ea7f30 100644 --- a/node-config/node-config-tests.ts +++ b/node-config/node-config-tests.ts @@ -2,7 +2,9 @@ import config = require('config'); -var value: string = config.get(""); +var value1: string = config.get(""); +var value2: any = config.get(""); + var has: boolean = config.has(""); // util tests: diff --git a/node-config/node-config.d.ts b/node-config/node-config.d.ts index 3db296850..c37eddae9 100644 --- a/node-config/node-config.d.ts +++ b/node-config/node-config.d.ts @@ -3,32 +3,32 @@ // Definitions by: Roman Korneev // Definitions: https://github.com/borisyankov/DefinitelyTyped -// see https://github.com/lorenwest/node-config/wiki/Using-Config-Utilities -interface IUtil { - // Extend an object (and any object it contains) with one or more objects (and objects contained in them). - extendDeep(mergeInto: any, mergeFrom: any, depth?: number): any; - - // Return a deep copy of the specified object. - cloneDeep(copyFrom: any, depth?: number): any; - - // Return true if two objects have equal contents. - equalsDeep(object1: any, object2: any, dept?: number): boolean; - - // Returns an object containing all elements that differ between two objects. - diffDeep(object1: any, object2: any, depth?: number): any; - - // Make a javascript object property immutable (assuring it cannot be changed from the current value). - makeImmutable(object: any, propertyName?: string, propertyValue?: string): any; - - // Make an object property hidden so it doesn't appear when enumerating elements of the object. - makeHidden(object: any, propertyName: string, propertyValue?: string): any; - - // Get the current value of a config environment variable - getEnv(varName: string): string; -} - declare module "config" { - export function get(setting: string): any; + // see https://github.com/lorenwest/node-config/wiki/Using-Config-Utilities + interface IUtil { + // Extend an object (and any object it contains) with one or more objects (and objects contained in them). + extendDeep(mergeInto: any, mergeFrom: any, depth?: number): any; + + // Return a deep copy of the specified object. + cloneDeep(copyFrom: any, depth?: number): any; + + // Return true if two objects have equal contents. + equalsDeep(object1: any, object2: any, dept?: number): boolean; + + // Returns an object containing all elements that differ between two objects. + diffDeep(object1: any, object2: any, depth?: number): any; + + // Make a javascript object property immutable (assuring it cannot be changed from the current value). + makeImmutable(object: any, propertyName?: string, propertyValue?: string): any; + + // Make an object property hidden so it doesn't appear when enumerating elements of the object. + makeHidden(object: any, propertyName: string, propertyValue?: string): any; + + // Get the current value of a config environment variable + getEnv(varName: string): string; + } + + export function get(setting: string): T; export function has(setting: string): boolean; export var util: IUtil; } From 21939fb51a4c0046a4c7ef44a10959a5faf14309 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 15 Sep 2015 13:37:24 +0300 Subject: [PATCH 3/3] rename node-config to config --- node-config/node-config-tests.ts => config/config-tests.ts | 2 +- node-config/node-config.d.ts => config/config.d.ts | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename node-config/node-config-tests.ts => config/config-tests.ts (95%) rename node-config/node-config.d.ts => config/config.d.ts (100%) diff --git a/node-config/node-config-tests.ts b/config/config-tests.ts similarity index 95% rename from node-config/node-config-tests.ts rename to config/config-tests.ts index f20ea7f30..2f53b76d6 100644 --- a/node-config/node-config-tests.ts +++ b/config/config-tests.ts @@ -1,4 +1,4 @@ -/// +/// import config = require('config'); diff --git a/node-config/node-config.d.ts b/config/config.d.ts similarity index 100% rename from node-config/node-config.d.ts rename to config/config.d.ts