nope/modules/mod-Net-Analyzer/helpers/IEC66113_helpers.ts
2020-11-05 18:01:47 +01:00

40 lines
1017 B
TypeScript

/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2020-07-18 10:31:26
* @modify date 2020-07-18 10:31:26
* @desc [description]
*/
import { IJsonSchemaTypes, IJsonSchemaBaseTypes } from '../../ZISS-TypeScript-Library/src/JSON';
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;
}
export function IEC_66113_ConvertType(type: IJsonSchemaTypes) {
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)
}