mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-01 18:09:30 +08:00
25 lines
776 B
Text
25 lines
776 B
Text
import {values} from 'micromark-util-symbol/values.js'
|
|
|
|
/**
|
|
* Normalize an identifier (such as used in definitions).
|
|
*
|
|
* @param {string} value
|
|
* @returns {string}
|
|
*/
|
|
export function normalizeIdentifier(value) {
|
|
return (
|
|
value
|
|
// Collapse Markdown whitespace.
|
|
.replace(/[\t\n\r ]+/g, values.space)
|
|
// Trim.
|
|
.replace(/^ | $/g, '')
|
|
// Some characters are considered “uppercase”, but if their lowercase
|
|
// counterpart is uppercased will result in a different uppercase
|
|
// character.
|
|
// Hence, to get that form, we perform both lower- and uppercase.
|
|
// Upper case makes sure keys will not interact with default prototypal
|
|
// methods: no method is uppercase.
|
|
.toLowerCase()
|
|
.toUpperCase()
|
|
)
|
|
}
|