Introduce asenv (#18573)

This commit is contained in:
remisery 2017-08-02 21:06:26 +02:00 committed by Sheetal Nandi
parent 1e211cd0d4
commit eddbc9e6f9
4 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,26 @@
import { unlessProduction, isDevelopment, isTest, isProduction, getEnv, setEnv } from 'asenv';
import { equal, throws } from 'assert';
// Test isDevelopment()
setEnv('development');
equal(getEnv(), 'development', 'Should return be true');
equal(isDevelopment(), true, 'NODE_ENV should be "development"');
equal(isTest(), false, 'NODE_ENV should be "development"');
equal(isProduction(), false, 'NODE_ENV should be "development"');
equal(unlessProduction(() => true), true, "Shound return true");
// Test isTest()
setEnv('test');
equal(getEnv(), 'test', 'Should return be true');
equal(isDevelopment(), false, 'NODE_ENV should be "test"');
equal(isTest(), true, 'NODE_ENV should be "test"');
equal(isProduction(), false, 'NODE_ENV should be "test"');
equal(unlessProduction(() => true), true, "Shound return true");
// Test isProduction()
setEnv('production');
equal(getEnv(), 'production', 'Should return be true');
equal(isDevelopment(), false, 'NODE_ENV should be "production"');
equal(isTest(), false, 'NODE_ENV should be "production"');
equal(isProduction(), true, 'NODE_ENV should be "production"');
equal(unlessProduction(() => true), false, "Shound return false");

18
types/asenv/index.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
// Type definitions for asenv 1.1
// Project: https://github.com/a-labo/asenv#readme
// Definitions by: Remisery <https://github.com/remisery>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
export function getEnv(): string;
export function isDevelopment(): boolean;
export function isProduction(): boolean;
export function isTest(): boolean;
export function setEnv(env: string): void;
export function unlessProduction(handle: () => any): any;

22
types/asenv/tsconfig.json Normal file
View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"asenv-tests.ts"
]
}

3
types/asenv/tslint.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}