@activecollab/components 2.0.114 → 2.0.116
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hooks/useInputNumber.js +2 -2
- package/dist/cjs/hooks/useInputNumber.js.map +1 -1
- package/dist/cjs/utils/currencyUtils.js +60 -2
- package/dist/cjs/utils/currencyUtils.js.map +1 -1
- package/dist/cjs/utils/currencyUtils.test.js +106 -10
- package/dist/cjs/utils/currencyUtils.test.js.map +1 -1
- package/dist/cjs/utils/index.js +7 -0
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/types.js.map +1 -1
- package/dist/esm/hooks/useInputNumber.js +2 -2
- package/dist/esm/hooks/useInputNumber.js.map +1 -1
- package/dist/esm/utils/currencyUtils.d.ts +43 -0
- package/dist/esm/utils/currencyUtils.d.ts.map +1 -1
- package/dist/esm/utils/currencyUtils.js +73 -1
- package/dist/esm/utils/currencyUtils.js.map +1 -1
- package/dist/esm/utils/currencyUtils.test.js +107 -11
- package/dist/esm/utils/currencyUtils.test.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/types.d.ts +4 -0
- package/dist/esm/utils/types.d.ts.map +1 -1
- package/dist/esm/utils/types.js.map +1 -1
- package/dist/index.js +62 -3
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -603,12 +603,33 @@
|
|
|
603
603
|
return parseFloat(String(number).replaceAll(thousandSeparator, ""));
|
|
604
604
|
}
|
|
605
605
|
};
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* @function formatNumber
|
|
609
|
+
* @description
|
|
610
|
+
* Formats a number or string into a human-readable format with options for thousand separators,
|
|
611
|
+
* decimal precision, and shortening the number using suffixes (K, M, B, T).
|
|
612
|
+
* It can handle negative numbers and optionally trim decimals and set number of decimal places based on the configuration.
|
|
613
|
+
*
|
|
614
|
+
* @param {string | number} n - The number or string to be formatted.
|
|
615
|
+
* @param {"," | "." | " " | ""} [thousandSeparator=","] - The character to use as a thousand separator.
|
|
616
|
+
* @param {"," | "."} [decimalSeperator="."] - The character to use as a decimal separator.
|
|
617
|
+
* @param {boolean} [trimDecimals=true] - Whether to trim decimals to the specified number of decimal spaces.
|
|
618
|
+
* @param {number} [decimalSpaces=2] - The number of decimal spaces to keep in the formatted output.
|
|
619
|
+
* @param {"long" | "short"} [format="long"] - The format type, either "long" for full numbers or "short" for shortened numbers with suffixes.
|
|
620
|
+
*
|
|
621
|
+
* @returns {string} - The formatted number as a string with separators and potentially with decimals.
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* formatNumber(1500) // "1,500.00"
|
|
625
|
+
* formatNumber(1500000, ",", ".", true, 2, "short") // "1.5M"
|
|
626
|
+
*/
|
|
606
627
|
var formatNumber = function formatNumber(n) {
|
|
607
628
|
var thousandSeparator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ",";
|
|
608
629
|
var decimalSeperator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ".";
|
|
609
630
|
var trimDecimals = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
610
631
|
var decimalSpaces = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 2;
|
|
611
|
-
var format = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "
|
|
632
|
+
var format = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "long";
|
|
612
633
|
var number = getNumberFromString(n, thousandSeparator, decimalSeperator);
|
|
613
634
|
if (isNaN(number)) {
|
|
614
635
|
return "";
|
|
@@ -641,6 +662,43 @@
|
|
|
641
662
|
return parts.join(decimalSeparator);
|
|
642
663
|
};
|
|
643
664
|
|
|
665
|
+
/**
|
|
666
|
+
* @function formatCurrency
|
|
667
|
+
* @description
|
|
668
|
+
* Formats a number or string as a currency string with options for thousand separators,
|
|
669
|
+
* decimal precision, currency code, currency code position, and the use of suffixes (K, M, B, T) if needed.
|
|
670
|
+
* It can handle negative values and supports customization of the currency code and its position.
|
|
671
|
+
*
|
|
672
|
+
* @param {string | number} n - The number or string to be formatted as currency.
|
|
673
|
+
* @param {"," | "." | " " | ""} [thousandSeparator=","] - The character to use as a thousand separator.
|
|
674
|
+
* @param {"," | "."} [decimalSeperator="."] - The character to use as a decimal separator.
|
|
675
|
+
* @param {boolean} [trimDecimals=false] - Whether to trim decimals to the specified number of decimal spaces.
|
|
676
|
+
* @param {number} [decimalSpaces=2] - The number of decimal spaces to keep in the formatted output.
|
|
677
|
+
* @param {"long" | "short"} [format="long"] - The format type, either "long" for full numbers or "short" for shortened numbers with suffixes.
|
|
678
|
+
* @param {string} [currencyCode=""] - The currency code to append or prepend to the formatted number.
|
|
679
|
+
* @param {"right" | "left"} [currencyCodePosition="right"] - The position of the currency code relative to the formatted number.
|
|
680
|
+
*
|
|
681
|
+
* @returns {string} - The formatted currency string, including the currency code if provided.
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* formatCurrency(1500, ",", ".", false, 2, "long", "USD", "right") // "1,500.00 USD"
|
|
685
|
+
* formatCurrency(1500000, ",", ".", true, 2, "short", "JPY", "left") // "JPY 1.5M"
|
|
686
|
+
*/
|
|
687
|
+
var formatCurrency = function formatCurrency(n) {
|
|
688
|
+
var thousandSeparator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ",";
|
|
689
|
+
var decimalSeperator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ".";
|
|
690
|
+
var trimDecimals = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
691
|
+
var decimalSpaces = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 2;
|
|
692
|
+
var format = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "long";
|
|
693
|
+
var currencyCode = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : "";
|
|
694
|
+
var currencyCodePosition = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : "right";
|
|
695
|
+
var formattedNum = formatNumber(n, thousandSeparator, decimalSeperator, trimDecimals, decimalSpaces, format);
|
|
696
|
+
if (!currencyCode) {
|
|
697
|
+
return formattedNum;
|
|
698
|
+
}
|
|
699
|
+
return currencyCodePosition === "right" ? "".concat(formattedNum, " ").concat(currencyCode) : "".concat(currencyCode, " ").concat(formattedNum);
|
|
700
|
+
};
|
|
701
|
+
|
|
644
702
|
var validateStopwatchTime = function validateStopwatchTime(value) {
|
|
645
703
|
return /^([0-9]{0,2})?(((:([0-5][0-9])?)|(:[0-5]?))|(\.[0-9]{0,2})|(,[0-9]{0,2}))?$/g.test(value);
|
|
646
704
|
};
|
|
@@ -12164,8 +12222,8 @@
|
|
|
12164
12222
|
if (value !== prevValue) {
|
|
12165
12223
|
setCurrentValue(formatNumber(value, thousandSeparator, decimalSeparator, trimDecimals, decimalLength, disableAbbreviation ? "long" : "short"));
|
|
12166
12224
|
setPrevValue(formatNumber(value, thousandSeparator, decimalSeparator, trimDecimals, decimalLength, disableAbbreviation ? "long" : "short"));
|
|
12167
|
-
setUnformattedValue(formatNumber(value, "", decimalSeparator,
|
|
12168
|
-
setUnformattedPrevValue(formatNumber(value, "", decimalSeparator,
|
|
12225
|
+
setUnformattedValue(formatNumber(value, "", decimalSeparator, trimDecimals, decimalLength, "long"));
|
|
12226
|
+
setUnformattedPrevValue(formatNumber(value, "", decimalSeparator, trimDecimals, decimalLength, "long"));
|
|
12169
12227
|
}
|
|
12170
12228
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
12171
12229
|
}, [disableAbbreviation, thousandSeparator, decimalSeparator, decimalLength, trimDecimals, value]);
|
|
@@ -19904,6 +19962,7 @@
|
|
|
19904
19962
|
exports._List = _List;
|
|
19905
19963
|
exports.colors = colors$1;
|
|
19906
19964
|
exports.decimalToHours = decimalToHours;
|
|
19965
|
+
exports.formatCurrency = formatCurrency;
|
|
19907
19966
|
exports.formatNumber = formatNumber;
|
|
19908
19967
|
exports.getNumberFromString = getNumberFromString;
|
|
19909
19968
|
exports.isOptionGroup = isOptionGroup;
|