@squeep/log-helper 1.0.1 → 1.0.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/README.md CHANGED
@@ -30,10 +30,10 @@ Utilities for standardized logging.
30
30
  - `prefix` A field included before the package name.
31
31
 
32
32
  Defaults, based on directory existing in project:
33
- | | `src` | `lib` | other |
33
+ | precedence -> | `lib` | `src` | other |
34
34
  |----------------|-------|-------|-------|
35
- | includePackage | false | true | false |
36
- | includeVersion | false | true | false |
35
+ | includePackage | true | false | false |
36
+ | includeVersion | true | false | false |
37
37
  | includePath | true | true | false |
38
38
  | leftTrim | 4 | 4 | 0 |
39
39
 
package/lib/file-scope.js CHANGED
@@ -8,6 +8,32 @@
8
8
  const path = require('node:path');
9
9
  const fs = require('node:fs');
10
10
 
11
+
12
+ /**
13
+ * @typedef {object} FileScopeOptions
14
+ * @property {boolean=} includePackage full package name
15
+ * @property {boolean=} includeVersion package version
16
+ * @property {boolean=} includePath when indicating filename
17
+ * @property {string=} prefix static string to include
18
+ * @property {number=} leftTrim characters to omit from start of path/filename
19
+ * @property {string=} errorPrefix string to include at start if an error was encountered
20
+ * @property {string=} delimiter joining selected components
21
+ */
22
+
23
+
24
+ /**
25
+ * @typedef {FileScopeOptions} FileScopeOptionsInternal
26
+ * @property {boolean=} _errorEncountered flag if error while setting defaults
27
+ */
28
+
29
+
30
+ /**
31
+ * @typedef {object} PackageDetails
32
+ * @property {string} name package name
33
+ * @property {string} version package version
34
+ */
35
+
36
+
11
37
  /**
12
38
  * Internal exception
13
39
  */
@@ -23,14 +49,9 @@ class FileScopeError extends Error {
23
49
  }
24
50
 
25
51
 
26
- /**
27
- * @typedef {object} PackageDetails
28
- * @property {string} name - package name
29
- * @property {string} version - package version
30
- */
31
52
  /**
32
53
  * Read and parse package.json from a path.
33
- * @param {string} packagePath - path to package.json
54
+ * @param {string} packagePath path to package.json
34
55
  * @returns {PackageDetails} selected details from package.json
35
56
  */
36
57
  function readPackageJSON(packagePath) {
@@ -47,7 +68,7 @@ function readPackageJSON(packagePath) {
47
68
 
48
69
 
49
70
  /**
50
- * Returns whether path p exists.
71
+ * Returns whether path p exists and is accessible.
51
72
  * @param {string} p path
52
73
  * @returns {boolean} exists
53
74
  */
@@ -56,7 +77,7 @@ function pathExists(p) {
56
77
  fs.statSync(p); // eslint-disable-line security/detect-non-literal-fs-filename
57
78
  return true;
58
79
  } catch (e) {
59
- if (e.code !== 'ENOENT') {
80
+ if (!(['ENOENT', 'EACCES'].includes(e.code))) {
60
81
  throw e;
61
82
  }
62
83
  return false;
@@ -74,13 +95,8 @@ function locatePackageBase(filename) {
74
95
  let currentPath = filename;
75
96
  do {
76
97
  const d = path.dirname(currentPath);
77
- try {
78
- fs.statSync(path.join(d, 'package.json')); // eslint-disable-line security/detect-non-literal-fs-filename
98
+ if (pathExists(path.join(d, 'package.json'))) {
79
99
  return d + '/';
80
- } catch (e) {
81
- if (e.code !== 'ENOENT') {
82
- throw e;
83
- }
84
100
  }
85
101
  currentPath = d;
86
102
  } while (currentPath !== '/');
@@ -91,7 +107,7 @@ function locatePackageBase(filename) {
91
107
  /**
92
108
  * Get default options based on package directory structure.
93
109
  * @param {string} packageBase path to package root
94
- * @returns {object} options
110
+ * @returns {FileScopeOptionsInternal} options
95
111
  */
96
112
  function defaultOptions(packageBase) {
97
113
  const options = {
@@ -128,15 +144,8 @@ function defaultOptions(packageBase) {
128
144
  * Returns a function suitable for decorating a function name with
129
145
  * package information and details of the source file.
130
146
  * @param {string} filepath full path from __filename
131
- * @param {object=} options controlling component inclusion
132
- * @param {boolean=} options.includePackage full package name
133
- * @param {boolean=} options.includeVersion package version
134
- * @param {boolean=} options.includePath when indicating filename
135
- * @param {string=} options.prefix static string to include
136
- * @param {number=} options.leftTrim characters to omit from start of path/filename
137
- * @param {string=} options.errorPrefix string to include at start if an error was encountered
138
- * @param {string=} options.delimiter joining selected components
139
- * @returns {Function} marks up provided string with selected components
147
+ * @param {FileScopeOptions=} options controlling component inclusion
148
+ * @returns {(name: string) => string} marks up provided string with selected components
140
149
  */
141
150
  function fileScope(filepath, options) {
142
151
  let errorEncountered = false;
@@ -181,7 +190,7 @@ function fileScope(filepath, options) {
181
190
  const trimmedFilename = rightTrimmed.slice(trim);
182
191
 
183
192
  const components = [errorEncountered ? errorPrefix : '', prefix, packageIdentifier, trimmedFilename]
184
- .filter((x) => x);
193
+ .filter(Boolean);
185
194
 
186
195
  const scope = components.join(delimiter);
187
196
 
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@squeep/log-helper",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Simple helpers for standardized logging",
5
5
  "main": "index.js",
6
6
  "engines": {
7
- "node": ">=14.13.1"
7
+ "node": ">=20.13.0"
8
8
  },
9
9
  "files": [
10
10
  "lib/*.js"
@@ -14,23 +14,17 @@
14
14
  "coverage": "nyc npm test",
15
15
  "coverage-check": "nyc check-coverage",
16
16
  "eslint": "eslint index.js lib test",
17
- "test": "mocha --recursive"
17
+ "test": "node --test",
18
+ "prepare": "husky"
18
19
  },
19
20
  "keywords": [],
20
21
  "author": "Justin Wind <jwind-npm@squeep.com>",
21
22
  "license": "ISC",
22
- "pre-commit": [
23
- "audit",
24
- "eslint",
25
- "coverage",
26
- "coverage-check"
27
- ],
28
23
  "devDependencies": {
29
24
  "@squeep/eslint-config": "^1",
30
25
  "eslint": "^9",
31
- "mocha": "^10",
32
- "nyc": "^15",
33
- "pre-commit": "^1",
34
- "sinon": "^17"
26
+ "husky": "^9",
27
+ "nyc": "^17",
28
+ "sinon": "^21"
35
29
  }
36
30
  }