(
tsConfig: serialization.ConfigDictValue, key?: string)
| 88 | * @returns Result of the conversion. |
| 89 | */ |
| 90 | export function convertTsToPythonic( |
| 91 | tsConfig: serialization.ConfigDictValue, key?: string): PyJsonValue { |
| 92 | if (tsConfig === null || tsConfig === undefined) { |
| 93 | return null; |
| 94 | } else if (typeof tsConfig === 'string') { |
| 95 | return generic_utils.toSnakeCase(tsConfig); |
| 96 | } else if ( |
| 97 | (typeof tsConfig === 'number') || (typeof tsConfig === 'boolean')) { |
| 98 | return tsConfig; |
| 99 | } else if (tsConfig instanceof Array) { |
| 100 | const pyArray = []; |
| 101 | const arrayLength = tsConfig.length; |
| 102 | for (let i = 0; i < arrayLength; ++i) { |
| 103 | const item = tsConfig[i]; |
| 104 | if (isArrayItemInputOrOutputName(key, i, item)) { |
| 105 | pyArray.push(item); |
| 106 | } else { |
| 107 | pyArray.push(convertTsToPythonic(item, key)); |
| 108 | } |
| 109 | } |
| 110 | return pyArray; |
| 111 | } else { |
| 112 | const pyDict: serialization.ConfigDict = {}; |
| 113 | for (const tsKey of Object.keys(tsConfig)) { |
| 114 | const tsValue = tsConfig[tsKey]; |
| 115 | const pyKey = generic_utils.toSnakeCase(tsKey); |
| 116 | if ((tsKey === 'name' || tsKey === 'className') && |
| 117 | typeof tsValue === 'string') { |
| 118 | // Special case the 'name' key with a string value. Name values, such as |
| 119 | // the names of LayersModel and Layer instances, should not undergo the |
| 120 | // snake-case conversion. |
| 121 | pyDict[pyKey] = tsValue; |
| 122 | } else { |
| 123 | pyDict[pyKey] = convertTsToPythonic(tsValue, tsKey); |
| 124 | } |
| 125 | } |
| 126 | return pyDict; |
| 127 | } |
| 128 | } |
no test coverage detected
searching dependent graphs…