edyt

Developerprompt

Document It

Add a docstring or doc comment to code.

مثال على النص المُدخل

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

/**
 * 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);
}

شغّل هذا الأمر على أي نص، في أي تطبيق

حدد نصًا، واضغط اختصارك، واختر هذا الأمر. تظهر النتيجة في مكانها. بلا نسخ ولصق، وبلا تبويب في المتصفح.