diff --git a/.gitignore b/.gitignore index fd5c110..f9d0d04 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .nyc_output coverage dist +node_modules diff --git a/src/hue-name.js b/src/hue-name.js index 41b9dce..a1f3e2c 100644 --- a/src/hue-name.js +++ b/src/hue-name.js @@ -10,7 +10,7 @@ const names = [ 'blue', // 210 'indigo', // 240 'violet', // 270 - 'fuschia', // 300 + 'fuchsia', // 300 'pink', // 330 'red', // 360 ] @@ -22,4 +22,3 @@ const hueName = h => { } module.exports = hueName - diff --git a/src/index.js b/src/index.js index 9326baa..7e7f4e7 100644 --- a/src/index.js +++ b/src/index.js @@ -2,33 +2,17 @@ const chroma = require('chroma-js') const hueName = require('./hue-name') -const lums = [ - 9, - 8, - 7, - 6, - 5, - 4, - 3, - 2, - 1, - 0 -] - .map(n => n + .5) +const lums = Array(10).fill() + .map((x, i) => i) + .reverse() + .map(n => n + 0.5) .map(n => n / 10) -const createArray = length => { - const arr = [] - for (let i = 0; i < length; i++) { - arr.push(i) - } - return arr -} - const createHues = length => { const hueStep = 360 / length return base => { - const hues = createArray(length) + const hues = Array(length).fill() + .map((x, i) => i) .map(n => Math.floor((base + (n * hueStep)) % 360)) return hues @@ -41,8 +25,13 @@ const desat = n => hex => { } const createBlack = hex => { - const d = desat(1/8)(hex) - return chroma(d).luminance(.05).hex() + const d = desat(1 / 8)(hex) + return chroma(d).luminance(lums.slice(-1).pop()).hex() +} + +const createWhite = hex => { + const d = desat(1 / 8)(hex) + return chroma(d).luminance(lums.slice().shift()).hex() } const createShades = hex => { @@ -54,7 +43,7 @@ const createShades = hex => { // Mappers const keyword = hex => { const [ hue, sat ] = chroma(hex).hsl() - if (sat < .5) { + if (sat < 0.5) { return 'gray' } const name = hueName(hue) @@ -77,12 +66,17 @@ const palx = (hex, options = {}) => { colors.push({ key: 'black', - value: createBlack('' + color.hex()) + value: createBlack('' + color.hex()), + }) + + colors.push({ + key: 'white', + value: createWhite('' + color.hex()), }) colors.push({ key: 'gray', - value: createShades(desat(1/8)('' + color.hex())) + value: createShades(desat(1 / 8)('' + color.hex())), }) hues.forEach(h => { @@ -90,7 +84,7 @@ const palx = (hex, options = {}) => { const key = keyword(c) colors.push({ key, - value: createShades('' + c.hex()) + value: createShades('' + c.hex()), }) }) @@ -102,4 +96,3 @@ const palx = (hex, options = {}) => { } module.exports = palx - diff --git a/test/index.js b/test/index.js index 0d78dcc..d06d44f 100644 --- a/test/index.js +++ b/test/index.js @@ -11,5 +11,5 @@ test('returns a gray object for desaturated base colors', t => { const colors = palx('#444') t.is(typeof colors, 'object') t.snapshot(colors) - t.is(Object.keys(colors).length, 4) + t.is(Object.keys(colors).length, 5) }) diff --git a/test/snapshots/index.js.md b/test/snapshots/index.js.md index ac7b000..fe7149d 100644 --- a/test/snapshots/index.js.md +++ b/test/snapshots/index.js.md @@ -35,7 +35,7 @@ Generated by [AVA](https://ava.li). '#007a70', '#004842', ], - fuschia: [ + fuchsia: [ '#fdf8fe', '#f9e8fa', '#f5d8f7', @@ -155,6 +155,7 @@ Generated by [AVA](https://ava.li). '#864adb', '#4c00b8', ], + white: '#f9f9fa', yellow: [ '#fbfaec', '#f3efc4', @@ -200,4 +201,5 @@ Generated by [AVA](https://ava.li). '#6c6c6c', '#3f3f3f', ], + white: '#f9f9f9', } diff --git a/test/snapshots/index.js.snap b/test/snapshots/index.js.snap index 2029afa..d0e1ae6 100644 Binary files a/test/snapshots/index.js.snap and b/test/snapshots/index.js.snap differ