| 63 | const hasStringIsWellFormed = 'isWellFormed' in String.prototype; |
| 64 | |
| 65 | function isWellFormedString(input: string): boolean { |
| 66 | // @ts-expect-error String::isWellFormed exists from ES2024. tsconfig lib is set to ES6 |
| 67 | if (hasStringIsWellFormed) return input.isWellFormed(); |
| 68 | |
| 69 | // https://github.com/tc39/proposal-is-usv-string/blob/main/README.md#algorithm |
| 70 | return !/\p{Surrogate}/u.test(input); |
| 71 | } |
| 72 | |
| 73 | // Matches the ECMAScript `IdentifierName` grammar, which (unlike a binding |
| 74 | // identifier) also accepts reserved words such as `switch`/`await`. Such names |