@01/env 2.0.3 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/junit.xml DELETED
@@ -1,39 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <testsuites name="jest tests" tests="17" failures="0" time="3.445">
3
- <testsuite name="env test suite" errors="0" failures="0" skipped="0" timestamp="2020-10-10T23:02:22" time="2.767" tests="17">
4
- <testcase classname="env test suite When reading string env variable Should return string" name="env test suite When reading string env variable Should return string" time="0.002">
5
- </testcase>
6
- <testcase classname="env test suite When reading undefined string env variable Should return default value" name="env test suite When reading undefined string env variable Should return default value" time="0">
7
- </testcase>
8
- <testcase classname="env test suite When reading undefined string env variable Should return undefined if there is no default value" name="env test suite When reading undefined string env variable Should return undefined if there is no default value" time="0.001">
9
- </testcase>
10
- <testcase classname="env test suite When reading int env variable Should return int" name="env test suite When reading int env variable Should return int" time="0">
11
- </testcase>
12
- <testcase classname="env test suite When reading undefined int env variable Should return default value" name="env test suite When reading undefined int env variable Should return default value" time="0">
13
- </testcase>
14
- <testcase classname="env test suite When reading undefined int env variable Should return undefined if there is no default value" name="env test suite When reading undefined int env variable Should return undefined if there is no default value" time="0">
15
- </testcase>
16
- <testcase classname="env test suite When reading float env variable Should return float" name="env test suite When reading float env variable Should return float" time="0.001">
17
- </testcase>
18
- <testcase classname="env test suite When reading undefined float env variable Should return default value" name="env test suite When reading undefined float env variable Should return default value" time="0">
19
- </testcase>
20
- <testcase classname="env test suite When reading undefined float env variable Should return undefined if there is no default value" name="env test suite When reading undefined float env variable Should return undefined if there is no default value" time="0.001">
21
- </testcase>
22
- <testcase classname="env test suite When reading boolean:true env variable Should return boolean:true" name="env test suite When reading boolean:true env variable Should return boolean:true" time="0">
23
- </testcase>
24
- <testcase classname="env test suite When reading boolean:false env variable Should return boolean:false" name="env test suite When reading boolean:false env variable Should return boolean:false" time="0">
25
- </testcase>
26
- <testcase classname="env test suite When reading undefined float env variable Should return default value" name="env test suite When reading undefined float env variable Should return default value" time="0.001">
27
- </testcase>
28
- <testcase classname="env test suite When reading undefined float env variable Should return undefined if there is no default value" name="env test suite When reading undefined float env variable Should return undefined if there is no default value" time="0">
29
- </testcase>
30
- <testcase classname="env test suite envJson test suite When reading valid json env variable Should return parsed json value" name="env test suite envJson test suite When reading valid json env variable Should return parsed json value" time="0.002">
31
- </testcase>
32
- <testcase classname="env test suite envJson test suite When reading invalid json env variable Should return parsed json value" name="env test suite envJson test suite When reading invalid json env variable Should return parsed json value" time="0">
33
- </testcase>
34
- <testcase classname="env test suite envJson test suite When reading undefined json env variable Should return default value" name="env test suite envJson test suite When reading undefined json env variable Should return default value" time="0.001">
35
- </testcase>
36
- <testcase classname="env test suite envJson test suite When reading undefined json env variable Should return undefined if there is no default value" name="env test suite envJson test suite When reading undefined json env variable Should return undefined if there is no default value" time="0">
37
- </testcase>
38
- </testsuite>
39
- </testsuites>
package/src/env.spec.ts DELETED
@@ -1,113 +0,0 @@
1
- import { env, envInt, envFloat, envBoolean, envJson } from "./env";
2
-
3
- describe("env test suite", () => {
4
- describe("When reading string env variable", () => {
5
- it("Should return string", () => {
6
- process.env.STRING_VALUE = "STRING_VALUE";
7
- expect(env("STRING_VALUE", "DEFAULT_VALUE")).toBe("STRING_VALUE");
8
- });
9
- });
10
-
11
- describe("When reading undefined string env variable", () => {
12
- it("Should return default value", () => {
13
- delete process.env.STRING_VALUE;
14
- expect(env("STRING_VALUE", "DEFAULT_VALUE")).toBe("DEFAULT_VALUE");
15
- });
16
-
17
- it("Should return undefined if there is no default value", () => {
18
- delete process.env.STRING_VALUE;
19
- expect(env("STRING_VALUE")).toBeUndefined();
20
- });
21
- });
22
-
23
- describe("When reading int env variable", () => {
24
- it("Should return int", () => {
25
- process.env.INT_VALUE = "9835591278";
26
- expect(envInt("INT_VALUE", 1)).toBe(9835591278);
27
- });
28
- });
29
-
30
- describe("When reading undefined int env variable", () => {
31
- it("Should return default value", () => {
32
- delete process.env.INT_VALUE;
33
- expect(envInt("INT_VALUE", 1)).toBe(1);
34
- });
35
-
36
- it("Should return undefined if there is no default value", () => {
37
- delete process.env.INT_VALUE;
38
- expect(envInt("INT_VALUE")).toBeUndefined();
39
- });
40
- });
41
-
42
- describe("When reading float env variable", () => {
43
- it("Should return float", () => {
44
- process.env.FLOAT_VALUE = "5.2694168";
45
- expect(envFloat("FLOAT_VALUE", 1.5)).toBe(5.2694168);
46
- });
47
- });
48
-
49
- describe("When reading undefined float env variable", () => {
50
- it("Should return default value", () => {
51
- delete process.env.FLOAT_VALUE;
52
- expect(envFloat("FLOAT_VALUE", 1.5)).toBe(1.5);
53
- });
54
-
55
- it("Should return undefined if there is no default value", () => {
56
- delete process.env.FLOAT_VALUE;
57
- expect(envFloat("FLOAT_VALUE")).toBeUndefined();
58
- });
59
- });
60
-
61
- describe("When reading boolean:true env variable", () => {
62
- it("Should return boolean:true", () => {
63
- process.env.BOOLEAN_VALUE = "true";
64
- expect(envBoolean("BOOLEAN_VALUE", false)).toBe(true);
65
- });
66
- });
67
-
68
- describe("When reading boolean:false env variable", () => {
69
- it("Should return boolean:false", () => {
70
- process.env.BOOLEAN_VALUE = "false";
71
- expect(envBoolean("BOOLEAN_VALUE", false)).toBe(false);
72
- });
73
- });
74
-
75
- describe("When reading undefined float env variable", () => {
76
- it("Should return default value", () => {
77
- delete process.env.BOOLEAN_VALUE;
78
- expect(envBoolean("BOOLEAN_VALUE", true)).toBe(true);
79
- });
80
-
81
- it("Should return undefined if there is no default value", () => {
82
- delete process.env.BOOLEAN_VALUE;
83
- expect(envBoolean("BOOLEAN_VALUE")).toBeUndefined();
84
- });
85
- });
86
-
87
- describe("envJson test suite", () => {
88
- describe("When reading valid json env variable", () => {
89
- it("Should return parsed json value", () => {
90
- process.env.JSON_VALUE = `{ "value": "some-value" }`;
91
- expect(envJson("JSON_VALUE")).toEqual({ value: "some-value" });
92
- });
93
- });
94
- describe("When reading invalid json env variable", () => {
95
- it("Should return parsed json value", () => {
96
- process.env.JSON_VALUE = `{ value: "some-value" }`;
97
- expect(envJson("JSON_VALUE")).toBeUndefined();
98
- });
99
- });
100
- describe("When reading undefined json env variable", () => {
101
- it("Should return default value", () => {
102
- delete process.env.JSON_VALUE;
103
- expect(envJson("JSON_VALUE", { value: true })).toEqual({
104
- value: true,
105
- });
106
- });
107
- it("Should return undefined if there is no default value", () => {
108
- delete process.env.JSON_VALUE;
109
- expect(envJson("JSON_VALUE")).toBeUndefined();
110
- });
111
- });
112
- });
113
- });
package/src/env.ts DELETED
@@ -1,47 +0,0 @@
1
- /**
2
- * Created by n.vinayakan on 06.06.17.
3
- */
4
- //tslint:disable-next-line
5
- export const isBrowser = new Function(
6
- "try {return this===window;}catch(e){ return false;}"
7
- )();
8
- //tslint:disable-next-line
9
- export const isWorker = new Function(
10
- "try {return this===self && typeof importScripts !== 'undefined';}catch(e){return false;}"
11
- )();
12
- //tslint:disable-next-line
13
- export const isNode =
14
- typeof global !== "undefined" &&
15
- typeof process !== "undefined" &&
16
- typeof process.stdout !== "undefined";
17
-
18
- const U = undefined as unknown;
19
- type U = undefined;
20
-
21
- export function env<T = U>(name: string, defaultValue: T = U as T) {
22
- const envValue = process.env[name];
23
- return envValue || defaultValue;
24
- }
25
-
26
- export function envInt<T = U>(name: string, defaultValue: T = U as T) {
27
- const envValue = process.env[name];
28
- return envValue ? parseInt(envValue) : defaultValue;
29
- }
30
-
31
- export function envFloat<T = U>(name: string, defaultValue: T = U as T) {
32
- const envValue = process.env[name];
33
- return envValue ? parseFloat(envValue) : defaultValue;
34
- }
35
- export function envBoolean<T = U>(name: string, defaultValue: T = U as T) {
36
- const envValue = process.env[name];
37
- return envValue ? envValue === "true" : defaultValue;
38
- }
39
- export function envJson<T = U>(name: string, defaultValue: T = U as T): any {
40
- const envValue = process.env[name];
41
- if (envValue) {
42
- try {
43
- return JSON.parse(envValue);
44
- } catch (e) {}
45
- }
46
- return defaultValue;
47
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./env";
package/tsconfig.json DELETED
@@ -1,33 +0,0 @@
1
- {
2
- "include": ["src"],
3
- "compilerOptions": {
4
- "module": "CommonJS",
5
- "target": "es2015",
6
- "lib": ["dom", "esnext"],
7
- "importHelpers": true,
8
- "declaration": true,
9
- "declarationMap": true,
10
- "sourceMap": true,
11
- "rootDir": "./src",
12
- "strict": true,
13
- "noImplicitAny": true,
14
- "strictNullChecks": true,
15
- "strictFunctionTypes": true,
16
- "strictPropertyInitialization": true,
17
- "noImplicitThis": true,
18
- "alwaysStrict": true,
19
- "noUnusedLocals": true,
20
- "noUnusedParameters": true,
21
- "noImplicitReturns": true,
22
- "noFallthroughCasesInSwitch": true,
23
- "moduleResolution": "node",
24
- "baseUrl": "./",
25
- "outDir": "./dist",
26
- "paths": {
27
- "~/*": ["./src/*"]
28
- },
29
- "jsx": "react",
30
- "esModuleInterop": true
31
- },
32
- "exclude": ["node_modules", "**/*.spec.ts"]
33
- }
package/webpack.config.ts DELETED
@@ -1,14 +0,0 @@
1
- import { WebpackNodeConfig } from "@01/core-utils";
2
-
3
- const entries = {
4
- index: ["./src/index.ts"],
5
- };
6
-
7
- const baseDir = __dirname;
8
- const baseConfig = WebpackNodeConfig({
9
- baseDir,
10
- entries,
11
- type: "library",
12
- });
13
-
14
- export default baseConfig;