@choksheak/ts-utils 0.2.9 → 0.3.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.
- package/README.md +2 -0
- package/{arrayBuffer.js → arrayBuffer.cjs} +0 -1
- package/arrayBuffer.d.mts +10 -0
- package/arrayBuffer.min.cjs +2 -0
- package/arrayBuffer.min.cjs.map +1 -0
- package/arrayBuffer.min.mjs +2 -0
- package/{arrayBuffer.js.map → arrayBuffer.min.mjs.map} +1 -1
- package/arrayBuffer.mjs +14 -0
- package/{assert.js → assert.cjs} +0 -1
- package/assert.d.mts +7 -0
- package/assert.min.cjs +2 -0
- package/assert.min.cjs.map +1 -0
- package/assert.min.mjs +2 -0
- package/{assert.js.map → assert.min.mjs.map} +1 -1
- package/assert.mjs +11 -0
- package/{average.js → average.cjs} +0 -1
- package/average.d.mts +7 -0
- package/average.min.cjs +2 -0
- package/{average.js.map → average.min.cjs.map} +1 -1
- package/average.min.mjs +2 -0
- package/average.min.mjs.map +1 -0
- package/average.mjs +20 -0
- package/{base64Url.js → base64Url.cjs} +0 -1
- package/base64Url.d.mts +10 -0
- package/base64Url.min.cjs +2 -0
- package/base64Url.min.cjs.map +1 -0
- package/base64Url.min.mjs +2 -0
- package/{base64Url.js.map → base64Url.min.mjs.map} +1 -1
- package/base64Url.mjs +14 -0
- package/{dateTimeStr.js → dateTimeStr.cjs} +0 -1
- package/dateTimeStr.d.mts +85 -0
- package/dateTimeStr.min.cjs +2 -0
- package/dateTimeStr.min.cjs.map +1 -0
- package/dateTimeStr.min.mjs +2 -0
- package/{dateTimeStr.js.map → dateTimeStr.min.mjs.map} +1 -1
- package/dateTimeStr.mjs +83 -0
- package/{duration.js → duration.cjs} +9 -11
- package/duration.d.mts +78 -0
- package/duration.min.cjs +2 -0
- package/duration.min.cjs.map +1 -0
- package/duration.min.mjs +2 -0
- package/duration.min.mjs.map +1 -0
- package/duration.mjs +154 -0
- package/{isEmpty.js → isEmpty.cjs} +0 -1
- package/isEmpty.d.mts +6 -0
- package/isEmpty.min.cjs +2 -0
- package/isEmpty.min.cjs.map +1 -0
- package/isEmpty.min.mjs +2 -0
- package/{isEmpty.js.map → isEmpty.min.mjs.map} +1 -1
- package/isEmpty.mjs +22 -0
- package/kvStore.cjs +333 -0
- package/kvStore.d.mts +97 -0
- package/kvStore.min.cjs +2 -0
- package/kvStore.min.cjs.map +1 -0
- package/kvStore.min.mjs +2 -0
- package/kvStore.min.mjs.map +1 -0
- package/kvStore.mjs +300 -0
- package/{localStorageCache.js → localStorageCache.cjs} +5 -7
- package/localStorageCache.d.mts +57 -0
- package/localStorageCache.min.cjs +2 -0
- package/localStorageCache.min.cjs.map +1 -0
- package/localStorageCache.min.mjs +2 -0
- package/localStorageCache.min.mjs.map +1 -0
- package/localStorageCache.mjs +92 -0
- package/{logging.js → logging.cjs} +0 -1
- package/logging.d.mts +4 -0
- package/logging.min.cjs +2 -0
- package/logging.min.cjs.map +1 -0
- package/logging.min.mjs +2 -0
- package/{logging.js.map → logging.min.mjs.map} +1 -1
- package/logging.mjs +21 -0
- package/{nonEmpty.js → nonEmpty.cjs} +0 -1
- package/nonEmpty.d.mts +10 -0
- package/nonEmpty.min.cjs +2 -0
- package/{nonEmpty.js.map → nonEmpty.min.cjs.map} +1 -1
- package/nonEmpty.min.mjs +2 -0
- package/nonEmpty.min.mjs.map +1 -0
- package/nonEmpty.mjs +30 -0
- package/{nonNil.js → nonNil.cjs} +0 -1
- package/{src/nonNil.ts → nonNil.d.mts} +3 -6
- package/nonNil.min.cjs +2 -0
- package/nonNil.min.cjs.map +1 -0
- package/nonNil.min.mjs +2 -0
- package/{nonNil.js.map → nonNil.min.mjs.map} +1 -1
- package/nonNil.mjs +10 -0
- package/package.json +414 -24
- package/{round.js → round.cjs} +0 -1
- package/{src/round.ts → round.d.mts} +4 -8
- package/round.min.cjs +2 -0
- package/round.min.cjs.map +1 -0
- package/round.min.mjs +2 -0
- package/{round.js.map → round.min.mjs.map} +1 -1
- package/round.mjs +12 -0
- package/{safeBtoa.js → safeBtoa.cjs} +0 -1
- package/safeBtoa.d.mts +6 -0
- package/safeBtoa.min.cjs +2 -0
- package/safeBtoa.min.cjs.map +1 -0
- package/safeBtoa.min.mjs +2 -0
- package/{safeBtoa.js.map → safeBtoa.min.mjs.map} +1 -1
- package/safeBtoa.mjs +9 -0
- package/{safeParseFloat.js → safeParseFloat.cjs} +0 -1
- package/safeParseFloat.d.mts +6 -0
- package/safeParseFloat.min.cjs +2 -0
- package/safeParseFloat.min.cjs.map +1 -0
- package/safeParseFloat.min.mjs +2 -0
- package/{safeParseFloat.js.map → safeParseFloat.min.mjs.map} +1 -1
- package/safeParseFloat.mjs +8 -0
- package/{safeParseInt.js → safeParseInt.cjs} +0 -1
- package/safeParseInt.d.mts +6 -0
- package/safeParseInt.min.cjs +2 -0
- package/safeParseInt.min.cjs.map +1 -0
- package/safeParseInt.min.mjs +2 -0
- package/{safeParseInt.js.map → safeParseInt.min.mjs.map} +1 -1
- package/safeParseInt.mjs +8 -0
- package/sha256.cjs +35 -0
- package/sha256.d.mts +6 -0
- package/sha256.min.cjs +2 -0
- package/sha256.min.cjs.map +1 -0
- package/sha256.min.mjs +2 -0
- package/{sha256.js.map → sha256.min.mjs.map} +1 -1
- package/sha256.mjs +10 -0
- package/{sleep.js → sleep.cjs} +0 -1
- package/{src/sleep.ts → sleep.d.mts} +3 -3
- package/sleep.min.cjs +2 -0
- package/sleep.min.cjs.map +1 -0
- package/sleep.min.mjs +2 -0
- package/{sleep.js.map → sleep.min.mjs.map} +1 -1
- package/sleep.mjs +7 -0
- package/{sum.js → sum.cjs} +0 -1
- package/sum.d.mts +7 -0
- package/sum.min.cjs +2 -0
- package/sum.min.cjs.map +1 -0
- package/sum.min.mjs +2 -0
- package/{sum.js.map → sum.min.mjs.map} +1 -1
- package/sum.mjs +13 -0
- package/{timeConstants.js → timeConstants.cjs} +0 -1
- package/timeConstants.d.mts +20 -0
- package/timeConstants.min.cjs +2 -0
- package/timeConstants.min.cjs.map +1 -0
- package/timeConstants.min.mjs +2 -0
- package/{timeConstants.js.map → timeConstants.min.mjs.map} +1 -1
- package/timeConstants.mjs +31 -0
- package/{timer.js → timer.cjs} +6 -6
- package/timer.d.mts +13 -0
- package/timer.min.cjs +2 -0
- package/timer.min.cjs.map +1 -0
- package/timer.min.mjs +2 -0
- package/timer.min.mjs.map +1 -0
- package/timer.mjs +161 -0
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -22
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1640
- package/docs/classes/kvStore.KVStore.html +0 -26
- package/docs/classes/kvStore.KVStoreField.html +0 -7
- package/docs/classes/timer.Timer.html +0 -8
- package/docs/functions/arrayBuffer.arrayBufferToBase64.html +0 -2
- package/docs/functions/arrayBuffer.arrayBufferToHex.html +0 -2
- package/docs/functions/assert.assert.html +0 -3
- package/docs/functions/average.average.html +0 -3
- package/docs/functions/base64Url.base64ToBase64URL.html +0 -2
- package/docs/functions/base64Url.base64UrlToBase64.html +0 -2
- package/docs/functions/dateTimeStr.getDisplayDateTime.html +0 -3
- package/docs/functions/dateTimeStr.getLongMonthNameOneIndexed.html +0 -4
- package/docs/functions/dateTimeStr.getLongMonthNameZeroIndexed.html +0 -4
- package/docs/functions/dateTimeStr.getShortMonthNameOneIndexed.html +0 -4
- package/docs/functions/dateTimeStr.getShortMonthNameZeroIndexed.html +0 -4
- package/docs/functions/dateTimeStr.hhMm.html +0 -4
- package/docs/functions/dateTimeStr.hhMmSs.html +0 -4
- package/docs/functions/dateTimeStr.hhMmSsMs.html +0 -5
- package/docs/functions/dateTimeStr.toDate.html +0 -4
- package/docs/functions/dateTimeStr.tzShort.html +0 -4
- package/docs/functions/dateTimeStr.yyyyMm.html +0 -4
- package/docs/functions/dateTimeStr.yyyyMmDd.html +0 -4
- package/docs/functions/duration.durationOrMsToMs.html +0 -2
- package/docs/functions/duration.durationToMs.html +0 -2
- package/docs/functions/duration.elapsed.html +0 -2
- package/docs/functions/duration.formatDuration.html +0 -4
- package/docs/functions/duration.msToDuration.html +0 -5
- package/docs/functions/duration.readableDuration.html +0 -4
- package/docs/functions/isEmpty.isEmpty.html +0 -2
- package/docs/functions/kvStore.kvStoreItem.html +0 -2
- package/docs/functions/localStorageCache.storeItem.html +0 -15
- package/docs/functions/logging.capLength.html +0 -1
- package/docs/functions/logging.stringify.html +0 -1
- package/docs/functions/nonEmpty.nonEmpty.html +0 -5
- package/docs/functions/nonNil.nonNil.html +0 -5
- package/docs/functions/round.round.html +0 -5
- package/docs/functions/round.roundS.html +0 -3
- package/docs/functions/safeBtoa.safeBtoa.html +0 -2
- package/docs/functions/safeParseFloat.safeParseFloat.html +0 -2
- package/docs/functions/safeParseInt.safeParseInt.html +0 -2
- package/docs/functions/sha256.sha256.html +0 -2
- package/docs/functions/sleep.sleep.html +0 -3
- package/docs/functions/sum.sum.html +0 -3
- package/docs/functions/timer.timer.html +0 -2
- package/docs/hierarchy.html +0 -1
- package/docs/index.html +0 -4
- package/docs/modules/arrayBuffer.html +0 -1
- package/docs/modules/assert.html +0 -1
- package/docs/modules/average.html +0 -1
- package/docs/modules/base64Url.html +0 -1
- package/docs/modules/dateTimeStr.html +0 -1
- package/docs/modules/duration.html +0 -1
- package/docs/modules/isEmpty.html +0 -1
- package/docs/modules/kvStore.html +0 -1
- package/docs/modules/localStorageCache.html +0 -1
- package/docs/modules/logging.html +0 -1
- package/docs/modules/nonEmpty.html +0 -1
- package/docs/modules/nonNil.html +0 -1
- package/docs/modules/round.html +0 -1
- package/docs/modules/safeBtoa.html +0 -1
- package/docs/modules/safeParseFloat.html +0 -1
- package/docs/modules/safeParseInt.html +0 -1
- package/docs/modules/sha256.html +0 -1
- package/docs/modules/sleep.html +0 -1
- package/docs/modules/sum.html +0 -1
- package/docs/modules/timeConstants.html +0 -1
- package/docs/modules/timer.html +0 -1
- package/docs/modules.html +0 -1
- package/docs/types/dateTimeStr.AnyDateTime.html +0 -1
- package/docs/types/duration.Duration.html +0 -6
- package/docs/types/duration.DurationStyle.html +0 -6
- package/docs/types/duration.DurationSuffixMap.html +0 -6
- package/docs/types/duration.DurationSuffixType.html +0 -1
- package/docs/types/duration.DurationType.html +0 -2
- package/docs/types/localStorageCache.StoredItem.html +0 -4
- package/docs/variables/duration.DURATION_STYLE_SUFFIX_MAP.html +0 -1
- package/docs/variables/duration.DURATION_TYPE_SEQUENCE.html +0 -2
- package/docs/variables/kvStore.DEFAULT_EXPIRY_DELTA_MS.html +0 -2
- package/docs/variables/kvStore.GC_INTERVAL_MS.html +0 -2
- package/docs/variables/kvStore.MILLIS_PER_DAY.html +0 -2
- package/docs/variables/kvStore.kvStore.html +0 -3
- package/docs/variables/timeConstants.HOURS_PER_DAY.html +0 -1
- package/docs/variables/timeConstants.HOURS_PER_WEEK.html +0 -1
- package/docs/variables/timeConstants.MINUTES_PER_DAY.html +0 -1
- package/docs/variables/timeConstants.MINUTES_PER_HOUR.html +0 -1
- package/docs/variables/timeConstants.MINUTES_PER_WEEK.html +0 -1
- package/docs/variables/timeConstants.MS_PER_DAY.html +0 -1
- package/docs/variables/timeConstants.MS_PER_HOUR.html +0 -1
- package/docs/variables/timeConstants.MS_PER_MINUTE.html +0 -1
- package/docs/variables/timeConstants.MS_PER_SECOND.html +0 -3
- package/docs/variables/timeConstants.MS_PER_WEEK.html +0 -1
- package/docs/variables/timeConstants.SECONDS_PER_DAY.html +0 -1
- package/docs/variables/timeConstants.SECONDS_PER_HOUR.html +0 -1
- package/docs/variables/timeConstants.SECONDS_PER_MINUTE.html +0 -1
- package/docs/variables/timeConstants.SECONDS_PER_WEEK.html +0 -1
- package/duration.js.map +0 -1
- package/kvStore.js +0 -383
- package/kvStore.js.map +0 -1
- package/localStorageCache.js.map +0 -1
- package/sha256.js +0 -58
- package/src/arrayBuffer.ts +0 -29
- package/src/assert.ts +0 -14
- package/src/average.ts +0 -13
- package/src/base64Url.ts +0 -20
- package/src/dateTimeStr.ts +0 -184
- package/src/duration.ts +0 -260
- package/src/isEmpty.ts +0 -32
- package/src/kvStore.ts +0 -444
- package/src/localStorageCache.ts +0 -121
- package/src/logging.ts +0 -26
- package/src/nonEmpty.ts +0 -18
- package/src/safeBtoa.ts +0 -15
- package/src/safeParseFloat.ts +0 -10
- package/src/safeParseInt.ts +0 -10
- package/src/sha256.ts +0 -13
- package/src/sum.ts +0 -17
- package/src/timeConstants.ts +0 -22
- package/src/timer.ts +0 -33
- package/timer.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,4 +4,6 @@ This package is a random bunch of Typescript utilities that I have needed in alm
|
|
|
4
4
|
|
|
5
5
|
The code supports full tree-shaking. Therefore your code will only grow in size by whatever you use. Any code that you are not using will not contribute to your code size.
|
|
6
6
|
|
|
7
|
+
Source code: https://github.com/choksheak/ts-utils
|
|
8
|
+
|
|
7
9
|
Online docs: https://choksheak.github.io/ts-utils/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encode an input ArrayBuffer into a hex string.
|
|
3
|
+
*/
|
|
4
|
+
declare function arrayBufferToHex(buffer: ArrayBuffer): string;
|
|
5
|
+
/**
|
|
6
|
+
* Encode an input ArrayBuffer into a base64 string.
|
|
7
|
+
*/
|
|
8
|
+
declare function arrayBufferToBase64(buffer: ArrayBuffer): string;
|
|
9
|
+
|
|
10
|
+
export { arrayBufferToBase64, arrayBufferToHex };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var u=(t,r)=>{for(var n in r)e(t,n,{get:r[n],enumerable:!0})},A=(t,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of i(r))!y.call(t,a)&&a!==n&&e(t,a,{get:()=>r[a],enumerable:!(o=f(r,a))||o.enumerable});return t};var s=t=>A(e({},"__esModule",{value:!0}),t);var m={};u(m,{arrayBufferToBase64:()=>g,arrayBufferToHex:()=>c});module.exports=s(m);function c(t){let r=new Uint8Array(t);return Array.from(r).map(n=>n.toString(16).padStart(2,"0")).join("")}function g(t){let r=new Uint8Array(t),n=Array.from(r).map(o=>String.fromCodePoint(o)).join("");return btoa(n)}0&&(module.exports={arrayBufferToBase64,arrayBufferToHex});
|
|
2
|
+
//# sourceMappingURL=arrayBuffer.min.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/arrayBuffer.ts"],"sourcesContent":["/**\n * Encode an input ArrayBuffer into a hex string.\n */\nexport function arrayBufferToHex(buffer: ArrayBuffer): string {\n // Create a Uint8Array view of the ArrayBuffer\n const byteArray = new Uint8Array(buffer);\n\n // Convert each byte to a two-character hexadecimal string\n return Array.from(byteArray)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Encode an input ArrayBuffer into a base64 string.\n */\nexport function arrayBufferToBase64(buffer: ArrayBuffer): string {\n // Convert the ArrayBuffer to a Uint8Array\n const byteArray = new Uint8Array(buffer);\n\n // Create a binary string from the byte array\n const binaryString = Array.from(byteArray)\n .map((byte) => String.fromCodePoint(byte))\n .join(\"\");\n\n // Encode the binary string to base64. No need to use safeBtoa because we\n // already simplified the binary input above.\n return btoa(binaryString);\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,qBAAAC,IAAA,eAAAC,EAAAJ,GAGO,SAASG,EAAiBE,EAA6B,CAE5D,IAAMC,EAAY,IAAI,WAAWD,CAAM,EAGvC,OAAO,MAAM,KAAKC,CAAS,EACxB,IAAKC,GAASA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAChD,KAAK,EAAE,CACZ,CAKO,SAASL,EAAoBG,EAA6B,CAE/D,IAAMC,EAAY,IAAI,WAAWD,CAAM,EAGjCG,EAAe,MAAM,KAAKF,CAAS,EACtC,IAAKC,GAAS,OAAO,cAAcA,CAAI,CAAC,EACxC,KAAK,EAAE,EAIV,OAAO,KAAKC,CAAY,CAC1B","names":["arrayBuffer_exports","__export","arrayBufferToBase64","arrayBufferToHex","__toCommonJS","buffer","byteArray","byte","binaryString"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function o(r){let t=new Uint8Array(r);return Array.from(t).map(n=>n.toString(16).padStart(2,"0")).join("")}function e(r){let t=new Uint8Array(r),n=Array.from(t).map(a=>String.fromCodePoint(a)).join("");return btoa(n)}export{e as arrayBufferToBase64,o as arrayBufferToHex};
|
|
2
|
+
//# sourceMappingURL=arrayBuffer.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/arrayBuffer.ts"],"sourcesContent":["/**\n * Encode an input ArrayBuffer into a hex string.\n */\nexport function arrayBufferToHex(buffer: ArrayBuffer): string {\n // Create a Uint8Array view of the ArrayBuffer\n const byteArray = new Uint8Array(buffer);\n\n // Convert each byte to a two-character hexadecimal string\n return Array.from(byteArray)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Encode an input ArrayBuffer into a base64 string.\n */\nexport function arrayBufferToBase64(buffer: ArrayBuffer): string {\n // Convert the ArrayBuffer to a Uint8Array\n const byteArray = new Uint8Array(buffer);\n\n // Create a binary string from the byte array\n const binaryString = Array.from(byteArray)\n .map((byte) => String.fromCodePoint(byte))\n .join(\"\");\n\n // Encode the binary string to base64. No need to use safeBtoa because we\n // already simplified the binary input above.\n return btoa(binaryString);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/arrayBuffer.ts"],"sourcesContent":["/**\n * Encode an input ArrayBuffer into a hex string.\n */\nexport function arrayBufferToHex(buffer: ArrayBuffer): string {\n // Create a Uint8Array view of the ArrayBuffer\n const byteArray = new Uint8Array(buffer);\n\n // Convert each byte to a two-character hexadecimal string\n return Array.from(byteArray)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Encode an input ArrayBuffer into a base64 string.\n */\nexport function arrayBufferToBase64(buffer: ArrayBuffer): string {\n // Convert the ArrayBuffer to a Uint8Array\n const byteArray = new Uint8Array(buffer);\n\n // Create a binary string from the byte array\n const binaryString = Array.from(byteArray)\n .map((byte) => String.fromCodePoint(byte))\n .join(\"\");\n\n // Encode the binary string to base64. No need to use safeBtoa because we\n // already simplified the binary input above.\n return btoa(binaryString);\n}\n"],"mappings":"AAGO,SAASA,EAAiBC,EAA6B,CAE5D,IAAMC,EAAY,IAAI,WAAWD,CAAM,EAGvC,OAAO,MAAM,KAAKC,CAAS,EACxB,IAAKC,GAASA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAChD,KAAK,EAAE,CACZ,CAKO,SAASC,EAAoBH,EAA6B,CAE/D,IAAMC,EAAY,IAAI,WAAWD,CAAM,EAGjCI,EAAe,MAAM,KAAKH,CAAS,EACtC,IAAKC,GAAS,OAAO,cAAcA,CAAI,CAAC,EACxC,KAAK,EAAE,EAIV,OAAO,KAAKE,CAAY,CAC1B","names":["arrayBufferToHex","buffer","byteArray","byte","arrayBufferToBase64","binaryString"]}
|
package/arrayBuffer.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/arrayBuffer.ts
|
|
2
|
+
function arrayBufferToHex(buffer) {
|
|
3
|
+
const byteArray = new Uint8Array(buffer);
|
|
4
|
+
return Array.from(byteArray).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
5
|
+
}
|
|
6
|
+
function arrayBufferToBase64(buffer) {
|
|
7
|
+
const byteArray = new Uint8Array(buffer);
|
|
8
|
+
const binaryString = Array.from(byteArray).map((byte) => String.fromCodePoint(byte)).join("");
|
|
9
|
+
return btoa(binaryString);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
arrayBufferToBase64,
|
|
13
|
+
arrayBufferToHex
|
|
14
|
+
};
|
package/{assert.js → assert.cjs}
RENAMED
package/assert.d.mts
ADDED
package/assert.min.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var r=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var o=Object.prototype.hasOwnProperty;var l=(e,s)=>{for(var n in s)r(e,n,{get:s[n],enumerable:!0})},d=(e,s,n,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of a(s))!o.call(e,i)&&i!==n&&r(e,i,{get:()=>s[i],enumerable:!(t=f(s,i))||t.enumerable});return e};var u=e=>d(r({},"__esModule",{value:!0}),e);var N={};l(N,{assert:()=>y});module.exports=u(N);function y(e,s){if(!e)throw new Error(s||`Assertion failed: ${JSON.stringify(e)} is falsy`)}0&&(module.exports={assert});
|
|
2
|
+
//# sourceMappingURL=assert.min.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Type asserts that `t` is truthy. Throws an error with `errorMessage` if\n * `t` is falsy.\n */\nexport function assert<T>(\n t: T | null | undefined | \"\" | 0 | -0 | 0n | false | typeof NaN,\n errorMessage?: string,\n): asserts t is T {\n if (!t) {\n throw new Error(\n errorMessage || `Assertion failed: ${JSON.stringify(t)} is falsy`,\n );\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAIO,SAASE,EACdE,EACAC,EACgB,CAChB,GAAI,CAACD,EACH,MAAM,IAAI,MACRC,GAAgB,qBAAqB,KAAK,UAAUD,CAAC,CAAC,WACxD,CAEJ","names":["assert_exports","__export","assert","__toCommonJS","t","errorMessage"]}
|
package/assert.min.mjs
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Type asserts that `t` is truthy. Throws an error with `errorMessage` if\n * `t` is falsy.\n */\nexport function assert<T>(\n t: T | null | undefined | \"\" | 0 | -0 | 0n | false | typeof NaN,\n errorMessage?: string,\n): asserts t is T {\n if (!t) {\n throw new Error(\n errorMessage || `Assertion failed: ${JSON.stringify(t)} is falsy`,\n );\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Type asserts that `t` is truthy. Throws an error with `errorMessage` if\n * `t` is falsy.\n */\nexport function assert<T>(\n t: T | null | undefined | \"\" | 0 | -0 | 0n | false | typeof NaN,\n errorMessage?: string,\n): asserts t is T {\n if (!t) {\n throw new Error(\n errorMessage || `Assertion failed: ${JSON.stringify(t)} is falsy`,\n );\n }\n}\n"],"mappings":"AAIO,SAASA,EACdC,EACAC,EACgB,CAChB,GAAI,CAACD,EACH,MAAM,IAAI,MACRC,GAAgB,qBAAqB,KAAK,UAAUD,CAAC,CAAC,WACxD,CAEJ","names":["assert","t","errorMessage"]}
|
package/assert.mjs
ADDED
package/average.d.mts
ADDED
package/average.min.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var i=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var d=(n,e)=>{for(var u in e)i(n,u,{get:e[u],enumerable:!0})},a=(n,e,u,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of m(e))!f.call(n,t)&&t!==u&&i(n,t,{get:()=>e[t],enumerable:!(r=o(e,t))||r.enumerable});return n};var b=n=>a(i({},"__esModule",{value:!0}),n);var s={};d(s,{average:()=>p});module.exports=b(s);function l(n){return n.reduce((e,u)=>{let r=typeof u=="number"&&!isNaN(u)&&isFinite(u)?u:0;return e+r},0)}function p(n){return n.length===0?0:l(n)/n.length}0&&(module.exports={average});
|
|
2
|
+
//# sourceMappingURL=average.min.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/average.ts","../src/sum.ts"],"sourcesContent":["import { sum } from \"./sum\";\n\n/**\n * Average all the numbers together in the given array. Treats null, undefined\n * and NaN as zero.\n */\nexport function average(numbers: (number | null | undefined)[]): number {\n if (numbers.length === 0) return 0;\n\n const total = sum(numbers);\n\n return total / numbers.length;\n}\n","/**\n * Add all the numbers together in the given array. Treats null, undefined and\n * NaN as zero.\n */\nexport function sum(numbers: (number | null | undefined)[]): number {\n return numbers.reduce(\n (accumulated: number, current: number | null | undefined) => {\n const value =\n typeof current === \"number\" && !isNaN(current) && isFinite(current)\n ? current\n : 0;\n\n return accumulated + value;\n },\n 0,\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/average.ts","../src/sum.ts"],"sourcesContent":["import { sum } from \"./sum\";\n\n/**\n * Average all the numbers together in the given array. Treats null, undefined\n * and NaN as zero.\n */\nexport function average(numbers: (number | null | undefined)[]): number {\n if (numbers.length === 0) return 0;\n\n const total = sum(numbers);\n\n return total / numbers.length;\n}\n","/**\n * Add all the numbers together in the given array. Treats null, undefined and\n * NaN as zero.\n */\nexport function sum(numbers: (number | null | undefined)[]): number {\n return numbers.reduce(\n (accumulated: number, current: number | null | undefined) => {\n const value =\n typeof current === \"number\" && !isNaN(current) && isFinite(current)\n ? current\n : 0;\n\n return accumulated + value;\n },\n 0,\n );\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GCIO,SAASI,EAAIC,EAAgD,CAClE,OAAOA,EAAQ,OACb,CAACC,EAAqBC,IAAuC,CAC3D,IAAMC,EACJ,OAAOD,GAAY,UAAY,CAAC,MAAMA,CAAO,GAAK,SAASA,CAAO,EAC9DA,EACA,EAEN,OAAOD,EAAcE,CACvB,EACA,CACF,CACF,CDVO,SAASC,EAAQC,EAAgD,CACtE,OAAIA,EAAQ,SAAW,EAAU,EAEnBC,EAAID,CAAO,EAEVA,EAAQ,MACzB","names":["average_exports","__export","average","__toCommonJS","sum","numbers","accumulated","current","value","average","numbers","sum"]}
|
package/average.min.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sum.ts","../src/average.ts"],"sourcesContent":["/**\n * Add all the numbers together in the given array. Treats null, undefined and\n * NaN as zero.\n */\nexport function sum(numbers: (number | null | undefined)[]): number {\n return numbers.reduce(\n (accumulated: number, current: number | null | undefined) => {\n const value =\n typeof current === \"number\" && !isNaN(current) && isFinite(current)\n ? current\n : 0;\n\n return accumulated + value;\n },\n 0,\n );\n}\n","import { sum } from \"./sum\";\n\n/**\n * Average all the numbers together in the given array. Treats null, undefined\n * and NaN as zero.\n */\nexport function average(numbers: (number | null | undefined)[]): number {\n if (numbers.length === 0) return 0;\n\n const total = sum(numbers);\n\n return total / numbers.length;\n}\n"],"mappings":"AAIO,SAASA,EAAIC,EAAgD,CAClE,OAAOA,EAAQ,OACb,CAACC,EAAqBC,IAAuC,CAC3D,IAAMC,EACJ,OAAOD,GAAY,UAAY,CAAC,MAAMA,CAAO,GAAK,SAASA,CAAO,EAC9DA,EACA,EAEN,OAAOD,EAAcE,CACvB,EACA,CACF,CACF,CCVO,SAASC,EAAQC,EAAgD,CACtE,OAAIA,EAAQ,SAAW,EAAU,EAEnBC,EAAID,CAAO,EAEVA,EAAQ,MACzB","names":["sum","numbers","accumulated","current","value","average","numbers","sum"]}
|
package/average.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/sum.ts
|
|
2
|
+
function sum(numbers) {
|
|
3
|
+
return numbers.reduce(
|
|
4
|
+
(accumulated, current) => {
|
|
5
|
+
const value = typeof current === "number" && !isNaN(current) && isFinite(current) ? current : 0;
|
|
6
|
+
return accumulated + value;
|
|
7
|
+
},
|
|
8
|
+
0
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/average.ts
|
|
13
|
+
function average(numbers) {
|
|
14
|
+
if (numbers.length === 0) return 0;
|
|
15
|
+
const total = sum(numbers);
|
|
16
|
+
return total / numbers.length;
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
average
|
|
20
|
+
};
|
package/base64Url.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a base64 string to a base64url string.
|
|
3
|
+
*/
|
|
4
|
+
declare function base64ToBase64URL(base64: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Convert a base64url string to a base64 string.
|
|
7
|
+
*/
|
|
8
|
+
declare function base64UrlToBase64(base64Url: string): string;
|
|
9
|
+
|
|
10
|
+
export { base64ToBase64URL, base64UrlToBase64 };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var a=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var o=(e,r)=>{for(var t in r)a(e,t,{get:r[t],enumerable:!0})},i=(e,r,t,g)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of c(r))!p.call(e,n)&&n!==t&&a(e,n,{get:()=>r[n],enumerable:!(g=s(r,n))||g.enumerable});return e};var l=e=>i(a({},"__esModule",{value:!0}),e);var b={};o(b,{base64ToBase64URL:()=>u,base64UrlToBase64:()=>f});module.exports=l(b);function u(e){return e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function f(e){if(!e)return"";let r=e.replace(/-/g,"+").replace(/_/g,"/"),t=(4-r.length%4)%4;return r+"=".repeat(t)}0&&(module.exports={base64ToBase64URL,base64UrlToBase64});
|
|
2
|
+
//# sourceMappingURL=base64Url.min.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/base64Url.ts"],"sourcesContent":["/**\n * Convert a base64 string to a base64url string.\n */\nexport function base64ToBase64URL(base64: string): string {\n return base64.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\"); // Remove padding\n}\n\n/**\n * Convert a base64url string to a base64 string.\n */\nexport function base64UrlToBase64(base64Url: string): string {\n if (!base64Url) return \"\";\n\n // Replace URL-safe characters\n const base64 = base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n\n // Calculate and add padding\n const padLength = (4 - (base64.length % 4)) % 4;\n return base64 + \"=\".repeat(padLength);\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,sBAAAC,IAAA,eAAAC,EAAAJ,GAGO,SAASE,EAAkBG,EAAwB,CACxD,OAAOA,EAAO,QAAQ,MAAO,GAAG,EAAE,QAAQ,MAAO,GAAG,EAAE,QAAQ,MAAO,EAAE,CACzE,CAKO,SAASF,EAAkBG,EAA2B,CAC3D,GAAI,CAACA,EAAW,MAAO,GAGvB,IAAMD,EAASC,EAAU,QAAQ,KAAM,GAAG,EAAE,QAAQ,KAAM,GAAG,EAGvDC,GAAa,EAAKF,EAAO,OAAS,GAAM,EAC9C,OAAOA,EAAS,IAAI,OAAOE,CAAS,CACtC","names":["base64Url_exports","__export","base64ToBase64URL","base64UrlToBase64","__toCommonJS","base64","base64Url","padLength"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function n(e){return e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function a(e){if(!e)return"";let r=e.replace(/-/g,"+").replace(/_/g,"/"),t=(4-r.length%4)%4;return r+"=".repeat(t)}export{n as base64ToBase64URL,a as base64UrlToBase64};
|
|
2
|
+
//# sourceMappingURL=base64Url.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/base64Url.ts"],"sourcesContent":["/**\n * Convert a base64 string to a base64url string.\n */\nexport function base64ToBase64URL(base64: string): string {\n return base64.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\"); // Remove padding\n}\n\n/**\n * Convert a base64url string to a base64 string.\n */\nexport function base64UrlToBase64(base64Url: string): string {\n if (!base64Url) return \"\";\n\n // Replace URL-safe characters\n const base64 = base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n\n // Calculate and add padding\n const padLength = (4 - (base64.length % 4)) % 4;\n return base64 + \"=\".repeat(padLength);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/base64Url.ts"],"sourcesContent":["/**\n * Convert a base64 string to a base64url string.\n */\nexport function base64ToBase64URL(base64: string): string {\n return base64.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\"); // Remove padding\n}\n\n/**\n * Convert a base64url string to a base64 string.\n */\nexport function base64UrlToBase64(base64Url: string): string {\n if (!base64Url) return \"\";\n\n // Replace URL-safe characters\n const base64 = base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n\n // Calculate and add padding\n const padLength = (4 - (base64.length % 4)) % 4;\n return base64 + \"=\".repeat(padLength);\n}\n"],"mappings":"AAGO,SAASA,EAAkBC,EAAwB,CACxD,OAAOA,EAAO,QAAQ,MAAO,GAAG,EAAE,QAAQ,MAAO,GAAG,EAAE,QAAQ,MAAO,EAAE,CACzE,CAKO,SAASC,EAAkBC,EAA2B,CAC3D,GAAI,CAACA,EAAW,MAAO,GAGvB,IAAMF,EAASE,EAAU,QAAQ,KAAM,GAAG,EAAE,QAAQ,KAAM,GAAG,EAGvDC,GAAa,EAAKH,EAAO,OAAS,GAAM,EAC9C,OAAOA,EAAS,IAAI,OAAOG,CAAS,CACtC","names":["base64ToBase64URL","base64","base64UrlToBase64","base64Url","padLength"]}
|
package/base64Url.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/base64Url.ts
|
|
2
|
+
function base64ToBase64URL(base64) {
|
|
3
|
+
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
4
|
+
}
|
|
5
|
+
function base64UrlToBase64(base64Url) {
|
|
6
|
+
if (!base64Url) return "";
|
|
7
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
8
|
+
const padLength = (4 - base64.length % 4) % 4;
|
|
9
|
+
return base64 + "=".repeat(padLength);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
base64ToBase64URL,
|
|
13
|
+
base64UrlToBase64
|
|
14
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
type AnyDateTime = number | Date | string;
|
|
2
|
+
/**
|
|
3
|
+
* Convert a number (epoch seconds or milliseconds), string (parseable
|
|
4
|
+
* date/time or epoch seconds or milliseconds), or Date object (no conversion)
|
|
5
|
+
* into a Date object.
|
|
6
|
+
*/
|
|
7
|
+
declare function toDate(ts: AnyDateTime): Date;
|
|
8
|
+
/**
|
|
9
|
+
* Returns a date in yyyy-MM format. E.g. '2000-01'.
|
|
10
|
+
*
|
|
11
|
+
* @param dt Specify a date object or default to the current date.
|
|
12
|
+
* @param separator Defaults to '-'.
|
|
13
|
+
*/
|
|
14
|
+
declare function yyyyMm(dt?: Date, separator?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Returns a date in yyyy-MM-dd format. E.g. '2000-01-02'.
|
|
17
|
+
*
|
|
18
|
+
* @param dt Specify a date object or default to the current date.
|
|
19
|
+
* @param separator Defaults to '-'.
|
|
20
|
+
*/
|
|
21
|
+
declare function yyyyMmDd(dt?: Date, separator?: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Returns a date in hh:mm format. E.g. '01:02'.
|
|
24
|
+
*
|
|
25
|
+
* @param dt Specify a date object or default to the current date/time.
|
|
26
|
+
* @param separator Defaults to ':'.
|
|
27
|
+
*/
|
|
28
|
+
declare function hhMm(dt?: Date, separator?: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a date in hh:mm:ss format. E.g. '01:02:03'.
|
|
31
|
+
*
|
|
32
|
+
* @param dt Specify a date object or default to the current date/time.
|
|
33
|
+
* @param separator Defaults to ':'.
|
|
34
|
+
*/
|
|
35
|
+
declare function hhMmSs(dt?: Date, separator?: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Returns a date in hh:mm:ss.SSS format. E.g. '01:02:03.004'.
|
|
38
|
+
*
|
|
39
|
+
* @param dt Specify a date object or default to the current date/time.
|
|
40
|
+
* @param timeSeparator Separator for hh/mm/ss. Defaults to ':'.
|
|
41
|
+
* @param msSeparator Separator before SSS. Defaults to '.'.
|
|
42
|
+
*/
|
|
43
|
+
declare function hhMmSsMs(dt?: Date, timeSeparator?: string, msSeparator?: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the timezone string for the given date. E.g. '+8', '-3.5'.
|
|
46
|
+
* Returns 'Z' for UTC.
|
|
47
|
+
*
|
|
48
|
+
* @param dt Specify a date object or default to the current date/time.
|
|
49
|
+
*/
|
|
50
|
+
declare function tzShort(dt?: Date): string;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the long month name, zero-indexed. E.g. 0 for 'January'.
|
|
53
|
+
*
|
|
54
|
+
* @param month Zero-indexed month.
|
|
55
|
+
* @param locales Specify the locale, e.g. 'en-US', new Intl.Locale("en-US").
|
|
56
|
+
*/
|
|
57
|
+
declare function getLongMonthNameZeroIndexed(month: number, locales?: Intl.LocalesArgument): string;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the long month name, one-indexed. E.g. 1 for 'January'.
|
|
60
|
+
*
|
|
61
|
+
* @param month One-indexed month.
|
|
62
|
+
* @param locales Specify the locale, e.g. 'en-US', new Intl.Locale("en-US").
|
|
63
|
+
*/
|
|
64
|
+
declare function getLongMonthNameOneIndexed(month: number, locales?: Intl.LocalesArgument): string;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the short month name, zero-indexed. E.g. 0 for 'Jan'.
|
|
67
|
+
*
|
|
68
|
+
* @param month Zero-indexed month.
|
|
69
|
+
* @param locales Specify the locale, e.g. 'en-US', new Intl.Locale("en-US").
|
|
70
|
+
*/
|
|
71
|
+
declare function getShortMonthNameZeroIndexed(month: number, locales?: Intl.LocalesArgument): string;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the short month name, one-indexed. E.g. 1 for 'Jan'.
|
|
74
|
+
*
|
|
75
|
+
* @param month One-indexed month.
|
|
76
|
+
* @param locales Specify the locale, e.g. 'en-US', new Intl.Locale("en-US").
|
|
77
|
+
*/
|
|
78
|
+
declare function getShortMonthNameOneIndexed(month: number, locales?: Intl.LocalesArgument): string;
|
|
79
|
+
/**
|
|
80
|
+
* Returns a human-readable string date/time like '2025-01-01 22:31:16Z'.
|
|
81
|
+
* Excludes the milliseconds assuming it is not necessary for display.
|
|
82
|
+
*/
|
|
83
|
+
declare function getDisplayDateTime(ts: AnyDateTime): string;
|
|
84
|
+
|
|
85
|
+
export { type AnyDateTime, getDisplayDateTime, getLongMonthNameOneIndexed, getLongMonthNameZeroIndexed, getShortMonthNameOneIndexed, getShortMonthNameZeroIndexed, hhMm, hhMmSs, hhMmSsMs, toDate, tzShort, yyyyMm, yyyyMmDd };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var h=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},x=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of l(t))!D.call(e,o)&&o!==n&&i(e,o,{get:()=>t[o],enumerable:!(r=f(t,o))||r.enumerable});return e};var y=e=>x(i({},"__esModule",{value:!0}),e);var A={};h(A,{getDisplayDateTime:()=>b,getLongMonthNameOneIndexed:()=>S,getLongMonthNameZeroIndexed:()=>c,getShortMonthNameOneIndexed:()=>I,getShortMonthNameZeroIndexed:()=>m,hhMm:()=>g,hhMmSs:()=>a,hhMmSsMs:()=>d,toDate:()=>u,tzShort:()=>w,yyyyMm:()=>s,yyyyMmDd:()=>M});module.exports=y(A);function p(e){return/^\d+$/.test(e)}function u(e){return typeof e=="number"?e<1e11?new Date(e*1e3):new Date(e):typeof e=="string"?p(e)?u(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 M(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 w(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 S(e,t="default"){return c(e-1,t)}function m(e,t="default"){return new Date(2e3,e,15).toLocaleString(t,{month:"short"})}function I(e,t="default"){return m(e-1,t)}function b(e){return(u(e).toISOString().slice(0,19)+"Z").replace("T"," ")}0&&(module.exports={getDisplayDateTime,getLongMonthNameOneIndexed,getLongMonthNameZeroIndexed,getShortMonthNameOneIndexed,getShortMonthNameZeroIndexed,hhMm,hhMmSs,hhMmSsMs,toDate,tzShort,yyyyMm,yyyyMmDd});
|
|
2
|
+
//# sourceMappingURL=dateTimeStr.min.cjs.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: AnyDateTime) {\n const iso = toDate(ts).toISOString();\n const noMs = iso.slice(0, 19) + \"Z\";\n return noMs.replace(\"T\", \" \");\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,+BAAAC,EAAA,gCAAAC,EAAA,gCAAAC,EAAA,iCAAAC,EAAA,SAAAC,EAAA,WAAAC,EAAA,aAAAC,EAAA,WAAAC,EAAA,YAAAC,EAAA,WAAAC,EAAA,aAAAC,IAAA,eAAAC,EAAAd,GAEA,SAASe,EAAYC,EAAsB,CACzC,MAAO,QAAQ,KAAKA,CAAG,CACzB,CAOO,SAASN,EAAOO,EAAuB,CAC5C,OAAI,OAAOA,GAAO,SAEZA,EAAK,KACA,IAAI,KAAKA,EAAK,GAAI,EAIpB,IAAI,KAAKA,CAAE,EAGhB,OAAOA,GAAO,SACZF,EAAYE,CAAE,EACTP,EAAO,OAAOO,CAAE,CAAC,EAGnB,IAAI,KAAKA,CAAE,EAGbA,CACT,CAQO,SAASL,EAAOM,EAAK,IAAI,KAAQC,EAAY,IAAa,CAC/D,IAAMC,EAAKF,EAAG,YAAY,EACpBG,EAAMH,EAAG,SAAS,EAAI,EAE5B,OAAOE,EAAKD,GAAaE,EAAM,GAAK,IAAMA,EAAMA,EAClD,CAQO,SAASR,EAASK,EAAK,IAAI,KAAQC,EAAY,IAAa,CACjE,IAAMG,EAAMJ,EAAG,QAAQ,EAEvB,OAAON,EAAOM,EAAIC,CAAS,EAAIA,GAAaG,EAAM,GAAK,IAAMA,EAAMA,EACrE,CAQO,SAASf,EAAKW,EAAK,IAAI,KAAQC,EAAY,IAAa,CAC7D,IAAMI,EAAKL,EAAG,SAAS,EACjBM,EAAMN,EAAG,WAAW,EAE1B,OAAQK,EAAK,GAAK,IAAMA,EAAKA,GAAMJ,GAAaK,EAAM,GAAK,IAAMA,EAAMA,EACzE,CAQO,SAAShB,EAAOU,EAAK,IAAI,KAAQC,EAAY,IAAa,CAC/D,IAAMM,EAAMP,EAAG,WAAW,EAE1B,OAAOX,EAAKW,EAAIC,CAAS,EAAIA,GAAaM,EAAM,GAAK,IAAMA,EAAMA,EACnE,CASO,SAAShB,EACdS,EAAK,IAAI,KACTQ,EAAgB,IAChBC,EAAc,IACN,CACR,IAAMC,EAAKV,EAAG,gBAAgB,EAE9B,OACEV,EAAOU,EAAIQ,CAAa,EACxBC,GACCC,EAAK,GAAK,KAAOA,EAAKA,EAAK,IAAM,IAAMA,EAAKA,EAEjD,CAQO,SAASjB,EAAQO,EAAK,IAAI,KAAgB,CAC/C,GAAIA,EAAG,kBAAkB,IAAM,EAC7B,MAAO,IAGT,IAAMW,EAAUX,EAAG,kBAAkB,EAAI,GACzC,OAAOW,GAAW,EAAI,IAAMA,EAAU,OAAOA,CAAO,CACtD,CAQO,SAASzB,EACd0B,EACAC,EAAgC,UACxB,CACR,OAAO,IAAI,KAAK,KAAMD,EAAO,EAAE,EAAE,eAAeC,EAAS,CACvD,MAAO,MACT,CAAC,CACH,CAQO,SAAS5B,EACd2B,EACAC,EAAgC,UACxB,CACR,OAAO3B,EAA4B0B,EAAQ,EAAGC,CAAO,CACvD,CAQO,SAASzB,EACdwB,EACAC,EAAgC,UACxB,CACR,OAAO,IAAI,KAAK,IAAMD,EAAO,EAAE,EAAE,eAAeC,EAAS,CACvD,MAAO,OACT,CAAC,CACH,CAQO,SAAS1B,EACdyB,EACAC,EAAgC,UACxB,CACR,OAAOzB,EAA6BwB,EAAQ,EAAGC,CAAO,CACxD,CAMO,SAAS7B,EAAmBe,EAAiB,CAGlD,OAFYP,EAAOO,CAAE,EAAE,YAAY,EAClB,MAAM,EAAG,EAAE,EAAI,KACpB,QAAQ,IAAK,GAAG,CAC9B","names":["dateTimeStr_exports","__export","getDisplayDateTime","getLongMonthNameOneIndexed","getLongMonthNameZeroIndexed","getShortMonthNameOneIndexed","getShortMonthNameZeroIndexed","hhMm","hhMmSs","hhMmSsMs","toDate","tzShort","yyyyMm","yyyyMmDd","__toCommonJS","isAllDigits","str","ts","dt","separator","yr","mth","day","hr","min","sec","timeSeparator","msSeparator","ms","tzHours","month","locales"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function i(e){return/^\d+$/.test(e)}function o(e){return typeof e=="number"?e<1e11?new Date(e*1e3):new Date(e):typeof e=="string"?i(e)?o(Number(e)):new Date(e):e}function u(e=new Date,t="-"){let n=e.getFullYear(),r=e.getMonth()+1;return n+t+(r<10?"0"+r:r)}function m(e=new Date,t="-"){let n=e.getDate();return u(e,t)+t+(n<10?"0"+n:n)}function s(e=new Date,t=":"){let n=e.getHours(),r=e.getMinutes();return(n<10?"0"+n:n)+t+(r<10?"0"+r:r)}function g(e=new Date,t=":"){let n=e.getSeconds();return s(e,t)+t+(n<10?"0"+n:n)}function f(e=new Date,t=":",n="."){let r=e.getMilliseconds();return g(e,t)+n+(r<10?"00"+r:r<100?"0"+r:r)}function l(e=new Date){if(e.getTimezoneOffset()===0)return"Z";let t=e.getTimezoneOffset()/60;return t>=0?"+"+t:String(t)}function a(e,t="default"){return new Date(2024,e,15).toLocaleString(t,{month:"long"})}function D(e,t="default"){return a(e-1,t)}function c(e,t="default"){return new Date(2e3,e,15).toLocaleString(t,{month:"short"})}function h(e,t="default"){return c(e-1,t)}function x(e){return(o(e).toISOString().slice(0,19)+"Z").replace("T"," ")}export{x as getDisplayDateTime,D as getLongMonthNameOneIndexed,a as getLongMonthNameZeroIndexed,h as getShortMonthNameOneIndexed,c as getShortMonthNameZeroIndexed,s as hhMm,g as hhMmSs,f as hhMmSsMs,o as toDate,l as tzShort,u as yyyyMm,m as yyyyMmDd};
|
|
2
|
+
//# sourceMappingURL=dateTimeStr.min.mjs.map
|
|
@@ -1 +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: AnyDateTime) {\n const iso = toDate(ts).toISOString();\n const noMs = iso.slice(0, 19) + \"Z\";\n return noMs.replace(\"T\", \" \");\n}\n"],"mappings":"
|
|
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: AnyDateTime) {\n const iso = toDate(ts).toISOString();\n const noMs = iso.slice(0, 19) + \"Z\";\n return noMs.replace(\"T\", \" \");\n}\n"],"mappings":"AAEA,SAASA,EAAYC,EAAsB,CACzC,MAAO,QAAQ,KAAKA,CAAG,CACzB,CAOO,SAASC,EAAOC,EAAuB,CAC5C,OAAI,OAAOA,GAAO,SAEZA,EAAK,KACA,IAAI,KAAKA,EAAK,GAAI,EAIpB,IAAI,KAAKA,CAAE,EAGhB,OAAOA,GAAO,SACZH,EAAYG,CAAE,EACTD,EAAO,OAAOC,CAAE,CAAC,EAGnB,IAAI,KAAKA,CAAE,EAGbA,CACT,CAQO,SAASC,EAAOC,EAAK,IAAI,KAAQC,EAAY,IAAa,CAC/D,IAAMC,EAAKF,EAAG,YAAY,EACpBG,EAAMH,EAAG,SAAS,EAAI,EAE5B,OAAOE,EAAKD,GAAaE,EAAM,GAAK,IAAMA,EAAMA,EAClD,CAQO,SAASC,EAASJ,EAAK,IAAI,KAAQC,EAAY,IAAa,CACjE,IAAMI,EAAML,EAAG,QAAQ,EAEvB,OAAOD,EAAOC,EAAIC,CAAS,EAAIA,GAAaI,EAAM,GAAK,IAAMA,EAAMA,EACrE,CAQO,SAASC,EAAKN,EAAK,IAAI,KAAQC,EAAY,IAAa,CAC7D,IAAMM,EAAKP,EAAG,SAAS,EACjBQ,EAAMR,EAAG,WAAW,EAE1B,OAAQO,EAAK,GAAK,IAAMA,EAAKA,GAAMN,GAAaO,EAAM,GAAK,IAAMA,EAAMA,EACzE,CAQO,SAASC,EAAOT,EAAK,IAAI,KAAQC,EAAY,IAAa,CAC/D,IAAMS,EAAMV,EAAG,WAAW,EAE1B,OAAOM,EAAKN,EAAIC,CAAS,EAAIA,GAAaS,EAAM,GAAK,IAAMA,EAAMA,EACnE,CASO,SAASC,EACdX,EAAK,IAAI,KACTY,EAAgB,IAChBC,EAAc,IACN,CACR,IAAMC,EAAKd,EAAG,gBAAgB,EAE9B,OACES,EAAOT,EAAIY,CAAa,EACxBC,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","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"]}
|
package/dateTimeStr.mjs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// src/dateTimeStr.ts
|
|
2
|
+
function isAllDigits(str) {
|
|
3
|
+
return /^\d+$/.test(str);
|
|
4
|
+
}
|
|
5
|
+
function toDate(ts) {
|
|
6
|
+
if (typeof ts === "number") {
|
|
7
|
+
if (ts < 1e11) {
|
|
8
|
+
return new Date(ts * 1e3);
|
|
9
|
+
}
|
|
10
|
+
return new Date(ts);
|
|
11
|
+
}
|
|
12
|
+
if (typeof ts === "string") {
|
|
13
|
+
if (isAllDigits(ts)) {
|
|
14
|
+
return toDate(Number(ts));
|
|
15
|
+
}
|
|
16
|
+
return new Date(ts);
|
|
17
|
+
}
|
|
18
|
+
return ts;
|
|
19
|
+
}
|
|
20
|
+
function yyyyMm(dt = /* @__PURE__ */ new Date(), separator = "-") {
|
|
21
|
+
const yr = dt.getFullYear();
|
|
22
|
+
const mth = dt.getMonth() + 1;
|
|
23
|
+
return yr + separator + (mth < 10 ? "0" + mth : mth);
|
|
24
|
+
}
|
|
25
|
+
function yyyyMmDd(dt = /* @__PURE__ */ new Date(), separator = "-") {
|
|
26
|
+
const day = dt.getDate();
|
|
27
|
+
return yyyyMm(dt, separator) + separator + (day < 10 ? "0" + day : day);
|
|
28
|
+
}
|
|
29
|
+
function hhMm(dt = /* @__PURE__ */ new Date(), separator = ":") {
|
|
30
|
+
const hr = dt.getHours();
|
|
31
|
+
const min = dt.getMinutes();
|
|
32
|
+
return (hr < 10 ? "0" + hr : hr) + separator + (min < 10 ? "0" + min : min);
|
|
33
|
+
}
|
|
34
|
+
function hhMmSs(dt = /* @__PURE__ */ new Date(), separator = ":") {
|
|
35
|
+
const sec = dt.getSeconds();
|
|
36
|
+
return hhMm(dt, separator) + separator + (sec < 10 ? "0" + sec : sec);
|
|
37
|
+
}
|
|
38
|
+
function hhMmSsMs(dt = /* @__PURE__ */ new Date(), timeSeparator = ":", msSeparator = ".") {
|
|
39
|
+
const ms = dt.getMilliseconds();
|
|
40
|
+
return hhMmSs(dt, timeSeparator) + msSeparator + (ms < 10 ? "00" + ms : ms < 100 ? "0" + ms : ms);
|
|
41
|
+
}
|
|
42
|
+
function tzShort(dt = /* @__PURE__ */ new Date()) {
|
|
43
|
+
if (dt.getTimezoneOffset() === 0) {
|
|
44
|
+
return "Z";
|
|
45
|
+
}
|
|
46
|
+
const tzHours = dt.getTimezoneOffset() / 60;
|
|
47
|
+
return tzHours >= 0 ? "+" + tzHours : String(tzHours);
|
|
48
|
+
}
|
|
49
|
+
function getLongMonthNameZeroIndexed(month, locales = "default") {
|
|
50
|
+
return new Date(2024, month, 15).toLocaleString(locales, {
|
|
51
|
+
month: "long"
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function getLongMonthNameOneIndexed(month, locales = "default") {
|
|
55
|
+
return getLongMonthNameZeroIndexed(month - 1, locales);
|
|
56
|
+
}
|
|
57
|
+
function getShortMonthNameZeroIndexed(month, locales = "default") {
|
|
58
|
+
return new Date(2e3, month, 15).toLocaleString(locales, {
|
|
59
|
+
month: "short"
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function getShortMonthNameOneIndexed(month, locales = "default") {
|
|
63
|
+
return getShortMonthNameZeroIndexed(month - 1, locales);
|
|
64
|
+
}
|
|
65
|
+
function getDisplayDateTime(ts) {
|
|
66
|
+
const iso = toDate(ts).toISOString();
|
|
67
|
+
const noMs = iso.slice(0, 19) + "Z";
|
|
68
|
+
return noMs.replace("T", " ");
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
getDisplayDateTime,
|
|
72
|
+
getLongMonthNameOneIndexed,
|
|
73
|
+
getLongMonthNameZeroIndexed,
|
|
74
|
+
getShortMonthNameOneIndexed,
|
|
75
|
+
getShortMonthNameZeroIndexed,
|
|
76
|
+
hhMm,
|
|
77
|
+
hhMmSs,
|
|
78
|
+
hhMmSsMs,
|
|
79
|
+
toDate,
|
|
80
|
+
tzShort,
|
|
81
|
+
yyyyMm,
|
|
82
|
+
yyyyMmDd
|
|
83
|
+
};
|
|
@@ -96,7 +96,7 @@ function getDurationTypeSeparator(style) {
|
|
|
96
96
|
}
|
|
97
97
|
function msToDuration(ms, durationTypeForZero) {
|
|
98
98
|
if (ms === 0) {
|
|
99
|
-
durationTypeForZero = durationTypeForZero
|
|
99
|
+
durationTypeForZero = durationTypeForZero ?? "milliseconds";
|
|
100
100
|
return { [durationTypeForZero]: 0 };
|
|
101
101
|
}
|
|
102
102
|
const duration = {};
|
|
@@ -137,19 +137,18 @@ function msToDuration(ms, durationTypeForZero) {
|
|
|
137
137
|
return duration;
|
|
138
138
|
}
|
|
139
139
|
function durationToMs(duration) {
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const msMs = (_e = duration.milliseconds) != null ? _e : 0;
|
|
140
|
+
const daysMs = (duration.days ?? 0) * MS_PER_DAY;
|
|
141
|
+
const hoursMs = (duration.hours ?? 0) * MS_PER_HOUR;
|
|
142
|
+
const minsMs = (duration.minutes ?? 0) * MS_PER_MINUTE;
|
|
143
|
+
const secsMs = (duration.seconds ?? 0) * MS_PER_SECOND;
|
|
144
|
+
const msMs = duration.milliseconds ?? 0;
|
|
146
145
|
return daysMs + hoursMs + minsMs + secsMs + msMs;
|
|
147
146
|
}
|
|
148
147
|
function durationOrMsToMs(duration) {
|
|
149
148
|
return typeof duration === "number" ? duration : durationToMs(duration);
|
|
150
149
|
}
|
|
151
150
|
function formatDuration(duration, style) {
|
|
152
|
-
style = style
|
|
151
|
+
style = style ?? "short";
|
|
153
152
|
const stylePlural = getDurationStyleForPlural(style);
|
|
154
153
|
const space = getValueAndUnitSeparator(style);
|
|
155
154
|
const a = [];
|
|
@@ -164,8 +163,8 @@ function formatDuration(duration, style) {
|
|
|
164
163
|
return a.join(separator);
|
|
165
164
|
}
|
|
166
165
|
function readableDuration(ms, options) {
|
|
167
|
-
const duration = msToDuration(ms, options
|
|
168
|
-
return formatDuration(duration, options
|
|
166
|
+
const duration = msToDuration(ms, options?.durationTypeForZero);
|
|
167
|
+
return formatDuration(duration, options?.style);
|
|
169
168
|
}
|
|
170
169
|
function elapsed(ms) {
|
|
171
170
|
if (ms > MS_PER_MINUTE) {
|
|
@@ -187,4 +186,3 @@ function elapsed(ms) {
|
|
|
187
186
|
msToDuration,
|
|
188
187
|
readableDuration
|
|
189
188
|
});
|
|
190
|
-
//# sourceMappingURL=duration.js.map
|