cronli5 0.2.0 → 0.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/dist/lang/es.cjs CHANGED
@@ -95,6 +95,48 @@ function orderWeekdaysForDisplay(segments) {
95
95
  function toFieldNumber(token, numberMap) {
96
96
  return isNonNegativeInteger(token) ? +token : numberMap[token.toUpperCase()];
97
97
  }
98
+ function segmentsOf(ir, field) {
99
+ return ir.analyses.segments[field] ?? [];
100
+ }
101
+ function stepSegment(ir, field) {
102
+ return segmentsOf(ir, field)[0];
103
+ }
104
+ function singleValues(segments) {
105
+ const values = [];
106
+ for (const segment of segments) {
107
+ if (segment.kind !== "single") {
108
+ return null;
109
+ }
110
+ values.push(+segment.value);
111
+ }
112
+ return values;
113
+ }
114
+ function offsetCleanStride(stride) {
115
+ return stride.start < stride.interval && 24 % stride.interval === 0;
116
+ }
117
+ function hourListStride(values) {
118
+ if (values.length < 2) {
119
+ return null;
120
+ }
121
+ const interval = values[1] - values[0];
122
+ if (interval < 2) {
123
+ return null;
124
+ }
125
+ for (let i = 2; i < values.length; i += 1) {
126
+ if (values[i] - values[i - 1] !== interval) {
127
+ return null;
128
+ }
129
+ }
130
+ if (values[0] !== 0 && values.length < 5) {
131
+ return null;
132
+ }
133
+ return { interval, last: values[values.length - 1], start: values[0] };
134
+ }
135
+
136
+ // src/core/shapes.ts
137
+ function isOpenStep(field) {
138
+ return field.indexOf("/") !== -1 && field.indexOf("-") === -1 && field.indexOf(",") === -1;
139
+ }
98
140
 
99
141
  // src/lang/es/dialects.ts
100
142
  var es = {
@@ -121,15 +163,6 @@ function resolveDialect(dialect) {
121
163
  }
122
164
 
123
165
  // src/lang/es/index.ts
124
- function stepSegment(segments) {
125
- return segments[0];
126
- }
127
- function hourSegments(ir) {
128
- return ir.analyses.segments.hour;
129
- }
130
- function fieldSegments(ir, field) {
131
- return ir.analyses.segments[field];
132
- }
133
166
  var numeros = [
134
167
  "cero",
135
168
  "uno",
@@ -215,8 +248,8 @@ function secondsListAtClock(ir, rest, opts) {
215
248
  });
216
249
  const grouped = groupClockTimesByArticle(clockPhrases);
217
250
  const clockList = grouped.startsWith("a ") ? grouped.slice(2) : grouped;
218
- const stride = strideFromSegments(fieldSegments(ir, "second"), "segundo", "", opts);
219
- const secondsPhrase = stride ?? "en los segundos " + joinList(segmentWords(fieldSegments(ir, "second")));
251
+ const stride = strideFromSegments(segmentsOf(ir, "second"), "segundo", "", opts);
252
+ const secondsPhrase = stride ?? "en los segundos " + joinList(segmentWords(segmentsOf(ir, "second")));
220
253
  const dayFrame = trailingQualifier(ir, opts);
221
254
  return (dayFrame ? dayFrame.trimStart() + ", " : "") + secondsPhrase + " de " + clockList;
222
255
  }
@@ -246,7 +279,7 @@ function renderComposeSeconds(ir, plan, opts) {
246
279
  const restNode = plan.rest;
247
280
  const window = hourWindow(boundedWindow(restNode), opts);
248
281
  const dayFrame = weekdayQualifier(ir) + monthScope(ir);
249
- const cadence = "cada " + numero(stepSegment(ir.analyses.segments.second).interval, opts) + " segundos del minuto " + ir.pattern.minute;
282
+ const cadence = "cada " + numero(stepSegment(ir, "second").interval, opts) + " segundos del minuto " + ir.pattern.minute;
250
283
  return dayFrame + ", " + window + ", " + cadence;
251
284
  }
252
285
  if (isEveryOtherMinuteSeconds(ir, plan)) {
@@ -260,7 +293,7 @@ function isEveryOtherMinuteSeconds(ir, plan) {
260
293
  if (plan.rest.kind !== "minuteFrequency" || ir.shapes.second !== "wildcard" || ir.shapes.hour !== "wildcard") {
261
294
  return false;
262
295
  }
263
- const minuteStep = stepSegment(ir.analyses.segments.minute);
296
+ const minuteStep = stepSegment(ir, "minute");
264
297
  return minuteStep.startToken === "*" && minuteStep.interval === 2;
265
298
  }
266
299
  function pinnedMinuteSeconds(ir, rest, opts) {
@@ -282,7 +315,7 @@ function secondsClause(ir, anchor, opts) {
282
315
  }
283
316
  if (shape === "step") {
284
317
  return stepCycle60(
285
- stepSegment(ir.analyses.segments.second),
318
+ stepSegment(ir, "second"),
286
319
  "segundo",
287
320
  anchor,
288
321
  opts
@@ -296,11 +329,11 @@ function secondsClause(ir, anchor, opts) {
296
329
  return "en el segundo " + secondField + " de cada " + anchor;
297
330
  }
298
331
  return strideFromSegments(
299
- fieldSegments(ir, "second"),
332
+ segmentsOf(ir, "second"),
300
333
  "segundo",
301
334
  anchor,
302
335
  opts
303
- ) ?? "en los segundos " + joinList(segmentWords(fieldSegments(ir, "second"))) + " de cada " + anchor;
336
+ ) ?? "en los segundos " + joinList(segmentWords(segmentsOf(ir, "second"))) + " de cada " + anchor;
304
337
  }
305
338
  function renderEveryMinute(ir, plan, opts) {
306
339
  return "cada minuto" + trailingQualifier(ir, opts);
@@ -316,11 +349,11 @@ function renderMultipleMinutes(ir, plan, opts) {
316
349
  }
317
350
  function minutesList(ir, opts) {
318
351
  return strideFromSegments(
319
- fieldSegments(ir, "minute"),
352
+ segmentsOf(ir, "minute"),
320
353
  "minuto",
321
354
  "hora",
322
355
  opts
323
- ) ?? "en los minutos " + joinList(segmentWords(fieldSegments(ir, "minute"))) + " de cada hora";
356
+ ) ?? "en los minutos " + joinList(segmentWords(segmentsOf(ir, "minute"))) + " de cada hora";
324
357
  }
325
358
  function minuteRangeLead(minuteField) {
326
359
  const bounds = minuteField.split("-");
@@ -377,7 +410,7 @@ function spanHours(hours) {
377
410
  }
378
411
  function renderMinuteFrequency(ir, plan, opts) {
379
412
  let phrase = stepCycle60(
380
- stepSegment(ir.analyses.segments.minute),
413
+ stepSegment(ir, "minute"),
381
414
  "minuto",
382
415
  "hora",
383
416
  opts
@@ -387,12 +420,12 @@ function renderMinuteFrequency(ir, plan, opts) {
387
420
  if (cadence) {
388
421
  phrase += ", " + cadence;
389
422
  } else {
390
- phrase += singleHourStep(ir.analyses.segments.hour) ? ", " + stepHourSpan(stepSegment(ir.analyses.segments.hour), opts) : " " + hourSpanFromTimes(ir, plan.hours.times, opts);
423
+ phrase += singleHourStep(ir.analyses.segments.hour) ? ", " + stepHourSpan(stepSegment(ir, "hour"), opts) : " " + hourSpanFromTimes(ir, plan.hours.times, opts);
391
424
  }
392
425
  } else if (plan.hours.kind === "window") {
393
426
  phrase += " " + hourWindow(plan.hours, opts);
394
427
  } else if (plan.hours.kind === "step") {
395
- phrase += ", " + stepHourSpan(stepSegment(ir.analyses.segments.hour), opts);
428
+ phrase += ", " + stepHourSpan(stepSegment(ir, "hour"), opts);
396
429
  }
397
430
  return phrase + trailingQualifier(ir, opts);
398
431
  }
@@ -413,7 +446,7 @@ function renderMinutesAcrossHours(ir, plan, opts) {
413
446
  return "cada minuto, " + cadence + trailingQualifier(ir, opts);
414
447
  }
415
448
  if (singleHourStep(ir.analyses.segments.hour)) {
416
- return "cada minuto, " + stepHourSpan(stepSegment(ir.analyses.segments.hour), opts) + trailingQualifier(ir, opts);
449
+ return "cada minuto, " + stepHourSpan(stepSegment(ir, "hour"), opts) + trailingQualifier(ir, opts);
417
450
  }
418
451
  return "cada minuto " + hourSpanFromTimes(ir, plan.times, opts) + trailingQualifier(ir, opts);
419
452
  }
@@ -424,7 +457,7 @@ function renderMinutesAcrossHours(ir, plan, opts) {
424
457
  return lead + ", " + atHourTimes(ir, plan.times, opts) + trailingQualifier(ir, opts);
425
458
  }
426
459
  function renderMinuteSpanAcrossHourStep(ir, plan, opts) {
427
- const segment = stepSegment(ir.analyses.segments.hour);
460
+ const segment = stepSegment(ir, "hour");
428
461
  const cadence = unevenHourCadence(ir, opts);
429
462
  if (plan.form === "wildcard") {
430
463
  return "cada minuto, " + stepHourSpan(segment, opts) + trailingQualifier(ir, opts);
@@ -454,7 +487,7 @@ function renderHourStep(ir, plan, opts) {
454
487
  if (cadence !== null) {
455
488
  return cadence + trailingQualifier(ir, opts);
456
489
  }
457
- return stepHours(stepSegment(ir.analyses.segments.hour), opts) + trailingQualifier(ir, opts);
490
+ return stepHours(stepSegment(ir, "hour"), opts) + trailingQualifier(ir, opts);
458
491
  }
459
492
  function boundedWindow(plan) {
460
493
  const last = plan.minuteForm === "wildcard" ? plan.boundMinute ?? 0 : 0;
@@ -475,7 +508,7 @@ function unionMonthLeadFull(ir) {
475
508
  return "";
476
509
  }
477
510
  const lead = monthPhrase(ir, monthRanged(ir) ? "de " : "en ");
478
- const segments = flattenSteps(fieldSegments(ir, "month"));
511
+ const segments = flattenSteps(segmentsOf(ir, "month"));
479
512
  const isEnumeration = !monthRanged(ir) && segments.length >= 2;
480
513
  return isEnumeration ? lead + "," : lead;
481
514
  }
@@ -488,7 +521,7 @@ function domArm(ir, opts) {
488
521
  if (isOpenStep(date)) {
489
522
  return stepDates(date, opts);
490
523
  }
491
- const segments = fieldSegments(ir, "date");
524
+ const segments = segmentsOf(ir, "date");
492
525
  if (segments.length === 1 && segments[0].kind === "range") {
493
526
  return "del " + segments[0].bounds[0] + " al " + segments[0].bounds[1] + " del mes";
494
527
  }
@@ -502,7 +535,7 @@ function dowArm(ir) {
502
535
  if (quartz) {
503
536
  return quartz;
504
537
  }
505
- const segments = orderWeekdaysForDisplay(fieldSegments(ir, "weekday"));
538
+ const segments = orderWeekdaysForDisplay(segmentsOf(ir, "weekday"));
506
539
  const allSingles = segments.every(function single(segment) {
507
540
  return segment.kind === "single";
508
541
  });
@@ -717,7 +750,7 @@ function renderCompactClockTimes(ir, plan, opts) {
717
750
  if (cadence2 !== null) {
718
751
  return cadence2;
719
752
  }
720
- const ranged = hourSegments(ir).some(function range(segment) {
753
+ const ranged = segmentsOf(ir, "hour").some(function range(segment) {
721
754
  return segment.kind === "range";
722
755
  });
723
756
  if (ranged && !ir.analyses.clockSecond) {
@@ -784,16 +817,6 @@ function strideFromSegments(segments, unit, anchor, opts) {
784
817
  const step = values && arithmeticStep(values);
785
818
  return step ? renderStride({ ...step, cycle: 60, unit, anchor }, opts) : null;
786
819
  }
787
- function singleValues(segments) {
788
- const values = [];
789
- for (const segment of segments) {
790
- if (segment.kind !== "single") {
791
- return null;
792
- }
793
- values.push(+segment.value);
794
- }
795
- return values;
796
- }
797
820
  function stepHours(segment, opts) {
798
821
  if (segment.startToken.indexOf("-") !== -1) {
799
822
  return groupClockTimesByArticle(atTimes(segment.fires, opts));
@@ -820,9 +843,6 @@ function hourStrideCadence(stride, opts) {
820
843
  }
821
844
  return cadence + " de " + timePhrase(start, 0, null, opts) + " a " + timePhrase(last, 0, null, opts);
822
845
  }
823
- function offsetCleanStride(stride) {
824
- return stride.start < stride.interval && 24 % stride.interval === 0;
825
- }
826
846
  function unevenHourCadence(ir, opts) {
827
847
  const stride = hourStride(ir);
828
848
  if (!stride || offsetCleanStride(stride)) {
@@ -830,26 +850,8 @@ function unevenHourCadence(ir, opts) {
830
850
  }
831
851
  return hourStrideCadence(stride, opts);
832
852
  }
833
- function hourListStride(values) {
834
- if (values.length < 2) {
835
- return null;
836
- }
837
- const interval = values[1] - values[0];
838
- if (interval < 2) {
839
- return null;
840
- }
841
- for (let i = 2; i < values.length; i += 1) {
842
- if (values[i] - values[i - 1] !== interval) {
843
- return null;
844
- }
845
- }
846
- if (values[0] !== 0 && values.length < 5) {
847
- return null;
848
- }
849
- return { interval, last: values[values.length - 1], start: values[0] };
850
- }
851
853
  function hourStride(ir) {
852
- const segments = fieldSegments(ir, "hour");
854
+ const segments = segmentsOf(ir, "hour");
853
855
  if (segments.length === 1 && segments[0].kind === "step") {
854
856
  const segment = segments[0];
855
857
  if (segment.fires.length < 2) {
@@ -896,7 +898,7 @@ function hourCadence(ir, minute, opts) {
896
898
  return hourCadenceLead(ir, minute, opts) + ", " + hourStrideCadence(stride, opts) + trailingQualifier(ir, opts);
897
899
  }
898
900
  function cleanStrideSegment(ir) {
899
- const segments = fieldSegments(ir, "hour");
901
+ const segments = segmentsOf(ir, "hour");
900
902
  const segment = segments.length === 1 && segments[0];
901
903
  if (!segment || segment.kind !== "step" || segment.startToken.indexOf("-") !== -1) {
902
904
  return null;
@@ -904,7 +906,7 @@ function cleanStrideSegment(ir) {
904
906
  return segment;
905
907
  }
906
908
  function hasHourWindow(ir) {
907
- return hourSegments(ir).some(function range(segment) {
909
+ return segmentsOf(ir, "hour").some(function range(segment) {
908
910
  return segment.kind === "range";
909
911
  });
910
912
  }
@@ -918,7 +920,7 @@ function hourRangeCadence(ir, minute, opts) {
918
920
  return hourCadenceLead(ir, minute, opts) + ", " + hourSegmentTimes(ir, 0, null, opts) + trailingQualifier(ir, opts);
919
921
  }
920
922
  function hourContextTimes(ir, opts) {
921
- const segments = hourSegments(ir);
923
+ const segments = segmentsOf(ir, "hour");
922
924
  const points = [];
923
925
  const hasRange = segments.some(function range(segment) {
924
926
  return segment.kind === "range";
@@ -982,7 +984,7 @@ function hourWindowsFromTimes(ir, times, opts) {
982
984
  return hourAsWindow(hour, opts);
983
985
  }));
984
986
  }
985
- return joinList(hourSegments(ir).map(function window(segment) {
987
+ return joinList(segmentsOf(ir, "hour").map(function window(segment) {
986
988
  if (segment.kind === "range") {
987
989
  return timeRange(
988
990
  { hour: +segment.bounds[0], minute: 0 },
@@ -1001,7 +1003,7 @@ function hourWindowsFromTimes(ir, times, opts) {
1001
1003
  function hourSegmentTimes(ir, minute, second, opts) {
1002
1004
  const pieces = [];
1003
1005
  const fromRange = [];
1004
- hourSegments(ir).forEach(function clock(segment) {
1006
+ segmentsOf(ir, "hour").forEach(function clock(segment) {
1005
1007
  if (segment.kind === "step") {
1006
1008
  segment.fires.forEach(function each(hour) {
1007
1009
  pieces.push(atTime(timePhrase(hour, minute, second, opts)));
@@ -1161,7 +1163,7 @@ function dateClause(ir, monthPart, opts) {
1161
1163
  if (isOpenStep(pattern.date)) {
1162
1164
  return stepDates(pattern.date, opts);
1163
1165
  }
1164
- const segments = fieldSegments(ir, "date");
1166
+ const segments = segmentsOf(ir, "date");
1165
1167
  if (segments.length === 1 && segments[0].kind === "range") {
1166
1168
  return "del " + segments[0].bounds[0] + " al " + segments[0].bounds[1] + monthPart + foldedYear(ir);
1167
1169
  }
@@ -1171,7 +1173,7 @@ function dateClause(ir, monthPart, opts) {
1171
1173
  return "los d\xEDas " + joinList(segmentWords(segments)) + monthPart + foldedYear(ir);
1172
1174
  }
1173
1175
  function monthRanged(ir) {
1174
- return ir.pattern.month !== "*" && fieldSegments(ir, "month").some(function range(segment) {
1176
+ return ir.pattern.month !== "*" && segmentsOf(ir, "month").some(function range(segment) {
1175
1177
  return segment.kind === "range";
1176
1178
  });
1177
1179
  }
@@ -1221,7 +1223,7 @@ function weekdayQualifier(ir) {
1221
1223
  if (quartz) {
1222
1224
  return quartz;
1223
1225
  }
1224
- const segments = orderWeekdaysForDisplay(fieldSegments(ir, "weekday"));
1226
+ const segments = orderWeekdaysForDisplay(segmentsOf(ir, "weekday"));
1225
1227
  const allSingles = segments.every(function single(segment) {
1226
1228
  return segment.kind === "single";
1227
1229
  });
@@ -1248,7 +1250,7 @@ function flattenSteps(segments) {
1248
1250
  });
1249
1251
  }
1250
1252
  function monthPhrase(ir, lead) {
1251
- const segments = flattenSteps(fieldSegments(ir, "month"));
1253
+ const segments = flattenSteps(segmentsOf(ir, "month"));
1252
1254
  const ranged = segments.some(function range(segment) {
1253
1255
  return segment.kind === "range";
1254
1256
  });
@@ -1345,9 +1347,6 @@ function pluralWeekday(token) {
1345
1347
  function monthName(token) {
1346
1348
  return monthNames[+token];
1347
1349
  }
1348
- function isOpenStep(field) {
1349
- return field.indexOf("/") !== -1 && field.indexOf("-") === -1 && field.indexOf(",") === -1;
1350
- }
1351
1350
  var es2 = {
1352
1351
  describe,
1353
1352
  fallback: "un patr\xF3n cron irreconocible",