(source: string, name: string, stopAt = Number.MAX_SAFE_INTEGER)
| 733 | * JavaScript and an identifier may not be. |
| 734 | */ |
| 735 | export function mentionCount(source: string, name: string, stopAt = Number.MAX_SAFE_INTEGER): number { |
| 736 | if (name.length === 0) return 0; |
| 737 | let count = 0; |
| 738 | let from = 0; |
| 739 | for (;;) { |
| 740 | const at = source.indexOf(name, from); |
| 741 | if (at < 0) return count; |
| 742 | from = at + name.length; |
| 743 | if (!isIdentifierChar(source[at - 1]) && !isIdentifierChar(source[from])) { |
| 744 | count += 1; |
| 745 | if (count >= stopAt) return count; |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | function isIdentifierChar(char: string | undefined): boolean { |
| 751 | if (char === undefined) return false; |
no test coverage detected