CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
1/**2 * Normalize an identifier (as found in references, definitions).3 *4 * Collapses markdown whitespace, trim, and then lower- and uppercase.5 *6 * Some characters are considered “uppercase”, such as U+03F4 (`ϴ`), but if their7 * lowercase counterpart (U+03B8 (`θ`)) is uppercased will result in a different8 * uppercase character (U+0398 (`Θ`)).9 * So, to get a canonical form, we perform both lower- and uppercase.10 *11 * Using uppercase last makes sure keys will never interact with default12 * prototypal values (such as `constructor`): nothing in the prototype of13 * `Object` is uppercase.14 *15 * @param {string} value16 *   Identifier to normalize.17 * @returns {string}18 *   Normalized identifier.19 */20export function normalizeIdentifier(value) {21  return value22  // Collapse markdown whitespace.23  .replace(/[\t\n\r ]+/g, " ")24  // Trim.25  .replace(/^ | $/g, '')26  // Some characters are considered “uppercase”, but if their lowercase27  // counterpart is uppercased will result in a different uppercase28  // character.29  // Hence, to get that form, we perform both lower- and uppercase.30  // Upper case makes sure keys will not interact with default prototypal31  // methods: no method is uppercase.32  .toLowerCase().toUpperCase();33}