Skip to content

⬅️ Back to Table of Contents

📄 requiresQuoting

📊 Analysis Summary

Metric Count
🔧 Functions 1

📚 Table of Contents

🛠️ File Location:

📂 packages/type-utils/src/requiresQuoting.ts

Functions

requiresQuoting(name: string, target: ts.ScriptTarget): boolean

  • Indicates whether identifiers require the use of quotation marks when accessing property definitions and dot notation.
Raw JSDoc
/*** Indicates whether identifiers require the use of quotation marks when accessing property definitions and dot notation. */

Calls:

  • ts.isIdentifierStart
  • name.charCodeAt
  • ts.isIdentifierPart
Code
export function requiresQuoting(
  name: string,
  target: ts.ScriptTarget = ts.ScriptTarget.ESNext,
): boolean {
  if (name.length === 0) {
    return true;
  }

  if (!ts.isIdentifierStart(name.charCodeAt(0), target)) {
    return true;
  }

  for (let i = 1; i < name.length; i += 1) {
    if (!ts.isIdentifierPart(name.charCodeAt(i), target)) {
      return true;
    }
  }

  return false;
}

Generated by Syntax Scribe