@symbolic/lib
Advanced tools
Comparing version 1.0.73 to 1.0.74
@@ -9,3 +9,2 @@ 'use strict'; | ||
var Cookies = _interopDefault(require('js-cookie')); | ||
require('color'); | ||
@@ -176,20 +175,23 @@ var fetch = require('node-fetch'); | ||
colors.validateHex = (color) => { | ||
colors.colorFor = (arg) => { | ||
var hue; | ||
}; | ||
if (typeof(arg) === 'object') { | ||
var {status, user, org} = arg; | ||
colors.constrain = (color) => { | ||
if (user) { | ||
hue = user.hue; | ||
arg = user.id - 1; | ||
} | ||
else if (org) { | ||
hue = org.hue; | ||
arg = org.id - 1; | ||
} | ||
else { | ||
var id = arg.userId || arg.orgId || arg.id || 1; | ||
}; | ||
colors.colorFor = (arg) => { | ||
if (typeof(arg) === 'object') { | ||
var {status} = arg; | ||
var id = arg.userId || arg.orgId || arg.id; | ||
if (id) arg = id - 1; | ||
arg = id - 1; | ||
} | ||
} | ||
// if (typeof(arg) === 'string') arg = _.sum(_.map(arg, (_character, index) => arg.charCodeAt(index))); | ||
var color = ''; | ||
@@ -209,7 +211,12 @@ | ||
else if (typeof(arg) === 'number') { | ||
var hueIsValid = hue && typeof(hue) === 'number' && hue > 0 && hue <= 360; | ||
var colorSet = colors.all; | ||
color = colorSet[(arg * 3) % colorSet.length]; | ||
if (!hueIsValid) { | ||
var colorCount = 30; | ||
var maxHue = 360; | ||
// var color = Color({h: seed, s: 0.5 + seed / 100 * 0.5, l: 0.7 + seed / 100 * 0.2}).hex(); | ||
hue = (arg % colorCount) * (maxHue / colorCount); | ||
} | ||
color = `hsl(${hue}, ${60}%, ${75}%)`; | ||
} | ||
@@ -216,0 +223,0 @@ |
{ | ||
"name": "@symbolic/lib", | ||
"version": "1.0.73", | ||
"version": "1.0.74", | ||
"description": "plain js utilities", | ||
@@ -15,3 +15,2 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"color": "^4.0.1", | ||
"js-cookie": "^2.2.1", | ||
@@ -18,0 +17,0 @@ "lodash": "^4.17.15", |
import _ from 'lodash'; | ||
import Color from 'color'; | ||
@@ -43,20 +42,23 @@ var colors = {}; | ||
colors.validateHex = (color) => { | ||
colors.colorFor = (arg) => { | ||
var hue; | ||
} | ||
if (typeof(arg) === 'object') { | ||
var {status, user, org} = arg; | ||
colors.constrain = (color) => { | ||
if (user) { | ||
hue = user.hue; | ||
arg = user.id - 1; | ||
} | ||
else if (org) { | ||
hue = org.hue; | ||
arg = org.id - 1; | ||
} | ||
else { | ||
var id = arg.userId || arg.orgId || arg.id || 1; | ||
} | ||
colors.colorFor = (arg) => { | ||
if (typeof(arg) === 'object') { | ||
var {status} = arg; | ||
var id = arg.userId || arg.orgId || arg.id; | ||
if (id) arg = id - 1; | ||
arg = id - 1; | ||
} | ||
} | ||
// if (typeof(arg) === 'string') arg = _.sum(_.map(arg, (_character, index) => arg.charCodeAt(index))); | ||
var color = ''; | ||
@@ -76,8 +78,12 @@ | ||
else if (typeof(arg) === 'number') { | ||
var seed = arg % 100; | ||
var hueIsValid = hue && typeof(hue) === 'number' && hue > 0 && hue <= 360; | ||
var colorSet = colors.all; | ||
color = colorSet[(arg * 3) % colorSet.length]; | ||
if (!hueIsValid) { | ||
var colorCount = 30; | ||
var maxHue = 360; | ||
// var color = Color({h: seed, s: 0.5 + seed / 100 * 0.5, l: 0.7 + seed / 100 * 0.2}).hex(); | ||
hue = (arg % colorCount) * (maxHue / colorCount); | ||
} | ||
color = `hsl(${hue}, ${60}%, ${75}%)`; | ||
} | ||
@@ -84,0 +90,0 @@ |
@@ -10,5 +10,5 @@ import colors from './colors'; | ||
it('should return the correct color for a given id', () => { | ||
expect(colors.colorFor({orgId: 2})).to.equal('rgb(229, 187, 187)'); | ||
expect(colors.colorFor({org: {id: 2}})).to.equal(''); | ||
}); | ||
}); | ||
}); |
25513
3
636
- Removedcolor@^4.0.1
- Removedcolor@4.2.3(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedcolor-string@1.9.1(transitive)
- Removedis-arrayish@0.3.2(transitive)
- Removedsimple-swizzle@0.2.2(transitive)