MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / colorFromObject

Function colorFromObject

packages/nativescript-inspector/src/index.ts:2511–2527  ·  view source on GitHub ↗
(object: JSONObject)

Source from the content-addressed store, hash-verified

2509}
2510
2511function 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}

Callers 1

decodeValueFunction · 0.85

Calls 2

numberValueFunction · 0.85
replaceMethod · 0.65

Tested by

no test coverage detected