@squared-functions/module
Advanced tools
Comparing version 0.14.1 to 0.14.2
66
index.js
@@ -1,2 +0,2 @@ | ||
/* @squared-functions/module 0.14.1 | ||
/* @squared-functions/module 0.14.2 | ||
https://github.com/anpham6/squared-functions */ | ||
@@ -46,3 +46,3 @@ | ||
static escapePattern(value) { | ||
return value.replace(/[-|\\{}()[\]^$+*?.]/g, capture => capture === '-' ? '\\x2d' : '\\' + capture); | ||
return typeof value === 'string' ? value.replace(/[-|\\{}()[\]^$+*?.]/g, capture => capture === '-' ? '\\x2d' : '\\' + capture) : ''; | ||
} | ||
@@ -102,16 +102,27 @@ static formatMessage(type, title, value, message, options = {}) { | ||
} | ||
const useColor = !(options.useColor === false || SETTINGS.color === false); | ||
if (Array.isArray(value)) { | ||
const hint = value[1]; | ||
let length = 0; | ||
if (typeof value[1] === 'string' && (length = value[1].length)) { | ||
const formatHint = (hint) => { | ||
if (typeof hint === 'string' && (length = hint.length)) { | ||
const getHint = () => length > 32 ? hint.substring(0, 29) + '...' : hint; | ||
const formatHint = (content) => { | ||
const { hintColor, hintBgColor } = options; | ||
if (hintColor) { | ||
hint = chalk[hintColor](hint); | ||
content = chalk[hintColor](content); | ||
} | ||
if (hintBgColor) { | ||
hint = chalk[hintBgColor](hint); | ||
content = chalk[hintBgColor](content); | ||
} | ||
return hint; | ||
return content; | ||
}; | ||
value = value[0].padEnd(38) + (length < 32 ? chalk.blackBright(' '.repeat(32 - length)) : '') + chalk.blackBright('[') + formatHint(length > 32 ? value[1].substring(0, 29) + '...' : value[1]) + chalk.blackBright(']'); | ||
value = value[0].padEnd(38); | ||
if (length < 32) { | ||
let padding = ' '.repeat(32 - length); | ||
if (useColor) { | ||
padding = chalk.blackBright(padding); | ||
} | ||
value += padding; | ||
} | ||
value += useColor ? chalk.blackBright('[') + formatHint(getHint()) + chalk.blackBright(']') : `[${getHint()}]`; | ||
} | ||
@@ -125,19 +136,24 @@ else { | ||
} | ||
const { titleColor = 'green', titleBgColor = 'bgBlack', valueColor, valueBgColor, messageColor, messageBgColor } = options; | ||
if (valueColor) { | ||
value = chalk[valueColor](value); | ||
} | ||
if (valueBgColor) { | ||
value = chalk[valueBgColor](value); | ||
} | ||
if (message) { | ||
if (messageColor) { | ||
message = chalk[messageColor](message); | ||
if (useColor) { | ||
const { titleColor = 'green', titleBgColor = 'bgBlack', valueColor, valueBgColor, messageColor, messageBgColor } = options; | ||
if (valueColor) { | ||
value = chalk[valueColor](value); | ||
} | ||
if (messageBgColor) { | ||
message = chalk[messageBgColor](message); | ||
if (valueBgColor) { | ||
value = chalk[valueBgColor](value); | ||
} | ||
message = ' ' + chalk.blackBright('(') + message + chalk.blackBright(')'); | ||
if (message) { | ||
if (messageColor) { | ||
message = chalk[messageColor](message); | ||
} | ||
if (messageBgColor) { | ||
message = chalk[messageBgColor](message); | ||
} | ||
message = ' ' + chalk.blackBright('(') + message + chalk.blackBright(')'); | ||
} | ||
console.log(chalk[titleBgColor].bold[titleColor](title.toUpperCase().padEnd(7)) + chalk.blackBright(':') + ' ' + value + (message || '')); // eslint-disable-line no-console | ||
} | ||
console.log(chalk[titleBgColor].bold[titleColor](title.toUpperCase().padEnd(7)) + chalk.blackBright(':') + ' ' + value + (message || '')); // eslint-disable-line no-console | ||
else { | ||
console.log(title.toUpperCase().padEnd(7) + ':' + ' ' + value + (message && ` (${message})` || '')); // eslint-disable-line no-console | ||
} | ||
} | ||
@@ -203,6 +219,6 @@ static writeFail(value, message, type) { | ||
static isFileUNC(value) { | ||
return /^\\\\([\w.-]+)\\([\w-]+\$?)((?<=\$)(?:[^\\]*|\\.+)|\\.+)$/.test(value); | ||
return /^(?:\\\\|\/\/)([\w.-]+)[\\/]([\w-]+\$?)((?<=\$)(?:[^\\/]*|[\\/].+)|[\\/].+)$/.test(value); | ||
} | ||
static isDirectoryUNC(value) { | ||
return /^\\\\([\w.-]+)\\([\w-]+\$|[\w-]+\$\\.+|[\w-]+\\.*)$/.test(value); | ||
return /^(?:\\\\|\/\/)([\w.-]+)[\\/]([\w-]+\$|[\w-]+\$[\\/].+|[\w-]+[\\/].*)$/.test(value); | ||
} | ||
@@ -268,3 +284,3 @@ static isUUID(value) { | ||
static joinPath(...values) { | ||
values = values.filter(value => value && value.trim().replace(/\\+/g, '/')); | ||
values = values.filter(value => value && value.trim().replace(/\\/g, '/')); | ||
let result = ''; | ||
@@ -271,0 +287,0 @@ for (let i = 0; i < values.length; ++i) { |
{ | ||
"name": "@squared-functions/module", | ||
"version": "0.14.1", | ||
"version": "0.14.2", | ||
"description": "Module extension class for squared-functions", | ||
@@ -18,3 +18,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@squared-functions/types": "^0.14.1", | ||
"@squared-functions/types": "^0.14.2", | ||
"uuid": "^8.3.2", | ||
@@ -21,0 +21,0 @@ "chalk": "^4.1.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15835
368