react-native-timer-picker 2.1.1 → 2.2.1
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/README.md +250 -174
- package/dist/commonjs/components/DurationScroll/DurationScroll.js +417 -0
- package/dist/commonjs/components/DurationScroll/DurationScroll.js.map +1 -0
- package/dist/commonjs/components/DurationScroll/index.js +20 -392
- package/dist/commonjs/components/DurationScroll/index.js.map +1 -1
- package/dist/commonjs/components/DurationScroll/types.js.map +1 -1
- package/dist/commonjs/components/Modal/Modal.js +107 -0
- package/dist/commonjs/components/Modal/Modal.js.map +1 -0
- package/dist/commonjs/components/Modal/index.js +20 -101
- package/dist/commonjs/components/Modal/index.js.map +1 -1
- package/dist/commonjs/components/TimerPicker/TimerPicker.js +225 -0
- package/dist/commonjs/components/TimerPicker/TimerPicker.js.map +1 -0
- package/dist/commonjs/components/TimerPicker/index.js +29 -166
- package/dist/commonjs/components/TimerPicker/index.js.map +1 -1
- package/dist/commonjs/components/TimerPicker/styles.js.map +1 -1
- package/dist/commonjs/components/TimerPicker/types.js.map +1 -1
- package/dist/commonjs/components/TimerPickerModal/TimerPickerModal.js +143 -0
- package/dist/commonjs/components/TimerPickerModal/TimerPickerModal.js.map +1 -0
- package/dist/commonjs/components/TimerPickerModal/index.js +30 -131
- package/dist/commonjs/components/TimerPickerModal/index.js.map +1 -1
- package/dist/commonjs/components/TimerPickerModal/types.js.map +1 -1
- package/dist/commonjs/index.js +9 -13
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/tests/DurationScroll.test.js +94 -0
- package/dist/commonjs/tests/DurationScroll.test.js.map +1 -1
- package/dist/commonjs/tests/Modal.test.js +79 -2
- package/dist/commonjs/tests/Modal.test.js.map +1 -1
- package/dist/commonjs/tests/TimerPicker.test.js +119 -1
- package/dist/commonjs/tests/TimerPicker.test.js.map +1 -1
- package/dist/commonjs/tests/TimerPickerModal.test.js +120 -0
- package/dist/commonjs/tests/TimerPickerModal.test.js.map +1 -1
- package/dist/commonjs/tests/colorToRgba.test.js +176 -0
- package/dist/commonjs/tests/colorToRgba.test.js.map +1 -0
- package/dist/commonjs/tests/generateNumbers.test.js +350 -0
- package/dist/commonjs/tests/generateNumbers.test.js.map +1 -0
- package/dist/commonjs/tests/getAdjustedLimit.test.js +324 -0
- package/dist/commonjs/tests/getAdjustedLimit.test.js.map +1 -0
- package/dist/commonjs/tests/getDurationAndIndexFromScrollOffset.test.js +424 -0
- package/dist/commonjs/tests/getDurationAndIndexFromScrollOffset.test.js.map +1 -0
- package/dist/commonjs/tests/getInitialScrollIndex.test.js +396 -0
- package/dist/commonjs/tests/getInitialScrollIndex.test.js.map +1 -0
- package/dist/commonjs/tests/getSafeInitialValue.test.js +497 -0
- package/dist/commonjs/tests/getSafeInitialValue.test.js.map +1 -0
- package/dist/commonjs/tests/padNumber.test.js +301 -0
- package/dist/commonjs/tests/padNumber.test.js.map +1 -0
- package/dist/commonjs/utils/colorToRgba.js +40 -4
- package/dist/commonjs/utils/colorToRgba.js.map +1 -1
- package/dist/commonjs/utils/generateNumbers.js +67 -0
- package/dist/commonjs/utils/generateNumbers.js.map +1 -1
- package/dist/commonjs/utils/getAdjustedLimit.js +28 -3
- package/dist/commonjs/utils/getAdjustedLimit.js.map +1 -1
- package/dist/commonjs/utils/getDurationAndIndexFromScrollOffset.js +38 -0
- package/dist/commonjs/utils/getDurationAndIndexFromScrollOffset.js.map +1 -1
- package/dist/commonjs/utils/getInitialScrollIndex.js +38 -0
- package/dist/commonjs/utils/getInitialScrollIndex.js.map +1 -1
- package/dist/commonjs/utils/getSafeInitialValue.js +28 -0
- package/dist/commonjs/utils/getSafeInitialValue.js.map +1 -1
- package/dist/commonjs/utils/padNumber.js +25 -0
- package/dist/commonjs/utils/padNumber.js.map +1 -1
- package/dist/module/components/DurationScroll/DurationScroll.js +410 -0
- package/dist/module/components/DurationScroll/DurationScroll.js.map +1 -0
- package/dist/module/components/DurationScroll/index.js +2 -390
- package/dist/module/components/DurationScroll/index.js.map +1 -1
- package/dist/module/components/DurationScroll/types.js.map +1 -1
- package/dist/module/components/Modal/Modal.js +99 -0
- package/dist/module/components/Modal/Modal.js.map +1 -0
- package/dist/module/components/Modal/index.js +2 -98
- package/dist/module/components/Modal/index.js.map +1 -1
- package/dist/module/components/TimerPicker/TimerPicker.js +217 -0
- package/dist/module/components/TimerPicker/TimerPicker.js.map +1 -0
- package/dist/module/components/TimerPicker/index.js +3 -166
- package/dist/module/components/TimerPicker/index.js.map +1 -1
- package/dist/module/components/TimerPicker/styles.js.map +1 -1
- package/dist/module/components/TimerPicker/types.js.map +1 -1
- package/dist/module/components/TimerPickerModal/TimerPickerModal.js +135 -0
- package/dist/module/components/TimerPickerModal/TimerPickerModal.js.map +1 -0
- package/dist/module/components/TimerPickerModal/index.js +3 -130
- package/dist/module/components/TimerPickerModal/index.js.map +1 -1
- package/dist/module/components/TimerPickerModal/types.js.map +1 -1
- package/dist/module/index.js +2 -6
- package/dist/module/index.js.map +1 -1
- package/dist/module/tests/DurationScroll.test.js +94 -0
- package/dist/module/tests/DurationScroll.test.js.map +1 -1
- package/dist/module/tests/Modal.test.js +80 -3
- package/dist/module/tests/Modal.test.js.map +1 -1
- package/dist/module/tests/TimerPicker.test.js +119 -1
- package/dist/module/tests/TimerPicker.test.js.map +1 -1
- package/dist/module/tests/TimerPickerModal.test.js +121 -1
- package/dist/module/tests/TimerPickerModal.test.js.map +1 -1
- package/dist/module/tests/colorToRgba.test.js +174 -0
- package/dist/module/tests/colorToRgba.test.js.map +1 -0
- package/dist/module/tests/generateNumbers.test.js +348 -0
- package/dist/module/tests/generateNumbers.test.js.map +1 -0
- package/dist/module/tests/getAdjustedLimit.test.js +322 -0
- package/dist/module/tests/getAdjustedLimit.test.js.map +1 -0
- package/dist/module/tests/getDurationAndIndexFromScrollOffset.test.js +422 -0
- package/dist/module/tests/getDurationAndIndexFromScrollOffset.test.js.map +1 -0
- package/dist/module/tests/getInitialScrollIndex.test.js +394 -0
- package/dist/module/tests/getInitialScrollIndex.test.js.map +1 -0
- package/dist/module/tests/getSafeInitialValue.test.js +495 -0
- package/dist/module/tests/getSafeInitialValue.test.js.map +1 -0
- package/dist/module/tests/padNumber.test.js +299 -0
- package/dist/module/tests/padNumber.test.js.map +1 -0
- package/dist/module/utils/colorToRgba.js +40 -4
- package/dist/module/utils/colorToRgba.js.map +1 -1
- package/dist/module/utils/generateNumbers.js +68 -0
- package/dist/module/utils/generateNumbers.js.map +1 -1
- package/dist/module/utils/getAdjustedLimit.js +28 -3
- package/dist/module/utils/getAdjustedLimit.js.map +1 -1
- package/dist/module/utils/getDurationAndIndexFromScrollOffset.js +38 -0
- package/dist/module/utils/getDurationAndIndexFromScrollOffset.js.map +1 -1
- package/dist/module/utils/getInitialScrollIndex.js +38 -0
- package/dist/module/utils/getInitialScrollIndex.js.map +1 -1
- package/dist/module/utils/getSafeInitialValue.js +28 -0
- package/dist/module/utils/getSafeInitialValue.js.map +1 -1
- package/dist/module/utils/padNumber.js +25 -0
- package/dist/module/utils/padNumber.js.map +1 -1
- package/dist/typescript/components/DurationScroll/DurationScroll.d.ts +4 -0
- package/dist/typescript/components/DurationScroll/index.d.ts +2 -4
- package/dist/typescript/components/DurationScroll/types.d.ts +13 -9
- package/dist/typescript/components/Modal/Modal.d.ts +5 -0
- package/dist/typescript/components/Modal/index.d.ts +2 -5
- package/dist/typescript/components/TimerPicker/TimerPicker.d.ts +4 -0
- package/dist/typescript/components/TimerPicker/index.d.ts +3 -4
- package/dist/typescript/components/TimerPicker/styles.d.ts +922 -771
- package/dist/typescript/components/TimerPicker/types.d.ts +26 -10
- package/dist/typescript/components/TimerPickerModal/TimerPickerModal.d.ts +4 -0
- package/dist/typescript/components/TimerPickerModal/index.d.ts +3 -4
- package/dist/typescript/components/TimerPickerModal/styles.d.ts +570 -474
- package/dist/typescript/components/TimerPickerModal/types.d.ts +8 -5
- package/dist/typescript/index.d.ts +2 -6
- package/dist/typescript/utils/colorToRgba.d.ts +34 -0
- package/dist/typescript/utils/generateNumbers.d.ts +66 -0
- package/dist/typescript/utils/getAdjustedLimit.d.ts +27 -2
- package/dist/typescript/utils/getDurationAndIndexFromScrollOffset.d.ts +38 -0
- package/dist/typescript/utils/getInitialScrollIndex.d.ts +38 -0
- package/dist/typescript/utils/getSafeInitialValue.d.ts +29 -0
- package/dist/typescript/utils/padNumber.d.ts +25 -0
- package/package.json +12 -30
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _padNumber = require("../utils/padNumber");
|
|
4
|
+
describe("padNumber", () => {
|
|
5
|
+
describe("padding with zero", () => {
|
|
6
|
+
it("pads single digit with zero", () => {
|
|
7
|
+
expect((0, _padNumber.padNumber)(0, {
|
|
8
|
+
padWithZero: true
|
|
9
|
+
})).toBe("00");
|
|
10
|
+
expect((0, _padNumber.padNumber)(1, {
|
|
11
|
+
padWithZero: true
|
|
12
|
+
})).toBe("01");
|
|
13
|
+
expect((0, _padNumber.padNumber)(5, {
|
|
14
|
+
padWithZero: true
|
|
15
|
+
})).toBe("05");
|
|
16
|
+
expect((0, _padNumber.padNumber)(9, {
|
|
17
|
+
padWithZero: true
|
|
18
|
+
})).toBe("09");
|
|
19
|
+
});
|
|
20
|
+
it("does not pad double digits", () => {
|
|
21
|
+
expect((0, _padNumber.padNumber)(10, {
|
|
22
|
+
padWithZero: true
|
|
23
|
+
})).toBe("10");
|
|
24
|
+
expect((0, _padNumber.padNumber)(15, {
|
|
25
|
+
padWithZero: true
|
|
26
|
+
})).toBe("15");
|
|
27
|
+
expect((0, _padNumber.padNumber)(99, {
|
|
28
|
+
padWithZero: true
|
|
29
|
+
})).toBe("99");
|
|
30
|
+
});
|
|
31
|
+
it("does not pad triple digits", () => {
|
|
32
|
+
expect((0, _padNumber.padNumber)(100, {
|
|
33
|
+
padWithZero: true
|
|
34
|
+
})).toBe("100");
|
|
35
|
+
expect((0, _padNumber.padNumber)(255, {
|
|
36
|
+
padWithZero: true
|
|
37
|
+
})).toBe("255");
|
|
38
|
+
expect((0, _padNumber.padNumber)(999, {
|
|
39
|
+
padWithZero: true
|
|
40
|
+
})).toBe("999");
|
|
41
|
+
});
|
|
42
|
+
it("handles very large numbers", () => {
|
|
43
|
+
expect((0, _padNumber.padNumber)(1000, {
|
|
44
|
+
padWithZero: true
|
|
45
|
+
})).toBe("1000");
|
|
46
|
+
expect((0, _padNumber.padNumber)(99999, {
|
|
47
|
+
padWithZero: true
|
|
48
|
+
})).toBe("99999");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe("padding with space", () => {
|
|
52
|
+
it("pads single digit with space", () => {
|
|
53
|
+
expect((0, _padNumber.padNumber)(0, {
|
|
54
|
+
padWithZero: false
|
|
55
|
+
})).toBe(" 0");
|
|
56
|
+
expect((0, _padNumber.padNumber)(1, {
|
|
57
|
+
padWithZero: false
|
|
58
|
+
})).toBe(" 1");
|
|
59
|
+
expect((0, _padNumber.padNumber)(5, {
|
|
60
|
+
padWithZero: false
|
|
61
|
+
})).toBe(" 5");
|
|
62
|
+
expect((0, _padNumber.padNumber)(9, {
|
|
63
|
+
padWithZero: false
|
|
64
|
+
})).toBe(" 9");
|
|
65
|
+
});
|
|
66
|
+
it("does not pad double digits", () => {
|
|
67
|
+
expect((0, _padNumber.padNumber)(10, {
|
|
68
|
+
padWithZero: false
|
|
69
|
+
})).toBe("10");
|
|
70
|
+
expect((0, _padNumber.padNumber)(15, {
|
|
71
|
+
padWithZero: false
|
|
72
|
+
})).toBe("15");
|
|
73
|
+
expect((0, _padNumber.padNumber)(99, {
|
|
74
|
+
padWithZero: false
|
|
75
|
+
})).toBe("99");
|
|
76
|
+
});
|
|
77
|
+
it("does not pad triple digits", () => {
|
|
78
|
+
expect((0, _padNumber.padNumber)(100, {
|
|
79
|
+
padWithZero: false
|
|
80
|
+
})).toBe("100");
|
|
81
|
+
expect((0, _padNumber.padNumber)(255, {
|
|
82
|
+
padWithZero: false
|
|
83
|
+
})).toBe("255");
|
|
84
|
+
expect((0, _padNumber.padNumber)(999, {
|
|
85
|
+
padWithZero: false
|
|
86
|
+
})).toBe("999");
|
|
87
|
+
});
|
|
88
|
+
it("handles very large numbers", () => {
|
|
89
|
+
expect((0, _padNumber.padNumber)(1000, {
|
|
90
|
+
padWithZero: false
|
|
91
|
+
})).toBe("1000");
|
|
92
|
+
expect((0, _padNumber.padNumber)(99999, {
|
|
93
|
+
padWithZero: false
|
|
94
|
+
})).toBe("99999");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe("no options provided", () => {
|
|
98
|
+
it("defaults to space padding for single digits", () => {
|
|
99
|
+
expect((0, _padNumber.padNumber)(0)).toBe(" 0");
|
|
100
|
+
expect((0, _padNumber.padNumber)(1)).toBe(" 1");
|
|
101
|
+
expect((0, _padNumber.padNumber)(5)).toBe(" 5");
|
|
102
|
+
expect((0, _padNumber.padNumber)(9)).toBe(" 9");
|
|
103
|
+
});
|
|
104
|
+
it("does not pad double digits", () => {
|
|
105
|
+
expect((0, _padNumber.padNumber)(10)).toBe("10");
|
|
106
|
+
expect((0, _padNumber.padNumber)(15)).toBe("15");
|
|
107
|
+
expect((0, _padNumber.padNumber)(99)).toBe("99");
|
|
108
|
+
});
|
|
109
|
+
it("does not pad triple digits", () => {
|
|
110
|
+
expect((0, _padNumber.padNumber)(100)).toBe("100");
|
|
111
|
+
expect((0, _padNumber.padNumber)(255)).toBe("255");
|
|
112
|
+
expect((0, _padNumber.padNumber)(999)).toBe("999");
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe("undefined padWithZero option", () => {
|
|
116
|
+
it("defaults to space padding", () => {
|
|
117
|
+
expect((0, _padNumber.padNumber)(0, {})).toBe(" 0");
|
|
118
|
+
expect((0, _padNumber.padNumber)(5, {})).toBe(" 5");
|
|
119
|
+
expect((0, _padNumber.padNumber)(9, {})).toBe(" 9");
|
|
120
|
+
});
|
|
121
|
+
it("does not pad double digits", () => {
|
|
122
|
+
expect((0, _padNumber.padNumber)(10, {})).toBe("10");
|
|
123
|
+
expect((0, _padNumber.padNumber)(50, {})).toBe("50");
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe("edge cases at boundary", () => {
|
|
127
|
+
it("handles value exactly 9 (last single digit)", () => {
|
|
128
|
+
expect((0, _padNumber.padNumber)(9, {
|
|
129
|
+
padWithZero: true
|
|
130
|
+
})).toBe("09");
|
|
131
|
+
expect((0, _padNumber.padNumber)(9, {
|
|
132
|
+
padWithZero: false
|
|
133
|
+
})).toBe(" 9");
|
|
134
|
+
expect((0, _padNumber.padNumber)(9)).toBe(" 9");
|
|
135
|
+
});
|
|
136
|
+
it("handles value exactly 10 (first double digit)", () => {
|
|
137
|
+
expect((0, _padNumber.padNumber)(10, {
|
|
138
|
+
padWithZero: true
|
|
139
|
+
})).toBe("10");
|
|
140
|
+
expect((0, _padNumber.padNumber)(10, {
|
|
141
|
+
padWithZero: false
|
|
142
|
+
})).toBe("10");
|
|
143
|
+
expect((0, _padNumber.padNumber)(10)).toBe("10");
|
|
144
|
+
});
|
|
145
|
+
it("handles value exactly 0", () => {
|
|
146
|
+
expect((0, _padNumber.padNumber)(0, {
|
|
147
|
+
padWithZero: true
|
|
148
|
+
})).toBe("00");
|
|
149
|
+
expect((0, _padNumber.padNumber)(0, {
|
|
150
|
+
padWithZero: false
|
|
151
|
+
})).toBe(" 0");
|
|
152
|
+
expect((0, _padNumber.padNumber)(0)).toBe(" 0");
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
describe("real-world scenarios", () => {
|
|
156
|
+
it("formats hours for 12-hour display", () => {
|
|
157
|
+
expect((0, _padNumber.padNumber)(1, {
|
|
158
|
+
padWithZero: true
|
|
159
|
+
})).toBe("01");
|
|
160
|
+
expect((0, _padNumber.padNumber)(12, {
|
|
161
|
+
padWithZero: true
|
|
162
|
+
})).toBe("12");
|
|
163
|
+
});
|
|
164
|
+
it("formats hours for 24-hour display", () => {
|
|
165
|
+
expect((0, _padNumber.padNumber)(0, {
|
|
166
|
+
padWithZero: true
|
|
167
|
+
})).toBe("00");
|
|
168
|
+
expect((0, _padNumber.padNumber)(9, {
|
|
169
|
+
padWithZero: true
|
|
170
|
+
})).toBe("09");
|
|
171
|
+
expect((0, _padNumber.padNumber)(23, {
|
|
172
|
+
padWithZero: true
|
|
173
|
+
})).toBe("23");
|
|
174
|
+
});
|
|
175
|
+
it("formats minutes", () => {
|
|
176
|
+
expect((0, _padNumber.padNumber)(0, {
|
|
177
|
+
padWithZero: true
|
|
178
|
+
})).toBe("00");
|
|
179
|
+
expect((0, _padNumber.padNumber)(5, {
|
|
180
|
+
padWithZero: true
|
|
181
|
+
})).toBe("05");
|
|
182
|
+
expect((0, _padNumber.padNumber)(30, {
|
|
183
|
+
padWithZero: true
|
|
184
|
+
})).toBe("30");
|
|
185
|
+
expect((0, _padNumber.padNumber)(59, {
|
|
186
|
+
padWithZero: true
|
|
187
|
+
})).toBe("59");
|
|
188
|
+
});
|
|
189
|
+
it("formats seconds", () => {
|
|
190
|
+
expect((0, _padNumber.padNumber)(0, {
|
|
191
|
+
padWithZero: true
|
|
192
|
+
})).toBe("00");
|
|
193
|
+
expect((0, _padNumber.padNumber)(9, {
|
|
194
|
+
padWithZero: true
|
|
195
|
+
})).toBe("09");
|
|
196
|
+
expect((0, _padNumber.padNumber)(45, {
|
|
197
|
+
padWithZero: true
|
|
198
|
+
})).toBe("45");
|
|
199
|
+
expect((0, _padNumber.padNumber)(59, {
|
|
200
|
+
padWithZero: true
|
|
201
|
+
})).toBe("59");
|
|
202
|
+
});
|
|
203
|
+
it("formats days without padding preference", () => {
|
|
204
|
+
expect((0, _padNumber.padNumber)(1, {
|
|
205
|
+
padWithZero: false
|
|
206
|
+
})).toBe(" 1");
|
|
207
|
+
expect((0, _padNumber.padNumber)(7, {
|
|
208
|
+
padWithZero: false
|
|
209
|
+
})).toBe(" 7");
|
|
210
|
+
expect((0, _padNumber.padNumber)(30, {
|
|
211
|
+
padWithZero: false
|
|
212
|
+
})).toBe("30");
|
|
213
|
+
expect((0, _padNumber.padNumber)(365, {
|
|
214
|
+
padWithZero: false
|
|
215
|
+
})).toBe("365");
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
describe("all single digits", () => {
|
|
219
|
+
it("correctly pads all single digits 0-9 with zero", () => {
|
|
220
|
+
for (let i = 0; i < 10; i++) {
|
|
221
|
+
const result = (0, _padNumber.padNumber)(i, {
|
|
222
|
+
padWithZero: true
|
|
223
|
+
});
|
|
224
|
+
expect(result).toBe(`0${i}`);
|
|
225
|
+
expect(result).toHaveLength(2);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
it("correctly pads all single digits 0-9 with space", () => {
|
|
229
|
+
for (let i = 0; i < 10; i++) {
|
|
230
|
+
const result = (0, _padNumber.padNumber)(i, {
|
|
231
|
+
padWithZero: false
|
|
232
|
+
});
|
|
233
|
+
expect(result).toBe(` ${i}`);
|
|
234
|
+
expect(result).toHaveLength(2);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
describe("return type", () => {
|
|
239
|
+
it("always returns a string", () => {
|
|
240
|
+
expect(typeof (0, _padNumber.padNumber)(0, {
|
|
241
|
+
padWithZero: true
|
|
242
|
+
})).toBe("string");
|
|
243
|
+
expect(typeof (0, _padNumber.padNumber)(5, {
|
|
244
|
+
padWithZero: true
|
|
245
|
+
})).toBe("string");
|
|
246
|
+
expect(typeof (0, _padNumber.padNumber)(10, {
|
|
247
|
+
padWithZero: true
|
|
248
|
+
})).toBe("string");
|
|
249
|
+
expect(typeof (0, _padNumber.padNumber)(100, {
|
|
250
|
+
padWithZero: true
|
|
251
|
+
})).toBe("string");
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
describe("string length", () => {
|
|
255
|
+
it("returns 2-character string for single digits", () => {
|
|
256
|
+
expect((0, _padNumber.padNumber)(0, {
|
|
257
|
+
padWithZero: true
|
|
258
|
+
})).toHaveLength(2);
|
|
259
|
+
expect((0, _padNumber.padNumber)(5, {
|
|
260
|
+
padWithZero: true
|
|
261
|
+
})).toHaveLength(2);
|
|
262
|
+
expect((0, _padNumber.padNumber)(9, {
|
|
263
|
+
padWithZero: true
|
|
264
|
+
})).toHaveLength(2);
|
|
265
|
+
});
|
|
266
|
+
it("returns 2-character string for single digits with space", () => {
|
|
267
|
+
expect((0, _padNumber.padNumber)(0, {
|
|
268
|
+
padWithZero: false
|
|
269
|
+
})).toHaveLength(2);
|
|
270
|
+
expect((0, _padNumber.padNumber)(5, {
|
|
271
|
+
padWithZero: false
|
|
272
|
+
})).toHaveLength(2);
|
|
273
|
+
expect((0, _padNumber.padNumber)(9, {
|
|
274
|
+
padWithZero: false
|
|
275
|
+
})).toHaveLength(2);
|
|
276
|
+
});
|
|
277
|
+
it("returns correct length for double digits", () => {
|
|
278
|
+
expect((0, _padNumber.padNumber)(10, {
|
|
279
|
+
padWithZero: true
|
|
280
|
+
})).toHaveLength(2);
|
|
281
|
+
expect((0, _padNumber.padNumber)(50, {
|
|
282
|
+
padWithZero: true
|
|
283
|
+
})).toHaveLength(2);
|
|
284
|
+
expect((0, _padNumber.padNumber)(99, {
|
|
285
|
+
padWithZero: true
|
|
286
|
+
})).toHaveLength(2);
|
|
287
|
+
});
|
|
288
|
+
it("returns correct length for triple digits", () => {
|
|
289
|
+
expect((0, _padNumber.padNumber)(100, {
|
|
290
|
+
padWithZero: true
|
|
291
|
+
})).toHaveLength(3);
|
|
292
|
+
expect((0, _padNumber.padNumber)(500, {
|
|
293
|
+
padWithZero: true
|
|
294
|
+
})).toHaveLength(3);
|
|
295
|
+
expect((0, _padNumber.padNumber)(999, {
|
|
296
|
+
padWithZero: true
|
|
297
|
+
})).toHaveLength(3);
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
//# sourceMappingURL=padNumber.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_padNumber","require","describe","it","expect","padNumber","padWithZero","toBe","i","result","toHaveLength"],"sources":["padNumber.test.ts"],"sourcesContent":["import { padNumber } from \"../utils/padNumber\";\n\ndescribe(\"padNumber\", () => {\n describe(\"padding with zero\", () => {\n it(\"pads single digit with zero\", () => {\n expect(padNumber(0, { padWithZero: true })).toBe(\"00\");\n expect(padNumber(1, { padWithZero: true })).toBe(\"01\");\n expect(padNumber(5, { padWithZero: true })).toBe(\"05\");\n expect(padNumber(9, { padWithZero: true })).toBe(\"09\");\n });\n\n it(\"does not pad double digits\", () => {\n expect(padNumber(10, { padWithZero: true })).toBe(\"10\");\n expect(padNumber(15, { padWithZero: true })).toBe(\"15\");\n expect(padNumber(99, { padWithZero: true })).toBe(\"99\");\n });\n\n it(\"does not pad triple digits\", () => {\n expect(padNumber(100, { padWithZero: true })).toBe(\"100\");\n expect(padNumber(255, { padWithZero: true })).toBe(\"255\");\n expect(padNumber(999, { padWithZero: true })).toBe(\"999\");\n });\n\n it(\"handles very large numbers\", () => {\n expect(padNumber(1000, { padWithZero: true })).toBe(\"1000\");\n expect(padNumber(99999, { padWithZero: true })).toBe(\"99999\");\n });\n });\n\n describe(\"padding with space\", () => {\n it(\"pads single digit with space\", () => {\n expect(padNumber(0, { padWithZero: false })).toBe(\" 0\");\n expect(padNumber(1, { padWithZero: false })).toBe(\" 1\");\n expect(padNumber(5, { padWithZero: false })).toBe(\" 5\");\n expect(padNumber(9, { padWithZero: false })).toBe(\" 9\");\n });\n\n it(\"does not pad double digits\", () => {\n expect(padNumber(10, { padWithZero: false })).toBe(\"10\");\n expect(padNumber(15, { padWithZero: false })).toBe(\"15\");\n expect(padNumber(99, { padWithZero: false })).toBe(\"99\");\n });\n\n it(\"does not pad triple digits\", () => {\n expect(padNumber(100, { padWithZero: false })).toBe(\"100\");\n expect(padNumber(255, { padWithZero: false })).toBe(\"255\");\n expect(padNumber(999, { padWithZero: false })).toBe(\"999\");\n });\n\n it(\"handles very large numbers\", () => {\n expect(padNumber(1000, { padWithZero: false })).toBe(\"1000\");\n expect(padNumber(99999, { padWithZero: false })).toBe(\"99999\");\n });\n });\n\n describe(\"no options provided\", () => {\n it(\"defaults to space padding for single digits\", () => {\n expect(padNumber(0)).toBe(\" 0\");\n expect(padNumber(1)).toBe(\" 1\");\n expect(padNumber(5)).toBe(\" 5\");\n expect(padNumber(9)).toBe(\" 9\");\n });\n\n it(\"does not pad double digits\", () => {\n expect(padNumber(10)).toBe(\"10\");\n expect(padNumber(15)).toBe(\"15\");\n expect(padNumber(99)).toBe(\"99\");\n });\n\n it(\"does not pad triple digits\", () => {\n expect(padNumber(100)).toBe(\"100\");\n expect(padNumber(255)).toBe(\"255\");\n expect(padNumber(999)).toBe(\"999\");\n });\n });\n\n describe(\"undefined padWithZero option\", () => {\n it(\"defaults to space padding\", () => {\n expect(padNumber(0, {})).toBe(\" 0\");\n expect(padNumber(5, {})).toBe(\" 5\");\n expect(padNumber(9, {})).toBe(\" 9\");\n });\n\n it(\"does not pad double digits\", () => {\n expect(padNumber(10, {})).toBe(\"10\");\n expect(padNumber(50, {})).toBe(\"50\");\n });\n });\n\n describe(\"edge cases at boundary\", () => {\n it(\"handles value exactly 9 (last single digit)\", () => {\n expect(padNumber(9, { padWithZero: true })).toBe(\"09\");\n expect(padNumber(9, { padWithZero: false })).toBe(\" 9\");\n expect(padNumber(9)).toBe(\" 9\");\n });\n\n it(\"handles value exactly 10 (first double digit)\", () => {\n expect(padNumber(10, { padWithZero: true })).toBe(\"10\");\n expect(padNumber(10, { padWithZero: false })).toBe(\"10\");\n expect(padNumber(10)).toBe(\"10\");\n });\n\n it(\"handles value exactly 0\", () => {\n expect(padNumber(0, { padWithZero: true })).toBe(\"00\");\n expect(padNumber(0, { padWithZero: false })).toBe(\" 0\");\n expect(padNumber(0)).toBe(\" 0\");\n });\n });\n\n describe(\"real-world scenarios\", () => {\n it(\"formats hours for 12-hour display\", () => {\n expect(padNumber(1, { padWithZero: true })).toBe(\"01\");\n expect(padNumber(12, { padWithZero: true })).toBe(\"12\");\n });\n\n it(\"formats hours for 24-hour display\", () => {\n expect(padNumber(0, { padWithZero: true })).toBe(\"00\");\n expect(padNumber(9, { padWithZero: true })).toBe(\"09\");\n expect(padNumber(23, { padWithZero: true })).toBe(\"23\");\n });\n\n it(\"formats minutes\", () => {\n expect(padNumber(0, { padWithZero: true })).toBe(\"00\");\n expect(padNumber(5, { padWithZero: true })).toBe(\"05\");\n expect(padNumber(30, { padWithZero: true })).toBe(\"30\");\n expect(padNumber(59, { padWithZero: true })).toBe(\"59\");\n });\n\n it(\"formats seconds\", () => {\n expect(padNumber(0, { padWithZero: true })).toBe(\"00\");\n expect(padNumber(9, { padWithZero: true })).toBe(\"09\");\n expect(padNumber(45, { padWithZero: true })).toBe(\"45\");\n expect(padNumber(59, { padWithZero: true })).toBe(\"59\");\n });\n\n it(\"formats days without padding preference\", () => {\n expect(padNumber(1, { padWithZero: false })).toBe(\" 1\");\n expect(padNumber(7, { padWithZero: false })).toBe(\" 7\");\n expect(padNumber(30, { padWithZero: false })).toBe(\"30\");\n expect(padNumber(365, { padWithZero: false })).toBe(\"365\");\n });\n });\n\n describe(\"all single digits\", () => {\n it(\"correctly pads all single digits 0-9 with zero\", () => {\n for (let i = 0; i < 10; i++) {\n const result = padNumber(i, { padWithZero: true });\n expect(result).toBe(`0${i}`);\n expect(result).toHaveLength(2);\n }\n });\n\n it(\"correctly pads all single digits 0-9 with space\", () => {\n for (let i = 0; i < 10; i++) {\n const result = padNumber(i, { padWithZero: false });\n expect(result).toBe(` ${i}`);\n expect(result).toHaveLength(2);\n }\n });\n });\n\n describe(\"return type\", () => {\n it(\"always returns a string\", () => {\n expect(typeof padNumber(0, { padWithZero: true })).toBe(\"string\");\n expect(typeof padNumber(5, { padWithZero: true })).toBe(\"string\");\n expect(typeof padNumber(10, { padWithZero: true })).toBe(\"string\");\n expect(typeof padNumber(100, { padWithZero: true })).toBe(\"string\");\n });\n });\n\n describe(\"string length\", () => {\n it(\"returns 2-character string for single digits\", () => {\n expect(padNumber(0, { padWithZero: true })).toHaveLength(2);\n expect(padNumber(5, { padWithZero: true })).toHaveLength(2);\n expect(padNumber(9, { padWithZero: true })).toHaveLength(2);\n });\n\n it(\"returns 2-character string for single digits with space\", () => {\n expect(padNumber(0, { padWithZero: false })).toHaveLength(2);\n expect(padNumber(5, { padWithZero: false })).toHaveLength(2);\n expect(padNumber(9, { padWithZero: false })).toHaveLength(2);\n });\n\n it(\"returns correct length for double digits\", () => {\n expect(padNumber(10, { padWithZero: true })).toHaveLength(2);\n expect(padNumber(50, { padWithZero: true })).toHaveLength(2);\n expect(padNumber(99, { padWithZero: true })).toHaveLength(2);\n });\n\n it(\"returns correct length for triple digits\", () => {\n expect(padNumber(100, { padWithZero: true })).toHaveLength(3);\n expect(padNumber(500, { padWithZero: true })).toHaveLength(3);\n expect(padNumber(999, { padWithZero: true })).toHaveLength(3);\n });\n });\n});\n"],"mappings":";;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEAC,QAAQ,CAAC,WAAW,EAAE,MAAM;EACxBA,QAAQ,CAAC,mBAAmB,EAAE,MAAM;IAChCC,EAAE,CAAC,6BAA6B,EAAE,MAAM;MACpCC,MAAM,CAAC,IAAAC,oBAAS,EAAC,CAAC,EAAE;QAAEC,WAAW,EAAE;MAAK,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;MACtDH,MAAM,CAAC,IAAAC,oBAAS,EAAC,CAAC,EAAE;QAAEC,WAAW,EAAE;MAAK,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;MACtDH,MAAM,CAAC,IAAAC,oBAAS,EAAC,CAAC,EAAE;QAAEC,WAAW,EAAE;MAAK,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;MACtDH,MAAM,CAAC,IAAAC,oBAAS,EAAC,CAAC,EAAE;QAAEC,WAAW,EAAE;MAAK,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;IAC1D,CAAC,CAAC;IAEFJ,E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,CAAC;MAC5DN,MAAM,CAAC,IAAAC,oBAAS,EAAC,EAAE,EAAE;QAAEC,WAAW,EAAE;MAAK,CAAC,CAAC,CAAC,CAACI,YAAY,CAAC,CAAC,CAAC;MAC5DN,MAAM,CAAC,IAAAC,oBAAS,EAAC,EAAE,EAAE;QAAEC,WAAW,EAAE;MAAK,CAAC,CAAC,CAAC,CAACI,YAAY,CAAC,CAAC,CAAC;IAChE,CAAC,CAAC;IAEFP,EAAE,CAAC,0CAA0C,EAAE,MAAM;MACjDC,MAAM,CAAC,IAAAC,oBAAS,EAAC,GAAG,EAAE;QAAEC,WAAW,EAAE;MAAK,CAAC,CAAC,CAAC,CAACI,YAAY,CAAC,CAAC,CAAC;MAC7DN,MAAM,CAAC,IAAAC,oBAAS,EAAC,GAAG,EAAE;QAAEC,WAAW,EAAE;MAAK,CAAC,CAAC,CAAC,CAACI,YAAY,CAAC,CAAC,CAAC;MAC7DN,MAAM,CAAC,IAAAC,oBAAS,EAAC,GAAG,EAAE;QAAEC,WAAW,EAAE;MAAK,CAAC,CAAC,CAAC,CAACI,YAAY,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
|
|
@@ -4,15 +4,46 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.colorToRgba = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Converts various color formats to RGBA string representation.
|
|
9
|
+
* This function is specifically required for expo-linear-gradient on iOS to handle transparent colors correctly.
|
|
10
|
+
* It supports named colors, RGB, and hex color formats.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} variables - The input variables object
|
|
13
|
+
* @param {string} variables.color - The color to convert. Can be:
|
|
14
|
+
* - Named color (e.g., 'transparent', 'black', 'white', 'blue', 'green', 'gray', 'red')
|
|
15
|
+
* - RGB format (e.g., 'rgb(255, 0, 0)')
|
|
16
|
+
* - Hex format (e.g., '#FF0000' or '#F00')
|
|
17
|
+
* @param {number} [variables.opacity=1] - The opacity value between 0 and 1
|
|
18
|
+
*
|
|
19
|
+
* @returns {string} The color in RGBA format (e.g., 'rgba(255, 0, 0, 0.5)')
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Using named color
|
|
23
|
+
* colorToRgba({ color: 'transparent' })
|
|
24
|
+
* // Returns: 'rgba(0, 0, 0, 0)'
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Using RGB with custom opacity
|
|
28
|
+
* colorToRgba({ color: 'rgb(255, 0, 0)', opacity: 0.5 })
|
|
29
|
+
* // Returns: 'rgba(255, 0, 0, 0.5)'
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // Using hex color
|
|
33
|
+
* colorToRgba({ color: '#FF0000' })
|
|
34
|
+
* // Returns: 'rgba(255, 0, 0, 1)'
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // Using short hex color
|
|
38
|
+
* colorToRgba({ color: '#F00' })
|
|
39
|
+
* // Returns: 'rgba(255, 0, 0, 1)'
|
|
40
|
+
*/
|
|
7
41
|
const colorToRgba = variables => {
|
|
8
|
-
// this function is required for expo-linear-gradient on iOS. To fade to transparent, we need
|
|
9
|
-
// to be able to add opacity to the background color. Supplying 'transparent' does not work
|
|
10
|
-
// because that is actually a transparent black (rgba(0, 0, 0, 1)), which results in dodgy rendering
|
|
11
|
-
|
|
12
42
|
const {
|
|
13
43
|
color,
|
|
14
44
|
opacity = 1
|
|
15
45
|
} = variables;
|
|
46
|
+
|
|
16
47
|
// Handle named colors
|
|
17
48
|
const namedColors = {
|
|
18
49
|
transparent: "rgba(0, 0, 0, 0)",
|
|
@@ -43,6 +74,11 @@ const colorToRgba = variables => {
|
|
|
43
74
|
const r = parseInt(hexColor.slice(0, 2), 16);
|
|
44
75
|
const g = parseInt(hexColor.slice(2, 4), 16);
|
|
45
76
|
const b = parseInt(hexColor.slice(4, 6), 16);
|
|
77
|
+
|
|
78
|
+
// Validate that all color components are valid numbers
|
|
79
|
+
if (isNaN(r) || isNaN(g) || isNaN(b)) {
|
|
80
|
+
return color; // Return original if malformed
|
|
81
|
+
}
|
|
46
82
|
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
47
83
|
}
|
|
48
84
|
return color; // Return unchanged if unable to parse
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["colorToRgba","variables","color","opacity","namedColors","transparent","black","white","blue","green","gray","red","startsWith","rgbValues","replace","split","map","value","parseInt","trim","r","g","b","hexColor","slice","length","join","exports"],"sources":["colorToRgba.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"names":["colorToRgba","variables","color","opacity","namedColors","transparent","black","white","blue","green","gray","red","startsWith","rgbValues","replace","split","map","value","parseInt","trim","r","g","b","hexColor","slice","length","join","isNaN","exports"],"sources":["colorToRgba.ts"],"sourcesContent":["/**\n * Converts various color formats to RGBA string representation.\n * This function is specifically required for expo-linear-gradient on iOS to handle transparent colors correctly.\n * It supports named colors, RGB, and hex color formats.\n *\n * @param {Object} variables - The input variables object\n * @param {string} variables.color - The color to convert. Can be:\n * - Named color (e.g., 'transparent', 'black', 'white', 'blue', 'green', 'gray', 'red')\n * - RGB format (e.g., 'rgb(255, 0, 0)')\n * - Hex format (e.g., '#FF0000' or '#F00')\n * @param {number} [variables.opacity=1] - The opacity value between 0 and 1\n *\n * @returns {string} The color in RGBA format (e.g., 'rgba(255, 0, 0, 0.5)')\n *\n * @example\n * // Using named color\n * colorToRgba({ color: 'transparent' })\n * // Returns: 'rgba(0, 0, 0, 0)'\n *\n * @example\n * // Using RGB with custom opacity\n * colorToRgba({ color: 'rgb(255, 0, 0)', opacity: 0.5 })\n * // Returns: 'rgba(255, 0, 0, 0.5)'\n *\n * @example\n * // Using hex color\n * colorToRgba({ color: '#FF0000' })\n * // Returns: 'rgba(255, 0, 0, 1)'\n *\n * @example\n * // Using short hex color\n * colorToRgba({ color: '#F00' })\n * // Returns: 'rgba(255, 0, 0, 1)'\n */\nexport const colorToRgba = (variables: {\n color: string;\n opacity?: number;\n}): string => {\n const { color, opacity = 1 } = variables;\n\n // Handle named colors\n const namedColors: { [key: string]: string } = {\n transparent: \"rgba(0, 0, 0, 0)\",\n black: \"rgba(0, 0, 0, 1)\",\n white: \"rgba(255, 255, 255, 1)\",\n blue: \"rgba(0, 0, 255, 1)\",\n green: \"rgba(0, 128, 0, 1)\",\n gray: \"rgba(128, 128, 128, 1)\",\n red: \"rgba(255, 0, 0, 1)\",\n };\n\n if (color in namedColors) {\n return namedColors[color];\n }\n\n // Handle RGB format\n if (color.startsWith(\"rgb(\")) {\n const rgbValues = color\n .replace(\"rgb(\", \"\")\n .replace(\")\", \"\")\n .split(\",\")\n .map((value) => parseInt(value.trim(), 10));\n const [r, g, b] = rgbValues;\n return `rgba(${r}, ${g}, ${b}, ${opacity})`;\n }\n\n // Handle hex format\n if (color.startsWith(\"#\")) {\n let hexColor = color.slice(1);\n if (hexColor.length === 3) {\n hexColor = hexColor\n .split(\"\")\n .map((value) => value + value)\n .join(\"\");\n }\n const r = parseInt(hexColor.slice(0, 2), 16);\n const g = parseInt(hexColor.slice(2, 4), 16);\n const b = parseInt(hexColor.slice(4, 6), 16);\n\n // Validate that all color components are valid numbers\n if (isNaN(r) || isNaN(g) || isNaN(b)) {\n return color; // Return original if malformed\n }\n\n return `rgba(${r}, ${g}, ${b}, ${opacity})`;\n }\n\n return color; // Return unchanged if unable to parse\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,WAAW,GAAIC,SAG3B,IAAa;EACV,MAAM;IAAEC,KAAK;IAAEC,OAAO,GAAG;EAAE,CAAC,GAAGF,SAAS;;EAExC;EACA,MAAMG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AQ,CAACK,QAAQ,CAACC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IAC5C,MAAMF,CAAC,GAAGJ,QAAQ,CAACK,QAAQ,CAACC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;;IAE5C;IACA,IAAIG,KAAK,CAACP,CAAC,CAAC,IAAIO,KAAK,CAACN,CAAC,CAAC,IAAIM,KAAK,CAACL,CAAC,CAAC,EAAE;MAClC,OAAOpB,KAAK,CAAC,CAAC;IAClB;IAEA,OAAO,QAAQkB,CAAC,KAAKC,CAAC,KAAKC,CAAC,KAAKnB,OAAO,GAAG;EAC/C;EAEA,OAAOD,KAAK,CAAC,CAAC;AAClB,CAAC;AAAC0B,OAAA,CAAA5B,WAAA,GAAAA,WAAA","ignoreList":[]}
|
|
@@ -5,6 +5,40 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.generateNumbers = exports.generate12HourNumbers = void 0;
|
|
7
7
|
var _padNumber = require("./padNumber");
|
|
8
|
+
/**
|
|
9
|
+
* Generates an array of formatted numbers for a number picker, with support for infinite scroll,
|
|
10
|
+
* padding, and number repetition.
|
|
11
|
+
*
|
|
12
|
+
* @param {number} numberOfItems - Total number of items to generate
|
|
13
|
+
* @param {Object} options - Configuration options for number generation
|
|
14
|
+
* @param {boolean} [options.disableInfiniteScroll] - Whether to disable infinite scroll
|
|
15
|
+
* @param {number} options.interval - The interval between consecutive numbers
|
|
16
|
+
* @param {boolean} [options.padNumbersWithZero] - Whether to pad single-digit numbers with leading zeros
|
|
17
|
+
* @param {number} options.padWithNItems - Number of empty items to pad with
|
|
18
|
+
* @param {number} options.repeatNTimes - How many times to repeat the number sequence
|
|
19
|
+
*
|
|
20
|
+
* @returns {string[]} Array of formatted number strings
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Generate numbers 0-9 with padding
|
|
24
|
+
* generateNumbers(10, {
|
|
25
|
+
* interval: 1,
|
|
26
|
+
* padWithNItems: 2,
|
|
27
|
+
* repeatNTimes: 1,
|
|
28
|
+
* padNumbersWithZero: true
|
|
29
|
+
* })
|
|
30
|
+
* // Returns: ['', '', '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '', '']
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Generate even numbers with infinite scroll
|
|
34
|
+
* generateNumbers(5, {
|
|
35
|
+
* interval: 2,
|
|
36
|
+
* padWithNItems: 2,
|
|
37
|
+
* repeatNTimes: 3,
|
|
38
|
+
* disableInfiniteScroll: false
|
|
39
|
+
* })
|
|
40
|
+
* // Returns: ['0', '2', '4', '6', '8', '0', '2', '4', '6', '8', '0', '2', '4', '6', '8']
|
|
41
|
+
*/
|
|
8
42
|
const generateNumbers = (numberOfItems, options) => {
|
|
9
43
|
if (numberOfItems <= 0) {
|
|
10
44
|
return [];
|
|
@@ -25,6 +59,39 @@ const generateNumbers = (numberOfItems, options) => {
|
|
|
25
59
|
}
|
|
26
60
|
return numbers;
|
|
27
61
|
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Generates an array of formatted 12-hour time strings (AM/PM) for a time picker.
|
|
65
|
+
* Supports infinite scroll, padding, and number repetition.
|
|
66
|
+
*
|
|
67
|
+
* @param {Object} options - Configuration options for time generation
|
|
68
|
+
* @param {boolean} [options.disableInfiniteScroll] - Whether to disable infinite scroll
|
|
69
|
+
* @param {number} options.interval - The interval between hours (must be a divisor of 12)
|
|
70
|
+
* @param {boolean} [options.padNumbersWithZero] - Whether to pad single-digit hours with leading zeros
|
|
71
|
+
* @param {number} options.padWithNItems - Number of empty items to pad with
|
|
72
|
+
* @param {number} [options.repeatNTimes] - How many times to repeat the time sequence (defaults to 1)
|
|
73
|
+
*
|
|
74
|
+
* @returns {string[]} Array of formatted 12-hour time strings
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // Generate hours with 1-hour interval
|
|
78
|
+
* generate12HourNumbers({
|
|
79
|
+
* interval: 1,
|
|
80
|
+
* padWithNItems: 2,
|
|
81
|
+
* padNumbersWithZero: true
|
|
82
|
+
* })
|
|
83
|
+
* // Returns: ['', '', '12 AM', '01 AM', '02 AM', ..., '11 PM', '', '']
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* // Generate hours with 2-hour interval and infinite scroll
|
|
87
|
+
* generate12HourNumbers({
|
|
88
|
+
* interval: 2,
|
|
89
|
+
* padWithNItems: 2,
|
|
90
|
+
* repeatNTimes: 2,
|
|
91
|
+
* disableInfiniteScroll: false
|
|
92
|
+
* })
|
|
93
|
+
* // Returns: ['12 AM', '2 AM', '4 AM', ..., '10 PM', '12 AM', '2 AM', ...]
|
|
94
|
+
*/
|
|
28
95
|
exports.generateNumbers = generateNumbers;
|
|
29
96
|
const generate12HourNumbers = options => {
|
|
30
97
|
let numbers = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_padNumber","require","generateNumbers","numberOfItems","options","numbers","i","value","interval","push","padNumber","padWithZero","padNumbersWithZero","repeatNTimes","Array","fill","flat","disableInfiniteScroll","padWithNItems","unshift","exports","generate12HourNumbers","hour"],"sources":["generateNumbers.ts"],"sourcesContent":["import { padNumber } from \"./padNumber\";\n\nexport const generateNumbers = (\n numberOfItems: number,\n options: {\n disableInfiniteScroll?: boolean;\n interval: number;\n padNumbersWithZero?: boolean;\n padWithNItems: number;\n repeatNTimes: number;\n }\n) => {\n if (numberOfItems <= 0) {\n return [];\n }\n\n let numbers: string[] = [];\n for (let i = 0; i < numberOfItems; i++) {\n const value = i * options.interval;\n numbers.push(\n padNumber(value, { padWithZero: options.padNumbersWithZero })\n );\n }\n\n if (options.repeatNTimes > 1) {\n numbers = Array(options.repeatNTimes).fill(numbers).flat();\n }\n if (options.disableInfiniteScroll || options.repeatNTimes === 1) {\n numbers.push(...Array(options.padWithNItems).fill(\"\"));\n numbers.unshift(...Array(options.padWithNItems).fill(\"\"));\n }\n return numbers;\n};\n\nexport const generate12HourNumbers = (options: {\n disableInfiniteScroll?: boolean;\n interval: number;\n padNumbersWithZero?: boolean;\n padWithNItems: number;\n repeatNTimes?: number;\n}) => {\n let numbers: string[] = [];\n\n // Generate numbers from 0 to 11 for AM\n for (let i = 0; i < 12; i += options.interval) {\n numbers.push(\n `${padNumber(i, { padWithZero: options.padNumbersWithZero })} AM`\n );\n }\n\n // Generate numbers from 12 to 11 for PM\n for (let i = 12; i < 24; i += options.interval) {\n const hour = i > 12 ? i - 12 : i;\n numbers.push(\n `${padNumber(hour, { padWithZero: options.padNumbersWithZero })} PM`\n );\n }\n\n if ((options.repeatNTimes ?? 1) > 1) {\n numbers = Array(options.repeatNTimes).fill(numbers).flat();\n }\n\n if (options.disableInfiniteScroll) {\n numbers.push(...Array(options.padWithNItems).fill(\"\"));\n numbers.unshift(...Array(options.padWithNItems).fill(\"\"));\n }\n\n return numbers;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;
|
|
1
|
+
{"version":3,"names":["_padNumber","require","generateNumbers","numberOfItems","options","numbers","i","value","interval","push","padNumber","padWithZero","padNumbersWithZero","repeatNTimes","Array","fill","flat","disableInfiniteScroll","padWithNItems","unshift","exports","generate12HourNumbers","hour"],"sources":["generateNumbers.ts"],"sourcesContent":["import { padNumber } from \"./padNumber\";\n\n/**\n * Generates an array of formatted numbers for a number picker, with support for infinite scroll,\n * padding, and number repetition.\n *\n * @param {number} numberOfItems - Total number of items to generate\n * @param {Object} options - Configuration options for number generation\n * @param {boolean} [options.disableInfiniteScroll] - Whether to disable infinite scroll\n * @param {number} options.interval - The interval between consecutive numbers\n * @param {boolean} [options.padNumbersWithZero] - Whether to pad single-digit numbers with leading zeros\n * @param {number} options.padWithNItems - Number of empty items to pad with\n * @param {number} options.repeatNTimes - How many times to repeat the number sequence\n *\n * @returns {string[]} Array of formatted number strings\n *\n * @example\n * // Generate numbers 0-9 with padding\n * generateNumbers(10, {\n * interval: 1,\n * padWithNItems: 2,\n * repeatNTimes: 1,\n * padNumbersWithZero: true\n * })\n * // Returns: ['', '', '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '', '']\n *\n * @example\n * // Generate even numbers with infinite scroll\n * generateNumbers(5, {\n * interval: 2,\n * padWithNItems: 2,\n * repeatNTimes: 3,\n * disableInfiniteScroll: false\n * })\n * // Returns: ['0', '2', '4', '6', '8', '0', '2', '4', '6', '8', '0', '2', '4', '6', '8']\n */\nexport const generateNumbers = (\n numberOfItems: number,\n options: {\n disableInfiniteScroll?: boolean;\n interval: number;\n padNumbersWithZero?: boolean;\n padWithNItems: number;\n repeatNTimes: number;\n }\n) => {\n if (numberOfItems <= 0) {\n return [];\n }\n\n let numbers: string[] = [];\n for (let i = 0; i < numberOfItems; i++) {\n const value = i * options.interval;\n numbers.push(\n padNumber(value, { padWithZero: options.padNumbersWithZero })\n );\n }\n\n if (options.repeatNTimes > 1) {\n numbers = Array(options.repeatNTimes).fill(numbers).flat();\n }\n if (options.disableInfiniteScroll || options.repeatNTimes === 1) {\n numbers.push(...Array(options.padWithNItems).fill(\"\"));\n numbers.unshift(...Array(options.padWithNItems).fill(\"\"));\n }\n return numbers;\n};\n\n/**\n * Generates an array of formatted 12-hour time strings (AM/PM) for a time picker.\n * Supports infinite scroll, padding, and number repetition.\n *\n * @param {Object} options - Configuration options for time generation\n * @param {boolean} [options.disableInfiniteScroll] - Whether to disable infinite scroll\n * @param {number} options.interval - The interval between hours (must be a divisor of 12)\n * @param {boolean} [options.padNumbersWithZero] - Whether to pad single-digit hours with leading zeros\n * @param {number} options.padWithNItems - Number of empty items to pad with\n * @param {number} [options.repeatNTimes] - How many times to repeat the time sequence (defaults to 1)\n *\n * @returns {string[]} Array of formatted 12-hour time strings\n *\n * @example\n * // Generate hours with 1-hour interval\n * generate12HourNumbers({\n * interval: 1,\n * padWithNItems: 2,\n * padNumbersWithZero: true\n * })\n * // Returns: ['', '', '12 AM', '01 AM', '02 AM', ..., '11 PM', '', '']\n *\n * @example\n * // Generate hours with 2-hour interval and infinite scroll\n * generate12HourNumbers({\n * interval: 2,\n * padWithNItems: 2,\n * repeatNTimes: 2,\n * disableInfiniteScroll: false\n * })\n * // Returns: ['12 AM', '2 AM', '4 AM', ..., '10 PM', '12 AM', '2 AM', ...]\n */\nexport const generate12HourNumbers = (options: {\n disableInfiniteScroll?: boolean;\n interval: number;\n padNumbersWithZero?: boolean;\n padWithNItems: number;\n repeatNTimes?: number;\n}) => {\n let numbers: string[] = [];\n\n // Generate numbers from 0 to 11 for AM\n for (let i = 0; i < 12; i += options.interval) {\n numbers.push(\n `${padNumber(i, { padWithZero: options.padNumbersWithZero })} AM`\n );\n }\n\n // Generate numbers from 12 to 11 for PM\n for (let i = 12; i < 24; i += options.interval) {\n const hour = i > 12 ? i - 12 : i;\n numbers.push(\n `${padNumber(hour, { padWithZero: options.padNumbersWithZero })} PM`\n );\n }\n\n if ((options.repeatNTimes ?? 1) > 1) {\n numbers = Array(options.repeatNTimes).fill(numbers).flat();\n }\n\n if (options.disableInfiniteScroll) {\n numbers.push(...Array(options.padWithNItems).fill(\"\"));\n numbers.unshift(...Array(options.padWithNItems).fill(\"\"));\n }\n\n return numbers;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,eAAe,GAAGA,CAC3BC,aAAqB,EACrBC,OAMC,KACA;EACD,IAAID,aAAa,IAAI,CAAC,EAAE;IACpB,OAAO,EAAE;EACb;EAEA,IAAIE,OAAiB,GAAG,EAAE;EAC1B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,aAAa,EAAEG,CAAC,EAAE,EAAE;IACpC,MAAMC,KAAK,GAAGD,CAAC,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EAAEA,CAAC,GAAG,EAAE,EAAEA,CAAC,IAAIF,OAAO,CAACI,QAAQ,EAAE;IAC5C,MAAMc,IAAI,GAAGhB,CAAC,GAAG,EAAE,GAAGA,CAAC,GAAG,EAAE,GAAGA,CAAC;IAChCD,OAAO,CAACI,IAAI,CACR,GAAG,IAAAC,oBAAS,EAACY,IAAI,EAAE;MAAEX,WAAW,EAAEP,OAAO,CAACQ;IAAmB,CAAC,CAAC,KACnE,CAAC;EACL;EAEA,IAAI,CAACR,OAAO,CAACS,YAAY,IAAI,CAAC,IAAI,CAAC,EAAE;IACjCR,OAAO,GAAGS,KAAK,CAACV,OAAO,CAACS,YAAY,CAAC,CAACE,IAAI,CAACV,OAAO,CAAC,CAACW,IAAI,CAAC,CAAC;EAC9D;EAEA,IAAIZ,OAAO,CAACa,qBAAqB,EAAE;IAC/BZ,OAAO,CAACI,IAAI,CAAC,GAAGK,KAAK,CAACV,OAAO,CAACc,aAAa,CAAC,CAACH,IAAI,CAAC,EAAE,CAAC,CAAC;IACtDV,OAAO,CAACc,OAAO,CAAC,GAAGL,KAAK,CAACV,OAAO,CAACc,aAAa,CAAC,CAACH,IAAI,CAAC,EAAE,CAAC,CAAC;EAC7D;EAEA,OAAOV,OAAO;AAClB,CAAC;AAACe,OAAA,CAAAC,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -4,9 +4,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getAdjustedLimit = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Adjusts and validates the min/max limits for a scrollable number picker.
|
|
9
|
+
* Ensures limits are within valid bounds and handles edge cases.
|
|
10
|
+
*
|
|
11
|
+
* @param {Limit | undefined} limit - The input limit object containing optional min and max values
|
|
12
|
+
* @param {number} numberOfItems - Total number of items in the picker
|
|
13
|
+
* @param {number} interval - The interval between consecutive numbers
|
|
14
|
+
*
|
|
15
|
+
* @returns {{ max: number; min: number }} An object containing the adjusted min and max limits
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // With valid limits
|
|
19
|
+
* getAdjustedLimit({ min: 5, max: 15 }, 20, 1)
|
|
20
|
+
* // Returns: { max: 15, min: 5 }
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // With out-of-bounds limits
|
|
24
|
+
* getAdjustedLimit({ min: -5, max: 25 }, 20, 1)
|
|
25
|
+
* // Returns: { max: 19, min: 0 }
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // With invalid limits (max < min)
|
|
29
|
+
* getAdjustedLimit({ min: 15, max: 5 }, 20, 1)
|
|
30
|
+
* // Returns: { max: 19, min: 0 }
|
|
31
|
+
*/
|
|
7
32
|
const getAdjustedLimit = (limit, numberOfItems, interval) => {
|
|
8
33
|
const maxValue = (numberOfItems - 1) * interval;
|
|
9
|
-
if (!limit ||
|
|
34
|
+
if (!limit || limit.max === undefined && limit.min === undefined) {
|
|
10
35
|
return {
|
|
11
36
|
max: maxValue,
|
|
12
37
|
min: 0
|
|
@@ -14,8 +39,8 @@ const getAdjustedLimit = (limit, numberOfItems, interval) => {
|
|
|
14
39
|
}
|
|
15
40
|
|
|
16
41
|
// guard against limits that are out of bounds
|
|
17
|
-
const adjustedMaxLimit = limit.max ? Math.min(limit.max, maxValue) : maxValue;
|
|
18
|
-
const adjustedMinLimit = limit.min ? Math.max(limit.min, 0) : 0;
|
|
42
|
+
const adjustedMaxLimit = limit.max !== undefined ? Math.min(limit.max, maxValue) : maxValue;
|
|
43
|
+
const adjustedMinLimit = limit.min !== undefined ? Math.max(limit.min, 0) : 0;
|
|
19
44
|
|
|
20
45
|
// guard against invalid limits
|
|
21
46
|
if (adjustedMaxLimit < adjustedMinLimit) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getAdjustedLimit","limit","numberOfItems","interval","maxValue","max","min","adjustedMaxLimit","Math","adjustedMinLimit","exports"],"sources":["getAdjustedLimit.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"names":["getAdjustedLimit","limit","numberOfItems","interval","maxValue","max","undefined","min","adjustedMaxLimit","Math","adjustedMinLimit","exports"],"sources":["getAdjustedLimit.ts"],"sourcesContent":["import type { Limit } from \"../components/DurationScroll/types\";\n\n/**\n * Adjusts and validates the min/max limits for a scrollable number picker.\n * Ensures limits are within valid bounds and handles edge cases.\n *\n * @param {Limit | undefined} limit - The input limit object containing optional min and max values\n * @param {number} numberOfItems - Total number of items in the picker\n * @param {number} interval - The interval between consecutive numbers\n *\n * @returns {{ max: number; min: number }} An object containing the adjusted min and max limits\n *\n * @example\n * // With valid limits\n * getAdjustedLimit({ min: 5, max: 15 }, 20, 1)\n * // Returns: { max: 15, min: 5 }\n *\n * @example\n * // With out-of-bounds limits\n * getAdjustedLimit({ min: -5, max: 25 }, 20, 1)\n * // Returns: { max: 19, min: 0 }\n *\n * @example\n * // With invalid limits (max < min)\n * getAdjustedLimit({ min: 15, max: 5 }, 20, 1)\n * // Returns: { max: 19, min: 0 }\n */\nexport const getAdjustedLimit = (\n limit: Limit | undefined,\n numberOfItems: number,\n interval: number\n): {\n max: number;\n min: number;\n} => {\n const maxValue = (numberOfItems - 1) * interval;\n\n if (!limit || (limit.max === undefined && limit.min === undefined)) {\n return {\n max: maxValue,\n min: 0,\n };\n }\n\n // guard against limits that are out of bounds\n const adjustedMaxLimit = limit.max !== undefined\n ? Math.min(limit.max, maxValue)\n : maxValue;\n const adjustedMinLimit = limit.min !== undefined ? Math.max(limit.min, 0) : 0;\n\n // guard against invalid limits\n if (adjustedMaxLimit < adjustedMinLimit) {\n return {\n max: maxValue,\n min: 0,\n };\n }\n\n return {\n max: adjustedMaxLimit,\n min: adjustedMinLimit,\n };\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,gBAAgB,GAAGA,CAC5BC,KAAwB,EACxBC,aAAqB,EACrBC,QAAgB,KAIf;EACD,MAAMC,QAAQ,GAAG,CAACF,aAAa,GAAG,CAAC,IAAIC,QAAQ;EAE/C,IAAI,CAACF,KAAK,IAAKA,KAAK,CAACI,GAAG,KAAKC,SAAS,IAAIL,KAAK,CAACM,GAAG,KAAKD,SAAU,EAAE;IAChE,OAAO;MACHD,GAAG,EAAED,QAAQ;MACbG,GAAG,EAAE;IACT,CAAC;EACL;;EAEA;EACA,MAAMC,gBAAgB,GAAGP,KAAK,CAACI,GAAG,KAAKC,SAAS,GAC1CG,IAAI,CAACF,GAAG,CAACN,KAAK,CAACI,GAAG,EAAED,QAAQ,CAAC,GAC7BA,QAAQ;EACd,MAAMM,gBAAgB,GAAGT,KAAK,CAACM,GAAG,KAAKD,SAAS,GAAGG,IAAI,CAACJ,GAAG,CAACJ,KAAK,CAACM,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC;;EAE7E;EACA,IAAIC,gBAAgB,GAAGE,gBAAgB,EAAE;IACrC,OAAO;MACHL,GAAG,EAAED,QAAQ;MACbG,GAAG,EAAE;IACT,CAAC;EACL;EAEA,OAAO;IACHF,GAAG,EAAEG,gBAAgB;IACrBD,GAAG,EAAEG;EACT,CAAC;AACL,CAAC;AAACC,OAAA,CAAAX,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -4,6 +4,44 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getDurationAndIndexFromScrollOffset = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Calculates the duration value and index from a scroll offset in a number picker.
|
|
9
|
+
* Handles both infinite and non-infinite scroll modes, taking into account padding and item height.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} variables - Configuration object for scroll offset calculation
|
|
12
|
+
* @param {boolean} variables.disableInfiniteScroll - Whether infinite scroll is disabled
|
|
13
|
+
* @param {number} variables.interval - The interval between consecutive numbers
|
|
14
|
+
* @param {number} variables.itemHeight - Height of each item in the picker
|
|
15
|
+
* @param {number} variables.numberOfItems - Total number of items in the picker
|
|
16
|
+
* @param {number} variables.padWithNItems - Number of empty items to pad with
|
|
17
|
+
* @param {number} variables.yContentOffset - The vertical scroll offset
|
|
18
|
+
*
|
|
19
|
+
* @returns {{ duration: number; index: number }} Object containing the calculated duration and index
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // With infinite scroll enabled
|
|
23
|
+
* getDurationAndIndexFromScrollOffset({
|
|
24
|
+
* disableInfiniteScroll: false,
|
|
25
|
+
* interval: 1,
|
|
26
|
+
* itemHeight: 50,
|
|
27
|
+
* numberOfItems: 24,
|
|
28
|
+
* padWithNItems: 2,
|
|
29
|
+
* yContentOffset: 100
|
|
30
|
+
* })
|
|
31
|
+
* // Returns: { duration: 2, index: 2 }
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // With infinite scroll disabled
|
|
35
|
+
* getDurationAndIndexFromScrollOffset({
|
|
36
|
+
* disableInfiniteScroll: true,
|
|
37
|
+
* interval: 1,
|
|
38
|
+
* itemHeight: 50,
|
|
39
|
+
* numberOfItems: 24,
|
|
40
|
+
* padWithNItems: 2,
|
|
41
|
+
* yContentOffset: 100
|
|
42
|
+
* })
|
|
43
|
+
* // Returns: { duration: 2, index: 2 }
|
|
44
|
+
*/
|
|
7
45
|
const getDurationAndIndexFromScrollOffset = variables => {
|
|
8
46
|
const {
|
|
9
47
|
disableInfiniteScroll,
|