}
+/**
+ * @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 {
/**
* Returns whether path p exists.
- * @param {String} p
- * @returns {Boolean}
+ * @param {string} p path
+ * @returns {boolean} exists
*/
function pathExists(p) {
try {
/**
* 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;
/**
* 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 = {
/**
* 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;
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;
}