update devDependencies, fix lint issues
[squeep-log-helper] / lib / file-scope.js
index 57421a42e810954884efadd182e235d664f6b013..06f4a1376c1beba637e00a4e2c1a65accba6dbac 100644 (file)
@@ -23,10 +23,15 @@ class FileScopeError extends Error {
 }
 
 
+/**
+ * @typedef {object} PackageDetails
+ * @property {string} name - package name
+ * @property {string} version - package version
+ */
 /**
  * Read and parse package.json from a path.
- * @param {String} packagePath
- * @returns {Object}
+ * @param {string} packagePath - path to package.json
+ * @returns {PackageDetails} selected details from package.json
  */
 function readPackageJSON(packagePath) {
   try {
@@ -43,8 +48,8 @@ function readPackageJSON(packagePath) {
 
 /**
  * Returns whether path p exists.
- * @param {String} p
- * @returns {Boolean}
+ * @param {string} p path
+ * @returns {boolean} exists
  */
 function pathExists(p) {
   try {
@@ -62,8 +67,8 @@ function pathExists(p) {
 /**
  * Walk up the path of provided filename until directory with
  * package.json is located.  We assume this is the package root.
- * @param {String} filename
- * @returns {String}
+ * @param {string} filename path to file
+ * @returns {string} path to package root
  */
 function locatePackageBase(filename) {
   let currentPath = filename;
@@ -85,8 +90,8 @@ function locatePackageBase(filename) {
 
 /**
  * Get default options based on package directory structure.
- * @param {String} packageBase
- * @returns {Object}
+ * @param {string} packageBase path to package root
+ * @returns {object} options
  */
 function defaultOptions(packageBase) {
   const options = {
@@ -122,16 +127,16 @@ function defaultOptions(packageBase) {
 /**
  * Returns a function suitable for decorating a function name with
  * package information and details of the source file.
- * @param {String} filepath full path from __filename
- * @param {Object=} options
- * @param {Boolean=} options.includePackage
- * @param {Boolean=} options.includeVersion
- * @param {Boolean=} options.includePath
- * @param {String=} options.prefix
- * @param {Number=} options.leftTrim
- * @param {String=} options.errorPrefix
- * @param {String=} options.delimiter
- * @returns {Function}
+ * @param {string} filepath full path from __filename
+ * @param {object=} options controlling component inclusion
+ * @param {boolean=} options.includePackage full package name
+ * @param {boolean=} options.includeVersion package version
+ * @param {boolean=} options.includePath when indicating filename
+ * @param {string=} options.prefix static string to include
+ * @param {number=} options.leftTrim characters to omit from start of path/filename
+ * @param {string=} options.errorPrefix string to include at start if an error was encountered
+ * @param {string=} options.delimiter joining selected components
+ * @returns {Function} marks up provided string with selected components
  */
 function fileScope(filepath, options) {
   let errorEncountered = false;
@@ -159,7 +164,7 @@ function fileScope(filepath, options) {
   let packageIdentifier;
   if (includePackage || includeVersion) {
     const { name: packageName, version: packageVersion } = readPackageJSON(packageBase);
-    // including version implies including package
+    // Including version implies including package
     packageIdentifier = includeVersion ? `${packageName}@${packageVersion}` : packageName;
   }