@vuu-ui/vuu-utils 0.13.82 → 0.13.84
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/cjs/packages/vuu-utils/src/date/formatter.js +18 -10
- package/cjs/packages/vuu-utils/src/date/formatter.js.map +1 -1
- package/cjs/packages/vuu-utils/src/date/types.js +1 -0
- package/cjs/packages/vuu-utils/src/date/types.js.map +1 -1
- package/cjs/packages/vuu-utils/src/formatting-utils.js +2 -2
- package/cjs/packages/vuu-utils/src/formatting-utils.js.map +1 -1
- package/cjs/packages/vuu-utils/src/index.js +0 -1
- package/cjs/packages/vuu-utils/src/index.js.map +1 -1
- package/esm/packages/vuu-utils/src/date/formatter.js +18 -10
- package/esm/packages/vuu-utils/src/date/formatter.js.map +1 -1
- package/esm/packages/vuu-utils/src/date/types.js +1 -0
- package/esm/packages/vuu-utils/src/date/types.js.map +1 -1
- package/esm/packages/vuu-utils/src/formatting-utils.js +2 -2
- package/esm/packages/vuu-utils/src/formatting-utils.js.map +1 -1
- package/esm/packages/vuu-utils/src/index.js +1 -1
- package/package.json +8 -8
- package/types/date/formatter.d.ts +6 -1
- package/types/date/index.d.ts +1 -1
- package/types/date/types.d.ts +7 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var date = require('@internationalized/date');
|
|
4
|
-
var tsUtils = require('../ts-utils.js');
|
|
5
4
|
|
|
6
5
|
const baseTimeFormatOptions = {
|
|
7
6
|
hour: "2-digit",
|
|
@@ -55,19 +54,28 @@ const formatConfigByDatePatterns = {
|
|
|
55
54
|
options: { ...baseDateFormatOptions, month: "long" }
|
|
56
55
|
}
|
|
57
56
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
const dateFormatterISO = {
|
|
58
|
+
format: (date) => new Date(+date - date.getTimezoneOffset() * 6e4).toISOString().replace(/T.*/, "")
|
|
59
|
+
};
|
|
60
|
+
function getDateFormatter({ locale, options }) {
|
|
61
|
+
return new date.DateFormatter(locale, options);
|
|
62
|
+
}
|
|
63
|
+
function getDateAndTimeFormatters({ date, time }) {
|
|
64
|
+
const out = [];
|
|
65
|
+
if (date === "yyyy-mm-dd") {
|
|
66
|
+
out.push(dateFormatterISO);
|
|
67
|
+
} else if (date) {
|
|
68
|
+
out.push(getDateFormatter(formatConfigByDatePatterns[date]));
|
|
69
|
+
}
|
|
70
|
+
if (time) {
|
|
71
|
+
out.push(getDateFormatter(formatConfigByTimePatterns[time]));
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
63
74
|
}
|
|
64
75
|
function formatDate(pattern) {
|
|
65
|
-
const formatters =
|
|
76
|
+
const formatters = getDateAndTimeFormatters(pattern);
|
|
66
77
|
return (d) => formatters.map((f) => f.format(d)).join(" ");
|
|
67
78
|
}
|
|
68
|
-
function getDateFormatter(locale, options) {
|
|
69
|
-
return new date.DateFormatter(locale, options);
|
|
70
|
-
}
|
|
71
79
|
|
|
72
80
|
exports.formatDate = formatDate;
|
|
73
81
|
exports.getDateFormatter = getDateFormatter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","sources":["../../../../../../../packages/vuu-utils/src/date/formatter.ts"],"sourcesContent":["import { DateFormatter } from \"@internationalized/date\";\nimport {
|
|
1
|
+
{"version":3,"file":"formatter.js","sources":["../../../../../../../packages/vuu-utils/src/date/formatter.ts"],"sourcesContent":["import { DateFormatter } from \"@internationalized/date\";\nimport { DatePattern, DateTimePattern, TimePattern } from \"./types\";\n\ntype DateTimeFormatConfig = {\n locale: string;\n options: Intl.DateTimeFormatOptions;\n};\n\n// Time format config\nconst baseTimeFormatOptions: Intl.DateTimeFormatOptions = {\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n};\nconst formatConfigByTimePatterns: Record<TimePattern, DateTimeFormatConfig> = {\n \"hh:mm:ss\": {\n locale: \"en-GB\",\n options: { ...baseTimeFormatOptions, hour12: false },\n },\n \"hh:mm:ss a\": {\n locale: \"en-GB\",\n options: { ...baseTimeFormatOptions, hour12: true },\n },\n \"hh:mm:ss.ms\": {\n locale: \"en-GB\",\n options: {\n ...baseTimeFormatOptions,\n hour12: false,\n fractionalSecondDigits: 3,\n },\n },\n};\n\n// Date format config\nconst baseDateFormatOptions: Intl.DateTimeFormatOptions = {\n day: \"2-digit\",\n month: \"2-digit\",\n year: \"numeric\",\n};\nconst formatConfigByDatePatterns: Record<\n Exclude<DatePattern, \"yyyy-mm-dd\">,\n DateTimeFormatConfig\n> = {\n \"dd.mm.yyyy\": {\n locale: \"de-De\",\n options: { ...baseDateFormatOptions },\n },\n \"dd/mm/yyyy\": { locale: \"en-GB\", options: { ...baseDateFormatOptions } },\n \"dd MMM yyyy\": {\n locale: \"en-GB\",\n options: { ...baseDateFormatOptions, month: \"short\" },\n },\n \"dd MMMM yyyy\": {\n locale: \"en-GB\",\n options: { ...baseDateFormatOptions, month: \"long\" },\n },\n \"mm/dd/yyyy\": { locale: \"en-US\", options: { ...baseDateFormatOptions } },\n \"MMM dd, yyyy\": {\n locale: \"en-US\",\n options: { ...baseDateFormatOptions, month: \"short\" },\n },\n \"MMMM dd, yyyy\": {\n locale: \"en-US\",\n options: { ...baseDateFormatOptions, month: \"long\" },\n },\n};\n\nconst dateFormatterISO = {\n format: (date: Date) =>\n new Date(+date - date.getTimezoneOffset() * 60_000)\n .toISOString()\n .replace(/T.*/, \"\"),\n};\n\nexport function getDateFormatter({ locale, options }: DateTimeFormatConfig) {\n return new DateFormatter(locale, options);\n}\n\nfunction getDateAndTimeFormatters({ date, time }: DateTimePattern) {\n const out = [];\n if (date === \"yyyy-mm-dd\") {\n out.push(dateFormatterISO);\n } else if (date) {\n out.push(getDateFormatter(formatConfigByDatePatterns[date]));\n }\n if (time) {\n out.push(getDateFormatter(formatConfigByTimePatterns[time]));\n }\n return out;\n}\n\nexport function formatDate(pattern: DateTimePattern): (d: Date) => string {\n const formatters = getDateAndTimeFormatters(pattern);\n return (d) => formatters.map((f) => f.format(d)).join(\" \");\n}\n"],"names":["DateFormatter"],"mappings":";;;;AASA,MAAM,qBAAoD,GAAA;AAAA,EACxD,IAAM,EAAA,SAAA;AAAA,EACN,MAAQ,EAAA,SAAA;AAAA,EACR,MAAQ,EAAA;AACV,CAAA;AACA,MAAM,0BAAwE,GAAA;AAAA,EAC5E,UAAY,EAAA;AAAA,IACV,MAAQ,EAAA,OAAA;AAAA,IACR,OAAS,EAAA,EAAE,GAAG,qBAAA,EAAuB,QAAQ,KAAM;AAAA,GACrD;AAAA,EACA,YAAc,EAAA;AAAA,IACZ,MAAQ,EAAA,OAAA;AAAA,IACR,OAAS,EAAA,EAAE,GAAG,qBAAA,EAAuB,QAAQ,IAAK;AAAA,GACpD;AAAA,EACA,aAAe,EAAA;AAAA,IACb,MAAQ,EAAA,OAAA;AAAA,IACR,OAAS,EAAA;AAAA,MACP,GAAG,qBAAA;AAAA,MACH,MAAQ,EAAA,KAAA;AAAA,MACR,sBAAwB,EAAA;AAAA;AAC1B;AAEJ,CAAA;AAGA,MAAM,qBAAoD,GAAA;AAAA,EACxD,GAAK,EAAA,SAAA;AAAA,EACL,KAAO,EAAA,SAAA;AAAA,EACP,IAAM,EAAA;AACR,CAAA;AACA,MAAM,0BAGF,GAAA;AAAA,EACF,YAAc,EAAA;AAAA,IACZ,MAAQ,EAAA,OAAA;AAAA,IACR,OAAA,EAAS,EAAE,GAAG,qBAAsB;AAAA,GACtC;AAAA,EACA,YAAA,EAAc,EAAE,MAAQ,EAAA,OAAA,EAAS,SAAS,EAAE,GAAG,uBAAwB,EAAA;AAAA,EACvE,aAAe,EAAA;AAAA,IACb,MAAQ,EAAA,OAAA;AAAA,IACR,OAAS,EAAA,EAAE,GAAG,qBAAA,EAAuB,OAAO,OAAQ;AAAA,GACtD;AAAA,EACA,cAAgB,EAAA;AAAA,IACd,MAAQ,EAAA,OAAA;AAAA,IACR,OAAS,EAAA,EAA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AA,UAAA,GAAa,yBAAyB,OAAO,CAAA;AACnD,EAAA,OAAO,CAAC,CAAA,KAAM,UAAW,CAAA,GAAA,CAAI,CAAC,CAAA,KAAM,CAAE,CAAA,MAAA,CAAO,CAAC,CAAC,CAAE,CAAA,IAAA,CAAK,GAAG,CAAA;AAC3D;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../../../../../packages/vuu-utils/src/date/types.ts"],"sourcesContent":["import { ColumnTypeFormatting } from \"@vuu-ui/vuu-table-types\";\n\nconst supportedDatePatterns = [\n \"dd.mm.yyyy\",\n \"dd/mm/yyyy\",\n \"dd MMM yyyy\",\n \"dd MMMM yyyy\",\n \"mm/dd/yyyy\",\n \"MMM dd, yyyy\",\n \"MMMM dd, yyyy\",\n] as const;\n\nconst supportedTimePatterns = [\n \"hh:mm:ss\",\n \"hh:mm:ss a\",\n \"hh:mm:ss.ms\",\n] as const;\n\nexport const supportedDateTimePatterns = {\n date: supportedDatePatterns,\n time: supportedTimePatterns,\n};\nexport const dateTimeLabelByType = { date: \"Date\", time: \"Time\" } as const;\n\nexport type DatePattern = (typeof supportedDatePatterns)[number];\nexport type TimePattern = (typeof supportedTimePatterns)[number];\n\nexport type DateTimePattern =\n | { date?: DatePattern; time: TimePattern }\n | { date: DatePattern; time?: TimePattern };\n\nexport const isDatePattern = (pattern?: string): pattern is DatePattern =>\n supportedDatePatterns.includes(pattern as DatePattern);\n\nexport const isTimePattern = (pattern?: string): pattern is TimePattern =>\n supportedTimePatterns.includes(pattern as TimePattern);\n\nexport const isDateTimePattern = (\n pattern?: ColumnTypeFormatting[\"pattern\"],\n): pattern is DateTimePattern =>\n isDatePattern(pattern?.date) || isTimePattern(pattern?.time);\n"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../../../../../packages/vuu-utils/src/date/types.ts"],"sourcesContent":["import { ColumnTypeFormatting } from \"@vuu-ui/vuu-table-types\";\n\n/**\n * In the code below we distinguish between an ISO date pattern (yyyy-mm-dd) and\n * other supported date patterns because the ISO format is not supported by the\n * Intl dateFormatting function\n */\nconst supportedDatePatterns = [\n \"yyyy-mm-dd\",\n \"dd.mm.yyyy\",\n \"dd/mm/yyyy\",\n \"dd MMM yyyy\",\n \"dd MMMM yyyy\",\n \"mm/dd/yyyy\",\n \"MMM dd, yyyy\",\n \"MMMM dd, yyyy\",\n] as const;\n\nconst supportedTimePatterns = [\n \"hh:mm:ss\",\n \"hh:mm:ss a\",\n \"hh:mm:ss.ms\",\n] as const;\n\nexport const supportedDateTimePatterns = {\n date: supportedDatePatterns,\n time: supportedTimePatterns,\n};\nexport const dateTimeLabelByType = { date: \"Date\", time: \"Time\" } as const;\n\nexport type DatePattern = (typeof supportedDatePatterns)[number];\nexport type TimePattern = (typeof supportedTimePatterns)[number];\n\nexport type DateTimePattern =\n | { date?: DatePattern; time: TimePattern }\n | { date: DatePattern; time?: TimePattern };\n\nexport const isDatePattern = (pattern?: string): pattern is DatePattern =>\n supportedDatePatterns.includes(pattern as DatePattern);\n\nexport const isTimePattern = (pattern?: string): pattern is TimePattern =>\n supportedTimePatterns.includes(pattern as TimePattern);\n\nexport const isDateTimePattern = (\n pattern?: ColumnTypeFormatting[\"pattern\"],\n): pattern is DateTimePattern =>\n isDatePattern(pattern?.date) || isTimePattern(pattern?.time);\n"],"names":[],"mappings":";;AAOA,MAAM,qBAAwB,GAAA;AAAA,EAC5B,YAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA,YAAA;AAAA,EACA,cAAA;AAAA,EACA;AACF,CAAA;AAEA,MAAM,qBAAwB,GAAA;AAAA,EAC5B,UAAA;AAAA,EACA,YAAA;AAAA,EACA;AACF,CAAA;AAEO,MAAM,yBAA4B,GAAA;AAAA,EACvC,IAAM,EAAA,qBAAA;AAAA,EACN,IAAM,EAAA;AACR;AACO,MAAM,mBAAsB,GAAA,EAAE,IAAM,EAAA,MAAA,EAAQ,MAAM,MAAO;AASzD,MAAM,aAAgB,GAAA,CAAC,OAC5B,KAAA,qBAAA,CAAsB,SAAS,OAAsB;AAEhD,MAAM,aAAgB,GAAA,CAAC,OAC5B,KAAA,qBAAA,CAAsB,SAAS,OAAsB;AAE1C,MAAA,iBAAA,GAAoB,CAC/B,OAEA,KAAA,aAAA,CAAc,SAAS,IAAI,CAAA,IAAK,aAAc,CAAA,OAAA,EAAS,IAAI;;;;;;;;"}
|
|
@@ -52,10 +52,10 @@ const getValueFormatter = (column, serverDataType = column.serverDataType) => {
|
|
|
52
52
|
const { type } = column;
|
|
53
53
|
if (columnUtils.isTypeDescriptor(type) && columnUtils.isMappedValueTypeRenderer(type?.renderer)) {
|
|
54
54
|
return mapFormatter(type.renderer.map);
|
|
55
|
+
} else if (serverDataType === "double" || columnUtils.isTypeDescriptor(type) && type.name === "number") {
|
|
56
|
+
return numericFormatter(column);
|
|
55
57
|
} else if (serverDataType === "string" || serverDataType === "char") {
|
|
56
58
|
return (value) => value;
|
|
57
|
-
} else if (serverDataType === "double") {
|
|
58
|
-
return numericFormatter(column);
|
|
59
59
|
}
|
|
60
60
|
return defaultValueFormatter;
|
|
61
61
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting-utils.js","sources":["../../../../../../packages/vuu-utils/src/formatting-utils.ts"],"sourcesContent":["import { DateTimeDataValueDescriptor } from \"@vuu-ui/vuu-data-types\";\nimport {\n ColumnDescriptor,\n ColumnTypeFormatting,\n ColumnTypeValueMap,\n ValueFormatter,\n} from \"@vuu-ui/vuu-table-types\";\nimport {\n isDateTimeDataValue,\n isMappedValueTypeRenderer,\n isTypeDescriptor,\n} from \"./column-utils\";\nimport { dateTimePattern, formatDate } from \"./date\";\nimport { roundDecimal } from \"./round-decimal\";\n\nexport type ValueFormatters = {\n [key: string]: ValueFormatter;\n};\n\nconst DEFAULT_NUMERIC_FORMAT: ColumnTypeFormatting = {};\n\nexport const defaultValueFormatter = (value: unknown) =>\n value == null ? \"\" : typeof value === \"string\" ? value : value.toString();\n\nconst dateFormatter = (column: DateTimeDataValueDescriptor) => {\n const pattern = dateTimePattern(column.type);\n const formatter = formatDate(pattern);\n\n return (value: unknown) => {\n if (typeof value === \"number\" && value !== 0) {\n return formatter(new Date(value));\n } else {\n return \"\";\n }\n };\n};\n\nexport const numericFormatter = ({\n align = \"right\",\n type,\n}: Partial<ColumnDescriptor>) => {\n if (type === undefined || typeof type === \"string\") {\n return defaultValueFormatter;\n } else {\n const {\n alignOnDecimals = false,\n decimals,\n zeroPad = false,\n } = type.formatting ?? DEFAULT_NUMERIC_FORMAT;\n return (value: unknown) => {\n if (\n typeof value === \"string\" &&\n (value.startsWith(\"Σ\") || value.startsWith(\"[\"))\n ) {\n return value;\n }\n const number =\n typeof value === \"number\"\n ? value\n : typeof value === \"string\"\n ? parseFloat(value)\n : undefined;\n return roundDecimal(number, align, decimals, zeroPad, alignOnDecimals);\n };\n }\n};\n\nconst mapFormatter = (map: ColumnTypeValueMap) => {\n return (value: unknown) => {\n return map[value as string] ?? \"\";\n };\n};\n\nexport const getValueFormatter = (\n column: ColumnDescriptor,\n serverDataType = column.serverDataType,\n): ValueFormatter => {\n if (isDateTimeDataValue(column)) {\n return dateFormatter(column);\n }\n\n const { type } = column;\n if (isTypeDescriptor(type) && isMappedValueTypeRenderer(type?.renderer)) {\n return mapFormatter(type.renderer.map);\n } else if (serverDataType === \"
|
|
1
|
+
{"version":3,"file":"formatting-utils.js","sources":["../../../../../../packages/vuu-utils/src/formatting-utils.ts"],"sourcesContent":["import { DateTimeDataValueDescriptor } from \"@vuu-ui/vuu-data-types\";\nimport {\n ColumnDescriptor,\n ColumnTypeFormatting,\n ColumnTypeValueMap,\n ValueFormatter,\n} from \"@vuu-ui/vuu-table-types\";\nimport {\n isDateTimeDataValue,\n isMappedValueTypeRenderer,\n isTypeDescriptor,\n} from \"./column-utils\";\nimport { dateTimePattern, formatDate } from \"./date\";\nimport { roundDecimal } from \"./round-decimal\";\n\nexport type ValueFormatters = {\n [key: string]: ValueFormatter;\n};\n\nconst DEFAULT_NUMERIC_FORMAT: ColumnTypeFormatting = {};\n\nexport const defaultValueFormatter = (value: unknown) =>\n value == null ? \"\" : typeof value === \"string\" ? value : value.toString();\n\nconst dateFormatter = (column: DateTimeDataValueDescriptor) => {\n const pattern = dateTimePattern(column.type);\n const formatter = formatDate(pattern);\n\n return (value: unknown) => {\n if (typeof value === \"number\" && value !== 0) {\n return formatter(new Date(value));\n } else {\n return \"\";\n }\n };\n};\n\nexport const numericFormatter = ({\n align = \"right\",\n type,\n}: Partial<ColumnDescriptor>) => {\n if (type === undefined || typeof type === \"string\") {\n return defaultValueFormatter;\n } else {\n const {\n alignOnDecimals = false,\n decimals,\n zeroPad = false,\n } = type.formatting ?? DEFAULT_NUMERIC_FORMAT;\n return (value: unknown) => {\n if (\n typeof value === \"string\" &&\n (value.startsWith(\"Σ\") || value.startsWith(\"[\"))\n ) {\n return value;\n }\n const number =\n typeof value === \"number\"\n ? value\n : typeof value === \"string\"\n ? parseFloat(value)\n : undefined;\n return roundDecimal(number, align, decimals, zeroPad, alignOnDecimals);\n };\n }\n};\n\nconst mapFormatter = (map: ColumnTypeValueMap) => {\n return (value: unknown) => {\n return map[value as string] ?? \"\";\n };\n};\n\nexport const getValueFormatter = (\n column: ColumnDescriptor,\n serverDataType = column.serverDataType,\n): ValueFormatter => {\n if (isDateTimeDataValue(column)) {\n return dateFormatter(column);\n }\n\n const { type } = column;\n if (isTypeDescriptor(type) && isMappedValueTypeRenderer(type?.renderer)) {\n return mapFormatter(type.renderer.map);\n } else if (\n serverDataType === \"double\" ||\n (isTypeDescriptor(type) && type.name === \"number\")\n ) {\n return numericFormatter(column);\n } else if (serverDataType === \"string\" || serverDataType === \"char\") {\n return (value: unknown) => value as string;\n }\n return defaultValueFormatter;\n};\n\n/**\n * Lowercases a string and returns as Lowercase typescript type\n *\n * @param str the input string\n * @returns str converted to Lowercase\n */\nexport const lowerCase = (str: string) =>\n str.toLowerCase() as Lowercase<string>;\n"],"names":["dateTimePattern","formatter","formatDate","roundDecimal","isDateTimeDataValue","isTypeDescriptor","isMappedValueTypeRenderer"],"mappings":";;;;;;;;AAmBA,MAAM,yBAA+C,EAAC;AAEzC,MAAA,qBAAA,GAAwB,CAAC,KAAA,KACpC,KAAS,IAAA,IAAA,GAAO,EAAK,GAAA,OAAO,KAAU,KAAA,QAAA,GAAW,KAAQ,GAAA,KAAA,CAAM,QAAS;AAE1E,MAAM,aAAA,GAAgB,CAAC,MAAwC,KAAA;AAC7D,EAAM,MAAA,OAAA,GAAUA,+BAAgB,CAAA,MAAA,CAAO,IAAI,CAAA;AAC3C,EAAM,MAAAC,WAAA,GAAYC,qBAAW,OAAO,CAAA;AAEpC,EAAA,OAAO,CAAC,KAAmB,KAAA;AACzB,IAAA,IAAI,OAAO,KAAA,KAAU,QAAY,IAAA,KAAA,KAAU,CAAG,EAAA;AAC5C,MAAA,OAAOD,WAAU,CAAA,IAAI,IAAK,CAAA,KAAK,CAAC,CAAA;AAAA,KAC3B,MAAA;AACL,MAAO,OAAA,EAAA;AAAA;AACT,GACF;AACF,CAAA;AAEO,MAAM,mBAAmB,CAAC;AAAA,EAC/B,KAAQ,GAAA,OAAA;AAAA,EACR;AACF,CAAiC,KAAA;AAC/B,EAAA,IAAI,IAAS,KAAA,KAAA,CAAA,IAAa,OAAO,IAAA,KAAS,QAAU,EAAA;AAClD,IAAO,OAAA,qBAAA;AAAA,GACF,MAAA;AACL,IAAM,MAAA;AAAA,MACJ,eAAkB,GAAA,KAAA;AAAA,MAClB,QAAA;AAAA,MACA,OAAU,GAAA;AAAA,KACZ,GAAI,KAAK,UAAc,IAAA,sBAAA;AACvB,IAAA,OAAO,CAAC,KAAmB,KAAA;AACzB,MACE,IAAA,OAAO,KAAU,KAAA,QAAA,KAChB,KAAM,CAAA,UAAA,CAAW,QAAG,CAAK,IAAA,KAAA,CAAM,UAAW,CAAA,GAAG,CAC9C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.formatDate;
|
|
|
247
247
|
exports.getDateFormatter = formatter.getDateFormatter;
|
|
248
248
|
exports.dateTimeLabelByType = types.dateTimeLabelByType;
|
|
249
249
|
exports.isDatePattern = types.isDatePattern;
|
|
250
|
-
exports.isDateTimePattern = types.isDateTimePattern;
|
|
251
250
|
exports.isTimePattern = types.isTimePattern;
|
|
252
251
|
exports.supportedDateTimePatterns = types.supportedDateTimePatterns;
|
|
253
252
|
exports.RangeMonitor = debugUtils.RangeMonitor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DateFormatter } from '@internationalized/date';
|
|
2
|
-
import { isNotNullOrUndefined } from '../ts-utils.js';
|
|
3
2
|
|
|
4
3
|
const baseTimeFormatOptions = {
|
|
5
4
|
hour: "2-digit",
|
|
@@ -53,19 +52,28 @@ const formatConfigByDatePatterns = {
|
|
|
53
52
|
options: { ...baseDateFormatOptions, month: "long" }
|
|
54
53
|
}
|
|
55
54
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
const dateFormatterISO = {
|
|
56
|
+
format: (date) => new Date(+date - date.getTimezoneOffset() * 6e4).toISOString().replace(/T.*/, "")
|
|
57
|
+
};
|
|
58
|
+
function getDateFormatter({ locale, options }) {
|
|
59
|
+
return new DateFormatter(locale, options);
|
|
60
|
+
}
|
|
61
|
+
function getDateAndTimeFormatters({ date, time }) {
|
|
62
|
+
const out = [];
|
|
63
|
+
if (date === "yyyy-mm-dd") {
|
|
64
|
+
out.push(dateFormatterISO);
|
|
65
|
+
} else if (date) {
|
|
66
|
+
out.push(getDateFormatter(formatConfigByDatePatterns[date]));
|
|
67
|
+
}
|
|
68
|
+
if (time) {
|
|
69
|
+
out.push(getDateFormatter(formatConfigByTimePatterns[time]));
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
61
72
|
}
|
|
62
73
|
function formatDate(pattern) {
|
|
63
|
-
const formatters =
|
|
74
|
+
const formatters = getDateAndTimeFormatters(pattern);
|
|
64
75
|
return (d) => formatters.map((f) => f.format(d)).join(" ");
|
|
65
76
|
}
|
|
66
|
-
function getDateFormatter(locale, options) {
|
|
67
|
-
return new DateFormatter(locale, options);
|
|
68
|
-
}
|
|
69
77
|
|
|
70
78
|
export { formatDate, getDateFormatter };
|
|
71
79
|
//# sourceMappingURL=formatter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","sources":["../../../../../../../packages/vuu-utils/src/date/formatter.ts"],"sourcesContent":["import { DateFormatter } from \"@internationalized/date\";\nimport {
|
|
1
|
+
{"version":3,"file":"formatter.js","sources":["../../../../../../../packages/vuu-utils/src/date/formatter.ts"],"sourcesContent":["import { DateFormatter } from \"@internationalized/date\";\nimport { DatePattern, DateTimePattern, TimePattern } from \"./types\";\n\ntype DateTimeFormatConfig = {\n locale: string;\n options: Intl.DateTimeFormatOptions;\n};\n\n// Time format config\nconst baseTimeFormatOptions: Intl.DateTimeFormatOptions = {\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n};\nconst formatConfigByTimePatterns: Record<TimePattern, DateTimeFormatConfig> = {\n \"hh:mm:ss\": {\n locale: \"en-GB\",\n options: { ...baseTimeFormatOptions, hour12: false },\n },\n \"hh:mm:ss a\": {\n locale: \"en-GB\",\n options: { ...baseTimeFormatOptions, hour12: true },\n },\n \"hh:mm:ss.ms\": {\n locale: \"en-GB\",\n options: {\n ...baseTimeFormatOptions,\n hour12: false,\n fractionalSecondDigits: 3,\n },\n },\n};\n\n// Date format config\nconst baseDateFormatOptions: Intl.DateTimeFormatOptions = {\n day: \"2-digit\",\n month: \"2-digit\",\n year: \"numeric\",\n};\nconst formatConfigByDatePatterns: Record<\n Exclude<DatePattern, \"yyyy-mm-dd\">,\n DateTimeFormatConfig\n> = {\n \"dd.mm.yyyy\": {\n locale: \"de-De\",\n options: { ...baseDateFormatOptions },\n },\n \"dd/mm/yyyy\": { locale: \"en-GB\", options: { ...baseDateFormatOptions } },\n \"dd MMM yyyy\": {\n locale: \"en-GB\",\n options: { ...baseDateFormatOptions, month: \"short\" },\n },\n \"dd MMMM yyyy\": {\n locale: \"en-GB\",\n options: { ...baseDateFormatOptions, month: \"long\" },\n },\n \"mm/dd/yyyy\": { locale: \"en-US\", options: { ...baseDateFormatOptions } },\n \"MMM dd, yyyy\": {\n locale: \"en-US\",\n options: { ...baseDateFormatOptions, month: \"short\" },\n },\n \"MMMM dd, yyyy\": {\n locale: \"en-US\",\n options: { ...baseDateFormatOptions, month: \"long\" },\n },\n};\n\nconst dateFormatterISO = {\n format: (date: Date) =>\n new Date(+date - date.getTimezoneOffset() * 60_000)\n .toISOString()\n .replace(/T.*/, \"\"),\n};\n\nexport function getDateFormatter({ locale, options }: DateTimeFormatConfig) {\n return new DateFormatter(locale, options);\n}\n\nfunction getDateAndTimeFormatters({ date, time }: DateTimePattern) {\n const out = [];\n if (date === \"yyyy-mm-dd\") {\n out.push(dateFormatterISO);\n } else if (date) {\n out.push(getDateFormatter(formatConfigByDatePatterns[date]));\n }\n if (time) {\n out.push(getDateFormatter(formatConfigByTimePatterns[time]));\n }\n return out;\n}\n\nexport function formatDate(pattern: DateTimePattern): (d: Date) => string {\n const formatters = getDateAndTimeFormatters(pattern);\n return (d) => formatters.map((f) => f.format(d)).join(\" \");\n}\n"],"names":[],"mappings":";;AASA,MAAM,qBAAoD,GAAA;AAAA,EACxD,IAAM,EAAA,SAAA;AAAA,EACN,MAAQ,EAAA,SAAA;AAAA,EACR,MAAQ,EAAA;AACV,CAAA;AACA,MAAM,0BAAwE,GAAA;AAAA,EAC5E,UAAY,EAAA;AAAA,IACV,MAAQ,EAAA,OAAA;AAAA,IACR,OAAS,EAAA,EAAE,GAAG,qBAAA,EAAuB,QAAQ,KAAM;AAAA,GACrD;AAAA,EACA,YAAc,EAAA;AAAA,IACZ,MAAQ,EAAA,OAAA;AAAA,IACR,OAAS,EAAA,EAAE,GAAG,qBAAA,EAAuB,QAAQ,IAAK;AAAA,GACpD;AAAA,EACA,aAAe,EAAA;AAAA,IACb,MAAQ,EAAA,OAAA;AAAA,IACR,OAAS,EAAA;AAAA,MACP,GAAG,qBAAA;AAAA,MACH,MAAQ,EAAA,KAAA;AAAA,MACR,sBAAwB,EAAA;AAAA;AAC1B;AAEJ,CAAA;AAGA,MAAM,qBAAoD,GAAA;AAAA,EACxD,GAAK,EAAA,SAAA;AAAA,EACL,KAAO,EAAA,SAAA;AAAA,EACP,IAAM,EAAA;AACR,CAAA;AACA,MAAM,0BAGF,GAAA;AAAA,EACF,YAAc,EAAA;AAAA,IACZ,MAAQ,EAAA,OAAA;AAAA,IACR,OAAA,EAAS,EAAE,GAAG,qBAAsB;AAAA,GACtC;AAAA,EACA,YAAA,EAAc,EAAE,MAAQ,EAAA,OAAA,EAAS,SAAS,EAAE,GAAG,uBAAwB,EAAA;AAAA,EACvE,aAAe,EAAA;AAAA,IACb,MAAQ,EAAA,OAAA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,CAAI,IAAK,CAAA,gBAAA,CAAiB,0BAA2B,CAAA,IAAI,CAAC,CAAC,CAAA;AAAA;AAE7D,EAAO,OAAA,GAAA;AACT;AAEO,SAAS,WAAW,OAA+C,EAAA;AACxE,EAAM,MAAA,UAAA,GAAa,yBAAyB,OAAO,CAAA;AACnD,EAAA,OAAO,CAAC,CAAA,KAAM,UAAW,CAAA,GAAA,CAAI,CAAC,CAAA,KAAM,CAAE,CAAA,MAAA,CAAO,CAAC,CAAC,CAAE,CAAA,IAAA,CAAK,GAAG,CAAA;AAC3D;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../../../../../packages/vuu-utils/src/date/types.ts"],"sourcesContent":["import { ColumnTypeFormatting } from \"@vuu-ui/vuu-table-types\";\n\nconst supportedDatePatterns = [\n \"dd.mm.yyyy\",\n \"dd/mm/yyyy\",\n \"dd MMM yyyy\",\n \"dd MMMM yyyy\",\n \"mm/dd/yyyy\",\n \"MMM dd, yyyy\",\n \"MMMM dd, yyyy\",\n] as const;\n\nconst supportedTimePatterns = [\n \"hh:mm:ss\",\n \"hh:mm:ss a\",\n \"hh:mm:ss.ms\",\n] as const;\n\nexport const supportedDateTimePatterns = {\n date: supportedDatePatterns,\n time: supportedTimePatterns,\n};\nexport const dateTimeLabelByType = { date: \"Date\", time: \"Time\" } as const;\n\nexport type DatePattern = (typeof supportedDatePatterns)[number];\nexport type TimePattern = (typeof supportedTimePatterns)[number];\n\nexport type DateTimePattern =\n | { date?: DatePattern; time: TimePattern }\n | { date: DatePattern; time?: TimePattern };\n\nexport const isDatePattern = (pattern?: string): pattern is DatePattern =>\n supportedDatePatterns.includes(pattern as DatePattern);\n\nexport const isTimePattern = (pattern?: string): pattern is TimePattern =>\n supportedTimePatterns.includes(pattern as TimePattern);\n\nexport const isDateTimePattern = (\n pattern?: ColumnTypeFormatting[\"pattern\"],\n): pattern is DateTimePattern =>\n isDatePattern(pattern?.date) || isTimePattern(pattern?.time);\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../../../../../packages/vuu-utils/src/date/types.ts"],"sourcesContent":["import { ColumnTypeFormatting } from \"@vuu-ui/vuu-table-types\";\n\n/**\n * In the code below we distinguish between an ISO date pattern (yyyy-mm-dd) and\n * other supported date patterns because the ISO format is not supported by the\n * Intl dateFormatting function\n */\nconst supportedDatePatterns = [\n \"yyyy-mm-dd\",\n \"dd.mm.yyyy\",\n \"dd/mm/yyyy\",\n \"dd MMM yyyy\",\n \"dd MMMM yyyy\",\n \"mm/dd/yyyy\",\n \"MMM dd, yyyy\",\n \"MMMM dd, yyyy\",\n] as const;\n\nconst supportedTimePatterns = [\n \"hh:mm:ss\",\n \"hh:mm:ss a\",\n \"hh:mm:ss.ms\",\n] as const;\n\nexport const supportedDateTimePatterns = {\n date: supportedDatePatterns,\n time: supportedTimePatterns,\n};\nexport const dateTimeLabelByType = { date: \"Date\", time: \"Time\" } as const;\n\nexport type DatePattern = (typeof supportedDatePatterns)[number];\nexport type TimePattern = (typeof supportedTimePatterns)[number];\n\nexport type DateTimePattern =\n | { date?: DatePattern; time: TimePattern }\n | { date: DatePattern; time?: TimePattern };\n\nexport const isDatePattern = (pattern?: string): pattern is DatePattern =>\n supportedDatePatterns.includes(pattern as DatePattern);\n\nexport const isTimePattern = (pattern?: string): pattern is TimePattern =>\n supportedTimePatterns.includes(pattern as TimePattern);\n\nexport const isDateTimePattern = (\n pattern?: ColumnTypeFormatting[\"pattern\"],\n): pattern is DateTimePattern =>\n isDatePattern(pattern?.date) || isTimePattern(pattern?.time);\n"],"names":[],"mappings":"AAOA,MAAM,qBAAwB,GAAA;AAAA,EAC5B,YAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA,YAAA;AAAA,EACA,cAAA;AAAA,EACA;AACF,CAAA;AAEA,MAAM,qBAAwB,GAAA;AAAA,EAC5B,UAAA;AAAA,EACA,YAAA;AAAA,EACA;AACF,CAAA;AAEO,MAAM,yBAA4B,GAAA;AAAA,EACvC,IAAM,EAAA,qBAAA;AAAA,EACN,IAAM,EAAA;AACR;AACO,MAAM,mBAAsB,GAAA,EAAE,IAAM,EAAA,MAAA,EAAQ,MAAM,MAAO;AASzD,MAAM,aAAgB,GAAA,CAAC,OAC5B,KAAA,qBAAA,CAAsB,SAAS,OAAsB;AAEhD,MAAM,aAAgB,GAAA,CAAC,OAC5B,KAAA,qBAAA,CAAsB,SAAS,OAAsB;AAE1C,MAAA,iBAAA,GAAoB,CAC/B,OAEA,KAAA,aAAA,CAAc,SAAS,IAAI,CAAA,IAAK,aAAc,CAAA,OAAA,EAAS,IAAI;;;;"}
|
|
@@ -50,10 +50,10 @@ const getValueFormatter = (column, serverDataType = column.serverDataType) => {
|
|
|
50
50
|
const { type } = column;
|
|
51
51
|
if (isTypeDescriptor(type) && isMappedValueTypeRenderer(type?.renderer)) {
|
|
52
52
|
return mapFormatter(type.renderer.map);
|
|
53
|
+
} else if (serverDataType === "double" || isTypeDescriptor(type) && type.name === "number") {
|
|
54
|
+
return numericFormatter(column);
|
|
53
55
|
} else if (serverDataType === "string" || serverDataType === "char") {
|
|
54
56
|
return (value) => value;
|
|
55
|
-
} else if (serverDataType === "double") {
|
|
56
|
-
return numericFormatter(column);
|
|
57
57
|
}
|
|
58
58
|
return defaultValueFormatter;
|
|
59
59
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting-utils.js","sources":["../../../../../../packages/vuu-utils/src/formatting-utils.ts"],"sourcesContent":["import { DateTimeDataValueDescriptor } from \"@vuu-ui/vuu-data-types\";\nimport {\n ColumnDescriptor,\n ColumnTypeFormatting,\n ColumnTypeValueMap,\n ValueFormatter,\n} from \"@vuu-ui/vuu-table-types\";\nimport {\n isDateTimeDataValue,\n isMappedValueTypeRenderer,\n isTypeDescriptor,\n} from \"./column-utils\";\nimport { dateTimePattern, formatDate } from \"./date\";\nimport { roundDecimal } from \"./round-decimal\";\n\nexport type ValueFormatters = {\n [key: string]: ValueFormatter;\n};\n\nconst DEFAULT_NUMERIC_FORMAT: ColumnTypeFormatting = {};\n\nexport const defaultValueFormatter = (value: unknown) =>\n value == null ? \"\" : typeof value === \"string\" ? value : value.toString();\n\nconst dateFormatter = (column: DateTimeDataValueDescriptor) => {\n const pattern = dateTimePattern(column.type);\n const formatter = formatDate(pattern);\n\n return (value: unknown) => {\n if (typeof value === \"number\" && value !== 0) {\n return formatter(new Date(value));\n } else {\n return \"\";\n }\n };\n};\n\nexport const numericFormatter = ({\n align = \"right\",\n type,\n}: Partial<ColumnDescriptor>) => {\n if (type === undefined || typeof type === \"string\") {\n return defaultValueFormatter;\n } else {\n const {\n alignOnDecimals = false,\n decimals,\n zeroPad = false,\n } = type.formatting ?? DEFAULT_NUMERIC_FORMAT;\n return (value: unknown) => {\n if (\n typeof value === \"string\" &&\n (value.startsWith(\"Σ\") || value.startsWith(\"[\"))\n ) {\n return value;\n }\n const number =\n typeof value === \"number\"\n ? value\n : typeof value === \"string\"\n ? parseFloat(value)\n : undefined;\n return roundDecimal(number, align, decimals, zeroPad, alignOnDecimals);\n };\n }\n};\n\nconst mapFormatter = (map: ColumnTypeValueMap) => {\n return (value: unknown) => {\n return map[value as string] ?? \"\";\n };\n};\n\nexport const getValueFormatter = (\n column: ColumnDescriptor,\n serverDataType = column.serverDataType,\n): ValueFormatter => {\n if (isDateTimeDataValue(column)) {\n return dateFormatter(column);\n }\n\n const { type } = column;\n if (isTypeDescriptor(type) && isMappedValueTypeRenderer(type?.renderer)) {\n return mapFormatter(type.renderer.map);\n } else if (serverDataType === \"
|
|
1
|
+
{"version":3,"file":"formatting-utils.js","sources":["../../../../../../packages/vuu-utils/src/formatting-utils.ts"],"sourcesContent":["import { DateTimeDataValueDescriptor } from \"@vuu-ui/vuu-data-types\";\nimport {\n ColumnDescriptor,\n ColumnTypeFormatting,\n ColumnTypeValueMap,\n ValueFormatter,\n} from \"@vuu-ui/vuu-table-types\";\nimport {\n isDateTimeDataValue,\n isMappedValueTypeRenderer,\n isTypeDescriptor,\n} from \"./column-utils\";\nimport { dateTimePattern, formatDate } from \"./date\";\nimport { roundDecimal } from \"./round-decimal\";\n\nexport type ValueFormatters = {\n [key: string]: ValueFormatter;\n};\n\nconst DEFAULT_NUMERIC_FORMAT: ColumnTypeFormatting = {};\n\nexport const defaultValueFormatter = (value: unknown) =>\n value == null ? \"\" : typeof value === \"string\" ? value : value.toString();\n\nconst dateFormatter = (column: DateTimeDataValueDescriptor) => {\n const pattern = dateTimePattern(column.type);\n const formatter = formatDate(pattern);\n\n return (value: unknown) => {\n if (typeof value === \"number\" && value !== 0) {\n return formatter(new Date(value));\n } else {\n return \"\";\n }\n };\n};\n\nexport const numericFormatter = ({\n align = \"right\",\n type,\n}: Partial<ColumnDescriptor>) => {\n if (type === undefined || typeof type === \"string\") {\n return defaultValueFormatter;\n } else {\n const {\n alignOnDecimals = false,\n decimals,\n zeroPad = false,\n } = type.formatting ?? DEFAULT_NUMERIC_FORMAT;\n return (value: unknown) => {\n if (\n typeof value === \"string\" &&\n (value.startsWith(\"Σ\") || value.startsWith(\"[\"))\n ) {\n return value;\n }\n const number =\n typeof value === \"number\"\n ? value\n : typeof value === \"string\"\n ? parseFloat(value)\n : undefined;\n return roundDecimal(number, align, decimals, zeroPad, alignOnDecimals);\n };\n }\n};\n\nconst mapFormatter = (map: ColumnTypeValueMap) => {\n return (value: unknown) => {\n return map[value as string] ?? \"\";\n };\n};\n\nexport const getValueFormatter = (\n column: ColumnDescriptor,\n serverDataType = column.serverDataType,\n): ValueFormatter => {\n if (isDateTimeDataValue(column)) {\n return dateFormatter(column);\n }\n\n const { type } = column;\n if (isTypeDescriptor(type) && isMappedValueTypeRenderer(type?.renderer)) {\n return mapFormatter(type.renderer.map);\n } else if (\n serverDataType === \"double\" ||\n (isTypeDescriptor(type) && type.name === \"number\")\n ) {\n return numericFormatter(column);\n } else if (serverDataType === \"string\" || serverDataType === \"char\") {\n return (value: unknown) => value as string;\n }\n return defaultValueFormatter;\n};\n\n/**\n * Lowercases a string and returns as Lowercase typescript type\n *\n * @param str the input string\n * @returns str converted to Lowercase\n */\nexport const lowerCase = (str: string) =>\n str.toLowerCase() as Lowercase<string>;\n"],"names":[],"mappings":";;;;;;AAmBA,MAAM,yBAA+C,EAAC;AAEzC,MAAA,qBAAA,GAAwB,CAAC,KAAA,KACpC,KAAS,IAAA,IAAA,GAAO,EAAK,GAAA,OAAO,KAAU,KAAA,QAAA,GAAW,KAAQ,GAAA,KAAA,CAAM,QAAS;AAE1E,MAAM,aAAA,GAAgB,CAAC,MAAwC,KAAA;AAC7D,EAAM,MAAA,OAAA,GAAU,eAAgB,CAAA,MAAA,CAAO,IAAI,CAAA;AAC3C,EAAM,MAAA,SAAA,GAAY,WAAW,OAAO,CAAA;AAEpC,EAAA,OAAO,CAAC,KAAmB,KAAA;AACzB,IAAA,IAAI,OAAO,KAAA,KAAU,QAAY,IAAA,KAAA,KAAU,CAAG,EAAA;AAC5C,MAAA,OAAO,SAAU,CAAA,IAAI,IAAK,CAAA,KAAK,CAAC,CAAA;AAAA,KAC3B,MAAA;AACL,MAAO,OAAA,EAAA;AAAA;AACT,GACF;AACF,CAAA;AAEO,MAAM,mBAAmB,CAAC;AAAA,EAC/B,KAAQ,GAAA,OAAA;AAAA,EACR;AACF,CAAiC,KAAA;AAC/B,EAAA,IAAI,IAAS,KAAA,KAAA,CAAA,IAAa,OAAO,IAAA,KAAS,QAAU,EAAA;AAClD,IAAO,OAAA,qBAAA;AAAA,GACF,MAAA;AACL,IAAM,MAAA;AAAA,MACJ,eAAkB,GAAA,KAAA;AAAA,MAClB,QAAA;AAAA,MACA,OAAU,GAAA;AAAA,KACZ,GAAI,KAAK,UAAc,IAAA,sBAAA;AACvB,IAAA,OAAO,CAAC,KAAmB,KAAA;AACzB,MACE,IAAA,OAAO,KAAU,KAAA,QAAA,KAChB,KAAM,CAAA,UAAA,CAAW,QAAG,CAAK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@@ -19,7 +19,7 @@ export { NO_CONFIG_CHANGES, NoFilter, NoSort, dataSourceRowToEntity, hasBaseFilt
|
|
|
19
19
|
export { Time, asTimeString, decrementTimeUnitValue, incrementTimeUnitValue, isValidTimeString, toCalendarDate, updateTimeString, zeroTime, zeroTimeUnit } from './date/date-utils.js';
|
|
20
20
|
export { dateTimePattern, defaultPatternsByType, fallbackDateTimePattern } from './date/dateTimePattern.js';
|
|
21
21
|
export { formatDate, getDateFormatter } from './date/formatter.js';
|
|
22
|
-
export { dateTimeLabelByType, isDatePattern,
|
|
22
|
+
export { dateTimeLabelByType, isDatePattern, isTimePattern, supportedDateTimePatterns } from './date/types.js';
|
|
23
23
|
export { RangeMonitor } from './debug-utils.js';
|
|
24
24
|
export { applyFilterToColumns, extractFilterForColumn, filtersAreEqual, getColumnValueFromFilter, isAndFilter, isBetweenFilter, isBetweenOperator, isCompleteFilter, isExtendedFilter, isFilterClause, isFilteredColumn, isInFilter, isMultiClauseFilter, isMultiValueFilter, isNamedFilter, isOrFilter, isSerializableFilter, isSingleValueFilter, isValidFilterClauseOp, stripFilterFromColumns } from './filters/filter-utils.js';
|
|
25
25
|
export { ONE_DAY_IN_MILLIS, dateFilterAsQuery, filterAsQuery } from './filters/filterAsQuery.js';
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.13.
|
|
2
|
+
"version": "0.13.84",
|
|
3
3
|
"author": "heswell",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"types": "types/index.d.ts",
|
|
6
6
|
"devDependencies": {
|
|
7
|
-
"@vuu-ui/vuu-data-types": "0.13.
|
|
8
|
-
"@vuu-ui/vuu-table-types": "0.13.
|
|
9
|
-
"@vuu-ui/vuu-filter-types": "0.13.
|
|
10
|
-
"@vuu-ui/vuu-protocol-types": "0.13.
|
|
7
|
+
"@vuu-ui/vuu-data-types": "0.13.84",
|
|
8
|
+
"@vuu-ui/vuu-table-types": "0.13.84",
|
|
9
|
+
"@vuu-ui/vuu-filter-types": "0.13.84",
|
|
10
|
+
"@vuu-ui/vuu-protocol-types": "0.13.84"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
13
|
"@internationalized/date": "^3.0.0",
|
|
14
|
-
"@vuu-ui/vuu-filter-parser": "0.13.
|
|
14
|
+
"@vuu-ui/vuu-filter-parser": "0.13.84",
|
|
15
15
|
"clsx": "^2.0.0",
|
|
16
|
-
"react": "^19.1
|
|
17
|
-
"react-dom": "^19.1
|
|
16
|
+
"react": "^19.2.1",
|
|
17
|
+
"react-dom": "^19.2.1"
|
|
18
18
|
},
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"files": [
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { DateFormatter } from "@internationalized/date";
|
|
2
2
|
import { DateTimePattern } from "./types";
|
|
3
|
+
type DateTimeFormatConfig = {
|
|
4
|
+
locale: string;
|
|
5
|
+
options: Intl.DateTimeFormatOptions;
|
|
6
|
+
};
|
|
7
|
+
export declare function getDateFormatter({ locale, options }: DateTimeFormatConfig): DateFormatter;
|
|
3
8
|
export declare function formatDate(pattern: DateTimePattern): (d: Date) => string;
|
|
4
|
-
export
|
|
9
|
+
export {};
|
package/types/date/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { asTimeString, decrementTimeUnitValue, incrementTimeUnitValue, isValidTimeString, Time, toCalendarDate, type DateStringISO, type Hours, type Minutes, type Seconds, type TimeString, type TimeUnit, type TimeUnitValue, updateTimeString, zeroTime, zeroTimeUnit, } from "./date-utils";
|
|
2
2
|
export { dateTimePattern, defaultPatternsByType, fallbackDateTimePattern, } from "./dateTimePattern";
|
|
3
3
|
export * from "./formatter";
|
|
4
|
-
export { dateTimeLabelByType, isDatePattern,
|
|
4
|
+
export { dateTimeLabelByType, isDatePattern, isTimePattern, supportedDateTimePatterns, type DatePattern, type DateTimePattern, type TimePattern, } from "./types";
|
package/types/date/types.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { ColumnTypeFormatting } from "@vuu-ui/vuu-table-types";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* In the code below we distinguish between an ISO date pattern (yyyy-mm-dd) and
|
|
4
|
+
* other supported date patterns because the ISO format is not supported by the
|
|
5
|
+
* Intl dateFormatting function
|
|
6
|
+
*/
|
|
7
|
+
declare const supportedDatePatterns: readonly ["yyyy-mm-dd", "dd.mm.yyyy", "dd/mm/yyyy", "dd MMM yyyy", "dd MMMM yyyy", "mm/dd/yyyy", "MMM dd, yyyy", "MMMM dd, yyyy"];
|
|
3
8
|
declare const supportedTimePatterns: readonly ["hh:mm:ss", "hh:mm:ss a", "hh:mm:ss.ms"];
|
|
4
9
|
export declare const supportedDateTimePatterns: {
|
|
5
|
-
date: readonly ["dd.mm.yyyy", "dd/mm/yyyy", "dd MMM yyyy", "dd MMMM yyyy", "mm/dd/yyyy", "MMM dd, yyyy", "MMMM dd, yyyy"];
|
|
10
|
+
date: readonly ["yyyy-mm-dd", "dd.mm.yyyy", "dd/mm/yyyy", "dd MMM yyyy", "dd MMMM yyyy", "mm/dd/yyyy", "MMM dd, yyyy", "MMMM dd, yyyy"];
|
|
6
11
|
time: readonly ["hh:mm:ss", "hh:mm:ss a", "hh:mm:ss.ms"];
|
|
7
12
|
};
|
|
8
13
|
export declare const dateTimeLabelByType: {
|