forked from ccm-innovation/react-initicon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared.js
50 lines (41 loc) · 1.41 KB
/
shared.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"use strict";
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function getBackgroundColor(props) {
var seed = props.seed,
saturation = props.saturation,
brightness = props.brightness,
color = props.color;
if (color) return color;
var hue = Math.sin(seed);
hue = hue < 0 ? -hue : hue;
hue = Math.round(hue * 359) + 1;
return "hsl(" + hue + "," + saturation + "," + brightness + ")";
}
function getFontSize(props) {
var single = props.single;
return single ? props.size / 1.7 : (props.size - 5) / 2;
}
function getInitials(props) {
var text = props.text,
single = props.single;
if (text !== null && (typeof text === "undefined" ? "undefined" : _typeof(text)) === 'object') {
return text;
} else if (text.indexOf(" ") > 0 && !single) {
return text.split(" ")[0].charAt(0) + text.split(" ")[1].charAt(0);
} else {
return text.charAt(0);
}
}
var defaultProps = {
size: 75,
saturation: "80%",
brightness: "40%",
color: false,
single: false
};
if (typeof exports != 'undefined') {
exports.getBackgroundColor = getBackgroundColor;
exports.getFontSize = getFontSize;
exports.getInitials = getInitials;
exports.defaultProps = defaultProps;
}