mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
Merge pull request #14440 from MugeSo/add-env-to-object
Add definition for env-to-object
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import * as envToObject from 'env-to-object';
|
||||
|
||||
const map = {
|
||||
'NODE_ENV': {
|
||||
'keypath': 'env',
|
||||
'type': 'string'
|
||||
},
|
||||
'PORT': {
|
||||
'keypath': 'server.port',
|
||||
'type': 'number'
|
||||
},
|
||||
'SSL': {
|
||||
'keypath': 'server.ssl',
|
||||
'type': 'boolean'
|
||||
},
|
||||
'LOG_LEVEL': {
|
||||
'keypath': 'logger.level',
|
||||
'type': 'string'
|
||||
},
|
||||
'INT': {
|
||||
'keypath': 'int',
|
||||
'type': 'integer',
|
||||
'radix': '2'
|
||||
}
|
||||
};
|
||||
|
||||
const result1:any = envToObject(map);
|
||||
const result2:any = envToObject(map, {
|
||||
parsers: {
|
||||
'my-custom-type': (str: string, opts: any) => {
|
||||
let foo: any = JSON.parse(str);
|
||||
return foo;
|
||||
}
|
||||
}
|
||||
});
|
||||
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
// Type definitions for env-to-object 1.1
|
||||
// Project: https://github.com/kgryte/node-env-to-object#readme
|
||||
// Definitions by: TANAKA Koichi <https://github.com/MugeSo>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace env {
|
||||
export interface Mappings {
|
||||
[enviromentVariableName: string]: Mapping;
|
||||
}
|
||||
|
||||
export type Mapping = IntegerMapping | BooleanMapping | GenericMapping;
|
||||
|
||||
interface GenericMapping {
|
||||
keypath: string;
|
||||
type?: string;
|
||||
[opt: string]: any;
|
||||
}
|
||||
|
||||
interface IntegerMapping extends GenericMapping {
|
||||
type: "integer";
|
||||
radix: number;
|
||||
}
|
||||
|
||||
interface BooleanMapping {
|
||||
type: "boolean";
|
||||
strict: boolean;
|
||||
}
|
||||
|
||||
export interface Parsers {
|
||||
[parserName: string]: (str: string, opts: any) => any;
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
parsers: Parsers;
|
||||
}
|
||||
}
|
||||
|
||||
declare function env(map: env.Mappings, options?: env.Options): any;
|
||||
export = env;
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"env-to-object-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user