@regardio/js 0.3.0 → 0.4.0
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/async/delay.d.ts +7 -2
- package/dist/async/delay.js +7 -4
- package/dist/browser/base64.d.ts +8 -2
- package/dist/browser/base64.js +12 -9
- package/dist/format/bytes.d.ts +3 -2
- package/dist/format/bytes.js +12 -9
- package/dist/format/measure.d.ts +3 -2
- package/dist/format/measure.js +14 -12
- package/dist/http/cookie.d.ts +15 -3
- package/dist/http/cookie.js +44 -43
- package/dist/http/domain.d.ts +9 -2
- package/dist/http/domain.js +15 -12
- package/dist/http/request-helpers.d.ts +3 -2
- package/dist/http/request-helpers.js +9 -6
- package/dist/intl/language-detector.d.ts +64 -6
- package/dist/intl/language-detector.js +128 -123
- package/dist/time/time.d.ts +8 -7
- package/dist/time/time.js +121 -118
- package/dist/validation/invariant.d.ts +34 -3
- package/dist/validation/invariant.js +14 -11
- package/dist/validation/verify-file-accept.d.ts +10 -2
- package/dist/validation/verify-file-accept.js +6 -3
- package/package.json +4 -3
- package/dist/async/delay.d.ts.map +0 -1
- package/dist/async/delay.test.d.ts +0 -2
- package/dist/async/delay.test.d.ts.map +0 -1
- package/dist/async/delay.test.js +0 -35
- package/dist/browser/base64.d.ts.map +0 -1
- package/dist/format/bytes.d.ts.map +0 -1
- package/dist/format/bytes.test.d.ts +0 -2
- package/dist/format/bytes.test.d.ts.map +0 -1
- package/dist/format/bytes.test.js +0 -49
- package/dist/format/measure.d.ts.map +0 -1
- package/dist/format/measure.test.d.ts +0 -2
- package/dist/format/measure.test.d.ts.map +0 -1
- package/dist/format/measure.test.js +0 -50
- package/dist/http/cookie.d.ts.map +0 -1
- package/dist/http/domain.d.ts.map +0 -1
- package/dist/http/domain.test.d.ts +0 -2
- package/dist/http/domain.test.d.ts.map +0 -1
- package/dist/http/domain.test.js +0 -29
- package/dist/http/request-helpers.d.ts.map +0 -1
- package/dist/http/request-helpers.test.d.ts +0 -2
- package/dist/http/request-helpers.test.d.ts.map +0 -1
- package/dist/http/request-helpers.test.js +0 -37
- package/dist/intl/language-detector.d.ts.map +0 -1
- package/dist/intl/language-detector.test.d.ts +0 -2
- package/dist/intl/language-detector.test.d.ts.map +0 -1
- package/dist/intl/language-detector.test.js +0 -186
- package/dist/time/time.d.ts.map +0 -1
- package/dist/time/time.test.d.ts +0 -2
- package/dist/time/time.test.d.ts.map +0 -1
- package/dist/time/time.test.js +0 -202
- package/dist/validation/invariant.d.ts.map +0 -1
- package/dist/validation/invariant.test.d.ts +0 -2
- package/dist/validation/invariant.test.d.ts.map +0 -1
- package/dist/validation/invariant.test.js +0 -110
- package/dist/validation/verify-file-accept.d.ts.map +0 -1
- package/dist/validation/verify-file-accept.test.d.ts +0 -2
- package/dist/validation/verify-file-accept.test.d.ts.map +0 -1
- package/dist/validation/verify-file-accept.test.js +0 -71
package/dist/time/time.test.js
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
-
import { dateTimeInUnix, friendlyDuration, oneDayFromNow, oneMinuteFromNow, oneWeekFromNow, timeAgo, } from './time';
|
|
3
|
-
describe('timeAgo', () => {
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
vi.useFakeTimers();
|
|
6
|
-
vi.setSystemTime(new Date('2024-01-15T12:00:00Z'));
|
|
7
|
-
});
|
|
8
|
-
afterEach(() => {
|
|
9
|
-
vi.useRealTimers();
|
|
10
|
-
});
|
|
11
|
-
test('should return "Just now" for very recent times', () => {
|
|
12
|
-
const now = new Date();
|
|
13
|
-
expect(timeAgo(now)).toBe('Just now');
|
|
14
|
-
});
|
|
15
|
-
test('should handle seconds ago', () => {
|
|
16
|
-
const date = new Date(Date.now() - 30 * 1000);
|
|
17
|
-
expect(timeAgo(date)).toMatch(/seconds? ago/);
|
|
18
|
-
});
|
|
19
|
-
test('should handle minutes ago', () => {
|
|
20
|
-
const date = new Date(Date.now() - 5 * 60 * 1000);
|
|
21
|
-
expect(timeAgo(date)).toMatch(/minutes? ago/);
|
|
22
|
-
});
|
|
23
|
-
test('should handle hours ago', () => {
|
|
24
|
-
const date = new Date(Date.now() - 3 * 60 * 60 * 1000);
|
|
25
|
-
expect(timeAgo(date)).toMatch(/hours? ago/);
|
|
26
|
-
});
|
|
27
|
-
test('should handle days ago', () => {
|
|
28
|
-
const date = new Date(Date.now() - 2 * 24 * 60 * 60 * 1000);
|
|
29
|
-
expect(timeAgo(date)).toMatch(/days? ago/);
|
|
30
|
-
});
|
|
31
|
-
test('should handle weeks ago', () => {
|
|
32
|
-
const date = new Date(Date.now() - 2 * 7 * 24 * 60 * 60 * 1000);
|
|
33
|
-
expect(timeAgo(date)).toMatch(/days? ago/);
|
|
34
|
-
});
|
|
35
|
-
test('should handle months ago', () => {
|
|
36
|
-
const date = new Date(Date.now() - 60 * 24 * 60 * 60 * 1000);
|
|
37
|
-
expect(timeAgo(date)).toMatch(/days? ago/);
|
|
38
|
-
});
|
|
39
|
-
test('should handle years ago', () => {
|
|
40
|
-
const date = new Date(Date.now() - 400 * 24 * 60 * 60 * 1000);
|
|
41
|
-
expect(timeAgo(date)).toMatch(/days? ago/);
|
|
42
|
-
});
|
|
43
|
-
test('should accept string input', () => {
|
|
44
|
-
const dateString = new Date(Date.now() - 5 * 60 * 1000).toISOString();
|
|
45
|
-
expect(timeAgo(dateString)).toMatch(/minutes? ago/);
|
|
46
|
-
});
|
|
47
|
-
test('should handle future dates', () => {
|
|
48
|
-
const futureDate = new Date(Date.now() + 5 * 60 * 1000);
|
|
49
|
-
expect(timeAgo(futureDate)).toMatch(/in \d+ minutes?/);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe('oneWeekFromNow', () => {
|
|
53
|
-
beforeEach(() => {
|
|
54
|
-
vi.useFakeTimers();
|
|
55
|
-
vi.setSystemTime(new Date('2024-01-15T12:00:00Z'));
|
|
56
|
-
});
|
|
57
|
-
afterEach(() => {
|
|
58
|
-
vi.useRealTimers();
|
|
59
|
-
});
|
|
60
|
-
test('should return a date 7 days from now', () => {
|
|
61
|
-
const result = oneWeekFromNow();
|
|
62
|
-
const expected = new Date('2024-01-22T12:00:00Z');
|
|
63
|
-
expect(result.getTime()).toBe(expected.getTime());
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
describe('oneDayFromNow', () => {
|
|
67
|
-
beforeEach(() => {
|
|
68
|
-
vi.useFakeTimers();
|
|
69
|
-
vi.setSystemTime(new Date('2024-01-15T12:00:00Z'));
|
|
70
|
-
});
|
|
71
|
-
afterEach(() => {
|
|
72
|
-
vi.useRealTimers();
|
|
73
|
-
});
|
|
74
|
-
test('should return a date 1 day from now', () => {
|
|
75
|
-
const result = oneDayFromNow();
|
|
76
|
-
const expected = new Date('2024-01-16T12:00:00Z');
|
|
77
|
-
expect(result.getTime()).toBe(expected.getTime());
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe('oneMinuteFromNow', () => {
|
|
81
|
-
beforeEach(() => {
|
|
82
|
-
vi.useFakeTimers();
|
|
83
|
-
vi.setSystemTime(new Date('2024-01-15T12:00:00Z'));
|
|
84
|
-
});
|
|
85
|
-
afterEach(() => {
|
|
86
|
-
vi.useRealTimers();
|
|
87
|
-
});
|
|
88
|
-
test('should return a date 1 minute from now', () => {
|
|
89
|
-
const result = oneMinuteFromNow();
|
|
90
|
-
const expected = new Date('2024-01-15T12:01:00Z');
|
|
91
|
-
expect(result.getTime()).toBe(expected.getTime());
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
describe('friendlyDuration', () => {
|
|
95
|
-
test('should return null for null input', () => {
|
|
96
|
-
expect(friendlyDuration(null, 'en')).toBeNull();
|
|
97
|
-
});
|
|
98
|
-
test('should return null for 0 minutes', () => {
|
|
99
|
-
expect(friendlyDuration(0, 'en')).toBeNull();
|
|
100
|
-
});
|
|
101
|
-
describe('short format', () => {
|
|
102
|
-
test('should format minutes under 120 as minutes', () => {
|
|
103
|
-
const result = friendlyDuration(70, 'en', true);
|
|
104
|
-
expect(result).toEqual({
|
|
105
|
-
key: 'common:duration.minutesShort',
|
|
106
|
-
vars: { minutes: '70' },
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
test('should format hours and minutes for durations over 120 minutes', () => {
|
|
110
|
-
const result = friendlyDuration(150, 'en', true);
|
|
111
|
-
expect(result).toEqual({
|
|
112
|
-
key: 'common:duration.hoursAndMinutesShort',
|
|
113
|
-
vars: { hours: '2', minutes: '30' },
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
test('should format hours only when no remaining minutes', () => {
|
|
117
|
-
const result = friendlyDuration(180, 'en', true);
|
|
118
|
-
expect(result).toEqual({
|
|
119
|
-
key: 'common:duration.hoursShort',
|
|
120
|
-
vars: { hours: '3' },
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
describe('long format', () => {
|
|
125
|
-
test('should format minutes for durations under 240 minutes', () => {
|
|
126
|
-
const result = friendlyDuration(120, 'en');
|
|
127
|
-
expect(result).toEqual({
|
|
128
|
-
key: 'common:duration.minutes',
|
|
129
|
-
vars: { count: 120, value: '120' },
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
test('should format hours for durations 240+ minutes', () => {
|
|
133
|
-
const result = friendlyDuration(240, 'en');
|
|
134
|
-
expect(result).toEqual({
|
|
135
|
-
key: 'common:duration.hours',
|
|
136
|
-
vars: { count: 4, value: '4' },
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
test('should format hours and minutes when there are remaining minutes', () => {
|
|
140
|
-
const result = friendlyDuration(270, 'en');
|
|
141
|
-
expect(result).toEqual({
|
|
142
|
-
key: 'common:duration.hoursAndMinutes',
|
|
143
|
-
vars: { hours: '4', minutes: '30' },
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
test('should format days for durations 1440+ minutes', () => {
|
|
147
|
-
const result = friendlyDuration(1440, 'en');
|
|
148
|
-
expect(result).toEqual({
|
|
149
|
-
key: 'common:duration.days',
|
|
150
|
-
vars: { count: 1, value: '1' },
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
test('should format weeks for durations 10080+ minutes', () => {
|
|
154
|
-
const result = friendlyDuration(10080, 'en');
|
|
155
|
-
expect(result).toEqual({
|
|
156
|
-
key: 'common:duration.weeks',
|
|
157
|
-
vars: { count: 1, value: '1' },
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
test('should format months for durations 43200+ minutes', () => {
|
|
161
|
-
const result = friendlyDuration(43200, 'en');
|
|
162
|
-
expect(result).toEqual({
|
|
163
|
-
key: 'common:duration.months',
|
|
164
|
-
vars: { count: 1, value: '1' },
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
test('should format years for durations 525600+ minutes', () => {
|
|
168
|
-
const result = friendlyDuration(525600, 'en');
|
|
169
|
-
expect(result).toEqual({
|
|
170
|
-
key: 'common:duration.years',
|
|
171
|
-
vars: { count: 1, value: '1' },
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
describe('locale formatting', () => {
|
|
176
|
-
test('should use locale-specific number formatting', () => {
|
|
177
|
-
const result = friendlyDuration(1500, 'de-DE', true);
|
|
178
|
-
expect(result).toEqual({
|
|
179
|
-
key: 'common:duration.hoursShort',
|
|
180
|
-
vars: { hours: '25' },
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
describe('dateTimeInUnix', () => {
|
|
186
|
-
test('should convert milliseconds to seconds', () => {
|
|
187
|
-
expect(dateTimeInUnix(1000)).toBe(1);
|
|
188
|
-
expect(dateTimeInUnix(1500)).toBe(1);
|
|
189
|
-
expect(dateTimeInUnix(2000)).toBe(2);
|
|
190
|
-
});
|
|
191
|
-
test('should handle 0', () => {
|
|
192
|
-
expect(dateTimeInUnix(0)).toBe(0);
|
|
193
|
-
});
|
|
194
|
-
test('should handle large timestamps', () => {
|
|
195
|
-
const timestamp = 1705320000000;
|
|
196
|
-
expect(dateTimeInUnix(timestamp)).toBe(1705320000);
|
|
197
|
-
});
|
|
198
|
-
test('should floor the result', () => {
|
|
199
|
-
expect(dateTimeInUnix(1999)).toBe(1);
|
|
200
|
-
expect(dateTimeInUnix(2001)).toBe(2);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../../src/validation/invariant.ts"],"names":[],"mappings":"AAeA,wBAAgB,SAAS,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,OAAO,CAAC,SAAS,CAIjG;AAiBD,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,EAChC,YAAY,CAAC,EAAE,YAAY,GAC1B,OAAO,CAAC,SAAS,CAOnB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invariant.test.d.ts","sourceRoot":"","sources":["../../src/validation/invariant.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import { invariant, invariantResponse } from './invariant';
|
|
3
|
-
describe('invariant', () => {
|
|
4
|
-
test('should not throw when condition is truthy', () => {
|
|
5
|
-
expect(() => invariant(true, 'error')).not.toThrow();
|
|
6
|
-
expect(() => invariant(1, 'error')).not.toThrow();
|
|
7
|
-
expect(() => invariant('string', 'error')).not.toThrow();
|
|
8
|
-
expect(() => invariant({}, 'error')).not.toThrow();
|
|
9
|
-
expect(() => invariant([], 'error')).not.toThrow();
|
|
10
|
-
});
|
|
11
|
-
test('should throw Error when condition is falsy', () => {
|
|
12
|
-
expect(() => invariant(false, 'test error')).toThrow(Error);
|
|
13
|
-
expect(() => invariant(false, 'test error')).toThrow('test error');
|
|
14
|
-
});
|
|
15
|
-
test('should throw for various falsy values', () => {
|
|
16
|
-
expect(() => invariant(null, 'null error')).toThrow('null error');
|
|
17
|
-
expect(() => invariant(undefined, 'undefined error')).toThrow('undefined error');
|
|
18
|
-
expect(() => invariant(0, 'zero error')).toThrow('zero error');
|
|
19
|
-
expect(() => invariant('', 'empty string error')).toThrow('empty string error');
|
|
20
|
-
expect(() => invariant(Number.NaN, 'NaN error')).toThrow('NaN error');
|
|
21
|
-
});
|
|
22
|
-
test('should accept message as a function', () => {
|
|
23
|
-
expect(() => invariant(false, () => 'lazy error')).toThrow('lazy error');
|
|
24
|
-
});
|
|
25
|
-
test('should not call message function when condition is truthy', () => {
|
|
26
|
-
let called = false;
|
|
27
|
-
invariant(true, () => {
|
|
28
|
-
called = true;
|
|
29
|
-
return 'error';
|
|
30
|
-
});
|
|
31
|
-
expect(called).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
test('should work as type assertion', () => {
|
|
34
|
-
const value = 'hello';
|
|
35
|
-
invariant(value !== null, 'value is null');
|
|
36
|
-
expect(value.toUpperCase()).toBe('HELLO');
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
describe('invariantResponse', () => {
|
|
40
|
-
test('should not throw when condition is truthy', () => {
|
|
41
|
-
expect(() => invariantResponse(true, 'error')).not.toThrow();
|
|
42
|
-
expect(() => invariantResponse(1, 'error')).not.toThrow();
|
|
43
|
-
expect(() => invariantResponse('string', 'error')).not.toThrow();
|
|
44
|
-
});
|
|
45
|
-
test('should throw Response when condition is falsy', () => {
|
|
46
|
-
expect(() => invariantResponse(false, 'test error')).toThrow();
|
|
47
|
-
});
|
|
48
|
-
test('should throw Response with status 400 by default', async () => {
|
|
49
|
-
let thrownError;
|
|
50
|
-
try {
|
|
51
|
-
invariantResponse(false, 'bad request');
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
thrownError = error;
|
|
55
|
-
}
|
|
56
|
-
expect(thrownError).toBeInstanceOf(Response);
|
|
57
|
-
const response = thrownError;
|
|
58
|
-
expect(response.status).toBe(400);
|
|
59
|
-
expect(await response.text()).toBe('bad request');
|
|
60
|
-
});
|
|
61
|
-
test('should accept custom responseInit', () => {
|
|
62
|
-
let thrownError;
|
|
63
|
-
try {
|
|
64
|
-
invariantResponse(false, 'not found', { status: 404 });
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
thrownError = error;
|
|
68
|
-
}
|
|
69
|
-
expect(thrownError).toBeInstanceOf(Response);
|
|
70
|
-
const response = thrownError;
|
|
71
|
-
expect(response.status).toBe(404);
|
|
72
|
-
});
|
|
73
|
-
test('should accept custom headers in responseInit', () => {
|
|
74
|
-
let thrownError;
|
|
75
|
-
try {
|
|
76
|
-
invariantResponse(false, 'error', {
|
|
77
|
-
headers: { 'X-Custom-Header': 'value' },
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
thrownError = error;
|
|
82
|
-
}
|
|
83
|
-
const response = thrownError;
|
|
84
|
-
expect(response.headers.get('X-Custom-Header')).toBe('value');
|
|
85
|
-
});
|
|
86
|
-
test('should accept message as a function', async () => {
|
|
87
|
-
let thrownError;
|
|
88
|
-
try {
|
|
89
|
-
invariantResponse(false, () => 'lazy error');
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
thrownError = error;
|
|
93
|
-
}
|
|
94
|
-
const response = thrownError;
|
|
95
|
-
expect(await response.text()).toBe('lazy error');
|
|
96
|
-
});
|
|
97
|
-
test('should not call message function when condition is truthy', () => {
|
|
98
|
-
let called = false;
|
|
99
|
-
invariantResponse(true, () => {
|
|
100
|
-
called = true;
|
|
101
|
-
return 'error';
|
|
102
|
-
});
|
|
103
|
-
expect(called).toBe(false);
|
|
104
|
-
});
|
|
105
|
-
test('should work as type assertion', () => {
|
|
106
|
-
const value = 'hello';
|
|
107
|
-
invariantResponse(value !== null, 'value is null');
|
|
108
|
-
expect(value.toUpperCase()).toBe('HELLO');
|
|
109
|
-
});
|
|
110
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"verify-file-accept.d.ts","sourceRoot":"","sources":["../../src/validation/verify-file-accept.ts"],"names":[],"mappings":"AAOA,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAGlE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"verify-file-accept.test.d.ts","sourceRoot":"","sources":["../../src/validation/verify-file-accept.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import { verifyAccept } from './verify-file-accept';
|
|
3
|
-
describe('verifyAccept', () => {
|
|
4
|
-
describe('exact mime type matching', () => {
|
|
5
|
-
test('should return true for exact match', () => {
|
|
6
|
-
expect(verifyAccept('image/png', 'image/png')).toBe(true);
|
|
7
|
-
expect(verifyAccept('image/jpeg', 'image/jpeg')).toBe(true);
|
|
8
|
-
expect(verifyAccept('application/pdf', 'application/pdf')).toBe(true);
|
|
9
|
-
});
|
|
10
|
-
test('should return false for non-matching mime type', () => {
|
|
11
|
-
expect(verifyAccept('image/png', 'image/jpeg')).toBe(false);
|
|
12
|
-
expect(verifyAccept('video/mp4', 'audio/mp3')).toBe(false);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
describe('wildcard matching', () => {
|
|
16
|
-
test('should match wildcard for same type', () => {
|
|
17
|
-
expect(verifyAccept('image/png', 'image/*')).toBe(true);
|
|
18
|
-
expect(verifyAccept('image/jpeg', 'image/*')).toBe(true);
|
|
19
|
-
expect(verifyAccept('image/gif', 'image/*')).toBe(true);
|
|
20
|
-
});
|
|
21
|
-
test('should match audio wildcard', () => {
|
|
22
|
-
expect(verifyAccept('audio/mp3', 'audio/*')).toBe(true);
|
|
23
|
-
expect(verifyAccept('audio/wav', 'audio/*')).toBe(true);
|
|
24
|
-
});
|
|
25
|
-
test('should match video wildcard', () => {
|
|
26
|
-
expect(verifyAccept('video/mp4', 'video/*')).toBe(true);
|
|
27
|
-
expect(verifyAccept('video/webm', 'video/*')).toBe(true);
|
|
28
|
-
});
|
|
29
|
-
test('should not match wildcard for different type', () => {
|
|
30
|
-
expect(verifyAccept('video/mp4', 'image/*')).toBe(false);
|
|
31
|
-
expect(verifyAccept('audio/mp3', 'video/*')).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
describe('multiple accept types', () => {
|
|
35
|
-
test('should match any of multiple exact types', () => {
|
|
36
|
-
expect(verifyAccept('image/png', 'image/png,image/jpeg')).toBe(true);
|
|
37
|
-
expect(verifyAccept('image/jpeg', 'image/png,image/jpeg')).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
test('should match with mixed exact and wildcard', () => {
|
|
40
|
-
expect(verifyAccept('image/png', 'audio/*,video/*,image/png')).toBe(true);
|
|
41
|
-
expect(verifyAccept('audio/mp3', 'audio/*,video/*,image/png')).toBe(true);
|
|
42
|
-
expect(verifyAccept('video/mp4', 'audio/*,video/*,image/png')).toBe(true);
|
|
43
|
-
});
|
|
44
|
-
test('should return false when no match in multiple types', () => {
|
|
45
|
-
expect(verifyAccept('application/pdf', 'image/*,video/*')).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
describe('whitespace handling', () => {
|
|
49
|
-
test('should handle spaces after commas', () => {
|
|
50
|
-
expect(verifyAccept('image/png', 'image/png, image/jpeg')).toBe(true);
|
|
51
|
-
expect(verifyAccept('image/jpeg', 'image/png, image/jpeg')).toBe(true);
|
|
52
|
-
});
|
|
53
|
-
test('should handle multiple spaces', () => {
|
|
54
|
-
expect(verifyAccept('image/png', 'image/png, image/jpeg, video/*')).toBe(true);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
describe('edge cases', () => {
|
|
58
|
-
test('should handle application types', () => {
|
|
59
|
-
expect(verifyAccept('application/json', 'application/*')).toBe(true);
|
|
60
|
-
expect(verifyAccept('application/xml', 'application/*')).toBe(true);
|
|
61
|
-
});
|
|
62
|
-
test('should handle text types', () => {
|
|
63
|
-
expect(verifyAccept('text/plain', 'text/*')).toBe(true);
|
|
64
|
-
expect(verifyAccept('text/html', 'text/*')).toBe(true);
|
|
65
|
-
});
|
|
66
|
-
test('should handle single accept value', () => {
|
|
67
|
-
expect(verifyAccept('image/png', 'image/png')).toBe(true);
|
|
68
|
-
expect(verifyAccept('image/png', 'image/*')).toBe(true);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|