Skip to content

Commit

Permalink
Codemod unnamed default exports to have names
Browse files Browse the repository at this point in the history
This makes debugging that much easier when functions have names instead of just being <anonymous>.

Using facebook/create-react-app#8924 (comment)
  • Loading branch information
akx committed Mar 5, 2021
1 parent db14c64 commit 7e5548c
Show file tree
Hide file tree
Showing 116 changed files with 466 additions and 116 deletions.
4 changes: 3 additions & 1 deletion src/_prepare.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import parse from './parse';

export default (color, mode) =>
const prepare = (color, mode) =>
color === undefined
? undefined
: typeof color !== 'object'
Expand All @@ -10,3 +10,5 @@ export default (color, mode) =>
: mode
? { ...color, mode }
: undefined;

export default prepare;
4 changes: 3 additions & 1 deletion src/a98/convertA98ToXyz65.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

const linearize = v => Math.pow(Math.abs(v), 563 / 256) * Math.sign(v);

export default a98 => {
const convertA98ToXyz65 = a98 => {
let r = linearize(a98.r);
let g = linearize(a98.g);
let b = linearize(a98.b);
Expand All @@ -33,3 +33,5 @@ export default a98 => {
}
return res;
};

export default convertA98ToXyz65;
4 changes: 3 additions & 1 deletion src/a98/convertXyz65ToA98.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

const gamma = v => Math.pow(Math.abs(v), 256 / 563) * Math.sign(v);

export default ({ x, y, z, alpha }) => {
const convertXyz65ToA98 = ({ x, y, z, alpha }) => {
let res = {
mode: 'a98',
r: gamma(
Expand All @@ -32,3 +32,5 @@ export default ({ x, y, z, alpha }) => {
}
return res;
};

export default convertXyz65ToA98;
6 changes: 5 additions & 1 deletion src/a98/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ import convertXyz65ToA98 from './convertXyz65ToA98';
import convertRgbToXyz65 from '../xyz65/convertRgbToXyz65';
import convertXyz65ToRgb from '../xyz65/convertXyz65ToRgb';

export default {
const definition = {
...rgb,
mode: 'a98',
alias: ['a98-rgb'],
parsers: [],

input: {
rgb: color => convertXyz65ToA98(convertRgbToXyz65(color)),
xyz65: convertXyz65ToA98
},

output: {
rgb: color => convertXyz65ToRgb(convertA98ToXyz65(color)),
xyz65: convertA98ToXyz65
}
};

export default definition;
4 changes: 3 additions & 1 deletion src/blend.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const BLENDS = {
exclusion: (b, s) => b + s - 2 * b * s
};

export default (colors, type = 'normal', mode = 'rgb') => {
const blend = (colors, type = 'normal', mode = 'rgb') => {
let fn = typeof type === 'function' ? type : BLENDS[type];

let conv = converter(mode);
Expand Down Expand Up @@ -77,3 +77,5 @@ export default (colors, type = 'normal', mode = 'rgb') => {
);
});
};

export default blend;
6 changes: 5 additions & 1 deletion src/colors/named.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
const named = {
aliceblue: 0xf0f8ff,
antiquewhite: 0xfaebd7,
aqua: 0x00ffff,
Expand Down Expand Up @@ -118,9 +118,11 @@ export default {
plum: 0xdda0dd,
powderblue: 0xb0e0e6,
purple: 0x800080,

// Added in CSS Colors Level 4:
// https://drafts.csswg.org/css-color/#changes-from-3
rebeccapurple: 0x663399,

red: 0xff0000,
rosybrown: 0xbc8f8f,
royalblue: 0x4169e1,
Expand Down Expand Up @@ -150,3 +152,5 @@ export default {
yellow: 0xffff00,
yellowgreen: 0x9acd32
};

export default named;
4 changes: 3 additions & 1 deletion src/cubehelix/convertCubehelixToRgb.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { degToRad, M } from './constants';

export default ({ h, s, l, alpha }) => {
const convertCubehelixToRgb = ({ h, s, l, alpha }) => {
let res = { mode: 'rgb' };

h = (h === undefined ? 0 : h + 120) * degToRad;
Expand All @@ -17,3 +17,5 @@ export default ({ h, s, l, alpha }) => {
if (alpha !== undefined) res.alpha = alpha;
return res;
};

export default convertCubehelixToRgb;
4 changes: 3 additions & 1 deletion src/cubehelix/convertRgbToCubehelix.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let DE = M[3] * M[4];
let BE = M[1] * M[4];
let BCAD = M[1] * M[2] - M[0] * M[3];

export default ({ r, g, b, alpha }) => {
const convertRgbToCubehelix = ({ r, g, b, alpha }) => {
let l = (BCAD * b + r * DE - g * BE) / (BCAD + DE - BE);
let x = b - l;
let y = (M[4] * (g - l) - M[2] * x) / M[3];
Expand All @@ -36,3 +36,5 @@ export default ({ r, g, b, alpha }) => {

return res;
};

export default convertRgbToCubehelix;
10 changes: 9 additions & 1 deletion src/cubehelix/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,23 @@ import convertCubehelixToRgb from './convertCubehelixToRgb';
import { differenceHueSaturation } from '../difference';
import { averageAngle } from '../average';

export default {
const definition = {
mode: 'cubehelix',
channels: ['h', 's', 'l', 'alpha'],

ranges: {
h: [0, 360],
s: [0, 4.6143]
},

input: {
rgb: convertRgbToCubehelix
},

output: {
rgb: convertCubehelixToRgb
},

interpolate: {
h: {
use: interpolatorLinear,
Expand All @@ -64,10 +68,14 @@ export default {
fixup: fixupAlpha
}
},

difference: {
h: differenceHueSaturation
},

average: {
h: averageAngle
}
};

export default definition;
4 changes: 3 additions & 1 deletion src/displayable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import converter from './converter';

let rgb = converter('rgb');

export default color => {
const displayable = color => {
let c = rgb(color);
return (
c !== undefined &&
Expand All @@ -14,3 +14,5 @@ export default color => {
c.b <= 1
);
};

export default displayable;
4 changes: 3 additions & 1 deletion src/dlab/convertDlabToLab65.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import convertDlabToDlch from '../dlch/convertDlabToDlch';
import convertDlchToLab65 from '../dlch/convertDlchToLab65';

export default c => convertDlchToLab65(convertDlabToDlch(c));
const convertDlabToLab65 = c => convertDlchToLab65(convertDlabToDlch(c));

export default convertDlabToLab65;
4 changes: 3 additions & 1 deletion src/dlab/convertLab65ToDlab.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import convertLab65ToDlch from '../dlch/convertLab65ToDlch';
import convertDlchToDlab from '../dlch/convertDlchToDlab';

export default c => convertDlchToDlab(convertLab65ToDlch(c));
const convertLab65ToDlab = c => convertDlchToDlab(convertLab65ToDlch(c));

export default convertLab65ToDlab;
9 changes: 8 additions & 1 deletion src/dlab/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ import convertRgbToLab65 from '../lab65/convertRgbToLab65';
import { interpolatorLinear } from '../interpolate/linear';
import { fixupAlpha } from '../fixup/alpha';

export default {
const definition = {
mode: 'dlab',

output: {
lab65: convertDlabToLab65,
rgb: c => convertLab65ToRgb(convertDlabToLab65(c))
},

input: {
lab65: convertLab65ToDlab,
rgb: c => convertLab65ToDlab(convertRgbToLab65(c))
},

channels: ['l', 'a', 'b', 'alpha'],

ranges: {
l: [0, 100],
a: [-40.09, 45.5],
b: [-40.47, 44.344]
},

interpolate: {
l: interpolatorLinear,
a: interpolatorLinear,
Expand All @@ -31,3 +36,5 @@ export default {
}
}
};

export default definition;
4 changes: 3 additions & 1 deletion src/dlch/convertDlabToDlch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import normalizeHue from '../util/normalizeHue';

export default ({ l, a, b, alpha }) => {
const convertDlabToDlch = ({ l, a, b, alpha }) => {
let c = Math.sqrt(a * a + b * b);
let res = {
mode: 'dlch',
Expand All @@ -11,3 +11,5 @@ export default ({ l, a, b, alpha }) => {
if (alpha !== undefined) res.alpha = alpha;
return res;
};

export default convertDlabToDlch;
4 changes: 3 additions & 1 deletion src/dlch/convertDlchToDlab.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default ({ l, c, h, alpha }) => {
const convertDlchToDlab = ({ l, c, h, alpha }) => {
let res = {
mode: 'dlab',
l: l,
Expand All @@ -8,3 +8,5 @@ export default ({ l, c, h, alpha }) => {
if (alpha !== undefined) res.alpha = alpha;
return res;
};

export default convertDlchToDlab;
4 changes: 3 additions & 1 deletion src/dlch/convertDlchToLab65.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { kCH, kE, sinθ, cosθ, θ, factor } from './constants';
--------------------------------
*/

export default ({ l, c, h, alpha }) => {
const convertDlchToLab65 = ({ l, c, h, alpha }) => {
let res = {
mode: 'lab65',
l: (Math.exp((l * kE) / factor) - 1) / 0.0039
Expand All @@ -24,3 +24,5 @@ export default ({ l, c, h, alpha }) => {
if (alpha !== undefined) res.alpha = alpha;
return res;
};

export default convertDlchToLab65;
4 changes: 3 additions & 1 deletion src/dlch/convertLab65ToDlch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import normalizeHue from '../util/normalizeHue';
================================
*/

export default ({ l, a, b, alpha }) => {
const convertLab65ToDlch = ({ l, a, b, alpha }) => {
let e = a * cosθ + b * sinθ;
let f = 0.83 * (b * cosθ - a * sinθ);
let G = Math.sqrt(e * e + f * f);
Expand All @@ -23,3 +23,5 @@ export default ({ l, a, b, alpha }) => {
if (alpha !== undefined) res.alpha = alpha;
return res;
};

export default convertLab65ToDlch;
11 changes: 10 additions & 1 deletion src/dlch/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,29 @@ import { interpolatorLinear } from '../interpolate/linear';
import { differenceHueChroma } from '../difference';
import { averageAngle } from '../average';

export default {
const definition = {
mode: 'dlch',

output: {
lab65: convertDlchToLab65,
dlab: convertDlchToDlab,
rgb: c => convertLab65ToRgb(convertDlchToLab65(c))
},

input: {
lab65: convertLab65ToDlch,
dlab: convertDlabToDlch,
rgb: c => convertLab65ToDlch(convertRgbToLab65(c))
},

channels: ['l', 'c', 'h', 'alpha'],

ranges: {
l: [0, 100],
c: [0, 51.484],
h: [0, 360]
},

interpolate: {
l: interpolatorLinear,
c: interpolatorLinear,
Expand All @@ -41,10 +46,14 @@ export default {
fixup: fixupAlpha
}
},

difference: {
h: differenceHueChroma
},

average: {
h: averageAngle
}
};

export default definition;
4 changes: 3 additions & 1 deletion src/easing/gamma.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export default (γ = 1) => (γ === 1 ? t => t : t => Math.pow(t, γ));
const gamma = (γ = 1) => (γ === 1 ? t => t : t => Math.pow(t, γ));

export default gamma;
4 changes: 3 additions & 1 deletion src/easing/inOutSine.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*
Sinusoidal (cosine) in-out easing
*/
export default t => (1 - Math.cos(t * Math.PI)) / 2;
const inOutSine = t => (1 - Math.cos(t * Math.PI)) / 2;

export default inOutSine;
4 changes: 3 additions & 1 deletion src/easing/midpoint.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Color interpolation hint exponential function
export default (H = 0.5) => t =>
const midpoint = (H = 0.5) => t =>
H <= 0 ? 1 : H >= 1 ? 0 : Math.pow(t, Math.log(0.5) / Math.log(H));

export default midpoint;
4 changes: 3 additions & 1 deletion src/easing/smootherstep.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
Smootherstep easing function proposed by K. Perlin
Reference: https://en.wikipedia.org/wiki/Smoothstep
*/
export default t => t * t * t * (t * (t * 6 - 15) + 10);
const smootherstep = t => t * t * t * (t * (t * 6 - 15) + 10);

export default smootherstep;
4 changes: 3 additions & 1 deletion src/easing/smoothstep.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
Smoothstep easing function.
Reference: https://en.wikipedia.org/wiki/Smoothstep
*/
export default t => t * t * (3 - 2 * t);
const smoothstep = t => t * t * (3 - 2 * t);

export default smoothstep;
2 changes: 1 addition & 1 deletion src/hsi/convertHsiToRgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import normalizeHue from '../util/normalizeHue';

// Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB

export default function ({ h, s, i, alpha }) {
export default function convertHsiToRgb({ h, s, i, alpha }) {
h = normalizeHue(h);
let f = Math.abs(((h / 60) % 2) - 1);
let res;
Expand Down
2 changes: 1 addition & 1 deletion src/hsi/convertRgbToHsi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Formal_derivation

export default function ({ r, g, b, alpha }) {
export default function convertRgbToHsi({ r, g, b, alpha }) {
let M = Math.max(r, g, b),
m = Math.min(r, g, b);
let res = {
Expand Down
Loading

0 comments on commit 7e5548c

Please sign in to comment.