Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { type Static, Type } from "npm:@sinclair/typebox";
const currencyCode = Type.Union([
Type.Literal("USD"),
Type.Literal("EUR"),
]);
const currency = Type.Object({
code: currencyCode,
rate: Type.Optional(Type.Number()),
});
const language = Type.Union([
Type.Literal("fr-FR"),
Type.Literal("en-US"),
]);
const textfield = Type.Union([
Type.String(),
Type.Object({}, {
additionalProperties: Type.String(),
}),
]);
const entity = Type.Object({
name: textfield,
email: Type.Optional(textfield),
address: Type.Optional(textfield),
phone: Type.Optional(textfield),
website: Type.Optional(textfield),
});
const item = Type.Object({
title: textfield,
quantity: Type.Number(),
price: Type.Number(),
});
export const schema = Type.Object({
id: Type.String(),
issued: Type.String({
format: "date",
}),
due: Type.String({
format: "date",
}),
currencies: Type.Array(currency),
logo: Type.Optional(Type.String({ description: "Your logo." })),
from: entity,
to: entity,
tax: Type.Optional(Type.Number()),
items: Type.Array(item),
note: Type.Optional(textfield),
});
export type Invoice = Static<typeof schema>;
type InvoiceItem = Static<typeof item>;
export type Language = Static<typeof language>;
type Entity = Static<typeof entity>;
export type Currency = Static<typeof currency>;
type RenderParams = {
to: string[];
from: string[];
title: string;
note: string;
details: string[][];
table: Table;
};
type Table = {
columns: string[];
rows: string[][];
summary: string[][];
};
function extractTitle(id: string, lang: Language) {
switch (lang) {
case "fr-FR":
return `Facture ${id}`;
case "en-US":
return `Invoice ${id}`;
}
}
function getTableColumns(lang: Language) {
switch (lang) {
case "fr-FR":
return [];
case "en-US":
return [];
}
}
function formatPrice(price: Number, currency: Currency) {
switch (currency.code) {
pomdtr-invoice_schema.web.val.run
April 20, 2024