(object: JSONObject)
| 2509 | } |
| 2510 | |
| 2511 | function colorFromObject(object: JSONObject): any { |
| 2512 | if (typeof object.hex === "string") { |
| 2513 | const hexValue = object.hex.replace(/^#/, ""); |
| 2514 | const red = parseInt(hexValue.slice(0, 2), 16) / 255; |
| 2515 | const green = parseInt(hexValue.slice(2, 4), 16) / 255; |
| 2516 | const blue = parseInt(hexValue.slice(4, 6), 16) / 255; |
| 2517 | const alpha = |
| 2518 | hexValue.length >= 8 ? parseInt(hexValue.slice(6, 8), 16) / 255 : 1; |
| 2519 | return UIColor.colorWithRedGreenBlueAlpha(red, green, blue, alpha); |
| 2520 | } |
| 2521 | return UIColor.colorWithRedGreenBlueAlpha( |
| 2522 | numberValue(object.red), |
| 2523 | numberValue(object.green), |
| 2524 | numberValue(object.blue), |
| 2525 | numberValue(object.alpha, 1), |
| 2526 | ); |
| 2527 | } |
no test coverage detected