Skip to content

Commit 6a1b0a5

Browse files
authored
feat: rename *.parse methods to *.fromString (#635)
1 parent b989dba commit 6a1b0a5

File tree

4 files changed

+42
-35
lines changed

4 files changed

+42
-35
lines changed

src/rrule-set.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ export class RRuleSet<
213213
* const str = `DTSTART:20240115T090000
214214
* RRULE:FREQ=WEEKLY;BYDAY=MO
215215
* EXDATE:20240101,20241225`;
216-
* const rruleSet = RRuleSet.parse(str);
216+
* const rruleSet = RRuleSet.fromString(str);
217217
* ```
218218
*/
219-
public static parse<DT extends DateTime<Time> | DateTime<undefined>>(
219+
public static fromString<DT extends DateTime<Time> | DateTime<undefined>>(
220220
str: string,
221221
): RRuleSet<DT> {
222222
return this.fromRust(Rust.parse(str));

src/rrule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ export class RRule<
256256
*
257257
* @example
258258
* ```typescript
259-
* const rrule = RRule.parse("FREQ=WEEKLY;BYDAY=MO,WE,FR;COUNT=10");
259+
* const rrule = RRule.fromString("FREQ=WEEKLY;BYDAY=MO,WE,FR;COUNT=10");
260260
* ```
261261
*/
262-
public static parse<DT extends DateTime<Time> | DateTime<undefined>>(
262+
public static fromString<DT extends DateTime<Time> | DateTime<undefined>>(
263263
str: string,
264264
): RRule<DT> {
265265
const rust = Rust.parse(str);

tests/unit/serialization/rrule_set.spec.ts renamed to tests/unit/serialization/rrule-set.spec.ts

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ describe(RRuleSet, () => {
1212
describe('EXDATE', () => {
1313
it('should throw when exdate datetimes value type do not match', () => {
1414
const act = () =>
15-
RRuleSet.parse('DTSTART:19970902\nEXDATE:20250101,20250102T000000Z');
15+
RRuleSet.fromString(
16+
'DTSTART:19970902\nEXDATE:20250101,20250102T000000Z',
17+
);
1618

1719
expect(act).toThrow(
1820
'All EXDATE instances must have the same value type as specified in EXDATE',
@@ -21,7 +23,7 @@ describe(RRuleSet, () => {
2123

2224
it('should throw when exdate value type and datetimes do not match', () => {
2325
const act = () =>
24-
RRuleSet.parse(
26+
RRuleSet.fromString(
2527
'DTSTART:19970902\nEXDATE;VALUE=DATE:20250101,20250102T000000Z',
2628
);
2729

@@ -32,7 +34,7 @@ describe(RRuleSet, () => {
3234

3335
it('should throw when dtsart value type and exdate value type do not match', () => {
3436
const act = () =>
35-
RRuleSet.parse(
37+
RRuleSet.fromString(
3638
'DTSTART:19970902T090000Z\nEXDATE;VALUE=DATE:20250101,20250102',
3739
);
3840

@@ -45,7 +47,9 @@ describe(RRuleSet, () => {
4547
describe('RDATE', () => {
4648
it('should throw when rdate datetimes value type do not match', () => {
4749
const act = () =>
48-
RRuleSet.parse('DTSTART:19970902\nRDATE:20250101,20250102T000000Z');
50+
RRuleSet.fromString(
51+
'DTSTART:19970902\nRDATE:20250101,20250102T000000Z',
52+
);
4953

5054
expect(act).toThrow(
5155
'All RDATE instances must have the same value type as specified in RDATE',
@@ -54,7 +58,7 @@ describe(RRuleSet, () => {
5458

5559
it('should throw when rdate value type and datetimes do not match', () => {
5660
const act = () =>
57-
RRuleSet.parse(
61+
RRuleSet.fromString(
5862
'DTSTART:19970902\nRDATE;VALUE=DATE:20250101,20250102T000000Z',
5963
);
6064

@@ -65,7 +69,7 @@ describe(RRuleSet, () => {
6569

6670
it('should throw when dtsart value type and rdate value type do not match', () => {
6771
const act = () =>
68-
RRuleSet.parse(
72+
RRuleSet.fromString(
6973
'DTSTART:19970902T090000Z\nRDATE;VALUE=DATE:20250101,20250102',
7074
);
7175

@@ -75,7 +79,7 @@ describe(RRuleSet, () => {
7579

7680
it('should throw when dtstart is datetime, but value type is date', () => {
7781
const act = () =>
78-
RRuleSet.parse(
82+
RRuleSet.fromString(
7983
'DTSTART;VALUE=DATE:19970902T090000Z\nRRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;BYDAY=MO,WE,FR',
8084
);
8185

@@ -84,15 +88,15 @@ describe(RRuleSet, () => {
8488

8589
it('should throw when dtstart is date, but value type is datetime', () => {
8690
const act = () =>
87-
RRuleSet.parse(
91+
RRuleSet.fromString(
8892
'DTSTART;VALUE=DATE-TIME:19970902\nRRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;BYDAY=MO,WE,FR',
8993
);
9094

9195
expect(act).toThrow('DTSTART value and value type do not match');
9296
});
9397

9498
it('should properly parse recurrence with date-only dtstart', () => {
95-
const set = RRuleSet.parse(
99+
const set = RRuleSet.fromString(
96100
'DTSTART:19970902\nRRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,WE,FR',
97101
);
98102

@@ -102,7 +106,7 @@ describe(RRuleSet, () => {
102106
});
103107

104108
it('should properly parse recurrence with date-only dtstart value and value type', () => {
105-
const set = RRuleSet.parse(
109+
const set = RRuleSet.fromString(
106110
'DTSTART;VALUE=DATE:19970902\nRRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,WE,FR',
107111
);
108112

@@ -112,7 +116,7 @@ describe(RRuleSet, () => {
112116
});
113117

114118
it('should properly parse recurrence with date-time dtstart value and value type', () => {
115-
const set = RRuleSet.parse(
119+
const set = RRuleSet.fromString(
116120
'DTSTART;VALUE=DATE-TIME:19970902T090000Z\nRRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;BYDAY=MO,WE,FR',
117121
);
118122

@@ -122,7 +126,7 @@ describe(RRuleSet, () => {
122126
});
123127

124128
it('should properly parse weekly recurrence', () => {
125-
const set = RRuleSet.parse(
129+
const set = RRuleSet.fromString(
126130
'DTSTART;TZID=US/Eastern:19970902T090000\nRRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR',
127131
);
128132

@@ -132,7 +136,7 @@ describe(RRuleSet, () => {
132136
});
133137

134138
it('should properly parse weekly recurrence', () => {
135-
const set = RRuleSet.parse(
139+
const set = RRuleSet.fromString(
136140
'DTSTART;TZID=US/Eastern:19970902T090000\nRRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR',
137141
);
138142

@@ -142,7 +146,7 @@ describe(RRuleSet, () => {
142146
});
143147

144148
it('should properly parse monthly recurrence', () => {
145-
const set = RRuleSet.parse(
149+
const set = RRuleSet.fromString(
146150
'DTSTART;TZID=US/Eastern:19970907T090000\nRRULE:FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU',
147151
);
148152

@@ -152,33 +156,36 @@ describe(RRuleSet, () => {
152156
});
153157

154158
it('should throw error on missing start date', () => {
155-
const act = () => RRuleSet.parse('FREQ=monthly;COUNT=10;INTERVAL=2');
159+
const act = () => RRuleSet.fromString('FREQ=monthly;COUNT=10;INTERVAL=2');
156160

157161
expect(act).toThrow('Invalid property: FREQ=monthly;COUNT=10;INTERVAL=2');
158162
});
159163

160164
it('should throw error on invalid rule set', () => {
161-
const act = () => RRuleSet.parse('Invalid');
165+
const act = () => RRuleSet.fromString('Invalid');
162166

163167
expect(act).toThrow('Invalid property: Invalid');
164168
});
165169

166170
it('should throw error on invalid timezone', () => {
167-
const act = () => RRuleSet.parse('DTSTART;TZID=Invalid:19970907T090000');
171+
const act = () =>
172+
RRuleSet.fromString('DTSTART;TZID=Invalid:19970907T090000');
168173

169174
expect(act).toThrow('Invalid timezone: Invalid');
170175
});
171176

172177
it('should throw error on invalid recurrence rule', () => {
173178
const act = () =>
174-
RRuleSet.parse('DTSTART;TZID=US/Eastern:19970907T090000\nRRULE:Invalid');
179+
RRuleSet.fromString(
180+
'DTSTART;TZID=US/Eastern:19970907T090000\nRRULE:Invalid',
181+
);
175182

176183
expect(act).toThrow('Invalid RRULE: Invalid');
177184
});
178185

179186
it('should throw error on invalid frequency', () => {
180187
const act = () =>
181-
RRuleSet.parse(
188+
RRuleSet.fromString(
182189
'DTSTART;TZID=US/Eastern:19970907T090000\nRRULE:FREQ=Invalid',
183190
);
184191

@@ -187,7 +194,7 @@ describe(RRuleSet, () => {
187194

188195
it('should throw error on invalid interval', () => {
189196
const act = () =>
190-
RRuleSet.parse(
197+
RRuleSet.fromString(
191198
'DTSTART;TZID=US/Eastern:19970907T090000\nRRULE:FREQ=DAILY;INTERVAL=Invalid',
192199
);
193200

@@ -196,7 +203,7 @@ describe(RRuleSet, () => {
196203

197204
it('should throw error on invalid count', () => {
198205
const act = () =>
199-
RRuleSet.parse(
206+
RRuleSet.fromString(
200207
'DTSTART;TZID=US/Eastern:19970907T090000\nRRULE:FREQ=DAILY;COUNT=Invalid',
201208
);
202209

@@ -205,7 +212,7 @@ describe(RRuleSet, () => {
205212

206213
it('should throw error on invalid until', () => {
207214
const act = () =>
208-
RRuleSet.parse(
215+
RRuleSet.fromString(
209216
'DTSTART;TZID=US/Eastern:19970907T090000\nRRULE:FREQ=DAILY;UNTIL=Invalid',
210217
);
211218

@@ -214,7 +221,7 @@ describe(RRuleSet, () => {
214221

215222
it('should throw error on invalid week start', () => {
216223
const act = () =>
217-
RRuleSet.parse(
224+
RRuleSet.fromString(
218225
'DTSTART;TZID=US/Eastern:19970907T090000\nRRULE:FREQ=DAILY;WKST=Invalid',
219226
);
220227

@@ -314,7 +321,7 @@ describe(RRuleSet, () => {
314321
])(
315322
'should parse exdate property when dtstart is $dtstart and exdate is $exdate',
316323
({ dtstart, exdate, expected }) => {
317-
const set = RRuleSet.parse(
324+
const set = RRuleSet.fromString(
318325
`${dtstart}\n${exdate}\nRRULE:FREQ=WEEKLY;UNTIL=20190208T045959Z;INTERVAL=2;BYDAY=FR`,
319326
);
320327

@@ -372,7 +379,7 @@ describe(RRuleSet, () => {
372379
])(
373380
'should parse rdate property when dtstart is $dtstart and rdate is $rdate',
374381
({ dtstart, rdate, expected }) => {
375-
const set = RRuleSet.parse(
382+
const set = RRuleSet.fromString(
376383
`${dtstart}\n${rdate}\nRRULE:FREQ=WEEKLY;UNTIL=20190208T045959Z;INTERVAL=2;BYDAY=FR`,
377384
);
378385

tests/unit/serialization/rrule.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe(RRule, () => {
3434
},
3535
},
3636
])('should properly parse $input', ({ input, expected }) => {
37-
const rule = RRule.parse(input);
37+
const rule = RRule.fromString(input);
3838

3939
expect(rule.frequency).toBe(expected.frequency);
4040
expect(rule.interval).toBe(expected.interval);
@@ -45,31 +45,31 @@ describe(RRule, () => {
4545
});
4646

4747
it('should throw error on invalid individual recurrence rule', () => {
48-
const act = () => RRule.parse('Invalid');
48+
const act = () => RRule.fromString('Invalid');
4949

5050
expect(act).toThrowError('Invalid RRULE: Invalid');
5151
});
5252

5353
it('should throw error on invalid individual recurrence rule frequency', () => {
54-
const act = () => RRule.parse('FREQ=Invalid');
54+
const act = () => RRule.fromString('FREQ=Invalid');
5555

5656
expect(act).toThrow('Invalid FREQ value: Invalid');
5757
});
5858

5959
it('should throw error on invalid individual recurrence rule interval', () => {
60-
const act = () => RRule.parse('FREQ=DAILY;INTERVAL=Invalid');
60+
const act = () => RRule.fromString('FREQ=DAILY;INTERVAL=Invalid');
6161

6262
expect(act).toThrow('Invalid INTERVAL value: Invalid');
6363
});
6464

6565
it('should throw error on invalid individual recurrence rule until', () => {
66-
const act = () => RRule.parse('FREQ=DAILY;UNTIL=Invalid');
66+
const act = () => RRule.fromString('FREQ=DAILY;UNTIL=Invalid');
6767

6868
expect(act).toThrow('Invalid UNTIL value: Invalid');
6969
});
7070

7171
it('should throw error on invalid individual recurrence rule week start', () => {
72-
const act = () => RRule.parse('FREQ=DAILY;WKST=Invalid');
72+
const act = () => RRule.fromString('FREQ=DAILY;WKST=Invalid');
7373

7474
expect(act).toThrow('Invalid WKST value: Invalid');
7575
});

0 commit comments

Comments
 (0)