edyt

Developerprompt

Document It

Add a docstring or doc comment to code.

Örnek girdi

function formatPrice(cents, currency = "USD", locale = "en-US") {
  if (!Number.isInteger(cents)) throw new TypeError("cents must be an integer");
  return new Intl.NumberFormat(locale, { style: "currency", currency }).format(cents / 100);
}

Edyt'in sonucu

/**
 * Formats a price in cents to a currency string based on the specified locale.
 *
 * @param {number} cents - The amount in cents, which must be an integer.
 * @param {string} [currency="USD"] - The currency code (e.g., "USD", "EUR").
 * @param {string} [locale="en-US"] - The locale to format the currency string.
 * @returns {string} The formatted currency string.
 * @throws {TypeError} If cents is not an integer.
 */
function formatPrice(cents, currency = "USD", locale = "en-US") {
  if (!Number.isInteger(cents)) throw new TypeError("cents must be an integer");
  return new Intl.NumberFormat(locale, { style: "currency", currency }).format(cents / 100);
}

Bunu her uygulamada, her metinde çalıştırın

Metni seçin, kısayolunuza basın ve bu komutu seçin. Sonuç metnin olduğu yerde belirir. Kopyala-yapıştır yok, tarayıcı sekmesi yok.