We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 529b96a commit 11b96d3Copy full SHA for 11b96d3
packages/mdx/lib/util/to-valid-identifier-name.js
@@ -0,0 +1,16 @@
1
+import {start, cont} from 'estree-util-is-identifier-name'
2
+
3
+/**
4
+ * Replace all invalid identifier characters with underscores "_"
5
+ * @param {string} str
6
+ */
7
+export function toValidIdentifierName(string_) {
8
+ if (string_.length === 0) return '_'
9
+ let validString = ''
10
+ validString += start(string_[0].charCodeAt(0)) ? string_[0] : '_'
11
+ for (const char of string_.slice(1)) {
12
+ validString += cont(char.charCodeAt(0)) ? char : '_'
13
+ }
14
15
+ return validString
16
+}
0 commit comments