(name: string)
| 17 | * ``` |
| 18 | */ |
| 19 | export function assertName(name: string): string { |
| 20 | if (name.length === 0) { |
| 21 | throw new GraphQLError('Expected name to be a non-empty string.'); |
| 22 | } |
| 23 | |
| 24 | for (let i = 1; i < name.length; ++i) { |
| 25 | if (!isNameContinue(name.charCodeAt(i))) { |
| 26 | throw new GraphQLError( |
| 27 | `Names must only contain [_a-zA-Z0-9] but "${name}" does not.`, |
| 28 | ); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | if (!isNameStart(name.charCodeAt(0))) { |
| 33 | throw new GraphQLError( |
| 34 | `Names must start with [_a-zA-Z] but "${name}" does not.`, |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | return name; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Upholds the spec rules about naming enum values. |
no test coverage detected