diff --git a/client/src/components/Supporters.js b/client/src/components/Supporters.js index 622247498f..192717add5 100644 --- a/client/src/components/Supporters.js +++ b/client/src/components/Supporters.js @@ -2,7 +2,6 @@ import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { Button, ProgressBar } from '@freecodecamp/react-bootstrap'; -import { commaNumber } from '../utils'; import FullWidthRow from '../components/helpers/FullWidthRow'; import Spacer from '../components/helpers/Spacer'; @@ -13,7 +12,11 @@ const propTypes = { isDonating: PropTypes.bool.isRequired }; +const supporterGoal = 10000; +const supportersLocale = supporterGoal.toLocaleString(); + function Supporters({ isDonating, activeDonations }) { + const donationsLocale = activeDonations.toLocaleString(); return ( @@ -24,7 +27,7 @@ function Supporters({ isDonating, activeDonations }) {
- {commaNumber(activeDonations)} supporters out of 10,000 supporter + {donationsLocale} supporters out of {supportersLocale} supporter goal
@@ -46,9 +49,7 @@ function Supporters({ isDonating, activeDonations }) { them to join the community.
) : ( - `Join ${commaNumber( - activeDonations - )} supporters. Your $5 / month donation will help ` + + `Join ${donationsLocale} supporters. Your $5 / month donation will help ` + 'keep tech education free and open.' )}

diff --git a/client/src/utils/index.js b/client/src/utils/index.js index 62fd627bfe..84b6546c43 100644 --- a/client/src/utils/index.js +++ b/client/src/utils/index.js @@ -20,26 +20,3 @@ export const getShortIdFromSlug = (slug = '') => { const [, maybeShortId = ''] = operableSlug.split('--'); return maybeShortId.replace(/\/*$/, ''); }; - -export function commaNumber(num) { - if (typeof num !== 'number') { - console.warn( - 'Expected a Number to be passed to `commaNumber`, instead received %s', - typeof num - ); - return ''; - } - const stringNum = String(num).replace(/^-/, ''); - const isNegative = num < 0; - const commaSpearated = stringNum - .split('') - .reverse() - .reduce((string, current, index, thisArray) => { - const withComma = - string.replace(/,/g, '').length % 3 === 0 && - index !== 0 && - index !== thisArray.length; - return `${withComma ? `${current},` : current}${string}`; - }, ''); - return `${isNegative ? '-' : ''}${commaSpearated}`; -} diff --git a/client/src/utils/utils.test.js b/client/src/utils/utils.test.js index 6bf7dc80c6..a63e70a792 100644 --- a/client/src/utils/utils.test.js +++ b/client/src/utils/utils.test.js @@ -8,7 +8,7 @@ import { mockId } from '../__mocks__/news-article'; -import { getShortIdFromSlug, commaNumber } from './'; +import { getShortIdFromSlug } from './'; describe('client/src utilities', () => { describe('getShortIdFromSlug', () => { @@ -42,35 +42,4 @@ describe('client/src utilities', () => { expect(result).toEqual(mockId); }); }); - - describe('commaNumber', () => { - it('returns a string', () => { - expect(typeof commaNumber(1)).toEqual('string'); - }); - - it('returns a comma separated number, positive', () => { - expect.assertions(6); - expect(commaNumber(1000)).toEqual('1,000'); - expect(commaNumber(10000)).toEqual('10,000'); - expect(commaNumber(100000)).toEqual('100,000'); - expect(commaNumber(1000000)).toEqual('1,000,000'); - expect(commaNumber(1234567890)).toEqual('1,234,567,890'); - expect(commaNumber(Number.MAX_SAFE_INTEGER)).toEqual( - '9,007,199,254,740,991' - ); - }); - - it('returns a comma separated number, negative', () => { - expect.assertions(6); - expect(commaNumber(-1000)).toEqual('-1,000'); - expect(commaNumber(-10000)).toEqual('-10,000'); - expect(commaNumber(-100000)).toEqual('-100,000'); - expect(commaNumber(-1000000)).toEqual('-1,000,000'); - expect(commaNumber(-1234567890)).toEqual('-1,234,567,890'); - expect(commaNumber(Number.MIN_SAFE_INTEGER)).toEqual( - '-9,007,199,254,740,991' - ); - }); - - }); });