@01/env 0.1.3
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/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/env.d.ts +8 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/esm/index.js +40 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/runtime.d.ts +4 -0
- package/dist/runtime.d.ts.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 01 Alchemist
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# env
|
|
2
|
+
[](https://circleci.com/gh/01alchemist/env) [](https://codeclimate.com/github/01alchemist/env/maintainability) [](https://codeclimate.com/github/01alchemist/env/test_coverage)
|
|
3
|
+
|
|
4
|
+
Nodejs env utils
|
|
5
|
+
|
|
6
|
+
### env
|
|
7
|
+
```ts
|
|
8
|
+
const nodeEnv:string = env("NODE_ENV", "development")
|
|
9
|
+
// process.env.NODE_ENV or "development"
|
|
10
|
+
```
|
|
11
|
+
### envInt
|
|
12
|
+
```ts
|
|
13
|
+
const timeout:number = envInt("TIMEOUT", 5000)
|
|
14
|
+
// process.env.TIMEOUT as int or 5000
|
|
15
|
+
```
|
|
16
|
+
### envFloat
|
|
17
|
+
```ts
|
|
18
|
+
const scaleFactor:number = envFloat("SCALE_FACTOR", 2.56)
|
|
19
|
+
// process.env.SCALE_FACTOR as float or 2.56
|
|
20
|
+
```
|
|
21
|
+
### envBoolean
|
|
22
|
+
```ts
|
|
23
|
+
const isEnabled:boolean = envBoolean("IS_ENABLED", false)
|
|
24
|
+
// process.env.IS_ENABLED as boolean or false
|
|
25
|
+
```
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});new Function("try {return this===window;}catch(e){ return false;}")();new Function("try {return this===self && typeof importScripts !== 'undefined';}catch(e){return false;}")();const r=typeof global<"u"&&typeof process<"u"&&typeof process.stdout<"u";function o(n,t){let e;return!r&&typeof window<"u"&&window.ENV?e=window.ENV&&window.ENV[n]:typeof process<"u"&&process.env&&(e=process.env[n]),e!==void 0?e:t}function u(n,t){const e=o(n);return e?parseInt(e):t}function s(n,t){const e=o(n);return e?parseFloat(e):t}function i(n,t){const e=o(n);return e?e.toLowerCase()==="true"||e==="1":t}function c(n,t){const e=o(n);if(e)try{return JSON.parse(e)}catch{}return t}exports.env=o;exports.envBoolean=i;exports.envFloat=s;exports.envInt=u;exports.envJson=c;
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/runtime.ts","../../src/env.ts"],"sourcesContent":["//tslint:disable-next-line\nexport const isBrowser = new Function(\n 'try {return this===window;}catch(e){ return false;}'\n)()\n//tslint:disable-next-line\nexport const isWorker = new Function(\n \"try {return this===self && typeof importScripts !== 'undefined';}catch(e){return false;}\"\n)()\n//tslint:disable-next-line\nexport const isNode =\n typeof global !== 'undefined' &&\n typeof process !== 'undefined' &&\n typeof process.stdout !== 'undefined'\n","///<reference path=\"./types.d.ts\"/>\n/**\n * Created by n.vinayakan on 06.06.17.\n */\nimport { isNode } from './runtime'\n\ntype DefaultReturnType<T, U> = T extends U ? T : undefined\n\nexport function env<T extends string | undefined>(\n name: string,\n defaultValue?: T\n) {\n let value\n if (!isNode && typeof window !== 'undefined' && window.ENV) {\n value = window.ENV && window.ENV[name]\n } else if (typeof process !== 'undefined' && process.env) {\n value = process.env[name]\n }\n return value !== undefined\n ? value\n : (defaultValue as DefaultReturnType<T, string>)\n}\n\nexport function envInt<T extends number | undefined>(\n name: string,\n defaultValue?: T\n) {\n const envValue = env(name)\n return envValue\n ? parseInt(envValue)\n : (defaultValue as DefaultReturnType<T, number>)\n}\n\nexport function envFloat<T extends number | undefined>(\n name: string,\n defaultValue?: T\n) {\n const envValue = env(name)\n return envValue\n ? parseFloat(envValue)\n : (defaultValue as DefaultReturnType<T, number>)\n}\n\nexport function envBoolean<T extends boolean | undefined>(\n name: string,\n defaultValue?: T\n) {\n const envValue = env(name)\n return envValue\n ? envValue.toLowerCase() === 'true' || envValue === '1'\n : (defaultValue as DefaultReturnType<T, boolean>)\n}\n\nexport function envJson(name: string, defaultValue?: any): any {\n const envValue = env(name)\n if (envValue) {\n try {\n return JSON.parse(envValue)\n } catch (e) {}\n }\n return defaultValue\n}\n"],"names":["isNode","env","name","defaultValue","value","envInt","envValue","envFloat","envBoolean","envJson"],"mappings":"gFACyB,IAAI,SAC3B,qDACF,EAAA,EAEwB,IAAI,SAC1B,0FACF,EAAA,EAEO,MAAMA,EACX,OAAO,OAAW,KAClB,OAAO,QAAY,KACnB,OAAO,QAAQ,OAAW,ICJrB,SAASC,EACdC,EACAC,EACA,CACA,IAAIC,EACJ,MAAI,CAACJ,GAAU,OAAO,OAAW,KAAe,OAAO,IACrDI,EAAQ,OAAO,KAAO,OAAO,IAAIF,CAAI,EAC5B,OAAO,QAAY,KAAe,QAAQ,MACnDE,EAAQ,QAAQ,IAAIF,CAAI,GAEnBE,IAAU,OACbA,EACCD,CACP,CAEO,SAASE,EACdH,EACAC,EACA,CACA,MAAMG,EAAWL,EAAIC,CAAI,EACzB,OAAOI,EACH,SAASA,CAAQ,EAChBH,CACP,CAEO,SAASI,EACdL,EACAC,EACA,CACA,MAAMG,EAAWL,EAAIC,CAAI,EACzB,OAAOI,EACH,WAAWA,CAAQ,EAClBH,CACP,CAEO,SAASK,EACdN,EACAC,EACA,CACA,MAAMG,EAAWL,EAAIC,CAAI,EACzB,OAAOI,EACHA,EAAS,YAAA,IAAkB,QAAUA,IAAa,IACjDH,CACP,CAEO,SAASM,EAAQP,EAAcC,EAAyB,CAC7D,MAAMG,EAAWL,EAAIC,CAAI,EACzB,GAAII,EACF,GAAI,CACF,OAAO,KAAK,MAAMA,CAAQ,CAC5B,MAAY,CAAC,CAEf,OAAOH,CACT"}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type DefaultReturnType<T, U> = T extends U ? T : undefined;
|
|
2
|
+
export declare function env<T extends string | undefined>(name: string, defaultValue?: T): string | DefaultReturnType<T, string>;
|
|
3
|
+
export declare function envInt<T extends number | undefined>(name: string, defaultValue?: T): number | DefaultReturnType<T, number>;
|
|
4
|
+
export declare function envFloat<T extends number | undefined>(name: string, defaultValue?: T): number | DefaultReturnType<T, number>;
|
|
5
|
+
export declare function envBoolean<T extends boolean | undefined>(name: string, defaultValue?: T): boolean | DefaultReturnType<T, boolean>;
|
|
6
|
+
export declare function envJson(name: string, defaultValue?: any): any;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAMA,KAAK,iBAAiB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,SAAS,CAAA;AAE1D,wBAAgB,GAAG,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,EAC9C,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,CAAC,yCAWjB;AAED,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,EACjD,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,CAAC,yCAMjB;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,EACnD,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,CAAC,yCAMjB;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,SAAS,EACtD,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,CAAC,2CAMjB;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,GAAG,GAAG,GAAG,CAQ7D"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
new Function(
|
|
2
|
+
"try {return this===window;}catch(e){ return false;}"
|
|
3
|
+
)();
|
|
4
|
+
new Function(
|
|
5
|
+
"try {return this===self && typeof importScripts !== 'undefined';}catch(e){return false;}"
|
|
6
|
+
)();
|
|
7
|
+
const r = typeof global < "u" && typeof process < "u" && typeof process.stdout < "u";
|
|
8
|
+
function o(n, t) {
|
|
9
|
+
let e;
|
|
10
|
+
return !r && typeof window < "u" && window.ENV ? e = window.ENV && window.ENV[n] : typeof process < "u" && process.env && (e = process.env[n]), e !== void 0 ? e : t;
|
|
11
|
+
}
|
|
12
|
+
function s(n, t) {
|
|
13
|
+
const e = o(n);
|
|
14
|
+
return e ? parseInt(e) : t;
|
|
15
|
+
}
|
|
16
|
+
function i(n, t) {
|
|
17
|
+
const e = o(n);
|
|
18
|
+
return e ? parseFloat(e) : t;
|
|
19
|
+
}
|
|
20
|
+
function c(n, t) {
|
|
21
|
+
const e = o(n);
|
|
22
|
+
return e ? e.toLowerCase() === "true" || e === "1" : t;
|
|
23
|
+
}
|
|
24
|
+
function f(n, t) {
|
|
25
|
+
const e = o(n);
|
|
26
|
+
if (e)
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(e);
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
return t;
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
o as env,
|
|
35
|
+
c as envBoolean,
|
|
36
|
+
i as envFloat,
|
|
37
|
+
s as envInt,
|
|
38
|
+
f as envJson
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/runtime.ts","../../src/env.ts"],"sourcesContent":["//tslint:disable-next-line\nexport const isBrowser = new Function(\n 'try {return this===window;}catch(e){ return false;}'\n)()\n//tslint:disable-next-line\nexport const isWorker = new Function(\n \"try {return this===self && typeof importScripts !== 'undefined';}catch(e){return false;}\"\n)()\n//tslint:disable-next-line\nexport const isNode =\n typeof global !== 'undefined' &&\n typeof process !== 'undefined' &&\n typeof process.stdout !== 'undefined'\n","///<reference path=\"./types.d.ts\"/>\n/**\n * Created by n.vinayakan on 06.06.17.\n */\nimport { isNode } from './runtime'\n\ntype DefaultReturnType<T, U> = T extends U ? T : undefined\n\nexport function env<T extends string | undefined>(\n name: string,\n defaultValue?: T\n) {\n let value\n if (!isNode && typeof window !== 'undefined' && window.ENV) {\n value = window.ENV && window.ENV[name]\n } else if (typeof process !== 'undefined' && process.env) {\n value = process.env[name]\n }\n return value !== undefined\n ? value\n : (defaultValue as DefaultReturnType<T, string>)\n}\n\nexport function envInt<T extends number | undefined>(\n name: string,\n defaultValue?: T\n) {\n const envValue = env(name)\n return envValue\n ? parseInt(envValue)\n : (defaultValue as DefaultReturnType<T, number>)\n}\n\nexport function envFloat<T extends number | undefined>(\n name: string,\n defaultValue?: T\n) {\n const envValue = env(name)\n return envValue\n ? parseFloat(envValue)\n : (defaultValue as DefaultReturnType<T, number>)\n}\n\nexport function envBoolean<T extends boolean | undefined>(\n name: string,\n defaultValue?: T\n) {\n const envValue = env(name)\n return envValue\n ? envValue.toLowerCase() === 'true' || envValue === '1'\n : (defaultValue as DefaultReturnType<T, boolean>)\n}\n\nexport function envJson(name: string, defaultValue?: any): any {\n const envValue = env(name)\n if (envValue) {\n try {\n return JSON.parse(envValue)\n } catch (e) {}\n }\n return defaultValue\n}\n"],"names":["isNode","env","name","defaultValue","value","envInt","envValue","envFloat","envBoolean","envJson"],"mappings":"AACyB,IAAI;AAAA,EAC3B;AACF,EAAA;AAEwB,IAAI;AAAA,EAC1B;AACF,EAAA;AAEO,MAAMA,IACX,OAAO,SAAW,OAClB,OAAO,UAAY,OACnB,OAAO,QAAQ,SAAW;ACJrB,SAASC,EACdC,GACAC,GACA;AACA,MAAIC;AACJ,SAAI,CAACJ,KAAU,OAAO,SAAW,OAAe,OAAO,MACrDI,IAAQ,OAAO,OAAO,OAAO,IAAIF,CAAI,IAC5B,OAAO,UAAY,OAAe,QAAQ,QACnDE,IAAQ,QAAQ,IAAIF,CAAI,IAEnBE,MAAU,SACbA,IACCD;AACP;AAEO,SAASE,EACdH,GACAC,GACA;AACA,QAAMG,IAAWL,EAAIC,CAAI;AACzB,SAAOI,IACH,SAASA,CAAQ,IAChBH;AACP;AAEO,SAASI,EACdL,GACAC,GACA;AACA,QAAMG,IAAWL,EAAIC,CAAI;AACzB,SAAOI,IACH,WAAWA,CAAQ,IAClBH;AACP;AAEO,SAASK,EACdN,GACAC,GACA;AACA,QAAMG,IAAWL,EAAIC,CAAI;AACzB,SAAOI,IACHA,EAAS,YAAA,MAAkB,UAAUA,MAAa,MACjDH;AACP;AAEO,SAASM,EAAQP,GAAcC,GAAyB;AAC7D,QAAMG,IAAWL,EAAIC,CAAI;AACzB,MAAII;AACF,QAAI;AACF,aAAO,KAAK,MAAMA,CAAQ;AAAA,IAC5B,QAAY;AAAA,IAAC;AAEf,SAAOH;AACT;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS,KAEnB,CAAA;AAEH,eAAO,MAAM,QAAQ,KAElB,CAAA;AAEH,eAAO,MAAM,MAAM,SAGoB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@01/env",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "A tiny env parser for nodejs and browser",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"package.json"
|
|
8
|
+
],
|
|
9
|
+
"main": "./dist/cjs/index.js",
|
|
10
|
+
"module": "./dist/esm/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/esm/index.js",
|
|
16
|
+
"require": "./dist/cjs/index.js",
|
|
17
|
+
"default": "./dist/cjs/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"author": "01 Alchemist <01@01alchemist.com>",
|
|
22
|
+
"keywords": [
|
|
23
|
+
"nodejs",
|
|
24
|
+
"env",
|
|
25
|
+
"utils"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"registry": "https://registry.npmjs.org"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/01alchemist/web-service-lib.git",
|
|
34
|
+
"directory": "packages/env"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"yalc:publish": "yalc publish --push --sig",
|
|
38
|
+
"prettier": "prettier --write '**/*.{js,json,ts,gql,graphql}'",
|
|
39
|
+
"lint": "prettier --check '**/*.{js,json,ts,gql,graphql}'",
|
|
40
|
+
"watch": "nodemon --watch webpack.config.ts ../../scripts/webpack.js -- --config=webpack.config.ts --watch",
|
|
41
|
+
"dev.build": "NODE_ENV=production && vite build && yalc push",
|
|
42
|
+
"build": "NODE_ENV=production && vite build",
|
|
43
|
+
"yalc.retreat": "yalc retreat --all",
|
|
44
|
+
"precommit": "lint-staged",
|
|
45
|
+
"test": "NODE_ENV=test jest --ci --coverage --reporters=default --reporters=jest-junit --runInBand",
|
|
46
|
+
"tdd": "NODE_ENV=test jest --coverage --watch",
|
|
47
|
+
"clean": "rm -rf ./dist",
|
|
48
|
+
"publish-pkg": "../../scripts/publish-package.js $PWD"
|
|
49
|
+
},
|
|
50
|
+
"lint-staged": {
|
|
51
|
+
"*.ts": [
|
|
52
|
+
"prettier --write",
|
|
53
|
+
"git add"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "0bcce8606dca97ebe097828c94723a59cd766df4",
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@01/core-tools": "^0.3.3",
|
|
59
|
+
"vite": "^5.0.0",
|
|
60
|
+
"vite-plugin-dts": "^3.6.0"
|
|
61
|
+
}
|
|
62
|
+
}
|