nope/modules/net-analyzer/helpers/IEC66113_helpers.ts
Martin Karkowski 838d910c2f adding gojs
2020-12-01 13:05:35 +01:00

54 lines
1.3 KiB
TypeScript

/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2020-07-18 10:31:26
* @modify date 2020-11-25 07:39:43
* @desc [description]
*/
import { IJsonSchemaBaseTypes, IJsonSchemaTypes } from "../../ZISS-TypeScript-Library/src/JSON";
/**
* Function to Convert a Value.
*
* @export
* @param {*} value The to convert
* @return {*}
*/
export function IEC_66113_convertValues(value: any) {
switch (typeof value) {
case "boolean":
return value.toString().toUpperCase();
case "string":
if (value === "true") {
return "TRUE";
} else if (value === "false") {
return "FALSE";
}
}
return value;
}
/**
* Define the Type of IEC-66113 based on a basic type in here.
*
* @export
* @param {IJsonSchemaTypes} type The type of the element to use.
* @return {*}
*/
export function IEC_66113_ConvertType(type: IJsonSchemaTypes): string {
const mapping: {
[T in IJsonSchemaBaseTypes]?: string
} = {
boolean: "BOOL",
integer: "INT",
number: "REAL",
string: "STRING",
};
if (!Array.isArray(type) && mapping[type]) {
return mapping[type];
}
return "// CANT PARSE THE TYPE: " + JSON.stringify(type);
}