cafe-utility 22.1.0 → 22.2.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.
Files changed (3) hide show
  1. package/index.d.ts +2 -0
  2. package/index.js +9 -1
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -248,6 +248,7 @@ declare function dateTimeSlug(optionalDate?: Date): string;
248
248
  declare function fromUtcString(string: string): Date;
249
249
  declare function fromMillis(millis: number): Date;
250
250
  declare function createTimeDigits(value: number): string;
251
+ declare function normalizeTime(time: string): string;
251
252
  declare function humanizeTime(millis: number): string;
252
253
  interface TimestampLabels {
253
254
  today: (hour: number, minute: number, pm: boolean) => string;
@@ -644,6 +645,7 @@ export declare const Dates: {
644
645
  minutes: typeof minutes;
645
646
  hours: typeof hours;
646
647
  make: typeof makeDate;
648
+ normalizeTime: typeof normalizeTime;
647
649
  };
648
650
  export declare const Objects: {
649
651
  safeParse: typeof safeParse;
package/index.js CHANGED
@@ -1300,6 +1300,13 @@ function fromMillis(n) {
1300
1300
  function createTimeDigits(n) {
1301
1301
  return String(Math.floor(n)).padStart(2, '0')
1302
1302
  }
1303
+ function normalizeTime(n) {
1304
+ let [t, e] = n.split(':')
1305
+ isNumber(parseInt(t, 10)) || (t = '0'), isNumber(parseInt(e, 10)) || (e = '0')
1306
+ let r = clamp(asInteger(t), 0, 23),
1307
+ o = clamp(asInteger(e), 0, 59)
1308
+ return `${createTimeDigits(r)}:${createTimeDigits(o)}`
1309
+ }
1303
1310
  function humanizeTime(n) {
1304
1311
  const t = Math.floor(n / 36e5)
1305
1312
  n = n % 36e5
@@ -2442,7 +2449,8 @@ function raycastCircle(n, t, e) {
2442
2449
  seconds,
2443
2450
  minutes,
2444
2451
  hours,
2445
- make: makeDate
2452
+ make: makeDate,
2453
+ normalizeTime
2446
2454
  }),
2447
2455
  (exports.Objects = {
2448
2456
  safeParse,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "22.1.0",
3
+ "version": "22.2.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {