feat: add doc template function address without area
This commit is contained in:
parent
4031a8121c
commit
ee53b8cbc4
1 changed files with 23 additions and 0 deletions
|
|
@ -146,6 +146,9 @@ export class DocTemplateController extends Controller {
|
||||||
dateLongEN: (date: string) => dateFormat({ date, locale: "en-US" }),
|
dateLongEN: (date: string) => dateFormat({ date, locale: "en-US" }),
|
||||||
dateTimeLongEN: (date: string) =>
|
dateTimeLongEN: (date: string) =>
|
||||||
dateFormat({ date, withTime: true, locale: "en-US", monthStyle: "long" }),
|
dateFormat({ date, withTime: true, locale: "en-US", monthStyle: "long" }),
|
||||||
|
address,
|
||||||
|
addressTH: (addr: FullAddress) => address(addr, "th"),
|
||||||
|
addressEN: (addr: FullAddress) => address(addr, "en"),
|
||||||
addressFull,
|
addressFull,
|
||||||
addressFullTH: (addr: FullAddress) => addressFull(addr, "th"),
|
addressFullTH: (addr: FullAddress) => addressFull(addr, "th"),
|
||||||
addressFullEN: (addr: FullAddress) => addressFull(addr, "en"),
|
addressFullEN: (addr: FullAddress) => addressFull(addr, "en"),
|
||||||
|
|
@ -193,6 +196,26 @@ type FullAddress = {
|
||||||
en?: boolean;
|
en?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function address(addr: FullAddress, lang: "th" | "en" = "en") {
|
||||||
|
let fragments: string[];
|
||||||
|
switch (lang) {
|
||||||
|
case "th":
|
||||||
|
fragments = [`${addr.address},`];
|
||||||
|
if (addr.moo) fragments.push(`หมู่ ${addr.moo},`);
|
||||||
|
if (addr.soi) fragments.push(`ซอย ${addr.soi},`);
|
||||||
|
if (addr.street) fragments.push(`ถนน${addr.street},`);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fragments = [`${addr.addressEN},`];
|
||||||
|
if (addr.mooEN) fragments.push(`Moo ${addr.mooEN},`);
|
||||||
|
if (addr.soiEN) fragments.push(`Soi ${addr.soiEN},`);
|
||||||
|
if (addr.streetEN) fragments.push(`${addr.streetEN} Rd.`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fragments.join(" ");
|
||||||
|
}
|
||||||
|
|
||||||
function addressFull(addr: FullAddress, lang: "th" | "en" = "en") {
|
function addressFull(addr: FullAddress, lang: "th" | "en" = "en") {
|
||||||
let fragments: string[];
|
let fragments: string[];
|
||||||
switch (lang) {
|
switch (lang) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue