diff --git a/README.md b/README.md index 1470f2b..e80946d 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Examples: - 2.5m = 2,500,000 - 3.456B = 3,456,000,000 -This can be turned off by passing in `turnOffAbbreviations`. +This can be turned off by passing in `disableAbbreviations`. ## Separators @@ -130,7 +130,7 @@ Example if `fixedDecimalLength` was 2: | decimalSeparator | `string` | locale default | Separator between integer part and fractional part of value | | groupSeparator | `string` | locale default | Separator between thousand, million and billion | | intlConfig | `object` | | International locale config | -| turnOffAbbreviations | `boolean` | `false` | Disable abbreviations eg. 1k > 1,000, 2m > 2,000,000 | +| disableAbbreviations | `boolean` | `false` | Disable abbreviations eg. 1k > 1,000, 2m > 2,000,000 | | disableGroupSeparators | `boolean` | `false` | Disable auto adding the group separator between values, eg. 1000 > 1,000 | ## Format values for display diff --git a/src/components/CurrencyInput.tsx b/src/components/CurrencyInput.tsx index ff66c8d..235f9aa 100644 --- a/src/components/CurrencyInput.tsx +++ b/src/components/CurrencyInput.tsx @@ -35,7 +35,7 @@ export const CurrencyInput: FC = forwardRef< intlConfig, step, disableGroupSeparators = false, - turnOffAbbreviations = false, + disableAbbreviations = false, ...props }: CurrencyInputProps, ref @@ -74,7 +74,7 @@ export const CurrencyInput: FC = forwardRef< allowDecimals, decimalsLimit: decimalsLimit || fixedDecimalLength || 2, allowNegativeValue, - turnOffAbbreviations, + disableAbbreviations, prefix, }; diff --git a/src/components/CurrencyInputProps.ts b/src/components/CurrencyInputProps.ts index 13b08b8..dccc252 100644 --- a/src/components/CurrencyInputProps.ts +++ b/src/components/CurrencyInputProps.ts @@ -68,7 +68,9 @@ export type CurrencyInputProps = Overwrite< /** * Value will always have the specified length of decimals * - * This formatting happens onBlur + * Eg. 123 -> 1.23 + * + * Note: This formatting only happens onBlur */ fixedDecimalLength?: number; @@ -124,7 +126,7 @@ export type CurrencyInputProps = Overwrite< * * Default = false */ - turnOffAbbreviations?: boolean; + disableAbbreviations?: boolean; /** * International locale config, examples: diff --git a/src/components/__tests__/CurrencyInput-abbreviated.spec.tsx b/src/components/__tests__/CurrencyInput-abbreviated.spec.tsx index b35977b..65641ec 100644 --- a/src/components/__tests__/CurrencyInput-abbreviated.spec.tsx +++ b/src/components/__tests__/CurrencyInput-abbreviated.spec.tsx @@ -54,9 +54,9 @@ describe(' component > abbreviated', () => { expect(view.update().find(`#${id}`).prop('value')).toBe(''); }); - describe('turnOffAbbreviations', () => { - it('should not allow abbreviations if turnOffAbbreviations is true', () => { - const view = shallow(); + describe('disableAbbreviations', () => { + it('should not allow abbreviations if disableAbbreviations is true', () => { + const view = shallow(); view.find(`#${id}`).simulate('change', { target: { value: '1k' } }); expect(view.update().find(`#${id}`).prop('value')).toBe('1'); diff --git a/src/components/utils/__tests__/cleanValue.spec.ts b/src/components/utils/__tests__/cleanValue.spec.ts index daff290..6f95b24 100644 --- a/src/components/utils/__tests__/cleanValue.spec.ts +++ b/src/components/utils/__tests__/cleanValue.spec.ts @@ -163,21 +163,21 @@ describe('cleanValue', () => { expect( cleanValue({ value: 'k', - turnOffAbbreviations: true, + disableAbbreviations: true, }) ).toEqual(''); expect( cleanValue({ value: 'm', - turnOffAbbreviations: true, + disableAbbreviations: true, }) ).toEqual(''); expect( cleanValue({ value: 'b', - turnOffAbbreviations: true, + disableAbbreviations: true, }) ).toEqual(''); }); @@ -187,7 +187,7 @@ describe('cleanValue', () => { cleanValue({ value: '$k', prefix: '$', - turnOffAbbreviations: true, + disableAbbreviations: true, }) ).toEqual(''); @@ -195,37 +195,37 @@ describe('cleanValue', () => { cleanValue({ value: '£m', prefix: '£', - turnOffAbbreviations: true, + disableAbbreviations: true, }) ).toEqual(''); }); - it('should ignore abbreviations if turnOffAbbreviations is true', () => { + it('should ignore abbreviations if disableAbbreviations is true', () => { expect( cleanValue({ value: '1k', - turnOffAbbreviations: true, + disableAbbreviations: true, }) ).toEqual('1'); expect( cleanValue({ value: '-2k', - turnOffAbbreviations: true, + disableAbbreviations: true, }) ).toEqual('-2'); expect( cleanValue({ value: '25.6m', - turnOffAbbreviations: true, + disableAbbreviations: true, }) ).toEqual('25.6'); expect( cleanValue({ value: '9b', - turnOffAbbreviations: true, + disableAbbreviations: true, }) ).toEqual('9'); }); diff --git a/src/components/utils/cleanValue.ts b/src/components/utils/cleanValue.ts index 44258d9..399ebf1 100644 --- a/src/components/utils/cleanValue.ts +++ b/src/components/utils/cleanValue.ts @@ -10,7 +10,7 @@ export type CleanValueOptions = { allowDecimals?: boolean; decimalsLimit?: number; allowNegativeValue?: boolean; - turnOffAbbreviations?: boolean; + disableAbbreviations?: boolean; prefix?: string; }; @@ -24,14 +24,14 @@ export const cleanValue = ({ allowDecimals = true, decimalsLimit = 2, allowNegativeValue = true, - turnOffAbbreviations = false, + disableAbbreviations = false, prefix = '', }: CleanValueOptions): string => { if (value === '-') { return value; } - const abbreviations = turnOffAbbreviations ? [] : ['k', 'm', 'b']; + const abbreviations = disableAbbreviations ? [] : ['k', 'm', 'b']; const isNegative = new RegExp(`^\\d?-${prefix ? `${escapeRegExp(prefix)}?` : ''}\\d`).test(value); const [prefixWithValue, preValue] = RegExp(`(\\d+)-?${escapeRegExp(prefix)}`).exec(value) || []; @@ -45,7 +45,7 @@ export const cleanValue = ({ let valueOnly = withoutInvalidChars; - if (!turnOffAbbreviations) { + if (!disableAbbreviations) { // disallow letter without number if (abbreviations.some((letter) => letter === withoutInvalidChars.toLowerCase())) { return '';