@choksheak/ts-utils 0.3.4 → 0.3.6
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/README.md +9 -3
- package/arrayBuffer.cjs +10 -39
- package/arrayBuffer.min.cjs +1 -1
- package/arrayBuffer.min.cjs.map +1 -1
- package/arrayBuffer.min.mjs +1 -1
- package/arrayBuffer.min.mjs.map +1 -1
- package/arrayBuffer.mjs +7 -10
- package/asNumber.cjs +6 -38
- package/asNumber.d.mts +1 -1
- package/asNumber.d.ts +1 -1
- package/asNumber.min.cjs +1 -1
- package/asNumber.min.cjs.map +1 -1
- package/asNumber.min.mjs +1 -1
- package/asNumber.min.mjs.map +1 -1
- package/asNumber.mjs +4 -11
- package/assert.cjs +4 -27
- package/assert.min.cjs +1 -1
- package/assert.min.cjs.map +1 -1
- package/assert.min.mjs +1 -1
- package/assert.min.mjs.map +1 -1
- package/assert.mjs +2 -0
- package/base64Url.cjs +5 -29
- package/base64Url.min.cjs +1 -1
- package/base64Url.min.cjs.map +1 -1
- package/base64Url.min.mjs +1 -1
- package/base64Url.min.mjs.map +1 -1
- package/base64Url.mjs +2 -0
- package/capLength.cjs +7 -71
- package/capLength.min.cjs +1 -5
- package/capLength.min.cjs.map +1 -1
- package/capLength.min.mjs +1 -5
- package/capLength.min.mjs.map +1 -1
- package/capLength.mjs +4 -41
- package/chunk-22JDWCOS.min.cjs +2 -0
- package/chunk-22JDWCOS.min.cjs.map +1 -0
- package/chunk-244NBT4Q.min.mjs +2 -0
- package/chunk-244NBT4Q.min.mjs.map +1 -0
- package/chunk-27MBP3ES.min.cjs +2 -0
- package/chunk-27MBP3ES.min.cjs.map +1 -0
- package/chunk-34ENP2B3.min.mjs +438 -0
- package/chunk-34ENP2B3.min.mjs.map +1 -0
- package/chunk-3EBQ2GO2.min.cjs +2 -0
- package/chunk-3EBQ2GO2.min.cjs.map +1 -0
- package/chunk-4GLOLTJ5.cjs +167 -0
- package/chunk-6TQBMXTL.min.cjs +2 -0
- package/chunk-6TQBMXTL.min.cjs.map +1 -0
- package/chunk-AWZBCFMG.min.cjs +2 -0
- package/chunk-AWZBCFMG.min.cjs.map +1 -0
- package/chunk-AXNETZET.cjs +20 -0
- package/chunk-BKZM6NWX.min.cjs +2 -0
- package/chunk-BKZM6NWX.min.cjs.map +1 -0
- package/chunk-BZKQXX3A.cjs +40 -0
- package/chunk-CERFUU5I.cjs +93 -0
- package/chunk-CSTKFJ6G.mjs +239 -0
- package/chunk-DUN4UY2Q.cjs +239 -0
- package/chunk-EDJJUP4K.min.cjs +6 -0
- package/chunk-EDJJUP4K.min.cjs.map +1 -0
- package/chunk-FFNQBZH5.cjs +14 -0
- package/chunk-FZZRSHSH.min.mjs +6 -0
- package/chunk-FZZRSHSH.min.mjs.map +1 -0
- package/chunk-GAP2HS5M.min.cjs +2 -0
- package/chunk-GAP2HS5M.min.cjs.map +1 -0
- package/chunk-GLYMAPS4.min.mjs +2 -0
- package/chunk-GLYMAPS4.min.mjs.map +1 -0
- package/chunk-I65KPVMO.min.cjs +438 -0
- package/chunk-I65KPVMO.min.cjs.map +1 -0
- package/chunk-ILGTU46T.cjs +39 -0
- package/chunk-IOKRXHKE.min.mjs +2 -0
- package/chunk-IOKRXHKE.min.mjs.map +1 -0
- package/chunk-ISP4SMRC.min.cjs +2 -0
- package/chunk-ISP4SMRC.min.cjs.map +1 -0
- package/chunk-KETP5HBF.cjs +24 -0
- package/chunk-KLHNGJ4Y.min.mjs +2 -0
- package/chunk-KLHNGJ4Y.min.mjs.map +1 -0
- package/chunk-KMNTU3DJ.mjs +45 -0
- package/chunk-LDVEXETI.cjs +45 -0
- package/chunk-LZENHV35.min.cjs +2 -0
- package/chunk-LZENHV35.min.cjs.map +1 -0
- package/chunk-M5PIM2HB.mjs +42 -0
- package/chunk-M6PYQYOX.mjs +39 -0
- package/chunk-MN5EYNZN.min.mjs +2 -0
- package/chunk-MN5EYNZN.min.mjs.map +1 -0
- package/chunk-NRIBJ2OJ.mjs +16031 -0
- package/chunk-NVLYXWLX.cjs +32 -0
- package/chunk-O352F2MT.mjs +24 -0
- package/chunk-O6B2TKFK.min.mjs +2 -0
- package/chunk-O6B2TKFK.min.mjs.map +1 -0
- package/chunk-OGF34H4T.min.cjs +2 -0
- package/chunk-OGF34H4T.min.cjs.map +1 -0
- package/chunk-OXSWWWOM.min.mjs +2 -0
- package/chunk-OXSWWWOM.min.mjs.map +1 -0
- package/chunk-PRUGHVRT.mjs +14 -0
- package/chunk-Q4WCMSOW.min.mjs +2 -0
- package/chunk-Q4WCMSOW.min.mjs.map +1 -0
- package/chunk-QH74JZCK.mjs +9 -0
- package/chunk-QNNJNLGK.min.cjs +2 -0
- package/chunk-QNNJNLGK.min.cjs.map +1 -0
- package/chunk-QWCFN7ZM.mjs +15 -0
- package/chunk-SDM2OPT6.mjs +32 -0
- package/chunk-SHKRZCF2.cjs +16031 -0
- package/chunk-SJDJDNDN.min.cjs +2 -0
- package/chunk-SJDJDNDN.min.cjs.map +1 -0
- package/chunk-SULNMALN.cjs +328 -0
- package/chunk-SV35RBZ7.min.mjs +2 -0
- package/chunk-SV35RBZ7.min.mjs.map +1 -0
- package/chunk-TJFYGFOW.mjs +328 -0
- package/chunk-UHRYBUUX.min.mjs +2 -0
- package/chunk-UHRYBUUX.min.mjs.map +1 -0
- package/chunk-UOU6IP3S.min.mjs +2 -0
- package/chunk-UOU6IP3S.min.mjs.map +1 -0
- package/chunk-V76XVNZ5.mjs +20 -0
- package/chunk-VFYQ7I5V.min.mjs +2 -0
- package/chunk-VFYQ7I5V.min.mjs.map +1 -0
- package/chunk-VG7VV7J2.mjs +167 -0
- package/chunk-VJCV56DO.cjs +15 -0
- package/chunk-VREA6AKG.cjs +9 -0
- package/chunk-W5I6Y5FK.min.mjs +2 -0
- package/chunk-W5I6Y5FK.min.mjs.map +1 -0
- package/chunk-Y7MC73BZ.cjs +42 -0
- package/chunk-YVWROQKU.mjs +40 -0
- package/chunk-ZKIZ5SWK.min.cjs +2 -0
- package/chunk-ZKIZ5SWK.min.cjs.map +1 -0
- package/chunk-ZZZB7NJX.mjs +93 -0
- package/concatIterators.cjs +4 -27
- package/concatIterators.min.cjs +1 -1
- package/concatIterators.min.cjs.map +1 -1
- package/concatIterators.min.mjs +1 -1
- package/concatIterators.min.mjs.map +1 -1
- package/concatIterators.mjs +2 -0
- package/dateTimeStr.cjs +31 -119
- package/dateTimeStr.min.cjs +1 -1
- package/dateTimeStr.min.cjs.map +1 -1
- package/dateTimeStr.min.mjs +1 -1
- package/dateTimeStr.min.mjs.map +1 -1
- package/dateTimeStr.mjs +17 -69
- package/duration.cjs +24 -188
- package/duration.min.cjs +1 -1
- package/duration.min.cjs.map +1 -1
- package/duration.min.mjs +1 -1
- package/duration.min.mjs.map +1 -1
- package/duration.mjs +14 -144
- package/getEnv.cjs +20 -0
- package/getEnv.d.mts +11 -0
- package/getEnv.d.ts +11 -0
- package/getEnv.min.cjs +2 -0
- package/getEnv.min.cjs.map +1 -0
- package/getEnv.min.mjs +2 -0
- package/getEnv.min.mjs.map +1 -0
- package/getEnv.mjs +20 -0
- package/isEmpty.cjs +8 -46
- package/isEmpty.min.cjs +1 -1
- package/isEmpty.min.cjs.map +1 -1
- package/isEmpty.min.mjs +1 -1
- package/isEmpty.min.mjs.map +1 -1
- package/isEmpty.mjs +6 -19
- package/isPromise.cjs +5 -29
- package/isPromise.min.cjs +1 -1
- package/isPromise.min.cjs.map +1 -1
- package/isPromise.min.mjs +1 -1
- package/isPromise.min.mjs.map +1 -1
- package/isPromise.mjs +2 -0
- package/kvStore.cjs +15 -362
- package/kvStore.d.mts +142 -44
- package/kvStore.d.ts +142 -44
- package/kvStore.min.cjs +1 -1
- package/kvStore.min.cjs.map +1 -1
- package/kvStore.min.mjs +1 -1
- package/kvStore.min.mjs.map +1 -1
- package/kvStore.mjs +13 -328
- package/localStore.cjs +15 -263
- package/localStore.d.mts +135 -34
- package/localStore.d.ts +135 -34
- package/localStore.min.cjs +1 -1
- package/localStore.min.cjs.map +1 -1
- package/localStore.min.mjs +1 -1
- package/localStore.min.mjs.map +1 -1
- package/localStore.mjs +13 -229
- package/magic-string.es-4UY437WL.min.mjs +14 -0
- package/magic-string.es-4UY437WL.min.mjs.map +1 -0
- package/magic-string.es-OAQWZQTY.mjs +1323 -0
- package/magic-string.es-UE2UVQEL.cjs +1323 -0
- package/magic-string.es-X6DNUB6Y.min.cjs +14 -0
- package/magic-string.es-X6DNUB6Y.min.cjs.map +1 -0
- package/mean.cjs +8 -48
- package/mean.min.cjs +1 -1
- package/mean.min.cjs.map +1 -1
- package/mean.min.mjs +1 -1
- package/mean.min.mjs.map +1 -1
- package/mean.mjs +5 -18
- package/median.cjs +7 -41
- package/median.min.cjs +1 -1
- package/median.min.cjs.map +1 -1
- package/median.min.mjs +1 -1
- package/median.min.mjs.map +1 -1
- package/median.mjs +5 -12
- package/nonEmpty.cjs +8 -48
- package/nonEmpty.min.cjs +1 -1
- package/nonEmpty.min.cjs.map +1 -1
- package/nonEmpty.min.mjs +1 -1
- package/nonEmpty.min.mjs.map +1 -1
- package/nonEmpty.mjs +6 -19
- package/nonNil.cjs +4 -27
- package/nonNil.min.cjs +1 -1
- package/nonNil.min.cjs.map +1 -1
- package/nonNil.min.mjs +1 -1
- package/nonNil.min.mjs.map +1 -1
- package/nonNil.mjs +2 -0
- package/package.json +274 -34
- package/round.cjs +6 -32
- package/round.min.cjs +1 -1
- package/round.min.cjs.map +1 -1
- package/round.min.mjs +1 -1
- package/round.min.mjs.map +1 -1
- package/round.mjs +4 -5
- package/roundToString.cjs +7 -35
- package/roundToString.min.cjs +1 -1
- package/roundToString.min.cjs.map +1 -1
- package/roundToString.min.mjs +1 -1
- package/roundToString.min.mjs.map +1 -1
- package/roundToString.mjs +4 -5
- package/safeBtoa.cjs +4 -27
- package/safeBtoa.d.mts +7 -0
- package/safeBtoa.d.ts +7 -0
- package/safeBtoa.min.cjs +1 -1
- package/safeBtoa.min.cjs.map +1 -1
- package/safeBtoa.min.mjs +1 -1
- package/safeBtoa.min.mjs.map +1 -1
- package/safeBtoa.mjs +2 -0
- package/sha256.cjs +8 -34
- package/sha256.min.cjs +1 -1
- package/sha256.min.cjs.map +1 -1
- package/sha256.min.mjs +1 -1
- package/sha256.min.mjs.map +1 -1
- package/sha256.mjs +6 -7
- package/sleep.cjs +4 -27
- package/sleep.min.cjs +1 -1
- package/sleep.min.cjs.map +1 -1
- package/sleep.min.mjs +1 -1
- package/sleep.min.mjs.map +1 -1
- package/sleep.mjs +2 -0
- package/storageAdapter.cjs +1 -18
- package/storageAdapter.min.cjs +1 -2
- package/storageAdapter.min.cjs.map +1 -1
- package/sum.cjs +5 -45
- package/sum.min.cjs +1 -1
- package/sum.min.cjs.map +1 -1
- package/sum.min.mjs +1 -1
- package/sum.min.mjs.map +1 -1
- package/sum.mjs +5 -18
- package/timeConstants.cjs +35 -69
- package/timeConstants.min.cjs +1 -1
- package/timeConstants.min.cjs.map +1 -1
- package/timeConstants.min.mjs +1 -1
- package/timeConstants.min.mjs.map +1 -1
- package/timeConstants.mjs +19 -15
- package/timer.cjs +7 -185
- package/timer.d.mts +9 -6
- package/timer.d.ts +9 -6
- package/timer.min.cjs +1 -1
- package/timer.min.cjs.map +1 -1
- package/timer.min.mjs +1 -1
- package/timer.min.mjs.map +1 -1
- package/timer.mjs +8 -158
- package/toReadableString.cjs +6 -68
- package/toReadableString.min.cjs +1 -5
- package/toReadableString.min.cjs.map +1 -1
- package/toReadableString.min.mjs +1 -5
- package/toReadableString.min.mjs.map +1 -1
- package/toReadableString.mjs +4 -41
- package/safeParseFloat.cjs +0 -33
- package/safeParseFloat.d.mts +0 -6
- package/safeParseFloat.d.ts +0 -6
- package/safeParseFloat.min.cjs +0 -2
- package/safeParseFloat.min.cjs.map +0 -1
- package/safeParseFloat.min.mjs +0 -2
- package/safeParseFloat.min.mjs.map +0 -1
- package/safeParseFloat.mjs +0 -8
- package/safeParseInt.cjs +0 -33
- package/safeParseInt.d.mts +0 -6
- package/safeParseInt.d.ts +0 -6
- package/safeParseInt.min.cjs +0 -2
- package/safeParseInt.min.cjs.map +0 -1
- package/safeParseInt.min.mjs +0 -2
- package/safeParseInt.min.mjs.map +0 -1
- package/safeParseInt.mjs +0 -8
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkQNNJNLGKmincjs = require('./chunk-QNNJNLGK.min.cjs');function u(e){return/^\d+$/.test(e)}function o(e){return typeof e=="number"?e<1e11?new Date(e*1e3):new Date(e):typeof e=="string"?u(e)?o(Number(e)):new Date(e):e}function s(e=new Date,t="-"){let n=e.getFullYear(),r=e.getMonth()+1;return n+t+(r<10?"0"+r:r)}function l(e=new Date,t="-"){let n=e.getDate();return s(e,t)+t+(n<10?"0"+n:n)}function g(e=new Date,t=":"){let n=e.getHours(),r=e.getMinutes();return(n<10?"0"+n:n)+t+(r<10?"0"+r:r)}function a(e=new Date,t=":"){let n=e.getSeconds();return g(e,t)+t+(n<10?"0"+n:n)}function D(e=new Date,t=":",n="."){let r=e.getMilliseconds();return a(e,t)+n+(r<10?"00"+r:r<100?"0"+r:r)}function h(e=new Date){if(e.getTimezoneOffset()===0)return"Z";let t=e.getTimezoneOffset()/60;return t>=0?"+"+t:String(t)}function c(e,t="default"){return new Date(2024,e,15).toLocaleString(t,{month:"long"})}function x(e,t="default"){return c(e-1,t)}function m(e,t="default"){return new Date(2e3,e,15).toLocaleString(t,{month:"short"})}function y(e,t="default"){return m(e-1,t)}function p(e){return(o(e).toISOString().slice(0,19)+"Z").replace("T"," ")}var f=_chunkQNNJNLGKmincjs.a.call(void 0, ()=>{});exports.a = o; exports.b = s; exports.c = l; exports.d = g; exports.e = a; exports.f = D; exports.g = h; exports.h = c; exports.i = x; exports.j = m; exports.k = y; exports.l = p; exports.m = f;
|
|
2
|
+
//# sourceMappingURL=chunk-SJDJDNDN.min.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/choksheaklau/src/ts-utils/dist/chunk-SJDJDNDN.min.cjs","../src/dateTimeStr.ts"],"names":["isAllDigits","str","toDate","ts","yyyyMm","dt","separator","yr","mth","yyyyMmDd","day","hhMm","hr","min","hhMmSs","sec","hhMmSsMs","timeSeparator","msSeparator","ms","tzShort","tzHours","getLongMonthNameZeroIndexed","month","locales","getLongMonthNameOneIndexed","getShortMonthNameZeroIndexed","getShortMonthNameOneIndexed","getDisplayDateTime","init_dateTimeStr","__esmMin"],"mappings":"AAAA,wIAA4C,SCEnCA,CAAAA,CAAYC,CAAAA,CAAsB,CACzC,MAAO,OAAA,CAAQ,IAAA,CAAKA,CAAG,CACzB,CAOO,SAASC,CAAAA,CAAOC,CAAAA,CAAuB,CAC5C,OAAI,OAAOA,CAAAA,EAAO,QAAA,CAEZA,CAAAA,CAAK,IAAA,CACA,IAAI,IAAA,CAAKA,CAAAA,CAAK,GAAI,CAAA,CAIpB,IAAI,IAAA,CAAKA,CAAE,CAAA,CAGhB,OAAOA,CAAAA,EAAO,QAAA,CACZH,CAAAA,CAAYG,CAAE,CAAA,CACTD,CAAAA,CAAO,MAAA,CAAOC,CAAE,CAAC,CAAA,CAGnB,IAAI,IAAA,CAAKA,CAAE,CAAA,CAGbA,CACT,CAQO,SAASC,CAAAA,CAAOC,CAAAA,CAAK,IAAI,IAAA,CAAQC,CAAAA,CAAY,GAAA,CAAa,CAC/D,IAAMC,CAAAA,CAAKF,CAAAA,CAAG,WAAA,CAAY,CAAA,CACpBG,CAAAA,CAAMH,CAAAA,CAAG,QAAA,CAAS,CAAA,CAAI,CAAA,CAE5B,OAAOE,CAAAA,CAAKD,CAAAA,CAAAA,CAAaE,CAAAA,CAAM,EAAA,CAAK,GAAA,CAAMA,CAAAA,CAAMA,CAAAA,CAClD,CAQO,SAASC,CAAAA,CAASJ,CAAAA,CAAK,IAAI,IAAA,CAAQC,CAAAA,CAAY,GAAA,CAAa,CACjE,IAAMI,CAAAA,CAAML,CAAAA,CAAG,OAA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,CAAA,CAAA,CAAA,kMAAA","file":"/Users/choksheaklau/src/ts-utils/dist/chunk-SJDJDNDN.min.cjs","sourcesContent":[null,"export type AnyDateTime = number | Date | string;\n\nfunction isAllDigits(str: string): boolean {\n return /^\\d+$/.test(str);\n}\n\n/**\n * Convert a number (epoch seconds or milliseconds), string (parseable\n * date/time or epoch seconds or milliseconds), or Date object (no conversion)\n * into a Date object.\n */\nexport function toDate(ts: AnyDateTime): Date {\n if (typeof ts === \"number\") {\n // Handle timestamp in seconds (less than 12 digits long).\n if (ts < 1_000_000_000_00) {\n return new Date(ts * 1000);\n }\n\n // Handle timestamp in milliseconds.\n return new Date(ts);\n }\n\n if (typeof ts === \"string\") {\n if (isAllDigits(ts)) {\n return toDate(Number(ts));\n }\n\n return new Date(ts);\n }\n\n return ts;\n}\n\n/**\n * Returns a date in yyyy-MM format. E.g. '2000-01'.\n *\n * @param dt Specify a date object or default to the current date.\n * @param separator Defaults to '-'.\n */\nexport function yyyyMm(dt = new Date(), separator = \"-\"): string {\n const yr = dt.getFullYear();\n const mth = dt.getMonth() + 1;\n\n return yr + separator + (mth < 10 ? \"0\" + mth : mth);\n}\n\n/**\n * Returns a date in yyyy-MM-dd format. E.g. '2000-01-02'.\n *\n * @param dt Specify a date object or default to the current date.\n * @param separator Defaults to '-'.\n */\nexport function yyyyMmDd(dt = new Date(), separator = \"-\"): string {\n const day = dt.getDate();\n\n return yyyyMm(dt, separator) + separator + (day < 10 ? \"0\" + day : day);\n}\n\n/**\n * Returns a date in hh:mm format. E.g. '01:02'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param separator Defaults to ':'.\n */\nexport function hhMm(dt = new Date(), separator = \":\"): string {\n const hr = dt.getHours();\n const min = dt.getMinutes();\n\n return (hr < 10 ? \"0\" + hr : hr) + separator + (min < 10 ? \"0\" + min : min);\n}\n\n/**\n * Returns a date in hh:mm:ss format. E.g. '01:02:03'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param separator Defaults to ':'.\n */\nexport function hhMmSs(dt = new Date(), separator = \":\"): string {\n const sec = dt.getSeconds();\n\n return hhMm(dt, separator) + separator + (sec < 10 ? \"0\" + sec : sec);\n}\n\n/**\n * Returns a date in hh:mm:ss.SSS format. E.g. '01:02:03.004'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param timeSeparator Separator for hh/mm/ss. Defaults to ':'.\n * @param msSeparator Separator before SSS. Defaults to '.'.\n */\nexport function hhMmSsMs(\n dt = new Date(),\n timeSeparator = \":\",\n msSeparator = \".\",\n): string {\n const ms = dt.getMilliseconds();\n\n return (\n hhMmSs(dt, timeSeparator) +\n msSeparator +\n (ms < 10 ? \"00\" + ms : ms < 100 ? \"0\" + ms : ms)\n );\n}\n\n/**\n * Returns the timezone string for the given date. E.g. '+8', '-3.5'.\n * Returns 'Z' for UTC.\n *\n * @param dt Specify a date object or default to the current date/time.\n */\nexport function tzShort(dt = new Date()): string {\n if (dt.getTimezoneOffset() === 0) {\n return \"Z\";\n }\n\n const tzHours = dt.getTimezoneOffset() / 60;\n return tzHours >= 0 ? \"+\" + tzHours : String(tzHours);\n}\n\n/**\n * Returns the long month name, zero-indexed. E.g. 0 for 'January'.\n *\n * @param month Zero-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getLongMonthNameZeroIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return new Date(2024, month, 15).toLocaleString(locales, {\n month: \"long\",\n });\n}\n\n/**\n * Returns the long month name, one-indexed. E.g. 1 for 'January'.\n *\n * @param month One-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getLongMonthNameOneIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return getLongMonthNameZeroIndexed(month - 1, locales);\n}\n\n/**\n * Returns the short month name, zero-indexed. E.g. 0 for 'Jan'.\n *\n * @param month Zero-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getShortMonthNameZeroIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return new Date(2000, month, 15).toLocaleString(locales, {\n month: \"short\",\n });\n}\n\n/**\n * Returns the short month name, one-indexed. E.g. 1 for 'Jan'.\n *\n * @param month One-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getShortMonthNameOneIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return getShortMonthNameZeroIndexed(month - 1, locales);\n}\n\n/**\n * Returns a human-readable string date/time like '2025-01-01 22:31:16Z'.\n * Excludes the milliseconds assuming it is not necessary for display.\n */\nexport function getDisplayDateTime(ts: AnyDateTime) {\n const iso = toDate(ts).toISOString();\n const noMs = iso.slice(0, 19) + \"Z\";\n return noMs.replace(\"T\", \" \");\n}\n"]}
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk4GLOLTJ5cjs = require('./chunk-4GLOLTJ5.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkY7MC73BZcjs = require('./chunk-Y7MC73BZ.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkILGTU46Tcjs = require('./chunk-ILGTU46T.cjs');
|
|
12
|
+
|
|
13
|
+
// src/kvStore.ts
|
|
14
|
+
function configureKvStore(config) {
|
|
15
|
+
Object.assign(KvStoreConfig, config);
|
|
16
|
+
}
|
|
17
|
+
function validateStoredObject(obj) {
|
|
18
|
+
if (!obj || typeof obj !== "object" || typeof obj.key !== "string" || obj.value === void 0 || typeof obj.storedMs !== "number" || typeof obj.expiryMs !== "number" || Date.now() >= obj.expiryMs) {
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
return obj;
|
|
22
|
+
}
|
|
23
|
+
function withOnError(request, reject) {
|
|
24
|
+
request.onerror = (event) => {
|
|
25
|
+
reject(event);
|
|
26
|
+
};
|
|
27
|
+
return request;
|
|
28
|
+
}
|
|
29
|
+
function createKvStore(dbName, options) {
|
|
30
|
+
let db;
|
|
31
|
+
const dbVersion = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.dbVersion]), () => ( KvStoreConfig.dbVersion));
|
|
32
|
+
const storeName = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.storeName]), () => ( KvStoreConfig.storeName));
|
|
33
|
+
const defaultExpiryMs = _optionalChain([options, 'optionalAccess', _3 => _3.defaultExpiryMs]) ? _chunk4GLOLTJ5cjs.durationOrMsToMs.call(void 0, options.defaultExpiryMs) : KvStoreConfig.expiryMs;
|
|
34
|
+
const gcIntervalMs = _optionalChain([options, 'optionalAccess', _4 => _4.gcIntervalMs]) ? _chunk4GLOLTJ5cjs.durationOrMsToMs.call(void 0, options.gcIntervalMs) : KvStoreConfig.gcIntervalMs;
|
|
35
|
+
const gcMsStorageKey = `__kvStore:lastGcMs:${dbName}:v${dbVersion}:${storeName}`;
|
|
36
|
+
async function getOrCreateDb() {
|
|
37
|
+
if (!db) {
|
|
38
|
+
db = await new Promise((resolve, reject) => {
|
|
39
|
+
const request = withOnError(indexedDB.open(dbName, dbVersion), reject);
|
|
40
|
+
request.onupgradeneeded = (event) => {
|
|
41
|
+
const db2 = event.target.result;
|
|
42
|
+
const objectStore = db2.createObjectStore(storeName, {
|
|
43
|
+
keyPath: "key"
|
|
44
|
+
});
|
|
45
|
+
objectStore.createIndex("key", "key", {
|
|
46
|
+
unique: true
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
request.onsuccess = (event) => {
|
|
50
|
+
const db2 = event.target.result;
|
|
51
|
+
resolve(db2);
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return db;
|
|
56
|
+
}
|
|
57
|
+
async function transact(mode, callback) {
|
|
58
|
+
const db2 = await getOrCreateDb();
|
|
59
|
+
return await new Promise((resolve, reject) => {
|
|
60
|
+
const transaction = withOnError(db2.transaction(storeName, mode), reject);
|
|
61
|
+
transaction.onabort = (event) => {
|
|
62
|
+
reject(event);
|
|
63
|
+
};
|
|
64
|
+
const objectStore = transaction.objectStore(storeName);
|
|
65
|
+
callback(objectStore, resolve, reject);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const obj = {
|
|
69
|
+
/** Input name for the DB. */
|
|
70
|
+
dbName,
|
|
71
|
+
/** Input version for the DB. */
|
|
72
|
+
dbVersion,
|
|
73
|
+
/** Input name for the DB store. */
|
|
74
|
+
storeName,
|
|
75
|
+
/** Default expiry to use if not specified in set(). */
|
|
76
|
+
defaultExpiryMs,
|
|
77
|
+
/** Time interval for when GC's occur. */
|
|
78
|
+
gcIntervalMs,
|
|
79
|
+
/** Local storage key name for the last GC completed timestamp. */
|
|
80
|
+
gcMsStorageKey,
|
|
81
|
+
/** Set a value in the store. */
|
|
82
|
+
async set(key, value, expiryDeltaMs) {
|
|
83
|
+
const nowMs = Date.now();
|
|
84
|
+
const stored = {
|
|
85
|
+
key,
|
|
86
|
+
value,
|
|
87
|
+
storedMs: nowMs,
|
|
88
|
+
expiryMs: nowMs + _chunk4GLOLTJ5cjs.durationOrMsToMs.call(void 0, _nullishCoalesce(expiryDeltaMs, () => ( defaultExpiryMs)))
|
|
89
|
+
};
|
|
90
|
+
return await transact("readwrite", (objectStore, resolve, reject) => {
|
|
91
|
+
const request = withOnError(objectStore.put(stored), reject);
|
|
92
|
+
request.onsuccess = () => {
|
|
93
|
+
resolve(value);
|
|
94
|
+
obj.gc();
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
/** Delete one or multiple keys. */
|
|
99
|
+
async delete(key) {
|
|
100
|
+
return await transact(
|
|
101
|
+
"readwrite",
|
|
102
|
+
(objectStore, resolve, reject) => {
|
|
103
|
+
objectStore.transaction.oncomplete = () => {
|
|
104
|
+
resolve();
|
|
105
|
+
};
|
|
106
|
+
if (typeof key === "string") {
|
|
107
|
+
withOnError(objectStore.delete(key), reject);
|
|
108
|
+
} else {
|
|
109
|
+
for (const k of key) {
|
|
110
|
+
withOnError(objectStore.delete(k), reject);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
},
|
|
116
|
+
/** Mainly used to get the expiration timestamp of an object. */
|
|
117
|
+
async getStoredObject(key) {
|
|
118
|
+
const stored = await transact(
|
|
119
|
+
"readonly",
|
|
120
|
+
(objectStore, resolve, reject) => {
|
|
121
|
+
const request = withOnError(objectStore.get(key), reject);
|
|
122
|
+
request.onsuccess = () => {
|
|
123
|
+
resolve(request.result);
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
if (!stored) {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const valid = validateStoredObject(stored);
|
|
132
|
+
if (!valid) {
|
|
133
|
+
await obj.delete(key);
|
|
134
|
+
obj.gc();
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
return valid;
|
|
138
|
+
} catch (e) {
|
|
139
|
+
console.error(`Invalid kv value: ${key}=${JSON.stringify(stored)}:`, e);
|
|
140
|
+
await obj.delete(key);
|
|
141
|
+
obj.gc();
|
|
142
|
+
return void 0;
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
/** Get a value by key, or undefined if it does not exist. */
|
|
146
|
+
async get(key) {
|
|
147
|
+
const stored = await obj.getStoredObject(key);
|
|
148
|
+
return _optionalChain([stored, 'optionalAccess', _5 => _5.value]);
|
|
149
|
+
},
|
|
150
|
+
/** Generic way to iterate through all entries. */
|
|
151
|
+
async forEach(callback) {
|
|
152
|
+
await transact("readonly", (objectStore, resolve, reject) => {
|
|
153
|
+
const request = withOnError(objectStore.openCursor(), reject);
|
|
154
|
+
request.onsuccess = async (event) => {
|
|
155
|
+
const cursor = event.target.result;
|
|
156
|
+
if (cursor) {
|
|
157
|
+
if (cursor.key) {
|
|
158
|
+
const valid = validateStoredObject(cursor.value);
|
|
159
|
+
if (valid !== void 0) {
|
|
160
|
+
await callback(
|
|
161
|
+
String(cursor.key),
|
|
162
|
+
valid.value,
|
|
163
|
+
valid.expiryMs,
|
|
164
|
+
valid.storedMs
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
cursor.continue();
|
|
169
|
+
} else {
|
|
170
|
+
resolve();
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
/**
|
|
176
|
+
* Returns the number of items in the store. Note that getting the size
|
|
177
|
+
* requires iterating through the entire store because the items could expire
|
|
178
|
+
* at any time, and hence the size is a dynamic number.
|
|
179
|
+
*/
|
|
180
|
+
async size() {
|
|
181
|
+
let count = 0;
|
|
182
|
+
await obj.forEach(() => {
|
|
183
|
+
count++;
|
|
184
|
+
});
|
|
185
|
+
return count;
|
|
186
|
+
},
|
|
187
|
+
/** Remove all items from the store. */
|
|
188
|
+
async clear() {
|
|
189
|
+
await transact("readwrite", (objectStore, resolve, reject) => {
|
|
190
|
+
const request = withOnError(objectStore.clear(), reject);
|
|
191
|
+
request.onsuccess = () => {
|
|
192
|
+
resolve();
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
/**
|
|
197
|
+
* Returns all items as map of key to value, mainly used for debugging dumps.
|
|
198
|
+
* The type T is applied to all values, even though they might not be of type
|
|
199
|
+
* T (in the case when you store different data types in the same store).
|
|
200
|
+
*/
|
|
201
|
+
async asMap() {
|
|
202
|
+
const map = /* @__PURE__ */ new Map();
|
|
203
|
+
await obj.forEach((key, value, expiryMs, storedMs) => {
|
|
204
|
+
map.set(key, { value, expiryMs, storedMs });
|
|
205
|
+
});
|
|
206
|
+
return map;
|
|
207
|
+
},
|
|
208
|
+
/** Returns the ms timestamp for the last GC (garbage collection). */
|
|
209
|
+
getLastGcMs() {
|
|
210
|
+
const lastGcMsStr = localStorage.getItem(gcMsStorageKey);
|
|
211
|
+
if (!lastGcMsStr) return 0;
|
|
212
|
+
const ms = Number(lastGcMsStr);
|
|
213
|
+
return isNaN(ms) ? 0 : ms;
|
|
214
|
+
},
|
|
215
|
+
/** Set the ms timestamp for the last GC (garbage collection). */
|
|
216
|
+
setLastGcMs(ms) {
|
|
217
|
+
localStorage.setItem(gcMsStorageKey, String(ms));
|
|
218
|
+
},
|
|
219
|
+
/** Perform garbage-collection if due, else do nothing. */
|
|
220
|
+
async gc() {
|
|
221
|
+
const lastGcMs = obj.getLastGcMs();
|
|
222
|
+
if (!lastGcMs) {
|
|
223
|
+
obj.setLastGcMs(Date.now());
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (Date.now() < lastGcMs + gcIntervalMs) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
await obj.gcNow();
|
|
230
|
+
},
|
|
231
|
+
/**
|
|
232
|
+
* Perform garbage collection immediately without checking whether we are
|
|
233
|
+
* due for the next GC or not.
|
|
234
|
+
*/
|
|
235
|
+
async gcNow() {
|
|
236
|
+
console.log(`Starting kvStore GC on ${dbName} v${dbVersion}...`);
|
|
237
|
+
obj.setLastGcMs(Date.now());
|
|
238
|
+
const keysToDelete = [];
|
|
239
|
+
await obj.forEach(
|
|
240
|
+
async (key, value, expiryMs) => {
|
|
241
|
+
if (value === void 0 || Date.now() >= expiryMs) {
|
|
242
|
+
keysToDelete.push(key);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
if (keysToDelete.length) {
|
|
247
|
+
await obj.delete(keysToDelete);
|
|
248
|
+
}
|
|
249
|
+
console.log(
|
|
250
|
+
`Finished kvStore GC on ${dbName} v${dbVersion} - deleted ${keysToDelete.length} keys`
|
|
251
|
+
);
|
|
252
|
+
obj.setLastGcMs(Date.now());
|
|
253
|
+
},
|
|
254
|
+
/** Returns `this` casted into a StorageAdapter<T>. */
|
|
255
|
+
asStorageAdapter() {
|
|
256
|
+
return obj;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
return obj;
|
|
260
|
+
}
|
|
261
|
+
function kvStoreItem(key, expiryMs, store = kvStore) {
|
|
262
|
+
const defaultExpiryMs = expiryMs && _chunk4GLOLTJ5cjs.durationOrMsToMs.call(void 0, expiryMs);
|
|
263
|
+
const obj = {
|
|
264
|
+
key,
|
|
265
|
+
defaultExpiryMs,
|
|
266
|
+
store,
|
|
267
|
+
/** Set a value in the store. */
|
|
268
|
+
async set(value, expiryDeltaMs) {
|
|
269
|
+
await store.set(key, value, _nullishCoalesce(expiryDeltaMs, () => ( defaultExpiryMs)));
|
|
270
|
+
},
|
|
271
|
+
/**
|
|
272
|
+
* Example usage:
|
|
273
|
+
*
|
|
274
|
+
* const { value, storedMs, expiryMs, storedMs } =
|
|
275
|
+
* await myKvItem.getStoredObject();
|
|
276
|
+
*/
|
|
277
|
+
async getStoredObject() {
|
|
278
|
+
return await store.getStoredObject(key);
|
|
279
|
+
},
|
|
280
|
+
/** Get a value by key, or undefined if it does not exist. */
|
|
281
|
+
async get() {
|
|
282
|
+
return await store.get(key);
|
|
283
|
+
},
|
|
284
|
+
/** Delete this key from the store. */
|
|
285
|
+
async delete() {
|
|
286
|
+
await store.delete(key);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
return obj;
|
|
290
|
+
}
|
|
291
|
+
var KvStoreConfig, kvStore;
|
|
292
|
+
var init_kvStore = _chunkILGTU46Tcjs.__esm.call(void 0, {
|
|
293
|
+
"src/kvStore.ts"() {
|
|
294
|
+
_chunk4GLOLTJ5cjs.init_duration.call(void 0, );
|
|
295
|
+
_chunkY7MC73BZcjs.init_timeConstants.call(void 0, );
|
|
296
|
+
KvStoreConfig = exports.KvStoreConfig = {
|
|
297
|
+
/**
|
|
298
|
+
* Name of the DB in the indexed DB.
|
|
299
|
+
* Updating the DB name will cause all old entries to be gone.
|
|
300
|
+
*/
|
|
301
|
+
dbName: "KVStore",
|
|
302
|
+
/**
|
|
303
|
+
* Version of the DB schema. Most likely you will never want to change this.
|
|
304
|
+
* Updating the version will cause all old entries to be gone.
|
|
305
|
+
*/
|
|
306
|
+
dbVersion: 1,
|
|
307
|
+
/**
|
|
308
|
+
* Name of the store within the indexed DB. Each DB can have multiple stores.
|
|
309
|
+
* In practice, it doesn't matter what you name this to be.
|
|
310
|
+
*/
|
|
311
|
+
storeName: "kvStore",
|
|
312
|
+
/** 30 days in ms. */
|
|
313
|
+
expiryMs: _chunkY7MC73BZcjs.MS_PER_DAY * 30,
|
|
314
|
+
/** Do GC once per day. */
|
|
315
|
+
gcIntervalMs: _chunkY7MC73BZcjs.MS_PER_DAY
|
|
316
|
+
};
|
|
317
|
+
kvStore = exports.kvStore = createKvStore(KvStoreConfig.dbName);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
exports.KvStoreConfig = KvStoreConfig; exports.configureKvStore = configureKvStore; exports.createKvStore = createKvStore; exports.kvStore = kvStore; exports.kvStoreItem = kvStoreItem; exports.init_kvStore = init_kvStore;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as i}from"./chunk-UOU6IP3S.min.mjs";function u(e){return/^\d+$/.test(e)}function o(e){return typeof e=="number"?e<1e11?new Date(e*1e3):new Date(e):typeof e=="string"?u(e)?o(Number(e)):new Date(e):e}function s(e=new Date,t="-"){let n=e.getFullYear(),r=e.getMonth()+1;return n+t+(r<10?"0"+r:r)}function l(e=new Date,t="-"){let n=e.getDate();return s(e,t)+t+(n<10?"0"+n:n)}function g(e=new Date,t=":"){let n=e.getHours(),r=e.getMinutes();return(n<10?"0"+n:n)+t+(r<10?"0"+r:r)}function a(e=new Date,t=":"){let n=e.getSeconds();return g(e,t)+t+(n<10?"0"+n:n)}function D(e=new Date,t=":",n="."){let r=e.getMilliseconds();return a(e,t)+n+(r<10?"00"+r:r<100?"0"+r:r)}function h(e=new Date){if(e.getTimezoneOffset()===0)return"Z";let t=e.getTimezoneOffset()/60;return t>=0?"+"+t:String(t)}function c(e,t="default"){return new Date(2024,e,15).toLocaleString(t,{month:"long"})}function x(e,t="default"){return c(e-1,t)}function m(e,t="default"){return new Date(2e3,e,15).toLocaleString(t,{month:"short"})}function y(e,t="default"){return m(e-1,t)}function p(e){return(o(e).toISOString().slice(0,19)+"Z").replace("T"," ")}var f=i(()=>{});export{o as a,s as b,l as c,g as d,a as e,D as f,h as g,c as h,x as i,m as j,y as k,p as l,f as m};
|
|
2
|
+
//# sourceMappingURL=chunk-SV35RBZ7.min.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dateTimeStr.ts"],"sourcesContent":["export type AnyDateTime = number | Date | string;\n\nfunction isAllDigits(str: string): boolean {\n return /^\\d+$/.test(str);\n}\n\n/**\n * Convert a number (epoch seconds or milliseconds), string (parseable\n * date/time or epoch seconds or milliseconds), or Date object (no conversion)\n * into a Date object.\n */\nexport function toDate(ts: AnyDateTime): Date {\n if (typeof ts === \"number\") {\n // Handle timestamp in seconds (less than 12 digits long).\n if (ts < 1_000_000_000_00) {\n return new Date(ts * 1000);\n }\n\n // Handle timestamp in milliseconds.\n return new Date(ts);\n }\n\n if (typeof ts === \"string\") {\n if (isAllDigits(ts)) {\n return toDate(Number(ts));\n }\n\n return new Date(ts);\n }\n\n return ts;\n}\n\n/**\n * Returns a date in yyyy-MM format. E.g. '2000-01'.\n *\n * @param dt Specify a date object or default to the current date.\n * @param separator Defaults to '-'.\n */\nexport function yyyyMm(dt = new Date(), separator = \"-\"): string {\n const yr = dt.getFullYear();\n const mth = dt.getMonth() + 1;\n\n return yr + separator + (mth < 10 ? \"0\" + mth : mth);\n}\n\n/**\n * Returns a date in yyyy-MM-dd format. E.g. '2000-01-02'.\n *\n * @param dt Specify a date object or default to the current date.\n * @param separator Defaults to '-'.\n */\nexport function yyyyMmDd(dt = new Date(), separator = \"-\"): string {\n const day = dt.getDate();\n\n return yyyyMm(dt, separator) + separator + (day < 10 ? \"0\" + day : day);\n}\n\n/**\n * Returns a date in hh:mm format. E.g. '01:02'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param separator Defaults to ':'.\n */\nexport function hhMm(dt = new Date(), separator = \":\"): string {\n const hr = dt.getHours();\n const min = dt.getMinutes();\n\n return (hr < 10 ? \"0\" + hr : hr) + separator + (min < 10 ? \"0\" + min : min);\n}\n\n/**\n * Returns a date in hh:mm:ss format. E.g. '01:02:03'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param separator Defaults to ':'.\n */\nexport function hhMmSs(dt = new Date(), separator = \":\"): string {\n const sec = dt.getSeconds();\n\n return hhMm(dt, separator) + separator + (sec < 10 ? \"0\" + sec : sec);\n}\n\n/**\n * Returns a date in hh:mm:ss.SSS format. E.g. '01:02:03.004'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param timeSeparator Separator for hh/mm/ss. Defaults to ':'.\n * @param msSeparator Separator before SSS. Defaults to '.'.\n */\nexport function hhMmSsMs(\n dt = new Date(),\n timeSeparator = \":\",\n msSeparator = \".\",\n): string {\n const ms = dt.getMilliseconds();\n\n return (\n hhMmSs(dt, timeSeparator) +\n msSeparator +\n (ms < 10 ? \"00\" + ms : ms < 100 ? \"0\" + ms : ms)\n );\n}\n\n/**\n * Returns the timezone string for the given date. E.g. '+8', '-3.5'.\n * Returns 'Z' for UTC.\n *\n * @param dt Specify a date object or default to the current date/time.\n */\nexport function tzShort(dt = new Date()): string {\n if (dt.getTimezoneOffset() === 0) {\n return \"Z\";\n }\n\n const tzHours = dt.getTimezoneOffset() / 60;\n return tzHours >= 0 ? \"+\" + tzHours : String(tzHours);\n}\n\n/**\n * Returns the long month name, zero-indexed. E.g. 0 for 'January'.\n *\n * @param month Zero-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getLongMonthNameZeroIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return new Date(2024, month, 15).toLocaleString(locales, {\n month: \"long\",\n });\n}\n\n/**\n * Returns the long month name, one-indexed. E.g. 1 for 'January'.\n *\n * @param month One-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getLongMonthNameOneIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return getLongMonthNameZeroIndexed(month - 1, locales);\n}\n\n/**\n * Returns the short month name, zero-indexed. E.g. 0 for 'Jan'.\n *\n * @param month Zero-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getShortMonthNameZeroIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return new Date(2000, month, 15).toLocaleString(locales, {\n month: \"short\",\n });\n}\n\n/**\n * Returns the short month name, one-indexed. E.g. 1 for 'Jan'.\n *\n * @param month One-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getShortMonthNameOneIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return getShortMonthNameZeroIndexed(month - 1, locales);\n}\n\n/**\n * Returns a human-readable string date/time like '2025-01-01 22:31:16Z'.\n * Excludes the milliseconds assuming it is not necessary for display.\n */\nexport function getDisplayDateTime(ts: Any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ACxBC,GACCC,EAAK,GAAK,KAAOA,EAAKA,EAAK,IAAM,IAAMA,EAAKA,EAEjD,CAQO,SAASC,EAAQf,EAAK,IAAI,KAAgB,CAC/C,GAAIA,EAAG,kBAAkB,IAAM,EAC7B,MAAO,IAGT,IAAMgB,EAAUhB,EAAG,kBAAkB,EAAI,GACzC,OAAOgB,GAAW,EAAI,IAAMA,EAAU,OAAOA,CAAO,CACtD,CAQO,SAASC,EACdC,EACAC,EAAgC,UACxB,CACR,OAAO,IAAI,KAAK,KAAMD,EAAO,EAAE,EAAE,eAAeC,EAAS,CACvD,MAAO,MACT,CAAC,CACH,CAQO,SAASC,EACdF,EACAC,EAAgC,UACxB,CACR,OAAOF,EAA4BC,EAAQ,EAAGC,CAAO,CACvD,CAQO,SAASE,EACdH,EACAC,EAAgC,UACxB,CACR,OAAO,IAAI,KAAK,IAAMD,EAAO,EAAE,EAAE,eAAeC,EAAS,CACvD,MAAO,OACT,CAAC,CACH,CAQO,SAASG,EACdJ,EACAC,EAAgC,UACxB,CACR,OAAOE,EAA6BH,EAAQ,EAAGC,CAAO,CACxD,CAMO,SAASI,EAAmBzB,EAAiB,CAGlD,OAFYD,EAAOC,CAAE,EAAE,YAAY,EAClB,MAAM,EAAG,EAAE,EAAI,KACpB,QAAQ,IAAK,GAAG,CAC9B,CAvLA,IAAA0B,EAAAC,EAAA","names":["isAllDigits","str","toDate","ts","yyyyMm","dt","separator","yr","mth","yyyyMmDd","day","hhMm","hr","min","hhMmSs","sec","hhMmSsMs","timeSeparator","msSeparator","ms","tzShort","tzHours","getLongMonthNameZeroIndexed","month","locales","getLongMonthNameOneIndexed","getShortMonthNameZeroIndexed","getShortMonthNameOneIndexed","getDisplayDateTime","init_dateTimeStr","__esmMin"]}
|