diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index ed8d80d..b4bf72e 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -680,5 +680,38 @@ const info = processInfo(); +#### randomColor([optns]) + +enerating attractive random colors + + + + +##### Parameters + +| Name | Type | Description | | +| ---- | ---- | ----------- | -------- | +| optns | `Object` | valid generator options | *Optional* | +| optns.luminosity=light | `Object` | controls the luminosity of the generated color. you can specify a string containing `bright`, `light` or
`dark`. | *Optional* | + + + + +##### Examples + +```javascript + +const color = randomColor(); +//=> #C349D8 +``` + + +##### Returns + + +- `String` random color + + + *Documentation generated with [doxdox](https://github.com/neogeek/doxdox).* diff --git a/es/index.js b/es/index.js index 2bf68aa..5a362e8 100644 --- a/es/index.js +++ b/es/index.js @@ -2,6 +2,7 @@ import { arch, cpus, endianness, freemem, homedir, hostname, loadavg, networkInt import { isBoolean, flattenDeep, map, reduce, cloneDeep, isArray, compact as compact$1, isPlainObject, omitBy, uniq as uniq$1, orderBy, merge, isEmpty, pick, words, get, camelCase, includes, every, some, forEach, toUpper, toLower, toString, first } from 'lodash'; import { sync } from 'read-pkg'; import { STATUS_CODES } from 'statuses'; +import generateColor from 'randomcolor'; /** * @name RESOURCE_ACTIONS @@ -724,4 +725,31 @@ const processInfo = () => { return info; }; -export { RESOURCE_ACTIONS, abbreviate, areNotEmpty, bagify, compact, has, hasAll, hasAny, idOf, isNotValue, mapErrorToObject, mapToLower, mapToUpper, mergeObjects, osInfo, pkg, processInfo, scopesFor, sortedUniq, uniq, variableNameFor }; +/** + * @function randomColor + * @name randomColor + * @description enerating attractive random colors + * @param {Object} [optns] valid generator options + * @param {Object} [optns.luminosity=light] controls the luminosity of the + * generated color. you can specify a string containing `bright`, `light` or + * `dark`. + * @return {String} random color + * @author lally elias + * @license MIT + * @since 0.18.0 + * @version 0.1.0 + * @static + * @public + * @example + * + * const color = randomColor(); + * //=> #C349D8 + * + */ +const randomColor = (optns = { luminosity: 'light' }) => { + const options = mergeObjects(optns); + const color = generateColor(options); + return color; +}; + +export { RESOURCE_ACTIONS, abbreviate, areNotEmpty, bagify, compact, has, hasAll, hasAny, idOf, isNotValue, mapErrorToObject, mapToLower, mapToUpper, mergeObjects, osInfo, pkg, processInfo, randomColor, scopesFor, sortedUniq, uniq, variableNameFor }; diff --git a/lib/index.js b/lib/index.js index 480b7ea..ac3d34b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,6 +4,7 @@ const os = require('os'); const lodash = require('lodash'); const readPkg = require('read-pkg'); const statuses = require('statuses'); +const generateColor = require('randomcolor'); /** * @name RESOURCE_ACTIONS @@ -726,6 +727,33 @@ const processInfo = () => { return info; }; +/** + * @function randomColor + * @name randomColor + * @description enerating attractive random colors + * @param {Object} [optns] valid generator options + * @param {Object} [optns.luminosity=light] controls the luminosity of the + * generated color. you can specify a string containing `bright`, `light` or + * `dark`. + * @return {String} random color + * @author lally elias + * @license MIT + * @since 0.18.0 + * @version 0.1.0 + * @static + * @public + * @example + * + * const color = randomColor(); + * //=> #C349D8 + * + */ +const randomColor = (optns = { luminosity: 'light' }) => { + const options = mergeObjects(optns); + const color = generateColor(options); + return color; +}; + exports.RESOURCE_ACTIONS = RESOURCE_ACTIONS; exports.abbreviate = abbreviate; exports.areNotEmpty = areNotEmpty; @@ -743,6 +771,7 @@ exports.mergeObjects = mergeObjects; exports.osInfo = osInfo; exports.pkg = pkg; exports.processInfo = processInfo; +exports.randomColor = randomColor; exports.scopesFor = scopesFor; exports.sortedUniq = sortedUniq; exports.uniq = uniq; diff --git a/rollup.config.js b/rollup.config.js index 3bd4706..b47a1db 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,7 +3,7 @@ import pkg from './package.json'; export default [ { input: 'src/index.js', - external: ['lodash', 'read-pkg', 'statuses', 'os'], + external: ['lodash', 'read-pkg', 'statuses', 'os', 'randomcolor'], output: [ { file: pkg.main,