Comparing version 14.0.0 to 14.1.0
@@ -0,1 +1,13 @@ | ||
# [14.1.0](https://github.com/esatterwhite/node-seeli/compare/v14.0.0...v14.1.0) (2022-12-08) | ||
### Chores | ||
* **dep**: nopt@7.0.0 [4dca598](https://github.com/esatterwhite/node-seeli/commit/4dca59848232ee8b24873055f02c5e4d82493d3d) - Eric Satterwhite | ||
### Features | ||
* **colorize**: enable color mode parsing [578801d](https://github.com/esatterwhite/node-seeli/commit/578801ddddb032097e4757d912fc5504a7e97829) - Eric Satterwhite | ||
# [14.0.0](https://github.com/esatterwhite/node-seeli/compare/v13.0.3...v14.0.0) (2022-09-05) | ||
@@ -2,0 +14,0 @@ |
@@ -12,9 +12,32 @@ 'use strict' | ||
const conf = require('./conf') | ||
const {InvalidColorModeException} = require('./exceptions') | ||
module.exports = colorize | ||
const MODES = new Set(['hex', 'ansi256']) | ||
function colorize(txt, override) { | ||
const color = chalk[override || conf.get('color')] || chalk.green | ||
let mode = null | ||
let value = null | ||
const key = override || conf.get('color') || 'green' | ||
const parsed = key.split(':') | ||
if (parsed.length === 1) { | ||
value = parsed[0] | ||
} else { | ||
mode = parsed[0] | ||
value = parsed[1] | ||
} | ||
if (mode && !MODES.has(mode)) { | ||
throw new InvalidColorModeException( | ||
`Invalid color mode: ${mode}` | ||
, Array.from(MODES) | ||
) | ||
} | ||
const color = mode ? chalk[mode](value) : chalk[value] | ||
if (!color) return txt | ||
return color(txt) | ||
} |
@@ -30,3 +30,2 @@ 'use strict' | ||
const debug = require('debug') | ||
const ora = require('ora') | ||
const toArray = require('mout/lang/toArray') | ||
@@ -40,2 +39,3 @@ const isFunction = require('mout/lang/isFunction') | ||
const conf = require('../conf') | ||
const ora = require('../ora') | ||
const usage = require('../usage') | ||
@@ -296,5 +296,4 @@ const object = require('../lang/object') | ||
invalidHandler(key, value, type) { | ||
const color = chalk[conf.get('color')] | ||
const got = color(typeOf(value)) | ||
const expected = color(typeOf(type)) | ||
const expected = colorize(typeOf(type)) | ||
const msg = `${chalk.white('Expected')} ${expected} got ${got}` | ||
@@ -301,0 +300,0 @@ const error = new exceptions.InvalidFieldException( |
@@ -255,2 +255,32 @@ 'use strict' | ||
class InvalidColorModeException extends Error { | ||
constructor(msg, modes) { | ||
super() | ||
/** | ||
* @readonly | ||
* @instance | ||
* @memberof module:seeli/lib/exceptions.PluginException | ||
* @name name | ||
* @property {String} name=PluginException Exception name | ||
**/ | ||
this.name = 'InvalidColorModeException' | ||
/** | ||
* @readonly | ||
* @instance | ||
* @memberof module:seeli/lib/exceptions.PluginException | ||
* @name message | ||
* @property {String} message Message to include in error output | ||
**/ | ||
this.message = `${msg}. Valid color modes: ${modes.join(', ')}` | ||
/** | ||
* @readonly | ||
* @instance | ||
* @memberof module:seeli/lib/exceptions.PluginException | ||
* @name code | ||
* @property {String} message A Unique error code identifier | ||
**/ | ||
this.code = 'ECOLORMODE' | ||
} | ||
} | ||
module.exports = { | ||
@@ -264,2 +294,3 @@ RequiredFieldException: RequiredFieldException | ||
, PluginException: PluginException | ||
, InvalidColorModeException: InvalidColorModeException | ||
} |
@@ -16,2 +16,3 @@ 'use strict' | ||
const conf = require('../conf') | ||
const colorize = require('../colorize') | ||
const usage = chalk.white.bold | ||
@@ -23,3 +24,2 @@ | ||
const registry = commands || require('../commands') | ||
const color = chalk[conf.get('color')] || noop | ||
@@ -31,7 +31,7 @@ try { | ||
descriptions.push( | ||
`${usage('* ')} ${color(name)} - ${cmd.description}` | ||
`${usage('* ')} ${colorize(name)} - ${cmd.description}` | ||
) | ||
} | ||
const content = [ | ||
`${usage('Usage: ')} ${conf.get('name')} <${color('command')}> [options]` | ||
`${usage('Usage: ')} ${conf.get('name')} <${colorize('command')}> [options]` | ||
, '' | ||
@@ -46,5 +46,1 @@ , 'Where <command> is the name the command to execute' | ||
} | ||
function noop(txt) { | ||
return txt | ||
} |
{ | ||
"name": "seeli", | ||
"version": "14.0.0", | ||
"version": "14.1.0", | ||
"description": "Object oriented, flexible CLI tools", | ||
@@ -96,3 +96,3 @@ "main": "index.js", | ||
"mout": "^1.2.2", | ||
"nopt": "^5.0.0", | ||
"nopt": "^7.0.0", | ||
"ora": "^5.4.1", | ||
@@ -99,0 +99,0 @@ "pkg-up": "^3.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
125441
24
1738
+ Addedabbrev@2.0.0(transitive)
+ Addednopt@7.2.1(transitive)
- Removednopt@5.0.0(transitive)
Updatednopt@^7.0.0