topkat-utils 1.2.9 → 1.2.11

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### v1.2.11
2
+ * FIX on terminal noColor detection nodeJs env
3
+
4
+ ### v1.2.10
5
+ * NEW isNodeJs fn
6
+ * Default terminal color when on nodejs
7
+
1
8
  ### v1.2.9
2
9
  * Fix error noStackTrace
3
10
 
@@ -1,13 +1,13 @@
1
1
  import { Color } from './types';
2
- export declare type TopkatUtilConfig = {
2
+ export declare type TopkatUtilConfig = Partial<{
3
3
  env: string;
4
4
  isProd: boolean;
5
- nbOfLogsToKeep?: number;
5
+ nbOfLogsToKeep: number;
6
6
  customTypes: object;
7
7
  preprocessLog?: Function;
8
- terminal: {
8
+ terminal: Partial<{
9
9
  noColor: boolean;
10
- theme: {
10
+ theme: Partial<{
11
11
  primary: Color;
12
12
  shade1: Color;
13
13
  shade2: Color;
@@ -17,9 +17,9 @@ export declare type TopkatUtilConfig = {
17
17
  fontColor?: Color;
18
18
  pageWidth?: number;
19
19
  debugModeColor?: Color;
20
- };
21
- };
22
- };
20
+ }>;
21
+ }>;
22
+ }>;
23
23
  /** Allow dynamic changing of config */
24
24
  export declare function configFn(): TopkatUtilConfig;
25
25
  /** Register custom config
@@ -41,4 +41,4 @@ export declare function configFn(): TopkatUtilConfig;
41
41
  * * }
42
42
  * * },
43
43
  */
44
- export declare function registerConfig(customConfig: any): void;
44
+ export declare function registerConfig(customConfig: TopkatUtilConfig): void;
@@ -2,13 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.registerConfig = exports.configFn = void 0;
4
4
  const isset_1 = require("./isset");
5
+ const is_nodejs_1 = require("./is-nodejs");
6
+ const isNode = (0, is_nodejs_1.isNodeJs)();
5
7
  let config = {
8
+ // Also used as default config
6
9
  env: 'development',
7
10
  isProd: false,
8
11
  nbOfLogsToKeep: 25,
9
12
  customTypes: {},
10
13
  terminal: {
11
- noColor: true,
14
+ noColor: !isNode,
12
15
  theme: {
13
16
  primary: [0, 149, 250],
14
17
  shade1: [0, 90, 250],
@@ -49,7 +52,7 @@ function registerConfig(customConfig) {
49
52
  newconfig.terminal = Object.assign(Object.assign({}, config.terminal), customConfig.terminal);
50
53
  newconfig.terminal.theme = Object.assign(Object.assign({}, config.terminal.theme), (customConfig.terminal.theme || {}));
51
54
  config = newconfig;
52
- config.isProd = config.env.includes('prod');
55
+ config.isProd = config.env.includes('prod'); // preprod | production
53
56
  }
54
57
  exports.registerConfig = registerConfig;
55
58
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;;AACA,mCAA+B;AAwB/B,IAAI,MAAM,GAAqB;IAC3B,GAAG,EAAE,aAAa;IAClB,MAAM,EAAE,KAAK;IACb,cAAc,EAAE,EAAE;IAClB,WAAW,EAAE,EAAE;IACf,QAAQ,EAAE;QACN,OAAO,EAAE,IAAI;QACb,KAAK,EAAE;YACH,OAAO,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC;YACtB,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC;YACpB,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC;YACrB,QAAQ,EAAE,CAAC;YACX,QAAQ,EAAE,CAAC;YACX,SAAS,EAAE,EAAE;YACb,cAAc,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,CAAC;SACjC;KACJ;CACJ,CAAA;AAED,uCAAuC;AACvC,SAAgB,QAAQ,KAAK,OAAO,MAAM,CAAA,CAAC,CAAC;AAA5C,4BAA4C;AAG5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,cAAc,CAAC,YAAY;IACvC,IAAI,CAAC,IAAA,aAAK,EAAC,YAAY,CAAC,QAAQ,CAAC;QAAE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9D,4BAA8D;AAG9D;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,cAAc,CAAC,YAA8B;IACzD,IAAI,CAAC,IAAA,aAAK,EAAC,YAAY,CAAC,QAAQ,CAAC;QAAE,YAAY,CAAC,QAAQ,GAAG,EAAE,CAAA;IAC7D,MAAM,SAAS,mCACR,MAAM,GACN,YAAY,CAClB,CAAA;IACD,SAAS,CAAC,QAAQ,mCACX,MAAM,CAAC,QAAQ,GACf,YAAY,CAAC,QAAQ,CAC3B,CAAA;IACD,SAAS,CAAC,QAAQ,CAAC,KAAK,mCACjB,MAAM,CAAC,QAAQ,CAAC,KAAK,GACrB,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,CACzC,CAAA;IACD,MAAM,GAAG,SAAS,CAAA;IAElB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA,CAAC,uBAAuB;AACvE,CAAC;AAjBD,wCAiBC"}
@@ -0,0 +1 @@
1
+ export declare function isNodeJs(): boolean;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNodeJs = void 0;
4
+ function isNodeJs() {
5
+ try {
6
+ return (typeof process !== 'undefined') && (typeof process.versions.node !== 'undefined');
7
+ }
8
+ catch (e) {
9
+ return false;
10
+ }
11
+ }
12
+ exports.isNodeJs = isNodeJs;
13
+ //# sourceMappingURL=is-nodejs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-nodejs.js","sourceRoot":"","sources":["../../src/is-nodejs.ts"],"names":[],"mappings":";;;AAEA,SAAgB,QAAQ;IACpB,IAAI;QACA,OAAO,CAAC,OAAO,OAAO,KAAK,WAAW,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,WAAW,CAAC,CAAA;KAC5F;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,KAAK,CAAA;KACf;AACL,CAAC;AAND,4BAMC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topkat-utils",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "type": "commonjs",
5
5
  "types": "index.ts",
6
6
  "private": false,
package/src/config.ts CHANGED
@@ -1,15 +1,18 @@
1
1
  import { Color } from './types'
2
2
  import { isset } from './isset'
3
+ import { isNodeJs } from './is-nodejs'
3
4
 
4
- export type TopkatUtilConfig = {
5
+ const isNode = isNodeJs()
6
+
7
+ export type TopkatUtilConfig = Partial<{
5
8
  env: string
6
9
  isProd: boolean
7
- nbOfLogsToKeep?: number
10
+ nbOfLogsToKeep: number
8
11
  customTypes: object,
9
12
  preprocessLog?: Function,
10
- terminal: {
13
+ terminal: Partial<{
11
14
  noColor: boolean
12
- theme: {
15
+ theme: Partial<{
13
16
  primary: Color, // blue theme
14
17
  shade1: Color,
15
18
  shade2: Color,
@@ -19,17 +22,18 @@ export type TopkatUtilConfig = {
19
22
  fontColor?: Color
20
23
  pageWidth?: number
21
24
  debugModeColor?: Color,
22
- }
23
- },
24
- }
25
+ }>
26
+ }>
27
+ }>
25
28
 
26
29
  let config: TopkatUtilConfig = {
30
+ // Also used as default config
27
31
  env: 'development',
28
32
  isProd: false,
29
33
  nbOfLogsToKeep: 25,
30
34
  customTypes: {},
31
35
  terminal: {
32
- noColor: true,
36
+ noColor: !isNode,
33
37
  theme: {
34
38
  primary: [0, 149, 250], // blue theme
35
39
  shade1: [0, 90, 250],
@@ -43,7 +47,7 @@ let config: TopkatUtilConfig = {
43
47
  }
44
48
 
45
49
  /** Allow dynamic changing of config */
46
- export function configFn() { return config }
50
+ export function configFn(): TopkatUtilConfig { return config }
47
51
 
48
52
 
49
53
  /** Register custom config
@@ -65,7 +69,7 @@ export function configFn() { return config }
65
69
  * * }
66
70
  * * },
67
71
  */
68
- export function registerConfig(customConfig) {
72
+ export function registerConfig(customConfig: TopkatUtilConfig) {
69
73
  if (!isset(customConfig.terminal)) customConfig.terminal = {}
70
74
  const newconfig = {
71
75
  ...config,
@@ -81,5 +85,5 @@ export function registerConfig(customConfig) {
81
85
  }
82
86
  config = newconfig
83
87
 
84
- config.isProd = config.env.includes('prod')
88
+ config.isProd = config.env.includes('prod') // preprod | production
85
89
  }
@@ -0,0 +1,9 @@
1
+
2
+
3
+ export function isNodeJs(): boolean {
4
+ try {
5
+ return (typeof process !== 'undefined') && (typeof process.versions.node !== 'undefined')
6
+ } catch (e) {
7
+ return false
8
+ }
9
+ }