yini-parser 1.0.0-alpha.2 → 1.0.0-alpha.4

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/README.md CHANGED
@@ -59,9 +59,10 @@ import YINI from 'yini-parser';
59
59
 
60
60
  // Parse from string.
61
61
  const config = YINI.parse(`
62
- ^ Database
63
- host = localhost
64
- port = 5432
62
+ ^ App
63
+ title = "My App Title"
64
+ items = 25
65
+ isDarkTheme = OFF
65
66
  `);
66
67
 
67
68
  // Parse from file.
@@ -105,10 +106,11 @@ Returns a JavaScript object representing the parsed YINI configuration file.
105
106
  ## Example Output
106
107
  ```js
107
108
  {
108
- Database: {
109
- host: "localhost",
110
- port: 5432
111
- }
109
+ App:{
110
+ title: "My App Title",
111
+ items: 25,
112
+ isDarkTheme: false
113
+ }
112
114
  }
113
115
  ```
114
116
 
@@ -127,5 +129,4 @@ In this project on GitHub, the `libs` directory contains third party software an
127
129
 
128
130
  ---
129
131
 
130
- > ~ **YINI ≡**
131
- > [https://yini-lang.org](https://yini-lang.org)
132
+ ~ **YINI ≡** • [https://yini-lang.org](https://yini-lang.org)
@@ -11,10 +11,24 @@ type TNodeEnv = 'development' | 'production' | 'test';
11
11
  * @note Since this is a library (as opposed to a Web/App), we don't use "staging".
12
12
  */
13
13
  type TAppEnv = 'local' | 'ci' | 'production';
14
- declare const NODE_ENV: TNodeEnv;
15
- declare const APP_ENV: TAppEnv;
16
- export declare const isDebug: () => boolean;
14
+ declare const localNodeEnv: TNodeEnv;
15
+ declare const localAppEnv: TAppEnv;
16
+ /** Are we running in the environment "development"? Will be based on the (global) environment variable process.env.NODE_ENV. */
17
+ export declare const isDevEnv: () => boolean;
18
+ /** Are we running in the environment "production"? Will be based on the (global) environment variable process.env.NODE_ENV. */
19
+ export declare const isProdEnv: () => boolean;
20
+ /** Are we running in the environment "test"? Will be based on the (global) variable process.env.NODE_ENV. */
21
+ export declare const isTestEnv: () => boolean;
22
+ /** Will be based on the local argument when this process was launched.
23
+ * @returns True if the DEV flag is set.
24
+ * @example npm run start -- isDev=1
25
+ * @example node dist/index.js isDev=1
26
+ */
17
27
  export declare const isDev: () => boolean;
18
- export declare const isProd: () => boolean;
19
- export declare const isTest: () => boolean;
20
- export { NODE_ENV, APP_ENV };
28
+ /** Will be based on the local argument when this process was launched.
29
+ * @returns True if the DEBUG flag is set.
30
+ * @example npm run start -- isDebug=1
31
+ * @example node dist/index.js isDebug=1
32
+ */
33
+ export declare const isDebug: () => boolean;
34
+ export { localNodeEnv, localAppEnv };
@@ -1,15 +1,62 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.APP_ENV = exports.NODE_ENV = exports.isTest = exports.isProd = exports.isDev = exports.isDebug = void 0;
4
- const NODE_ENV = (process.env.NODE_ENV || 'development');
5
- exports.NODE_ENV = NODE_ENV;
6
- const APP_ENV = (process.env.APP_ENV || 'local');
7
- exports.APP_ENV = APP_ENV;
8
- const isDebug = () => !!process.env.IS_DEBUG;
9
- exports.isDebug = isDebug;
10
- const isDev = () => NODE_ENV === 'development';
3
+ exports.localAppEnv = exports.localNodeEnv = exports.isDebug = exports.isDev = exports.isTestEnv = exports.isProdEnv = exports.isDevEnv = void 0;
4
+ const localNodeEnv = (process.env.NODE_ENV || 'production');
5
+ exports.localNodeEnv = localNodeEnv;
6
+ const localAppEnv = (process.env.APP_ENV || 'production');
7
+ exports.localAppEnv = localAppEnv;
8
+ // export const initEnvs = () => {
9
+ // const localNodeEnv = (process.env.NODE_ENV || 'production') as TNodeEnv
10
+ // const localAppEnv = (process.env?.APP_ENV || 'production') as TAppEnv
11
+ // return { localNodeEnv, localAppEnv }
12
+ // }
13
+ // const { localNodeEnv, localAppEnv } = initEnvs()
14
+ /** Are we running in the environment "development"? Will be based on the (global) environment variable process.env.NODE_ENV. */
15
+ const isDevEnv = () => localNodeEnv === 'development';
16
+ exports.isDevEnv = isDevEnv;
17
+ /** Are we running in the environment "production"? Will be based on the (global) environment variable process.env.NODE_ENV. */
18
+ const isProdEnv = () => localNodeEnv === 'production';
19
+ exports.isProdEnv = isProdEnv;
20
+ /** Are we running in the environment "test"? Will be based on the (global) variable process.env.NODE_ENV. */
21
+ const isTestEnv = () => localNodeEnv === 'test';
22
+ exports.isTestEnv = isTestEnv;
23
+ /** Will be based on the local argument when this process was launched.
24
+ * @returns True if the DEV flag is set.
25
+ * @example npm run start -- isDev=1
26
+ * @example node dist/index.js isDev=1
27
+ */
28
+ const isDev = () => {
29
+ const len = process.argv.length;
30
+ // NOTE: We will start with index 2, since the first element will be
31
+ // execPath. The second element will be the path to the
32
+ // JavaScript file being executed.
33
+ for (let i = 2; i < len; i++) {
34
+ const val = process.argv[i] || '';
35
+ if (val.toLowerCase() === 'isdev=1' ||
36
+ val.toLowerCase() === 'isdev=true') {
37
+ return true;
38
+ }
39
+ }
40
+ return false;
41
+ };
11
42
  exports.isDev = isDev;
12
- const isProd = () => NODE_ENV === 'production';
13
- exports.isProd = isProd;
14
- const isTest = () => NODE_ENV === 'test';
15
- exports.isTest = isTest;
43
+ /** Will be based on the local argument when this process was launched.
44
+ * @returns True if the DEBUG flag is set.
45
+ * @example npm run start -- isDebug=1
46
+ * @example node dist/index.js isDebug=1
47
+ */
48
+ const isDebug = () => {
49
+ const len = process.argv.length;
50
+ // NOTE: We will start with index 2, since the first element will be
51
+ // execPath. The second element will be the path to the
52
+ // JavaScript file being executed.
53
+ for (let i = 2; i < len; i++) {
54
+ const val = process.argv[i] || '';
55
+ if (val.toLowerCase() === 'isdebug=1' ||
56
+ val.toLowerCase() === 'isdebug=true') {
57
+ return true;
58
+ }
59
+ }
60
+ return false;
61
+ };
62
+ exports.isDebug = isDebug;
@@ -21,6 +21,16 @@ export interface IParseMetaData {
21
21
  errors: null | number;
22
22
  warnings: null | number;
23
23
  infoAndNotices: null | number;
24
+ envs: {
25
+ NODE_ENV: undefined | string;
26
+ APP_ENV: undefined | string;
27
+ libNodeEnv: undefined | string;
28
+ libAppEnv: undefined | string;
29
+ };
30
+ libFlags: {
31
+ isDev: boolean;
32
+ isDebug: boolean;
33
+ };
24
34
  };
25
35
  timing?: {
26
36
  totalMs: null | number;
package/dist/index.js CHANGED
@@ -21,16 +21,24 @@ const system_1 = require("./utils/system");
21
21
  const YINI_1 = __importDefault(require("./YINI"));
22
22
  var YINI_2 = require("./YINI");
23
23
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(YINI_2).default; } });
24
- if ((0, env_1.isDev)() || (0, env_1.isDebug)()) {
25
- console.log('process.env?.NODE_ENV = ' + ((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV));
26
- console.log('process.env?.APP_ENV = ' + ((_b = process.env) === null || _b === void 0 ? void 0 : _b.APP_ENV));
27
- console.log('process.env?.IS_DEBUG = ' + ((_c = process.env) === null || _c === void 0 ? void 0 : _c.IS_DEBUG));
28
- }
29
- // console.log('NODE_ENV = ' + NODE_ENV)
30
- // console.log('APP_ENV = ' + APP_ENV)
31
24
  (0, system_1.debugPrint)();
32
25
  (0, system_1.debugPrint)('-> Entered index.ts');
33
26
  (0, system_1.debugPrint)();
27
+ if ((0, env_1.isDev)() || (0, env_1.isDebug)()) {
28
+ console.log(`process.env?.NODE_ENV = '${(_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV}'`);
29
+ console.log(`process.env?.APP_ENV = '${(_b = process.env) === null || _b === void 0 ? void 0 : _b.APP_ENV}'`);
30
+ console.log(`process.env?.IS_DEBUG = '${(_c = process.env) === null || _c === void 0 ? void 0 : _c.IS_DEBUG}'`);
31
+ (0, system_1.debugPrint)();
32
+ console.log(`localNodeEnv = '${env_1.localNodeEnv}'`);
33
+ console.log(` localAppEnv = '${env_1.localAppEnv}'`);
34
+ console.log(' isProdEnv() = ' + (0, env_1.isProdEnv)());
35
+ console.log(' isDevEnv() = ' + (0, env_1.isDevEnv)());
36
+ console.log(' isTestEnv() = ' + (0, env_1.isTestEnv)());
37
+ console.log();
38
+ console.log(' isDev() = ' + (0, env_1.isDev)());
39
+ console.log(' isDebug() = ' + (0, env_1.isDebug)());
40
+ console.log();
41
+ }
34
42
  const debugTestObj = {
35
43
  name: 'e_test',
36
44
  lang: 'TypeScript',
@@ -38,7 +46,7 @@ const debugTestObj = {
38
46
  (0, system_1.debugPrint)('debugTestObj:');
39
47
  (0, system_1.debugPrint)(debugTestObj);
40
48
  (0, system_1.debugPrint)();
41
- if ((0, env_1.isProd)()) {
49
+ if ((0, env_1.isProdEnv)()) {
42
50
  // Do nothing, and exit.
43
51
  }
44
52
  else {
@@ -89,7 +97,7 @@ listItems = ["a", "b", "c"]
89
97
  // console.debug(invalidInput1)
90
98
  // }
91
99
  // YINI.parse(invalidInput1)
92
- if (env_1.APP_ENV === 'local' && env_1.NODE_ENV !== 'test') {
100
+ if (env_1.localAppEnv === 'local' && env_1.localNodeEnv !== 'test') {
93
101
  /*
94
102
  YINI.parse(`
95
103
  --^ Section0
@@ -127,6 +127,16 @@ const parseMain = (yiniContent, options = {
127
127
  errors: errorHandler.getNumOfErrors(),
128
128
  warnings: errorHandler.getNumOfWarnings(),
129
129
  infoAndNotices: errorHandler.getNumOfInfoAndNotices(),
130
+ envs: {
131
+ NODE_ENV: process.env.NODE_ENV,
132
+ APP_ENV: process.env.APP_ENV,
133
+ libNodeEnv: env_1.localNodeEnv,
134
+ libAppEnv: env_1.localAppEnv,
135
+ },
136
+ libFlags: {
137
+ isDev: (0, env_1.isDev)(),
138
+ isDebug: (0, env_1.isDebug)(),
139
+ },
130
140
  };
131
141
  }
132
142
  if (options.isWithTiming) {
@@ -11,11 +11,11 @@ const debugPrint = (str = '') => {
11
11
  };
12
12
  exports.debugPrint = debugPrint;
13
13
  const devPrint = (str = '') => {
14
- (0, env_1.isDev)() && !(0, env_1.isTest)() && console.log('DEV: ' + str);
14
+ (0, env_1.isDev)() && !(0, env_1.isTestEnv)() && console.log('DEV: ' + str);
15
15
  };
16
16
  exports.devPrint = devPrint;
17
17
  const printObject = (obj) => {
18
- if ((0, env_1.isProd)() || ((0, env_1.isTest)() && !(0, env_1.isDebug)()))
18
+ if ((0, env_1.isProdEnv)() || ((0, env_1.isTestEnv)() && !(0, env_1.isDebug)()))
19
19
  return;
20
20
  const str = JSON.stringify(obj, null, 4);
21
21
  console.log(str);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yini-parser",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.4",
4
4
  "description": "YINI parser for JavaScript/TypeScript, an INI-inspired configuration format, meant to be readable, and easy to use.",
5
5
  "keywords": [
6
6
  "read",
@@ -36,19 +36,19 @@
36
36
  },
37
37
  "private": false,
38
38
  "scripts": {
39
- "start": "cross-env NODE_ENV=production APP_ENV=production node dist/index.js",
40
- "start:debug": "cross-env IS_DEBUG=1 npm run start",
41
- "start:dev": "cross-env NODE_ENV=development APP_ENV=local ts-node src/index.ts",
42
- "start:dev:debug": "cross-env IS_DEBUG=1 npm run start:dev",
39
+ "start": "npm run build && node dist/index.js",
40
+ "start:debug": "npm run start -- isDebug=1",
41
+ "start:dev": "cross-env NODE_ENV=development APP_ENV=local ts-node src/index.ts isDev=1",
42
+ "start:dev:debug": "cross-env npm run start:dev -- isDebug=1",
43
43
  "start-w-clean": "npm run tsc && npm run clean:ts-js && npm run start:dev",
44
44
  "test": "cross-env NODE_ENV=test APP_ENV=local jest --bail --verbose --runInBand",
45
- "test:debug": "cross-env IS_DEBUG=1 npm run test",
45
+ "test:debug": "cross-env npm run test -- --isDebug=1",
46
46
  "test:smoke": "cross-env NODE_ENV=test APP_ENV=local jest tests/smoke --bail --verbose --runInBand",
47
47
  "test:unit": "cross-env NODE_ENV=test APP_ENV=local jest tests/unit --bail --verbose --runInBand",
48
48
  "test:integr": "cross-env NODE_ENV=test APP_ENV=local jest tests/integration --bail --verbose --runInBand",
49
- "test:smoke:debug": "cross-env IS_DEBUG=1 npm run test:smoke",
50
- "test:unit:debug": "cross-env IS_DEBUG=1 npm run test:unit",
51
- "test:integr:debug": "cross-env IS_DEBUG=1 npm run test:integr",
49
+ "test:smoke:debug": "cross-env npm run test:smoke -- --isDebug=1",
50
+ "test:unit:debug": "cross-env npm run test:unit -- --isDebug=1",
51
+ "test:integr:debug": "cross-env npm run test:integr -- --isDebug=1",
52
52
  "ci:test": "cross-env NODE_ENV=test APP_ENV=ci jest --verbose --runInBand",
53
53
  "ci:test:smoke": "cross-env NODE_ENV=test APP_ENV=ci jest tests/smoke --verbose --runInBand",
54
54
  "tsc": "npx tsc -p ./tsconfig.json",