d3-time-format-thai
Version:
Thai locale for d3-time-format
92 lines (90 loc) • 4.22 kB
JavaScript
'use client'
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
THAI_LOCALE_DEFINITION: () => THAI_LOCALE_DEFINITION,
TimeFormats: () => TimeFormats,
timeFormat: () => timeFormat,
utcFormat: () => utcFormat
});
module.exports = __toCommonJS(index_exports);
var import_d3_time_format = require("@visx/vendor/d3-time-format");
var TimeFormats = {
FULL_DATE: "%A\u0E17\u0E35\u0E48 %-d %B \u0E1E.\u0E28. %Y",
SHORT_DATE: "%-d %b %y"
};
var THAI_LOCALE_DEFINITION = {
dateTime: "%x %H:%M \u0E19.",
date: TimeFormats.SHORT_DATE,
time: "%H:%M \u0E19.",
periods: ["", ""],
days: ["\u0E27\u0E31\u0E19\u0E2D\u0E32\u0E17\u0E34\u0E15\u0E22\u0E4C", "\u0E27\u0E31\u0E19\u0E08\u0E31\u0E19\u0E17\u0E23\u0E4C", "\u0E27\u0E31\u0E19\u0E2D\u0E31\u0E07\u0E04\u0E32\u0E23", "\u0E27\u0E31\u0E19\u0E1E\u0E38\u0E18", "\u0E27\u0E31\u0E19\u0E1E\u0E24\u0E2B\u0E31\u0E2A", "\u0E27\u0E31\u0E19\u0E28\u0E38\u0E01\u0E23\u0E4C", "\u0E27\u0E31\u0E19\u0E40\u0E2A\u0E32\u0E23\u0E4C"],
shortDays: ["\u0E2D\u0E32.", "\u0E08.", "\u0E2D.", "\u0E1E.", "\u0E1E\u0E24.", "\u0E28.", "\u0E2A."],
months: [
"\u0E21\u0E01\u0E23\u0E32\u0E04\u0E21",
"\u0E01\u0E38\u0E21\u0E20\u0E32\u0E1E\u0E31\u0E19\u0E18\u0E4C",
"\u0E21\u0E35\u0E19\u0E32\u0E04\u0E21",
"\u0E40\u0E21\u0E29\u0E32\u0E22\u0E19",
"\u0E1E\u0E24\u0E29\u0E20\u0E32\u0E04\u0E21",
"\u0E21\u0E34\u0E16\u0E38\u0E19\u0E32\u0E22\u0E19",
"\u0E01\u0E23\u0E01\u0E0E\u0E32\u0E04\u0E21",
"\u0E2A\u0E34\u0E07\u0E2B\u0E32\u0E04\u0E21",
"\u0E01\u0E31\u0E19\u0E22\u0E32\u0E22\u0E19",
"\u0E15\u0E38\u0E25\u0E32\u0E04\u0E21",
"\u0E1E\u0E24\u0E28\u0E08\u0E34\u0E01\u0E32\u0E22\u0E19",
"\u0E18\u0E31\u0E19\u0E27\u0E32\u0E04\u0E21"
],
shortMonths: ["\u0E21.\u0E04.", "\u0E01.\u0E1E.", "\u0E21\u0E35.\u0E04.", "\u0E40\u0E21.\u0E22.", "\u0E1E.\u0E04.", "\u0E21\u0E34.\u0E22.", "\u0E01.\u0E04.", "\u0E2A.\u0E04.", "\u0E01.\u0E22.", "\u0E15.\u0E04.", "\u0E1E.\u0E22.", "\u0E18.\u0E04."]
};
var PLACEHOLDER_YEAR = "##Y";
var PLACEHOLDER_SHORT_YEAR = "##y";
var shortYearRegex = /%y/g;
var yearRegex = /%Y/g;
var placeholderShortYearRegex = new RegExp(PLACEHOLDER_SHORT_YEAR, "g");
var placeholderYearRegex = new RegExp(PLACEHOLDER_YEAR, "g");
var locale = (0, import_d3_time_format.timeFormatLocale)(THAI_LOCALE_DEFINITION);
function factory(originalFormat) {
return (format) => {
const hasYear = format.includes("%Y") || format.includes("%y") || format.includes("%x") || format.includes("%c");
if (hasYear) {
const cleanedFormatter = originalFormat(
format.replace(/%c/g, THAI_LOCALE_DEFINITION.dateTime).replace(/%x/g, THAI_LOCALE_DEFINITION.date).replace(shortYearRegex, PLACEHOLDER_SHORT_YEAR).replace(yearRegex, PLACEHOLDER_YEAR)
);
const fullYearFormat = originalFormat("%Y");
return (time) => {
const fullYear = fullYearFormat(time);
const correctYear = `${Number(fullYear) + 543}`;
const { length } = correctYear;
return cleanedFormatter(time).replace(placeholderShortYearRegex, correctYear.slice(length - 2, length)).replace(placeholderYearRegex, correctYear);
};
}
return originalFormat(format);
};
}
var timeFormat = factory(locale.format);
var utcFormat = factory(locale.utcFormat);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
THAI_LOCALE_DEFINITION,
TimeFormats,
timeFormat,
utcFormat
});