How to use the @automattic/format-currency.getCurrencyDefaults function in @automattic/format-currency

To help you get started, we’ve selected a few @automattic/format-currency examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Automattic / wp-calypso / client / components / tinymce / plugins / simple-payments / dialog / form.jsx View on Github external
const renderPriceField = ( { price, currency, ...props } ) => {
	const { precision } = getCurrencyDefaults( currency.input.value );
	// Tune the placeholder to the precision value: 0 -> '1', 1 -> '1.0', 2 -> '1.00'
	const placeholder = precision > 0 ? padEnd( '1.', precision + 2, '0' ) : '1';
	return (
		
	);
};
github Automattic / wp-calypso / packages / jetpack-blocks / src / blocks / simple-payments / edit.js View on Github external
getCurrencyList = SUPPORTED_CURRENCY_LIST.map( value => {
		const { symbol } = getCurrencyDefaults( value );
		// if symbol is equal to the code (e.g., 'CHF' === 'CHF'), don't duplicate it.
		// trim the dot at the end, e.g., 'kr.' becomes 'kr'
		const label = symbol === value ? value : `${ value } ${ trimEnd( symbol, '.' ) }`;
		return { value, label };
	} );
github Automattic / vip-go-mu-plugins-built / jetpack / extensions / blocks / simple-payments / edit.js View on Github external
getCurrencyList = SUPPORTED_CURRENCY_LIST.map( value => {
		const { symbol } = getCurrencyDefaults( value );
		// if symbol is equal to the code (e.g., 'CHF' === 'CHF'), don't duplicate it.
		// trim the dot at the end, e.g., 'kr.' becomes 'kr'
		const label = symbol === value ? value : `${ value } ${ trimEnd( symbol, '.' ) }`;
		return { value, label };
	} );
github Automattic / jetpack / extensions / blocks / simple-payments / edit.js View on Github external
getCurrencyList = SUPPORTED_CURRENCY_LIST.map( value => {
		const { symbol } = getCurrencyDefaults( value );
		// if symbol is equal to the code (e.g., 'CHF' === 'CHF'), don't duplicate it.
		// trim the dot at the end, e.g., 'kr.' becomes 'kr'
		const label = symbol === value ? value : `${ value } ${ trimEnd( symbol, '.' ) }`;
		return { value, label };
	} );
github Automattic / wp-calypso / client / components / tinymce / plugins / simple-payments / dialog / form.jsx View on Github external
const VISUAL_CURRENCY_LIST = SUPPORTED_CURRENCY_LIST.map( code => {
	const { symbol } = getCurrencyDefaults( code );
	// if symbol is equal to the code (e.g., 'CHF' === 'CHF'), don't duplicate it.
	// trim the dot at the end, e.g., 'kr.' becomes 'kr'
	const label = symbol === code ? code : `${ code } ${ trimEnd( symbol, '.' ) }`;
	return { code, label };
} );
github Automattic / wp-calypso / client / extensions / woocommerce / lib / currency / index.js View on Github external
export function getCurrencyFormatDecimal( number, currency = 'USD' ) {
	const { precision } = getCurrencyDefaults( currency );
	if ( 'number' !== typeof number ) {
		number = parseFloat( number );
	}
	if ( isNaN( number ) ) {
		return 0;
	}
	return Math.round( number * Math.pow( 10, precision ) ) / Math.pow( 10, precision );
}
github Automattic / wp-calypso / client / components / marketing-survey / cancel-purchase-form / index.jsx View on Github external
{ translate( 'How can we help?' ) }
						{ this.renderLiveChat() }
					
				);
			}

			if ( surveyStep === steps.BUSINESS_AT_STEP ) {
				return ;
			}

			if ( surveyStep === steps.UPGRADE_AT_STEP ) {
				return ;
			}

			if ( surveyStep === steps.DOWNGRADE_STEP ) {
				const { precision } = getCurrencyDefaults( purchase.currencyCode );
				const planCost = parseFloat( this.props.downgradePlanPrice ).toFixed( precision );
				return (
					
				);
			}

			return (
				<div>
					
						{ translate( 'One more question before you go.' ) }
					
					{ this.renderFreeformQuestion() }</div>
github Automattic / wp-calypso / client / me / purchases / cancel-purchase / refund-information.jsx View on Github external
}
					),
					i18n.translate(
						'The domain %(mappedDomain)s itself is not canceled. Only the connection between WordPress.com and ' +
							'your domain is removed. %(mappedDomain)s is registered elsewhere and you can still use it with other sites.',
						{
							args: {
								mappedDomain: includedDomainPurchase.meta,
							},
						}
					)
				);

				showSupportLink = false;
			} else if ( includedDomainPurchase && isDomainRegistration( includedDomainPurchase ) ) {
				const { precision } = getCurrencyDefaults( purchase.currencyCode );
				const planCostText =
					purchase.currencySymbol +
					parseFloat( purchase.refundAmount + includedDomainPurchase.costToUnbundle ).toFixed(
						precision
					);
				if ( isRefundable( includedDomainPurchase ) ) {
					text.push(
						i18n.translate(
							'Your plan included the custom domain %(domain)s. You can cancel your domain as well as the plan, but keep ' +
								'in mind that when you cancel a domain you risk losing it forever, and visitors to your site may ' +
								'experience difficulties accessing it.',
							{
								args: {
									domain: includedDomainPurchase.meta,
								},
							}
github Automattic / jetpack / extensions / blocks / simple-payments / edit.js View on Github external
validatePrice = () => {
		const { currency, price } = this.props.attributes;
		const { precision } = getCurrencyDefaults( currency );

		if ( ! price || parseFloat( price ) === 0 ) {
			this.setState( {
				fieldPriceError: __(
					'If you’re selling something, you need a price tag. Add yours here.',
					'jetpack'
				),
			} );
			return false;
		}

		if ( Number.isNaN( parseFloat( price ) ) ) {
			this.setState( {
				fieldPriceError: __( 'Invalid price', 'jetpack' ),
			} );
			return false;
github Automattic / wp-calypso / client / me / purchases / cancel-purchase / button.jsx View on Github external
renderCancellationEffect = () =&gt; {
		const { purchase, translate, includedDomainPurchase, cancelBundledDomain } = this.props;
		const overrides = {};

		if (
			cancelBundledDomain &amp;&amp;
			includedDomainPurchase &amp;&amp;
			isDomainRegistration( includedDomainPurchase )
		) {
			const { precision } = getCurrencyDefaults( purchase.currencyCode );
			overrides.refundText =
				purchase.currencySymbol +
				parseFloat( purchase.refundAmount + includedDomainPurchase.amount ).toFixed( precision );
		}

		return (
			<p>
				{ cancellationEffectHeadline( purchase, translate ) }
				{ cancellationEffectDetail( purchase, translate, overrides ) }
			</p>
		);
	};

@automattic/format-currency

JavaScript library for formatting currency.

GPL-2.0
Latest version published 5 months ago

Package Health Score

92 / 100
Full package analysis