diff options
Diffstat (limited to 'plugins/jetpack/extensions/blocks/simple-payments/utils.js')
-rw-r--r-- | plugins/jetpack/extensions/blocks/simple-payments/utils.js | 29 |
1 files changed, 0 insertions, 29 deletions
diff --git a/plugins/jetpack/extensions/blocks/simple-payments/utils.js b/plugins/jetpack/extensions/blocks/simple-payments/utils.js deleted file mode 100644 index c29e367b..00000000 --- a/plugins/jetpack/extensions/blocks/simple-payments/utils.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * External dependencies - */ -import { getCurrencyDefaults } from '@automattic/format-currency'; -import { trimEnd } from 'lodash'; - -/** - * Internal dependencies - */ -import { SIMPLE_PAYMENTS_PRODUCT_POST_TYPE } from './constants'; - -export const isValidSimplePaymentsProduct = product => - product.type === SIMPLE_PAYMENTS_PRODUCT_POST_TYPE && product.status === 'publish'; - -// based on https://stackoverflow.com/a/10454560/59752 -export const decimalPlaces = number => { - const match = ( '' + number ).match( /(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/ ); - if ( ! match ) { - return 0; - } - return Math.max( 0, ( match[ 1 ] ? match[ 1 ].length : 0 ) - ( match[ 2 ] ? +match[ 2 ] : 0 ) ); -}; - -export const formatPrice = ( price, currency, withSymbol = true ) => { - const { precision, symbol } = getCurrencyDefaults( currency ); - const value = price.toFixed( precision ); - // Trim the dot at the end of symbol, e.g., 'kr.' becomes 'kr' - return withSymbol ? `${ value } ${ trimEnd( symbol, '.' ) }` : value; -}; |