react-restyle-components 0.2.75 → 0.2.77

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/lib/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './src/core-components';
2
+ export * from './src/core-utils';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC"}
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  // import './tc.css';
2
2
  // import './global.css';
3
3
  export * from './src/core-components';
4
+ export * from './src/core-utils';
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-restyle-components",
3
- "version": "0.2.75",
3
+ "version": "0.2.76",
4
4
  "private": false,
5
5
  "description": "Easy use restyle components",
6
6
  "author": {
@@ -0,0 +1,27 @@
1
+ type Amounts = {
2
+ grossAmount: number;
3
+ netAmount: number;
4
+ discountedAmount: number;
5
+ discountPercent: number;
6
+ };
7
+ type AmountKey = 'grossAmount' | 'netAmount' | 'discountedAmount' | 'discountPercent';
8
+ type AmountMode = 'gross-net' | 'gross-discountPercent' | 'net-discountPercent' | 'gross-discounted' | 'net-discounted';
9
+ /**
10
+ * Calculates all amount fields based on the last changed key.
11
+ * @param amounts The amounts object.
12
+ * @param changedKey The key that was last changed.
13
+ */
14
+ export declare function calculateAmount(amounts: Amounts, changedKey: AmountKey): {
15
+ grossAmount: number;
16
+ netAmount: number;
17
+ discountedAmount: number;
18
+ discountPercent: number;
19
+ };
20
+ export declare const calculateAmountByKey: (amounts: Amounts, mode: AmountMode) => {
21
+ grossAmount: number;
22
+ netAmount: number;
23
+ discountedAmount: number;
24
+ discountPercent: number;
25
+ };
26
+ export {};
27
+ //# sourceMappingURL=calculation.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculation.util.d.ts","sourceRoot":"","sources":["../../../../src/core-utils/calculation/calculation.util.ts"],"names":[],"mappings":"AAAA,KAAK,OAAO,GAAG;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,KAAK,SAAS,GACV,aAAa,GACb,WAAW,GACX,kBAAkB,GAClB,iBAAiB,CAAC;AAEtB,KAAK,UAAU,GACX,WAAW,GACX,uBAAuB,GACvB,qBAAqB,GACrB,kBAAkB,GAClB,gBAAgB,CAAC;AAqBrB;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,SAAS,GACpB;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;CACzB,CAGA;AAED,eAAO,MAAM,oBAAoB,YACtB,OAAO,QACV,UAAU;iBAEH,MAAM;eACR,MAAM;sBACC,MAAM;qBACP,MAAM;CA+DxB,CAAC"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Maps the changed AmountKey to the correct AmountMode.
3
+ * You can adjust this mapping as per your business logic.
4
+ */
5
+ function getAmountModeByKey(key) {
6
+ switch (key) {
7
+ case 'grossAmount':
8
+ return 'gross-net';
9
+ case 'netAmount':
10
+ return 'gross-net';
11
+ case 'discountedAmount':
12
+ return 'gross-discounted';
13
+ case 'discountPercent':
14
+ return 'gross-discountPercent';
15
+ default:
16
+ return 'gross-net';
17
+ }
18
+ }
19
+ /**
20
+ * Calculates all amount fields based on the last changed key.
21
+ * @param amounts The amounts object.
22
+ * @param changedKey The key that was last changed.
23
+ */
24
+ export function calculateAmount(amounts, changedKey) {
25
+ const mode = getAmountModeByKey(changedKey);
26
+ return calculateAmountByKey(amounts, mode);
27
+ }
28
+ export const calculateAmountByKey = (amounts, mode) => {
29
+ const { grossAmount, netAmount, discountedAmount, discountPercent } = amounts;
30
+ switch (mode) {
31
+ case 'gross-discountPercent': {
32
+ const discountedAmountCalc = (grossAmount * discountPercent) / 100;
33
+ const netAmountCalc = grossAmount - discountedAmountCalc;
34
+ return {
35
+ grossAmount: Number(grossAmount?.toFixed(2)),
36
+ netAmount: Number(netAmountCalc?.toFixed(2)),
37
+ discountedAmount: Number(discountedAmountCalc?.toFixed(2)),
38
+ discountPercent: Number(discountPercent?.toFixed(2)),
39
+ };
40
+ }
41
+ case 'gross-net': {
42
+ const discountedAmountCalc = grossAmount - netAmount;
43
+ const discountPercentCalc = (discountedAmountCalc / grossAmount) * 100;
44
+ return {
45
+ grossAmount: Number(grossAmount?.toFixed(2)),
46
+ netAmount: Number(netAmount?.toFixed(2)),
47
+ discountedAmount: Number(discountedAmountCalc?.toFixed(2)),
48
+ discountPercent: Number(discountPercentCalc?.toFixed(2)),
49
+ };
50
+ }
51
+ case 'net-discountPercent': {
52
+ const grossAmountCalc = netAmount / (1 - discountPercent / 100);
53
+ const discountedAmountCalc = grossAmountCalc - netAmount;
54
+ return {
55
+ grossAmount: Number(grossAmountCalc?.toFixed(2)),
56
+ netAmount: Number(netAmount?.toFixed(2)),
57
+ discountedAmount: Number(discountedAmountCalc?.toFixed(2)),
58
+ discountPercent: Number(discountPercent?.toFixed(2)),
59
+ };
60
+ }
61
+ case 'gross-discounted': {
62
+ const netAmountCalc = grossAmount - discountedAmount;
63
+ const discountPercentCalc = (discountedAmount / grossAmount) * 100;
64
+ return {
65
+ grossAmount: Number(grossAmount?.toFixed(2)),
66
+ netAmount: Number(netAmountCalc?.toFixed(2)),
67
+ discountedAmount: Number(discountedAmount?.toFixed(2)),
68
+ discountPercent: Number(discountPercentCalc?.toFixed(2)),
69
+ };
70
+ }
71
+ case 'net-discounted': {
72
+ const grossAmountCalc = netAmount + discountedAmount;
73
+ const discountPercentCalc = (discountedAmount / grossAmountCalc) * 100;
74
+ return {
75
+ grossAmount: Number(grossAmountCalc?.toFixed(2)),
76
+ netAmount: Number(netAmount?.toFixed(2)),
77
+ discountedAmount: Number(discountedAmount?.toFixed(2)),
78
+ discountPercent: Number(discountPercentCalc?.toFixed(2)),
79
+ };
80
+ }
81
+ default:
82
+ return {
83
+ grossAmount,
84
+ netAmount,
85
+ discountedAmount,
86
+ discountPercent,
87
+ };
88
+ }
89
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Converts a number to words using the Indian numbering system (supports lakh, crore, arab, etc.).
3
+ */
4
+ export declare const numToWords: (n: number | string) => string;
5
+ //# sourceMappingURL=numToWords.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numToWords.util.d.ts","sourceRoot":"","sources":["../../../../../src/core-utils/convert/numberToWords/numToWords.util.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,eAAO,MAAM,UAAU,MAAO,MAAM,GAAG,MAAM,KAAG,MAgI/C,CAAC"}
@@ -0,0 +1,145 @@
1
+ const isEmpty = (xs) => xs.length === 0;
2
+ const take = (n) => (xs) => xs.slice(0, n);
3
+ const drop = (n) => (xs) => xs.slice(n);
4
+ const chunk = (n) => (xs) => isEmpty(xs) ? [] : [take(n)(xs), ...chunk(n)(drop(n)(xs))];
5
+ /**
6
+ * Converts a number to words using the Indian numbering system (supports lakh, crore, arab, etc.).
7
+ */
8
+ export const numToWords = (n) => {
9
+ const a = [
10
+ '',
11
+ 'one',
12
+ 'two',
13
+ 'three',
14
+ 'four',
15
+ 'five',
16
+ 'six',
17
+ 'seven',
18
+ 'eight',
19
+ 'nine',
20
+ 'ten',
21
+ 'eleven',
22
+ 'twelve',
23
+ 'thirteen',
24
+ 'fourteen',
25
+ 'fifteen',
26
+ 'sixteen',
27
+ 'seventeen',
28
+ 'eighteen',
29
+ 'nineteen',
30
+ ];
31
+ const b = [
32
+ '',
33
+ '',
34
+ 'twenty',
35
+ 'thirty',
36
+ 'forty',
37
+ 'fifty',
38
+ 'sixty',
39
+ 'seventy',
40
+ 'eighty',
41
+ 'ninety',
42
+ ];
43
+ const g = [
44
+ '',
45
+ 'thousand',
46
+ 'lakh',
47
+ 'crore',
48
+ 'arab',
49
+ 'kharab',
50
+ 'neel',
51
+ 'padma',
52
+ 'shankh',
53
+ ];
54
+ // Plural forms for units
55
+ const gPlural = [
56
+ '',
57
+ 'thousand',
58
+ 'lakhs',
59
+ 'crores',
60
+ 'arabs',
61
+ 'kharabs',
62
+ 'neels',
63
+ 'padmas',
64
+ 'shankhs',
65
+ ];
66
+ if (typeof n === 'number')
67
+ n = String(n);
68
+ if (n === '0')
69
+ return 'zero';
70
+ // Indian chunking: last 3 digits, then every 2 digits
71
+ const chunkIndian = (xs) => {
72
+ if (xs.length <= 3)
73
+ return [xs];
74
+ const last3 = xs.slice(xs.length - 3);
75
+ const rest = xs.slice(0, xs.length - 3);
76
+ const pairs = [];
77
+ while (rest.length > 0) {
78
+ pairs.unshift(rest.splice(-2));
79
+ }
80
+ return [...pairs, last3];
81
+ };
82
+ // Convert a group (1 or 2 or 3 digits) to words
83
+ const groupToWords = (group) => {
84
+ let numVal = Number(group.join(''));
85
+ if (numVal === 0)
86
+ return '';
87
+ if (group.length === 3) {
88
+ // 3 digits: hundreds
89
+ let [h, t, o] = group.map(Number);
90
+ let str = '';
91
+ if (h)
92
+ str += a[h] + ' hundred ';
93
+ let lastTwo = t * 10 + o;
94
+ if (lastTwo) {
95
+ if (str)
96
+ str += 'and ';
97
+ if (lastTwo < 20)
98
+ str += a[lastTwo];
99
+ else
100
+ str += b[t] + (o ? '-' + a[o] : '');
101
+ }
102
+ return str.trim();
103
+ }
104
+ else if (group.length === 2) {
105
+ // 2 digits
106
+ let [t, o] = group.map(Number);
107
+ if (t === 0)
108
+ return a[o];
109
+ if (t * 10 + o < 20)
110
+ return a[t * 10 + o];
111
+ return b[t] + (o ? '-' + a[o] : '');
112
+ }
113
+ else if (group.length === 1) {
114
+ return a[Number(group[0])];
115
+ }
116
+ return '';
117
+ };
118
+ const digits = Array.from(n);
119
+ const groups = chunkIndian(digits);
120
+ const words = groups
121
+ .map((group, i, arr) => {
122
+ // Only pad the last group (units) to 3 digits, others to 2
123
+ if (i === arr.length - 1) {
124
+ while (group.length < 3)
125
+ group.unshift('0');
126
+ }
127
+ else {
128
+ while (group.length < 2)
129
+ group.unshift('0');
130
+ }
131
+ return groupToWords(group);
132
+ })
133
+ .map((word, i, arr) => {
134
+ const unitIdx = arr.length - 1 - i;
135
+ // Use plural for units if value > 1 and unit is not ''
136
+ const groupValue = Number(groups[i].join(''));
137
+ const unit = groupValue > 1 && g[unitIdx] ? gPlural[unitIdx] : g[unitIdx];
138
+ return word ? `${word} ${unit}`.trim() : '';
139
+ })
140
+ .filter(Boolean)
141
+ .join(' ')
142
+ .replace(/\s+/g, ' ')
143
+ .trim();
144
+ return words;
145
+ };
@@ -1,2 +1,4 @@
1
1
  export * from './utility.util';
2
+ export * from './calculation/calculation.util';
3
+ export * from './convert/numberToWords/numToWords.util';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core-utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core-utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yCAAyC,CAAC"}
@@ -1 +1,3 @@
1
1
  export * from './utility.util';
2
+ export * from './calculation/calculation.util';
3
+ export * from './convert/numberToWords/numToWords.util';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-restyle-components",
3
- "version": "0.2.75",
3
+ "version": "0.2.77",
4
4
  "private": false,
5
5
  "description": "Easy use restyle components",
6
6
  "author": {