react-restyle-components 0.2.76 → 0.2.78
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 +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/package.json +1 -1
- package/lib/src/core-hooks/index.d.ts +4 -0
- package/lib/src/core-hooks/index.d.ts.map +1 -0
- package/lib/src/core-hooks/index.js +3 -0
- package/lib/src/core-hooks/useClickOutside/useClickOutside.hook.d.ts +4 -0
- package/lib/src/core-hooks/useClickOutside/useClickOutside.hook.d.ts.map +1 -0
- package/lib/src/core-hooks/useClickOutside/useClickOutside.hook.js +46 -0
- package/lib/src/core-hooks/useDebounce/useDebounce.hook.d.ts +2 -0
- package/lib/src/core-hooks/useDebounce/useDebounce.hook.d.ts.map +1 -0
- package/lib/src/core-hooks/useDebounce/useDebounce.hook.js +30 -0
- package/lib/src/core-hooks/usePreventEKey/usePreventEKey.hook.d.ts +2 -0
- package/lib/src/core-hooks/usePreventEKey/usePreventEKey.hook.d.ts.map +1 -0
- package/lib/src/core-hooks/usePreventEKey/usePreventEKey.hook.js +8 -0
- package/lib/src/core-utils/convert/numberToWords/numToWords.util.d.ts +5 -0
- package/lib/src/core-utils/convert/numberToWords/numToWords.util.d.ts.map +1 -0
- package/lib/src/core-utils/convert/numberToWords/numToWords.util.js +145 -0
- package/lib/src/core-utils/convert/typography/camelCaseToTitleCase.util.d.ts +2 -0
- package/lib/src/core-utils/convert/typography/camelCaseToTitleCase.util.d.ts.map +1 -0
- package/lib/src/core-utils/convert/typography/camelCaseToTitleCase.util.js +5 -0
- package/lib/src/core-utils/index.d.ts +2 -0
- package/lib/src/core-utils/index.d.ts.map +1 -1
- package/lib/src/core-utils/index.js +2 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core-hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sCAAsC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useClickOutside.hook.d.ts","sourceRoot":"","sources":["../../../../src/core-hooks/useClickOutside/useClickOutside.hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAEvC,eAAO,MAAM,eAAe,QAAS,GAAG,WAAW,GAAG,SAwBrD,CAAC;AAEF,eAAO,MAAM,2BAA2B,QACjC,MAAM,SAAS,CAAC,WAAW,CAAC,YACvB,MAAM,IAAI,SAkBrB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
export const useClickOutside = (ref, handler) => {
|
|
3
|
+
useEffect(() => {
|
|
4
|
+
let startedInside = false;
|
|
5
|
+
let startedWhenMounted = false;
|
|
6
|
+
const listener = (event) => {
|
|
7
|
+
// Do nothing if `mousedown` or `touchstart` started inside ref element
|
|
8
|
+
if (startedInside || !startedWhenMounted)
|
|
9
|
+
return;
|
|
10
|
+
// Do nothing if clicking ref's element or descendent elements
|
|
11
|
+
if (!ref.current || ref.current.contains(event.target))
|
|
12
|
+
return;
|
|
13
|
+
handler(event);
|
|
14
|
+
};
|
|
15
|
+
const validateEventStart = (event) => {
|
|
16
|
+
startedWhenMounted = ref.current;
|
|
17
|
+
startedInside = ref.current && ref.current.contains(event.target);
|
|
18
|
+
};
|
|
19
|
+
document.addEventListener('mousedown', validateEventStart);
|
|
20
|
+
document.addEventListener('touchstart', validateEventStart);
|
|
21
|
+
document.addEventListener('click', listener);
|
|
22
|
+
return () => {
|
|
23
|
+
document.removeEventListener('mousedown', validateEventStart);
|
|
24
|
+
document.removeEventListener('touchstart', validateEventStart);
|
|
25
|
+
document.removeEventListener('click', listener);
|
|
26
|
+
};
|
|
27
|
+
}, [ref, handler]);
|
|
28
|
+
};
|
|
29
|
+
export const useClickOutsideWithoutInput = (ref, callback) => {
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const handleClickOutside = (event) => {
|
|
32
|
+
// Check if the target is an input element
|
|
33
|
+
if (event.target.tagName === 'INPUT') {
|
|
34
|
+
return; // Skip calling the callback if the target is an input
|
|
35
|
+
}
|
|
36
|
+
// Check if the click is outside the ref element
|
|
37
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
38
|
+
callback();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
42
|
+
return () => {
|
|
43
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
44
|
+
};
|
|
45
|
+
}, [ref, callback]);
|
|
46
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebounce.hook.d.ts","sourceRoot":"","sources":["../../../../src/core-hooks/useDebounce/useDebounce.hook.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,qBAAsB,GAAG,KAAK,IAAI,SAAS,MAAM,aAKpD,GAAG,SAyBvB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
export const useDebounce = (callback, delay) => {
|
|
3
|
+
const timeoutRef = useRef(null);
|
|
4
|
+
const debouncedCallback = useMemo(() => {
|
|
5
|
+
const debounce = (func, wait) => {
|
|
6
|
+
return (value) => {
|
|
7
|
+
if (timeoutRef.current) {
|
|
8
|
+
clearTimeout(timeoutRef.current);
|
|
9
|
+
}
|
|
10
|
+
timeoutRef.current = setTimeout(() => {
|
|
11
|
+
if (typeof func === 'function') {
|
|
12
|
+
func(value);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
console.error('func is not a function');
|
|
16
|
+
}
|
|
17
|
+
}, wait);
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
return debounce(callback, delay);
|
|
21
|
+
}, [callback, delay]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
return () => {
|
|
24
|
+
if (timeoutRef.current) {
|
|
25
|
+
clearTimeout(timeoutRef.current);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
return debouncedCallback;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePreventEKey.hook.d.ts","sourceRoot":"","sources":["../../../../src/core-hooks/usePreventEKey/usePreventEKey.hook.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,YACF,mBAAmB,CAAC,gBAAgB,CAAC,SAK7D,CAAC"}
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camelCaseToTitleCase.util.d.ts","sourceRoot":"","sources":["../../../../../src/core-utils/convert/typography/camelCaseToTitleCase.util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,QAAS,MAAM,WAI/C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
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"}
|
|
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;AACxD,cAAc,gDAAgD,CAAC"}
|