color-name-list 11.9.0 → 11.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,17 @@
1
- import { execSync } from "child_process";
1
+ import { execSync } from 'child_process';
2
2
 
3
3
  function cmd(c) {
4
- const stdout = execSync(c);
4
+ const stdout = execSync(c, {
5
+ maxBuffer: 1024 * 1024 * 100,
6
+ });
5
7
  return stdout.toString().trim();
6
8
  }
7
9
 
8
10
  // Print the list of colors added/removed/changed by date.
9
11
  async function main() {
10
12
  // Grab the list of all git commits
11
- const allCommits = cmd("git log --pretty=format:%h")
12
- .split("\n")
13
+ const allCommits = cmd('git log --pretty=format:%h --no-merges --follow -- ./src/colornames.csv')
14
+ .split('\n')
13
15
  .filter(Boolean);
14
16
 
15
17
  // The data, one element for each commit (date)
@@ -17,8 +19,8 @@ async function main() {
17
19
 
18
20
  for (const commit of allCommits) {
19
21
  // Figure out what changed in that particular commit
20
- const diff = cmd(`git show ${commit} -- ./src/colornames.csv`)
21
- .split("\n")
22
+ const diff = cmd(`git show -w --ignore-cr-at-eol ${commit} -- ./src/colornames.csv`)
23
+ .split('\n')
22
24
  .filter(Boolean);
23
25
 
24
26
  // Grab the date for said commit
@@ -28,18 +30,23 @@ async function main() {
28
30
  const modified = {};
29
31
 
30
32
  for (const line of diff) {
33
+ // Ignore the header row
34
+ if (line.match(/^(\+|-)?name,hex/)) {
35
+ continue;
36
+ }
37
+
31
38
  const res = line.match(/^((?<op>(\+|-)))(?<name>[^,]+),(?<hex>[^,]+)/);
32
39
  if (!res) {
33
40
  continue;
34
41
  }
35
42
  const name = res.groups?.name;
36
43
  const hex = res.groups?.hex?.trim(); // Remove any \r or whitespace
37
- var op = res.groups?.op;
44
+ let op = res.groups?.op;
38
45
 
39
46
  // If a value already introduced with a different op, then it's
40
47
  // a modification
41
48
  if (modified[hex] && modified[hex].op !== op) {
42
- op = "~";
49
+ op = '~';
43
50
  }
44
51
 
45
52
  modified[hex] = { hex, name, op };
@@ -48,15 +55,15 @@ async function main() {
48
55
  // Partition by added/removed/changed
49
56
 
50
57
  const added = Object.values(modified)
51
- .filter((x) => x.op === "+")
58
+ .filter((x) => x.op === '+')
52
59
  .map(({ name, hex }) => ({ name, hex }));
53
60
 
54
61
  const removed = Object.values(modified)
55
- .filter((x) => x.op === "-")
62
+ .filter((x) => x.op === '-')
56
63
  .map(({ name, hex }) => ({ name, hex }));
57
64
 
58
65
  const changed = Object.values(modified)
59
- .filter((x) => x.op === "~")
66
+ .filter((x) => x.op === '~')
60
67
  .map(({ name, hex }) => ({ name, hex }));
61
68
 
62
69
  // Add the day only if there were changes
@@ -1,8 +1,6 @@
1
1
  const fs = require('fs');
2
2
  const colors = fs.readFileSync('colors.csv').toString().split(`\n`);
3
- const namedColors = JSON.parse(
4
- fs.readFileSync(__dirname + '/../../dist/colornames.json', 'utf8')
5
- );
3
+ const namedColors = JSON.parse(fs.readFileSync(__dirname + '/../../dist/colornames.json', 'utf8'));
6
4
  const nearestColor = require('../../node_modules/nearest-color/nearestColor.js');
7
5
 
8
6
  // object containing the name:hex pairs for nearestColor()
@@ -15,7 +13,7 @@ namedColors.forEach((c) => {
15
13
  const nc = nearestColor.from(colorsObj);
16
14
 
17
15
  const newNames = [];
18
- colors.forEach(color => {
16
+ colors.forEach((color) => {
19
17
  if (!color) return;
20
18
  let n = nc(color);
21
19
  newNames.push(n.name + ',' + color);
@@ -2,21 +2,21 @@
2
2
  // and rexports them as csv
3
3
 
4
4
  const fs = require('fs');
5
- const tinycolor = require("tinycolor2");
5
+ const tinycolor = require('tinycolor2');
6
6
  const colors = JSON.parse(fs.readFileSync('someColorList.json').toString());
7
7
 
8
8
  let newColors = [];
9
9
 
10
10
  colors.forEach((col) => {
11
- const rand = Math.round( 4 * Math.random() * (Math.random() < .5 ? -1 : 1) );
12
- const lightMod = Math.round( Math.random() * 5);
11
+ const rand = Math.round(4 * Math.random() * (Math.random() < 0.5 ? -1 : 1));
12
+ const lightMod = Math.round(Math.random() * 5);
13
13
  let hex;
14
14
 
15
15
  let tinyCol = tinycolor(col.hex).spin(rand);
16
16
 
17
- if (tinyCol.isDark() ) {
17
+ if (tinyCol.isDark()) {
18
18
  tinyCol.lighten(lightMod);
19
- }else{
19
+ } else {
20
20
  tinyCol.darken(lightMod);
21
21
  }
22
22
 
@@ -24,7 +24,7 @@ colors.forEach((col) => {
24
24
 
25
25
  newColors.push({
26
26
  name: col.name,
27
- hex: hex
27
+ hex: hex,
28
28
  });
29
29
 
30
30
  console.log(`${col.hex} => ${hex} : ${col.name}`);
@@ -34,7 +34,7 @@ colors.forEach((col) => {
34
34
  // create CSV
35
35
  let csv = 'name,hex\n';
36
36
 
37
- newColors.forEach(col => {
37
+ newColors.forEach((col) => {
38
38
  csv += `${col.name},${col.hex}\n`;
39
39
  });
40
40