(casing: Expression<any>, result: string, model: string)
| 142 | }; |
| 143 | |
| 144 | function processCasing(casing: Expression<any>, result: string, model: string) { |
| 145 | const opNode = casing.toOperationNode(); |
| 146 | invariant(ValueNode.is(opNode) && typeof opNode.value === 'string', '"casting" parameter must be a string value'); |
| 147 | result = match(opNode.value) |
| 148 | .with('original', () => model) |
| 149 | .with('upper', () => result.toUpperCase()) |
| 150 | .with('lower', () => result.toLowerCase()) |
| 151 | .with('capitalize', () => upperCaseFirst(result)) |
| 152 | .with('uncapitalize', () => lowerCaseFirst(result)) |
| 153 | .otherwise(() => { |
| 154 | throw new Error( |
| 155 | `Invalid casing value: ${opNode.value}. Must be "original", "upper", "lower", "capitalize", or "uncapitalize".`, |
| 156 | ); |
| 157 | }); |
| 158 | return result; |
| 159 | } |
| 160 | |
| 161 | function readBoolean(expr: Expression<any> | undefined, defaultValue: boolean) { |
| 162 | if (expr === undefined) { |
no test coverage detected