homeflowjs 1.0.57 → 1.0.59

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "1.0.57",
3
+ "version": "1.0.59",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",
@@ -17,10 +17,19 @@ export default function PropertyResultsPaginationItem({
17
17
  currentPage === pageNumber ? `${className}--active` : '';
18
18
 
19
19
  const pageLink = () => {
20
+ if (pageNumber === 1){
21
+ const urlPathParts = window.location.pathname.split('/page-');
22
+ return urlPathParts[0];
23
+ }
20
24
  if (window.location.pathname.includes('page-')) {
21
25
  return window.location.pathname.replace(/page-\d+/, `page-${pageNumber}`);
22
26
  }
23
- return `${window.location.pathname}/page-${pageNumber}`;
27
+ const urlLink = window.location.pathname;
28
+ const pagePartLink = urlLink[urlLink.length - 1] === '/'
29
+ ? `page-${pageNumber}`
30
+ : `/page-${pageNumber}`;
31
+
32
+ return `${window.location.pathname}${pagePartLink}`;
24
33
  };
25
34
 
26
35
  return (
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Formats a numeric value into a human-readable price string with appropriate suffixes (e.g., "k" for thousand, "m" for million).
3
+ *
4
+ * - Values in the millions are formatted with "m" (e.g., £1.2m).
5
+ * - Values in the thousands are formatted with "k" (e.g., £120k).
6
+ * - Values below £1 are converted to pence (e.g., 0.5 becomes "50p").
7
+ *
8
+ * @param {number} value - The numeric value to format.
9
+ * @returns {string} The formatted price string.
10
+ */
11
+ export const formattedPrice = (value) => {
12
+ const ONE_THOUSAND = 1_000;
13
+ const TEN_THOUSAND = 10_000;
14
+ const ONE_HUNDRED_THOUSAND = 100_000;
15
+ const ONE_MILLION = 1_000_000;
16
+ const TEN_MILLION = 10_000_000;
17
+
18
+ const getReducedNumber = (number, symbol, decimals = 0) => {
19
+ const factor = Math.pow(10, decimals);
20
+ const reducedNumber = number / symbol;
21
+ return Math.round(reducedNumber * factor) / factor;
22
+ };
23
+
24
+ const formatNumber = (price) => {
25
+ if (price >= TEN_MILLION) {
26
+ const reducedNumber = getReducedNumber(price, ONE_MILLION, 2);
27
+ return `£${reducedNumber}m`;
28
+ }
29
+
30
+ if (price >= ONE_MILLION) {
31
+ const millionFraction = price / ONE_MILLION;
32
+ const wholeMillions = Math.floor(millionFraction);
33
+ const fractionalPart = millionFraction - wholeMillions;
34
+
35
+ if ((fractionalPart >= 0.95 && price < TEN_MILLION) || price >= TEN_MILLION) {
36
+ return `£${wholeMillions + 1}m`;
37
+ } else {
38
+ const reducedNumber = getReducedNumber(price, ONE_MILLION, 1);
39
+ return `£${reducedNumber}m`;
40
+ }
41
+ }
42
+
43
+ if (price >= ONE_HUNDRED_THOUSAND && price <= 994999) {
44
+ const reducedNumber = getReducedNumber(price, ONE_THOUSAND);
45
+ return `£${reducedNumber}k`;
46
+ }
47
+
48
+ if (price >= TEN_THOUSAND * 2 && price <= 99499) {
49
+ return `£${Math.floor(price / ONE_THOUSAND)}k`;
50
+ }
51
+
52
+ if (price >= 99499 && price < ONE_HUNDRED_THOUSAND) {
53
+ const nextThousand = Math.ceil(price / ONE_THOUSAND);
54
+ return `£${nextThousand}k`;
55
+ }
56
+
57
+ if (price >= 994999 && price < ONE_MILLION) {
58
+ const nextMillon = Math.ceil(price / ONE_MILLION);
59
+ return `£${nextMillon}m`;
60
+ }
61
+
62
+ if (price >= 1) {
63
+ return `£${Math.round(price).toLocaleString()}`;
64
+ } else {
65
+ const penceValue = Math.round(price * 100);
66
+ return `${penceValue}p`;
67
+ }
68
+ };
69
+
70
+ return formatNumber(value);
71
+ };
72
+
73
+
74
+ /**
75
+ * Formats a numeric value into a price string prefixed with "£".
76
+ *
77
+ * @param {number} value - The numeric value to format.
78
+ * @returns {string} The formatted price string.
79
+ */
80
+ export const getFormattedPrice = (value) => `£${value.toLocaleString()}`;
81
+
82
+ /**
83
+ * Calculates the monthly price based on a given yield percentage.
84
+ *
85
+ * @param {number} value - The base value to calculate the price from.
86
+ * @param {number} yieldPercentage - The yield percentage to apply.
87
+ * @returns {string} The formatted monthly price string.
88
+ * @throws {ReferenceError} If `formattedPrice` is not defined.
89
+ */
90
+ export const calculatePriceBasedOnYield = (value, yieldPercentage) => {
91
+ const percentage = yieldPercentage / 100;
92
+ return formattedPrice((value * percentage) / 12);
93
+ };