@darksheep/logger 1.0.2 โ†’ 1.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.4](https://github.com/DarkSheepSoftware/node-packages/compare/logger-v1.0.3...logger-v1.0.4) (2024-08-28)
4
+
5
+
6
+ ### ๐Ÿ”จ Code Refactoring
7
+
8
+ * Remove all eslint inline suppressions ([dc1d62f](https://github.com/DarkSheepSoftware/node-packages/commit/dc1d62f5fa9cd50f884d6b68a30d448685c6c2d2))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @darksheep/environment bumped from 3.0.6 to 3.0.7
16
+
17
+ ## [1.0.3](https://github.com/DarkSheepSoftware/node-packages/compare/logger-v1.0.2...logger-v1.0.3) (2024-08-12)
18
+
19
+
20
+ ### ๐Ÿงน Chores
21
+
22
+ * update env access ([#309](https://github.com/DarkSheepSoftware/node-packages/issues/309)) ([c0bb192](https://github.com/DarkSheepSoftware/node-packages/commit/c0bb192deb0d016f3893e14ab6270461d5f5b07d))
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @darksheep/environment bumped from 3.0.5 to 3.0.6
30
+
3
31
  ## [1.0.2](https://github.com/DarkSheepSoftware/node-packages/compare/logger-v1.0.1...logger-v1.0.2) (2024-08-01)
4
32
 
5
33
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darksheep/logger",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Logging your stuff to where ever you want it",
5
5
  "license": "UNLICENCED",
6
6
  "type": "module",
@@ -17,23 +17,19 @@
17
17
  "!assert.zod.js"
18
18
  ],
19
19
  "scripts": {
20
- "lint": "eslint .",
21
- "lint:fix": "eslint . --fix",
22
20
  "prepack": "tsc",
23
21
  "test": "node --test src/**/*.test.js",
24
22
  "test:watch": "node --watch --test src/**/*.test.js"
25
23
  },
26
24
  "dependencies": {
25
+ "@darksheep/environment": "3.0.7",
27
26
  "deepmerge-ts": "7.1.0",
28
27
  "stacktrace-parser": "0.1.10",
29
28
  "traverse": "0.6.9"
30
29
  },
31
30
  "devDependencies": {
32
- "@darksheep/eslint": "~5.1.0",
33
- "@types/eslint": "~9.6.0",
34
- "@types/node": "~20.14.0",
31
+ "@types/node": "~20.16.0",
35
32
  "@types/traverse": "~0.6.33",
36
- "eslint": "~9.8.0",
37
33
  "nock": "~13.5.0",
38
34
  "typescript": "~5.5.0",
39
35
  "zod": "~3.23.0"
package/src/replacer.js CHANGED
@@ -1,5 +1,3 @@
1
- /* eslint no-invalid-this: 0 */
2
-
3
1
  import Traverse from 'traverse';
4
2
 
5
3
  import { nodesToPath } from './utilities/json-path.js';
@@ -20,50 +18,61 @@ import { nodesToPath } from './utilities/json-path.js';
20
18
  * @returns {unknown}
21
19
  */
22
20
  export function replace(object, replacers = []) {
23
- /** @type {import('traverse').Traverse<unknown>} */
24
- const traverse = Traverse(object);
21
+ return Traverse(object).forEach(
22
+ /**
23
+ * @param {unknown} value Current property in the traversed object
24
+ * @this {import('traverse').TraverseContext}
25
+ * @returns {void}
26
+ */
27
+ function (value) {
28
+ if (value == null) {
29
+ return this.remove();
30
+ }
25
31
 
26
- return traverse.forEach(function (value) {
27
- if (value == null) {
28
- return this.remove();
29
- }
32
+ if (this.circular != null) {
33
+ return this.update({ $ref: nodesToPath(this.circular.path) });
34
+ }
30
35
 
31
- if (this.circular != null) {
32
- return this.update({ $ref: nodesToPath(this.circular.path) });
33
- }
36
+ for (const replacer of replacers) {
37
+ if (replacer.shouldReplace(value, this.path)) {
38
+ const replaced = replacer.replace(value, this.path);
34
39
 
35
- for (const replacer of replacers) {
36
- if (replacer.shouldReplace(value, this.path)) {
37
- const replaced = replacer.replace(value, this.path);
40
+ if (replaced == null) {
41
+ return this.remove(replacer.stopHere);
42
+ }
38
43
 
39
- if (replaced == null) {
40
- return this.remove(replacer.stopHere);
44
+ return this.update(replaced, replacer.stopHere);
41
45
  }
42
-
43
- return this.update(replaced, replacer.stopHere);
44
46
  }
45
- }
46
47
 
47
- if (typeof value.toJSON === 'function') {
48
- try {
49
- return this.update(value.toJSON());
50
- } catch { }
51
- }
48
+ if (
49
+ typeof value === 'object' &&
50
+ 'toJSON' in value &&
51
+ typeof value.toJSON === 'function'
52
+ ) {
53
+ try {
54
+ return this.update(value.toJSON());
55
+ } catch { }
56
+ }
52
57
 
53
- if (
54
- value instanceof Object &&
55
- Object.getPrototypeOf(value) !== Object.getPrototypeOf({}) &&
56
- Object.getPrototypeOf(value) !== Object.getPrototypeOf([])
57
- ) {
58
- return this.update({ $class: value.constructor.name });
59
- }
58
+ if (
59
+ value instanceof Object &&
60
+ Object.getPrototypeOf(value) !== Object.getPrototypeOf({}) &&
61
+ Object.getPrototypeOf(value) !== Object.getPrototypeOf([])
62
+ ) {
63
+ return this.update({ $class: value.constructor.name });
64
+ }
60
65
 
61
- if (Object.getPrototypeOf(value).constructor === Object) {
62
- this.update({ ...value });
63
- }
66
+ if (Object.getPrototypeOf(value).constructor === Object) {
67
+ this.update({ ...value });
68
+ }
64
69
 
65
- if (Object.getPrototypeOf(value).constructor === Array) {
66
- this.update([ ...value ]);
67
- }
68
- });
70
+ if (
71
+ Array.isArray(value) &&
72
+ Object.getPrototypeOf(value).constructor === Array
73
+ ) {
74
+ this.update([ ...value ]);
75
+ }
76
+ },
77
+ );
69
78
  }
@@ -1,61 +1,32 @@
1
+ import { getTypedEnv } from '@darksheep/environment';
2
+
1
3
  import { parseFilters } from './parse-filters.js';
2
4
  import { parseLogLevel } from './parse-log-level.js';
3
5
 
4
- /**
5
- * @param {undefined | string} input The env var to check for booleaness
6
- * @param {boolean} fallback The fallback bool
7
- * @returns {boolean}
8
- */
9
- function parseBoolean(input, fallback) {
10
- if (input === 'true' || input === '1') {
11
- return true;
12
- }
13
-
14
- if (input === 'false' || input === '0') {
15
- return false;
16
- }
17
-
18
- return fallback;
19
- }
20
-
21
- /**
22
- * @param {undefined | string} input The env var to check to see if its an int
23
- * @param {number} fallback The fallback number
24
- * @returns {number}
25
- */
26
- function parseInt(input, fallback) {
27
- if (typeof input === 'string') {
28
- const number = Number.parseInt(input, 10);
29
-
30
- if (Number.isNaN(number) === false) {
31
- return number;
32
- }
33
- }
34
-
35
- return fallback;
36
- }
37
-
38
- const isDevelopment = process.env.NODE_ENV === 'development';
39
- const isTesting = process.env.NODE_ENV === 'test';
40
- const isProduction = process.env.NODE_ENV === 'production';
41
-
42
- const logLevel = parseLogLevel(
43
- process.env.LOG_LEVEL,
44
- process.env.NODE_ENV,
45
- );
46
- const logFilters = parseFilters(process.env.LOG_FILTERS, [ /.*/ ]);
47
- const secretFilters = parseFilters(process.env.LOG_SECRETS);
48
- const includeCallsite = parseBoolean(process.env.LOG_CALLSITES, false);
49
- const stringMaxLength = parseInt(process.env.LOG_MAX_LENGTH, 1024);
6
+ const {
7
+ NODE_ENV = 'production',
8
+ LOG_LEVEL,
9
+ LOG_FILTERS,
10
+ LOG_SECRETS,
11
+ LOG_CALLSITES = false,
12
+ LOG_MAX_LENGTH = 1024,
13
+ } = getTypedEnv({
14
+ NODE_ENV: '?string',
15
+ LOG_LEVEL: '?string',
16
+ LOG_FILTERS: '?string',
17
+ LOG_SECRETS: '?string',
18
+ LOG_CALLSITES: '?boolean',
19
+ LOG_MAX_LENGTH: '?number',
20
+ });
50
21
 
51
22
  export const environment = {
52
- isDevelopment,
53
- isTesting,
54
- isProduction,
55
-
56
- logLevel,
57
- logFilters,
58
- secretFilters,
59
- includeCallsite,
60
- stringMaxLength,
23
+ isDevelopment: NODE_ENV === 'development',
24
+ isTesting: NODE_ENV === 'test',
25
+ isProduction: NODE_ENV === 'production',
26
+
27
+ logLevel: parseLogLevel(LOG_LEVEL, NODE_ENV),
28
+ logFilters: parseFilters(LOG_FILTERS, [ /.*/ ]),
29
+ secretFilters: parseFilters(LOG_SECRETS),
30
+ includeCallsite: LOG_CALLSITES,
31
+ stringMaxLength: LOG_MAX_LENGTH,
61
32
  };
@@ -1,25 +1,19 @@
1
1
  export namespace environment {
2
- export { isDevelopment };
3
- export { isTesting };
4
- export { isProduction };
5
- export { logLevel };
6
- export { logFilters };
7
- export { secretFilters };
8
- export { includeCallsite };
9
- export { stringMaxLength };
2
+ export let isDevelopment: boolean;
3
+ export let isTesting: boolean;
4
+ export let isProduction: boolean;
5
+ export let logLevel: import("./log-types.js").LogLevel;
6
+ export let logFilters: {
7
+ allowed: RegExp[];
8
+ blocked: RegExp[];
9
+ };
10
+ export let secretFilters: {
11
+ allowed: RegExp[];
12
+ blocked: RegExp[];
13
+ };
14
+ export { LOG_CALLSITES as includeCallsite };
15
+ export { LOG_MAX_LENGTH as stringMaxLength };
10
16
  }
11
- declare const isDevelopment: boolean;
12
- declare const isTesting: boolean;
13
- declare const isProduction: boolean;
14
- declare const logLevel: import("./log-types.js").LogLevel;
15
- declare const logFilters: {
16
- allowed: RegExp[];
17
- blocked: RegExp[];
18
- };
19
- declare const secretFilters: {
20
- allowed: RegExp[];
21
- blocked: RegExp[];
22
- };
23
- declare const includeCallsite: boolean;
24
- declare const stringMaxLength: number;
17
+ declare const LOG_CALLSITES: boolean;
18
+ declare const LOG_MAX_LENGTH: number;
25
19
  export {};