mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import color = require("color");
|
|
import enums = require("ui/enums");
|
|
import types = require("utils/types");
|
|
|
|
export function colorConverter(value: string): color.Color {
|
|
return new color.Color(value);
|
|
}
|
|
|
|
export function fontSizeConverter(value: string): number {
|
|
// TODO: parse different unit types
|
|
var result: number = parseFloat(value);
|
|
return result;
|
|
}
|
|
|
|
export function textAlignConverter(value: string): string {
|
|
switch (value) {
|
|
case enums.TextAlignment.left:
|
|
case enums.TextAlignment.center:
|
|
case enums.TextAlignment.right:
|
|
return value;
|
|
break;
|
|
default:
|
|
throw new Error("CSS text-align \"" + value + "\" is not supported.");
|
|
break;
|
|
}
|
|
}
|
|
|
|
export var numberConverter = parseFloat;
|
|
|
|
export function visibilityConverter(value: string): string {
|
|
if (value.toLowerCase() === enums.Visibility.collapsed) {
|
|
return enums.Visibility.collapsed;
|
|
}
|
|
return enums.Visibility.visible;
|
|
}
|
|
|
|
export function opacityConverter(value: string): number {
|
|
var result = parseFloat(value);
|
|
result = Math.max(0.0, result);
|
|
result = Math.min(1.0, result);
|
|
|
|
return result;
|
|
}
|
|
|