color-name-list 9.7.0 → 9.9.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.
@@ -0,0 +1,48 @@
1
+ const seedrandom = require('seedrandom');
2
+
3
+ /**
4
+ * getPaletteTitle
5
+ * @param {string[]} namesArr
6
+ * @param {int(0-1)} rnd1
7
+ * @param {int(0-1)} rnd2
8
+ * @param {int(0-1)} longPartFirst
9
+ * @param {RegExp} separatorRegex
10
+ * @returns {string}
11
+ */
12
+
13
+ module.exports = function getPaletteTitle(
14
+ namesArr, // array of names
15
+ separatorRegex = /(\s|-)+/g
16
+ ) {
17
+ let localnames = [...namesArr];
18
+
19
+ const rng = seedrandom(namesArr.join('-'));
20
+ const rnd1 = rng();
21
+ const rnd2 = rng();
22
+ const longPartFirst = rng() < .5;
23
+
24
+ // select a random name from the list for the first word in the palette title
25
+ const indexFirst = Math.round(rnd1 * (localnames.length - 1));
26
+
27
+ // remove the selected name from the list
28
+ const firstName = localnames.splice(indexFirst, 1)[0];
29
+
30
+ // select a random name from the list as a last word in the palette title
31
+ const lastIndex = Math.round(rnd2 * (localnames.length - 1));
32
+ const lastName = localnames[lastIndex];
33
+
34
+ const partsFirst = firstName.split(separatorRegex);
35
+ const partsLast = lastName.split(separatorRegex);
36
+
37
+ if (longPartFirst) {
38
+ partsFirst.length > 1 ?
39
+ partsFirst.pop() :
40
+ partsFirst[0] = `${partsFirst[0]} `;
41
+ return partsFirst.join('') + partsLast.pop();
42
+ } else {
43
+ partsLast.length > 1 ?
44
+ partsLast.shift() :
45
+ partsLast[0] = ` ${partsLast[0]}`;
46
+ return partsFirst.shift() + partsLast.join('');
47
+ }
48
+ }
package/scripts/server.js CHANGED
@@ -2,6 +2,7 @@ const http = require('http');
2
2
  const url = require('url');
3
3
  const fs = require('fs');
4
4
  const zlib = require('zlib');
5
+ const colorNameLists = require('color-name-lists');
5
6
  const colors = JSON.parse(
6
7
  fs.readFileSync(__dirname + '/../dist/colornames.json', 'utf8')
7
8
  );
@@ -9,6 +10,7 @@ const colorsBestOf = JSON.parse(
9
10
  fs.readFileSync(__dirname + '/../dist/colornames.bestof.json', 'utf8')
10
11
  );
11
12
  const FindColors = require('./findColors.js');
13
+ const getPaletteTitle = require('./generatePaletteName.js');
12
14
  const port = process.env.PORT || 8080;
13
15
  const currentVersion = 'v1';
14
16
  const urlNameSubpath = 'names';
@@ -26,7 +28,18 @@ const responseHeaderObj = {
26
28
  'Content-Type': 'application/json; charset=utf-8',
27
29
  };
28
30
 
29
- const findColors = new FindColors(colors, colorsBestOf);
31
+ // [{name: 'red', value: '#f00'}, ...]
32
+ const colorsLists = {
33
+ default: colors,
34
+ colors: colors,
35
+ bestOf: colorsBestOf,
36
+ };
37
+
38
+ Object.assign(colorsLists, colorNameLists);
39
+
40
+ const avalibleColorNameLists = Object.keys(colorsLists);
41
+
42
+ const findColors = new FindColors(colorsLists);
30
43
 
31
44
  /**
32
45
  * validates a hex color
@@ -53,7 +66,7 @@ const httpRespond = (response, responseObj = {}, statusCode = 200) => {
53
66
 
54
67
  const respondNameSearch = (
55
68
  searchParams = new URLSearchParams(''),
56
- goodNamesMode = false,
69
+ listKey = 'default',
57
70
  requestUrl,
58
71
  request,
59
72
  response
@@ -77,13 +90,13 @@ const respondNameSearch = (
77
90
  }
78
91
 
79
92
  return httpRespond(response, {
80
- colors: findColors.searchNames(searchString, goodNamesMode),
93
+ colors: findColors.searchNames(searchString, listKey),
81
94
  }, 200);
82
95
  };
83
96
 
84
97
  const respondValueSearch = (
85
98
  searchParams = new URLSearchParams(''),
86
- goodNamesMode = false,
99
+ listKey = 'default',
87
100
  requestUrl,
88
101
  request,
89
102
  response
@@ -116,10 +129,32 @@ const respondValueSearch = (
116
129
  }}, 404);
117
130
  }
118
131
 
132
+ let paletteTitle;
133
+ let colorsResponse;
134
+
135
+ if (urlColorList[0]) {
136
+ colorsResponse = findColors.getNamesForValues(
137
+ urlColorList, uniqueMode, listKey
138
+ );
139
+ } else {
140
+ colorsResponse = colorsLists[listKey];
141
+ }
142
+
143
+ if (urlColorList.length === 1) {
144
+ // if there is only one color, just return its name as palette title
145
+ paletteTitle = colorsResponse[0].name;
146
+ } else if (urlColorList.length > 1) {
147
+ // get a palette title for the returned colors
148
+ paletteTitle = getPaletteTitle(colorsResponse.map((color) => color.name));
149
+ } else {
150
+ // return all colors if no colors were given
151
+ paletteTitle = `All the ${listKey} names`;
152
+ }
153
+
154
+ // actual http response
119
155
  return httpRespond(response, {
120
- colors: urlColorList[0] ?
121
- findColors.getNamesForValues(urlColorList, uniqueMode, goodNamesMode):
122
- (goodNamesMode ? colorsBestOf : colors),
156
+ paletteTitle,
157
+ colors: colorsResponse,
123
158
  }, 200);
124
159
  };
125
160
 
@@ -159,10 +194,25 @@ const requestHandler = (request, response) => {
159
194
  const goodNamesMode = searchParams.has('goodnamesonly')
160
195
  && searchParams.get('goodnamesonly') === 'true';
161
196
 
197
+ let listKey = searchParams.has('list')
198
+ && searchParams.get('list');
199
+
200
+ listKey = goodNamesMode ? 'bestOf' : listKey;
201
+ listKey = listKey || 'default';
202
+
203
+ const isValidListKey = listKey && avalibleColorNameLists.includes(listKey);
204
+
205
+ if (!isValidListKey) {
206
+ return httpRespond(response, {error: {
207
+ status: 404,
208
+ message: `invalid list key: '${listKey}, available keys are: ${avalibleColorNameLists.join(', ')}`,
209
+ }}, 404);
210
+ }
211
+
162
212
  if (!isNamesAPI) {
163
213
  return respondValueSearch(
164
214
  searchParams,
165
- goodNamesMode,
215
+ listKey,
166
216
  requestUrl,
167
217
  request,
168
218
  response
@@ -170,7 +220,7 @@ const requestHandler = (request, response) => {
170
220
  } else {
171
221
  return respondNameSearch(
172
222
  searchParams,
173
- goodNamesMode,
223
+ listKey,
174
224
  requestUrl,
175
225
  request,
176
226
  response
@@ -1 +1,2 @@
1
+ # git log --follow -pU0 --date=iso -- src/colornames.csv | grep '^+[^+]\|^Date'
1
2
  git log --follow -pU0 --date=iso -- src/colornames.csv | awk '/^Date:/ { date = $2 } /^+[^+]/ { print date "," substr($0,2) }'
@@ -1411,6 +1411,7 @@ Atoll Sand,#ffcf9e,
1411
1411
  Atom Blue,#8f9cac,
1412
1412
  Atomic,#3d4b52,
1413
1413
  Atomic Lime,#b9ff03,x
1414
+ Atomic Orange,#f88605,x
1414
1415
  Atomic Pink,#fb7efd,x
1415
1416
  Atomic Tangerine,#ff9966,x
1416
1417
  Atrium White,#f1eee4,
@@ -1800,7 +1801,7 @@ Banana Cream,#fff49c,x
1800
1801
  Banana Crepe,#e7d3ad,
1801
1802
  Banana Custard,#fcf3c5,
1802
1803
  Banana Farm,#ffdf38,
1803
- Banana Flash,#eeff00,
1804
+ Banana Flash,#eefe02,x
1804
1805
  Banana Frappé,#ddd5b6,x
1805
1806
  Banana Ice Cream,#f1d3b2,
1806
1807
  Banana King,#fffb08,x
@@ -1925,7 +1926,7 @@ Barricade,#84623e,
1925
1926
  Barrier Reef,#0084a1,
1926
1927
  Barro Verde,#9f8e71,
1927
1928
  Basalt Black,#4d423e,
1928
- Basalt Grey,#999999,
1929
+ Basalt Grey,#989998,
1929
1930
  Base Camp,#575c3a,
1930
1931
  Base Sand,#bb9955,
1931
1932
  Baseball Base,#f4eadc,
@@ -2645,6 +2646,7 @@ Blasphemous Blue,#3356aa,x
2645
2646
  Blast-Off Bronze,#a57164,
2646
2647
  Blasted Lands Rocks,#6c3550,
2647
2648
  Blaze,#fa8c4f,
2649
+ Blaze It Dark Magenta,#420420,
2648
2650
  Blaze Orange,#fe6700,
2649
2651
  Blazing Autumn,#f3ad63,
2650
2652
  Blazing Bonfire,#ffa035,
@@ -2964,6 +2966,7 @@ Blue Linen,#5a5e6a,
2964
2966
  Blue Lips,#a6bce2,x
2965
2967
  Blue Lobelia,#28314d,
2966
2968
  Blue Lobster,#0055aa,
2969
+ Blue Loneliness,#486d83,
2967
2970
  Blue Lullaby,#c8d7d2,
2968
2971
  Blue Lust,#012389,
2969
2972
  Blue Luxury,#007593,
@@ -5121,7 +5124,7 @@ Cherry Race,#a64137,
5121
5124
  Cherry Red,#f7022a,
5122
5125
  Cherry Sangria,#c92435,x
5123
5126
  Cherry Shine,#d81d26,
5124
- Cherry Soda,#ff0044,
5127
+ Cherry Soda,#ff0044,x
5125
5128
  Cherry Tart,#933d3e,
5126
5129
  Cherry Tomato,#f2013f,x
5127
5130
  Cherry Tree,#dfb7b4,
@@ -5353,7 +5356,7 @@ Chocolate Pancakes,#884400,
5353
5356
  Chocolate Plum,#3c2d2e,
5354
5357
  Chocolate Powder,#a58c7b,
5355
5358
  Chocolate Praline,#66424d,
5356
- Chocolate Pretzel,#60504b,
5359
+ Chocolate Pretzel,#60504b,x
5357
5360
  Chocolate Pudding,#6f6665,
5358
5361
  Chocolate Rain,#714f29,x
5359
5362
  Chocolate Red,#4d3635,
@@ -5544,7 +5547,7 @@ Clairvoyant,#480656,x
5544
5547
  Clam,#dad1c0,
5545
5548
  Clam Chowder,#f4d9af,
5546
5549
  Clam Shell,#d2b3a9,
5547
- Clam Up,#ebdbc1,
5550
+ Clam Up,#ebdbc1,x
5548
5551
  Clambake,#e0d1bb,
5549
5552
  Clamshell,#edd0b6,
5550
5553
  Claret,#680018,
@@ -7220,7 +7223,7 @@ Decorator White,#f6f4ec,
7220
7223
  Decore Splash,#00829e,
7221
7224
  Decorous Amber,#ac7559,
7222
7225
  Decorum,#b39aa0,
7223
- Decreasing Brown,#987654,
7226
+ Decreasing Brown,#987654,x
7224
7227
  Dedication,#fee2c8,
7225
7228
  Deduction,#d4cb83,
7226
7229
  Deep Amethyst,#5b3082,
@@ -8409,7 +8412,7 @@ Eiderdown,#e6dbc6,
8409
8412
  Eiffel Tower,#998e83,x
8410
8413
  Eigengrau,#16161d,x
8411
8414
  Eiger Nordwand,#7799bb,
8412
- Eight Ball,#103020,x
8415
+ Eight Ball,#03050a,x
8413
8416
  Eine kleine Nachtmusik,#552299,
8414
8417
  Eire,#d2be9d,
8415
8418
  El Capitan,#b7a696,
@@ -8430,6 +8433,7 @@ Elderflower,#fbf9e8,
8430
8433
  Eleanor Ann,#40373e,
8431
8434
  Election Night,#110320,
8432
8435
  Electra,#55b492,x
8436
+ Electric Banana,#fbff00,x
8433
8437
  Electric Blue,#7df9ff,
8434
8438
  Electric Brown,#b56257,
8435
8439
  Electric Crimson,#ff003f,
@@ -8445,6 +8449,7 @@ Electric Lavender,#f4bfff,
8445
8449
  Electric Leaf,#89dd01,
8446
8450
  Electric Lime,#ccff00,
8447
8451
  Electric Orange,#ff3503,
8452
+ Electric Pickle,#00ff04,
8448
8453
  Electric Pink,#ff0490,
8449
8454
  Electric Purple,#bf00ff,
8450
8455
  Electric Red,#e60000,
@@ -8930,6 +8935,7 @@ Explorer Blue,#57a3b3,
8930
8935
  Explorer Khaki,#b6ac95,
8931
8936
  Explorer of the Galaxies,#3a1f76,x
8932
8937
  Exploring Khaki,#aa9a79,
8938
+ Explosive Grey,#c4c4c4,x
8933
8939
  Explosive Purple,#cc11bb,x
8934
8940
  Express Blue,#395a73,
8935
8941
  Expressionism,#39497b,
@@ -12589,6 +12595,7 @@ Hot Desert,#eae4da,
12589
12595
  Hot Dog Relish,#717c3e,
12590
12596
  Hot Embers,#f55931,
12591
12597
  Hot Fever,#d40301,
12598
+ Hot Flamin Chilli,#dd180e,x
12592
12599
  Hot Flamingo,#b35966,x
12593
12600
  Hot Fudge,#5e2912,x
12594
12601
  Hot Ginger,#a36736,
@@ -12719,7 +12726,7 @@ Hyper Green,#55ff00,
12719
12726
  Hyper Light Drifter,#eddbda,x
12720
12727
  Hyper Pink,#ec006c,x
12721
12728
  Hyperlink Blue,#0000ee,x
12722
- Hyperpop Green,#17f9a6,
12729
+ Hyperpop Green,#17f9a6,x
12723
12730
  Hypnotic,#687783,
12724
12731
  Hypnotic Green,#73e608,x
12725
12732
  Hypnotic Red,#cf0d14,x
@@ -13201,6 +13208,7 @@ Irish Jig,#66cc11,
13201
13208
  Irish Linen,#eee4e0,
13202
13209
  Irish Mist,#e7e5db,
13203
13210
  Irish Moor,#b5c0b3,x
13211
+ Irish Spring,#90cca3,x
13204
13212
  Irogon Blue,#9dacb5,
13205
13213
  Iroko,#433120,
13206
13214
  Iron,#5e5e5e,x
@@ -13310,6 +13318,7 @@ Ivory Steam,#f0eada,
13310
13318
  Ivory Stone,#eee1cc,
13311
13319
  Ivory Tassel,#f8ead8,
13312
13320
  Ivory Tower,#fbf3f1,x
13321
+ Ivory Wedding,#edede4,x
13313
13322
  Ivy,#226c63,x
13314
13323
  Ivy Enchantment,#93a272,
13315
13324
  Ivy Garden,#818068,
@@ -13833,6 +13842,7 @@ Kiss Candy,#aa854a,
13833
13842
  Kiss Good Night,#e5c8d9,
13834
13843
  Kiss Me Kate,#e7eeec,
13835
13844
  Kiss Me More,#de6b86,x
13845
+ Kiss of a Vampire,#8a0009,x
13836
13846
  Kiss of the Scorpion,#dc331a,x
13837
13847
  Kissable,#fd8f79,x
13838
13848
  Kissed by a Zombies,#b15363,
@@ -15275,6 +15285,7 @@ Lucky Day,#929a7d,
15275
15285
  Lucky Dog,#d3c8ba,
15276
15286
  Lucky Duck,#f4ecd7,
15277
15287
  Lucky Green,#238652,
15288
+ Lucky Grey,#777777,x
15278
15289
  Lucky Lime,#9acd32,
15279
15290
  Lucky Lobster,#cc3322,x
15280
15291
  Lucky Orange,#ff7700,
@@ -15747,6 +15758,7 @@ Marilyn Monroe,#e7c3ac,
15747
15758
  Marilyn MonRouge,#c9001e,x
15748
15759
  Marina,#4f84c4,x
15749
15760
  Marina Isle,#b1c8bf,
15761
+ Marinara Red,#ff0008,x
15750
15762
  Marine,#042e60,x
15751
15763
  Marine Blue,#01386a,
15752
15764
  Marine Green,#40a48e,
@@ -16439,6 +16451,7 @@ Millbrook,#595648,
16439
16451
  Mille-Feuille,#efc87d,x
16440
16452
  Millennial Pink,#f6c8c1,x
16441
16453
  Millennium Silver,#8c9595,
16454
+ Million Grey,#999999,x
16442
16455
  Millionaire,#b6843c,
16443
16456
  Millstream,#b9d4de,
16444
16457
  Milly Green,#99bd91,
@@ -16566,6 +16579,7 @@ Minted Blueberry Lemonade,#b32651,x
16566
16579
  Minted Ice,#d8f3eb,
16567
16580
  Minted Lemon,#c1c6a8,
16568
16581
  Mintie,#abf4d2,
16582
+ Mintnight,#7cbbae,x
16569
16583
  Mintos,#80d9cc,
16570
16584
  Minty Fresh,#d2f2e7,
16571
16585
  Minty Frosting,#dbe8cf,
@@ -16636,6 +16650,7 @@ Misty Bead,#d2d59b,
16636
16650
  Misty Blue,#bfcdcc,
16637
16651
  Misty Blush,#ddc9c6,
16638
16652
  Misty Coast,#d5d9d3,
16653
+ Misty Cold Sea,#83bbc1,x
16639
16654
  Misty Dawn,#e4e5e0,
16640
16655
  Misty Glen,#cde7db,
16641
16656
  Misty Grape,#65434d,
@@ -17613,6 +17628,7 @@ New Wheat,#d7b57f,
17613
17628
  New Wool,#d6c3b9,
17614
17629
  New Yellow,#e8c247,
17615
17630
  New York Pink,#dd8374,
17631
+ New York Sunset,#ff0059,
17616
17632
  New Youth,#f0e1df,
17617
17633
  Newbury Moss,#616550,
17618
17634
  Newburyport,#445a79,
@@ -20220,6 +20236,7 @@ Poised Taupe,#8c7e78,
20220
20236
  Poison Green,#40fd14,
20221
20237
  Poison Ivy,#00ad43,x
20222
20238
  Poison Purple,#7f01fe,x
20239
+ Poison Purple Paradise,#b300ff,x
20223
20240
  Poisonberry,#73403e,
20224
20241
  Poisoning Green,#66ff11,
20225
20242
  Poisonous,#55ff11,x
@@ -22952,7 +22969,7 @@ Sauvignon,#f4eae4,
22952
22969
  Sauvignon Blanc,#b18276,
22953
22970
  Savanna,#874c44,
22954
22971
  Savannah,#d1bd92,
22955
- Savannah Grass,#babc72,fv
22972
+ Savannah Grass,#babc72,x
22956
22973
  Savannah Moss,#47533f,
22957
22974
  Savannah Sun,#ffb989,
22958
22975
  Saveloy,#aa2200,
@@ -23001,6 +23018,7 @@ Scarlet,#ff2400,x
23001
23018
  Scarlet Apple,#922e4a,
23002
23019
  Scarlet Cattleya Orchid,#c70752,
23003
23020
  Scarlet Flame,#993366,
23021
+ Scarlet Glow,#cb0103,x
23004
23022
  Scarlet Gum,#4a2d57,
23005
23023
  Scarlet Ibis,#f45520,
23006
23024
  Scarlet Past,#a53b3d,
@@ -24154,6 +24172,7 @@ Smoked Amethyst,#5a4351,
24154
24172
  Smoked Black Coffee,#3b2f2f,x
24155
24173
  Smoked Claret,#583a39,
24156
24174
  Smoked Flamingo,#674244,
24175
+ Smoked Ham,#f2b381,
24157
24176
  Smoked Lavender,#ceb5b3,
24158
24177
  Smoked Mauve,#a89c97,
24159
24178
  Smoked Mulberry,#725f6c,
@@ -25109,7 +25128,7 @@ Steel Pan Mallet,#71a6a1,
25109
25128
  Steel Pink,#cc33cc,
25110
25129
  Steel Teal,#5f8a8b,
25111
25130
  Steel Toe,#929894,
25112
- Steel Wool,#777777,
25131
+ Steel Wool,#767574,
25113
25132
  Steely Grey,#90979b,x
25114
25133
  Steeple Grey,#827e7c,
25115
25134
  Stegadon Scale Green,#074863,
@@ -26403,9 +26422,11 @@ The Bluff,#ffc8c2,
26403
26422
  The Boulevard,#d0a492,
26404
26423
  The Broadway,#145775,
26405
26424
  The Cottage,#837663,
26425
+ The Count's Black,#102030,x
26406
26426
  The Devil's Grass,#666420,x
26407
26427
  The Ego Has Landed,#a75455,
26408
26428
  The End,#2a2a2a,x
26429
+ The End Is Beer,#eed508,
26409
26430
  The Fang,#585673,
26410
26431
  The Fang Grey,#436174,
26411
26432
  The Fifth Sun,#f0e22c,
@@ -28308,7 +28329,7 @@ Weathered Plastic,#f9f4d9,
28308
28329
  Weathered Saddle,#b5745c,
28309
28330
  Weathered Sandstone,#dfc0a6,
28310
28331
  Weathered Shingle,#937f68,
28311
- Weathered Stone,#c4c4c4,x
28332
+ Weathered Stone,#c4c5c6,x
28312
28333
  Weathered White,#e6e3d9,
28313
28334
  Weathered Wicker,#97774d,
28314
28335
  Weathered Wood,#b19c86,x
@@ -29367,6 +29388,7 @@ Zeus,#3b3c38,
29367
29388
  Zeus Palace,#3c343d,
29368
29389
  Zeus Purple,#660077,
29369
29390
  Zeus Temple,#6c94cd,
29391
+ Zeus's Bolt,#eeff00,x
29370
29392
  Zheleznogorsk Yellow,#fef200,
29371
29393
  Zhēn Zhū Bái Pearl,#f8f8f9,
29372
29394
  Zhohltyi Yellow,#e4c500,