utils.d.ts.map 2.8 KB

1
  1. {"version":3,"sources":["../src/count-down/utils.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;CACtB;AAOD,eAAO,MAAM,aAAa,SAAmB,MAAM,KAAG,QAarD,CAAC;AAEF,eAAO,MAAM,YAAY,UAAoB,MAAM,SAAS,MAAM,KAAG,OAEpE,CAAC;AAEF,oBAAY,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC;AAEzE;;;;GAIG;AACH,eAAO,MAAM,WAAW,SAAmB,MAAM,UAAU,MAAM;;;CAiChE,CAAC","file":"utils.d.ts","sourcesContent":["export interface TimeData {\n days: number;\n hours: number;\n minutes: number;\n seconds: number;\n milliseconds: number;\n}\n\nconst SECOND = 1000;\nconst MINUTE = 60 * SECOND;\nconst HOUR = 60 * MINUTE;\nconst DAY = 24 * HOUR;\n\nexport const parseTimeData = function (time: number): TimeData {\n const days = Math.floor(time / DAY);\n const hours = Math.floor((time % DAY) / HOUR);\n const minutes = Math.floor((time % HOUR) / MINUTE);\n const seconds = Math.floor((time % MINUTE) / SECOND);\n const milliseconds = Math.floor(time % SECOND);\n return {\n days,\n hours,\n minutes,\n seconds,\n milliseconds,\n };\n};\n\nexport const isSameSecond = function (time1: number, time2: number): boolean {\n return Math.floor(time1 / 1000) === Math.floor(time2 / 1000);\n};\n\nexport type TTimeList = { digit: string; unit: string; match: string }[];\n\n/**\n *\n * @param time 倒计时时间,毫秒单位\n * @param format 倒计时格式化字符串,例如:dd天hh小时mm分ss秒SSS毫秒,hh:mm:ss.SSS,hh:mm:ss\n */\nexport const parseFormat = function (time: number, format: string) {\n const obj = {\n 'D+': Math.floor(time / 86400000), // 日\n 'H+': Math.floor((time % 86400000) / 3600000), // 小时\n 'm+': Math.floor((time % 3600000) / 60000), // 分\n 's+': Math.floor((time % 60000) / 1000), // 秒\n 'S+': Math.floor(time % 1000), // 毫秒\n };\n const timeList: TTimeList = [];\n let timeText = format;\n\n Object.keys(obj).forEach((prop) => {\n if (new RegExp(`(${prop})`).test(timeText)) {\n timeText = timeText.replace(RegExp.$1, (match, offset, source) => {\n const v = `${(obj as any)[prop]}`;\n let digit = v;\n if (match.length > 1) {\n digit = (match.replace(new RegExp(match[0], 'g'), '0') + v).substr(v.length);\n }\n const unit = source.substr(offset + match.length);\n const last = timeList[timeList.length - 1];\n if (last) {\n const index = last.unit.indexOf(match);\n if (index !== -1) {\n last.unit = last.unit.substr(0, index);\n }\n }\n timeList.push({ digit, unit, match });\n return digit;\n });\n }\n });\n return { timeText, timeList };\n};\n"]}