Skip to content

Commit 653d860

Browse files
author
Matthew Palmer
authored
Add ESLint and Autofix (#10)
* Add eslint with StandardJS style guide * Autolint * Add format npm script and test specific eslint config
1 parent 6e2e65c commit 653d860

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2122
-1242
lines changed

.eslintrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
extends: 'standard',
3+
plugins: [
4+
'standard',
5+
'promise'
6+
]
7+
};

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"test": "BABEL_ENV=test mocha --compilers js:babel-core/register",
1111
"build": "npm run build:umd && npm run build:es",
1212
"build:umd": "rollup -c --format umd --output dist/chromatism.js",
13-
"build:es": "rollup -c --format es --output dist/chromatism.esm.js"
13+
"build:es": "rollup -c --format es --output dist/chromatism.esm.js",
14+
"format": "eslint --fix src/**/*.js test/**/*.js"
1415
},
1516
"keywords": [
1617
"color",
@@ -29,6 +30,12 @@
2930
"babel-core": "^6.22.1",
3031
"babel-plugin-external-helpers": "^6.22.0",
3132
"babel-preset-env": "^1.5.2",
33+
"eslint": "^3.19.0",
34+
"eslint-config-standard": "^10.2.1",
35+
"eslint-plugin-import": "^2.3.0",
36+
"eslint-plugin-node": "^5.0.0",
37+
"eslint-plugin-promise": "^3.5.0",
38+
"eslint-plugin-standard": "^3.0.1",
3239
"mocha": "^3.2.0",
3340
"rollup": "^0.41.6",
3441
"rollup-plugin-babel": "^2.7.1",

rollup.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import resolve from 'rollup-plugin-node-resolve'
22
import commonjs from 'rollup-plugin-commonjs'
3-
import babel from 'rollup-plugin-babel';
4-
import uglify from 'rollup-plugin-uglify';
3+
import babel from 'rollup-plugin-babel'
4+
import uglify from 'rollup-plugin-uglify'
55
import { minify } from 'uglify-es'
66

77
export default {

src/conversions/fromCieLab.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ const white = helpers.getIlluminant('D65')
66
const toR = f => Math.pow(f, 3) > epsilon ? Math.pow(f, 3) : ((116 * f) - 16) / kappa
77

88
module.exports = {
9-
XYZ: value => {
10-
const Fy = (value.L + 16) / 116
11-
const Fx = (value.a / 500) + Fy
12-
const Fz = Fy - (value.b / 200)
9+
XYZ: value => {
10+
const Fy = (value.L + 16) / 116
11+
const Fx = (value.a / 500) + Fy
12+
const Fz = Fy - (value.b / 200)
1313

14+
const Xr = toR(Fx), Zr = toR(Fz)
15+
const Yr = value.L > (kappa * epsilon) ? Math.pow(Fy, 3) : value.L / kappa
1416

15-
const Xr = toR(Fx), Zr = toR(Fz)
16-
const Yr = value.L > (kappa * epsilon) ? Math.pow(Fy, 3) : value.L / kappa
17-
18-
return {
19-
X: Xr * white.X,
20-
Y: Yr * white.Y,
21-
Z: Zr * white.Z
22-
}
23-
}
17+
return {
18+
X: Xr * white.X,
19+
Y: Yr * white.Y,
20+
Z: Zr * white.Z
21+
}
22+
}
2423
}

src/conversions/fromCieLch.js

+53-53
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
1-
const { toRad, getTransform, } = require('../helpers.js')
1+
const { toRad, getTransform } = require('../helpers.js')
22

33
module.exports = {
4-
cieluv: value => {
5-
const h = toRad(value.h)
4+
cieluv: value => {
5+
const h = toRad(value.h)
66

7-
const u = value.C * Math.cos(h)
8-
const v = value.C * Math.sin(h)
7+
const u = value.C * Math.cos(h)
8+
const v = value.C * Math.sin(h)
99

10-
return {
11-
L: value.L,
12-
u,
13-
v
14-
}
15-
},
10+
return {
11+
L: value.L,
12+
u,
13+
v
14+
}
15+
},
1616

17-
hsluv: value => {
18-
if (value.L > 99.9999999) {
19-
return { hu: value.h, s: 0, l: 100 }
20-
}
21-
if (value.L < 0.00000001) {
22-
return { hu: value.h, s: 0, l: 0 }
23-
}
17+
hsluv: value => {
18+
if (value.L > 99.9999999) {
19+
return { hu: value.h, s: 0, l: 100 }
20+
}
21+
if (value.L < 0.00000001) {
22+
return { hu: value.h, s: 0, l: 0 }
23+
}
2424

25-
const epsilon = 0.008856
26-
const kappa = 903.3
25+
const epsilon = 0.008856
26+
const kappa = 903.3
2727

28-
const s1 = (value.L + 16) / 1560896
29-
const s2 = s1 > epsilon ? s1 : value.L / kappa
28+
const s1 = (value.L + 16) / 1560896
29+
const s2 = s1 > epsilon ? s1 : value.L / kappa
3030

31-
const m = getTransform('INVERSE_SRGB_XYZ')
32-
let rays = []
31+
const m = getTransform('INVERSE_SRGB_XYZ')
32+
let rays = []
3333

34-
for (let c = 0; c < 3; c++) {
35-
let m1 = m[c][0]
36-
let m2 = m[c][1]
37-
let m3 = m[c][2]
34+
for (let c = 0; c < 3; c++) {
35+
let m1 = m[c][0]
36+
let m2 = m[c][1]
37+
let m3 = m[c][2]
3838

39-
for (let t = 0; t < 2; t++) {
40-
let top1 = (284517 * m1 - 94839 * m3) * s2
41-
let top2 = (838422 * m3 + 769860 * m2 + 731718 * m1) * value.L * s2 - 769860 * t * value.L
42-
let bottom = (632260 * m3 - 126452 * m2) * s2 + 126452 * t
39+
for (let t = 0; t < 2; t++) {
40+
let top1 = (284517 * m1 - 94839 * m3) * s2
41+
let top2 = (838422 * m3 + 769860 * m2 + 731718 * m1) * value.L * s2 - 769860 * t * value.L
42+
let bottom = (632260 * m3 - 126452 * m2) * s2 + 126452 * t
4343

44-
rays.push({
45-
m: top1 / bottom,
46-
b: top2 / bottom
47-
})
48-
}
49-
}
44+
rays.push({
45+
m: top1 / bottom,
46+
b: top2 / bottom
47+
})
48+
}
49+
}
5050

51-
var min = Number.MAX_VALUE
52-
let hrad = toRad(value.h)
51+
var min = Number.MAX_VALUE
52+
let hrad = toRad(value.h)
5353

54-
rays.forEach((ray) => {
55-
let length = ray.b / (Math.sin(hrad) - ray.m * Math.cos(hrad))
56-
if (length >= 0) {
57-
min = Math.min(min, length)
58-
}
59-
})
54+
rays.forEach((ray) => {
55+
let length = ray.b / (Math.sin(hrad) - ray.m * Math.cos(hrad))
56+
if (length >= 0) {
57+
min = Math.min(min, length)
58+
}
59+
})
6060

61-
let max = min
61+
let max = min
6262

63-
return {
64-
hu: value.h,
65-
s: value.C / max * 100,
66-
l: value.L
67-
}
68-
}
63+
return {
64+
hu: value.h,
65+
s: value.C / max * 100,
66+
l: value.L
67+
}
68+
}
6969
}

src/conversions/fromCieLuv.js

+42-42
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
const helpers = require('../helpers.js')
22

33
module.exports = {
4-
XYZ: value => {
5-
const epsilon = 0.008856
6-
const kappa = 903.3
7-
const white = helpers.getIlluminant('D65')
8-
9-
const chromeCoordsU = (c) => (c.X * 4) / (c.X + (15 * c.Y) + (3 * c.Z))
10-
const chromeCoordsV = (c) => (c.Y * 9) / (c.X + (15 * c.Y) + (3 * c.Z))
11-
12-
const u0 = chromeCoordsU(white)
13-
const v0 = chromeCoordsV(white)
14-
15-
const a = (1 / 3) * (((52 * value.L) / (value.u + ((13 * value.L) * u0))) - 1)
16-
17-
const Y = value.L > (kappa * epsilon) ? (Math.pow(((value.L + 16) / 116), 3)) : value.L / kappa
18-
19-
const b = -5 * Y
20-
const d = Y * (((39 * value.L) / (value.v + ((13 * value.L) * v0))) - 5)
21-
22-
const X = (d - b) / (a - (-1 / 3))
23-
const Z = (X * a) + b
24-
25-
return {
26-
X: X * 100,
27-
Y: Y * 100,
28-
Z: Z * 100
29-
}
30-
},
31-
32-
cielch: value => {
33-
const C = Math.sqrt(Math.pow(value.u, 2) + Math.pow(value.v, 2))
34-
let h = Math.atan2(value.v, value.u)
35-
if (h < 0) {
36-
h += (2 * Math.PI)
37-
}
38-
h = helpers.toDeg(h)
39-
40-
return {
41-
L: value.L,
42-
C,
43-
h
44-
}
45-
}
4+
XYZ: value => {
5+
const epsilon = 0.008856
6+
const kappa = 903.3
7+
const white = helpers.getIlluminant('D65')
8+
9+
const chromeCoordsU = (c) => (c.X * 4) / (c.X + (15 * c.Y) + (3 * c.Z))
10+
const chromeCoordsV = (c) => (c.Y * 9) / (c.X + (15 * c.Y) + (3 * c.Z))
11+
12+
const u0 = chromeCoordsU(white)
13+
const v0 = chromeCoordsV(white)
14+
15+
const a = (1 / 3) * (((52 * value.L) / (value.u + ((13 * value.L) * u0))) - 1)
16+
17+
const Y = value.L > (kappa * epsilon) ? (Math.pow(((value.L + 16) / 116), 3)) : value.L / kappa
18+
19+
const b = -5 * Y
20+
const d = Y * (((39 * value.L) / (value.v + ((13 * value.L) * v0))) - 5)
21+
22+
const X = (d - b) / (a - (-1 / 3))
23+
const Z = (X * a) + b
24+
25+
return {
26+
X: X * 100,
27+
Y: Y * 100,
28+
Z: Z * 100
29+
}
30+
},
31+
32+
cielch: value => {
33+
const C = Math.sqrt(Math.pow(value.u, 2) + Math.pow(value.v, 2))
34+
let h = Math.atan2(value.v, value.u)
35+
if (h < 0) {
36+
h += (2 * Math.PI)
37+
}
38+
h = helpers.toDeg(h)
39+
40+
return {
41+
L: value.L,
42+
C,
43+
h
44+
}
45+
}
4646
}

src/conversions/fromCmyk.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
const rgb = value => {
2-
var r = 255 * (1 - value.c) * (1 - value.k)
3-
var g = 255 * (1 - value.m) * (1 - value.k)
4-
var b = 255 * (1 - value.y) * (1 - value.k)
5-
return { r: r, g: g, b: b }
2+
var r = 255 * (1 - value.c) * (1 - value.k)
3+
var g = 255 * (1 - value.m) * (1 - value.k)
4+
var b = 255 * (1 - value.y) * (1 - value.k)
5+
return { r: r, g: g, b: b }
66
}
77

88
module.exports = {
9-
rgb,
9+
rgb,
1010

11-
cssrgb: value => {
12-
const { r, g, b } = rgb(value)
11+
cssrgb: value => {
12+
const { r, g, b } = rgb(value)
1313

14-
return "rgb(" + Math.round(r) + "," + Math.round(g) + "," + Math.round(b) + ")"
15-
}
14+
return 'rgb(' + Math.round(r) + ',' + Math.round(g) + ',' + Math.round(b) + ')'
15+
}
1616
}

src/conversions/fromCssHsl.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module.exports = {
2-
hsl: value => {
3-
const values = value
2+
hsl: value => {
3+
const values = value
44
.replace(/(hsl\(|\)|%|[\s]*)/g, '')
5-
.split(",")
5+
.split(',')
66
.map(value => parseInt(value, 10))
77

8-
return {
9-
h: values[0],
10-
s: values[1],
11-
l: values[2]
12-
}
13-
}
8+
return {
9+
h: values[0],
10+
s: values[1],
11+
l: values[2]
12+
}
13+
}
1414
}

src/conversions/fromCssRgb.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module.exports = {
2-
rgb: value => {
3-
const values = value
2+
rgb: value => {
3+
const values = value
44
.replace(/((rgb\(|\))|[\s]*)/g, '')
5-
.split(",")
5+
.split(',')
66
.map(value => parseInt(value, 10))
77

8-
return {
9-
r: values[0],
10-
g: values[1],
11-
b: values[2]
12-
}
13-
}
8+
return {
9+
r: values[0],
10+
g: values[1],
11+
b: values[2]
12+
}
13+
}
1414
}

src/conversions/fromHex.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module.exports = {
2-
rgb: value => {
3-
const values = value
2+
rgb: value => {
3+
const values = value
44
.replace('#', '')
55
.match(/.{2}/g)
66
.map(value => parseInt(value, 16))
77

8-
return {
9-
r: values[0],
10-
g: values[1],
11-
b: values[2]
12-
}
13-
}
8+
return {
9+
r: values[0],
10+
g: values[1],
11+
b: values[2]
12+
}
13+
}
1414
}

0 commit comments

Comments
 (0)