@ham2k/extension-sdk 0.5.1 → 0.5.2
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/dist/index.d.ts +1 -1
- package/dist/templates.js +13 -0
- package/docs/templates.md +12 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/templates.js
CHANGED
|
@@ -38,6 +38,19 @@ function registerFilters(liquid2) {
|
|
|
38
38
|
const chosen = String(digits ?? "");
|
|
39
39
|
return String(value ?? "").replace(/[0159]/g, (digit) => chosen.includes(digit) ? CUT_NUMBERS[digit] : digit);
|
|
40
40
|
});
|
|
41
|
+
liquid2.registerFilter(
|
|
42
|
+
"refLabels",
|
|
43
|
+
(value) => (Array.isArray(value) ? value : []).flatMap((ref) => {
|
|
44
|
+
const label = [ref?.shortLabel, ref?.label, ref?.ref].map((text) => typeof text === "string" || typeof text === "number" ? String(text).trim() : "").find((text) => text !== "");
|
|
45
|
+
return label === void 0 ? [] : [label];
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
liquid2.registerFilter("sentence", (value, separator = ", ", final = " & ") => {
|
|
49
|
+
if (!Array.isArray(value)) return String(value ?? "");
|
|
50
|
+
const items = value.map((item) => String(item ?? "").trim()).filter((item) => item !== "");
|
|
51
|
+
if (items.length < 2) return items.join("");
|
|
52
|
+
return `${items.slice(0, -1).join(String(separator))}${String(final)}${items[items.length - 1]}`;
|
|
53
|
+
});
|
|
41
54
|
}
|
|
42
55
|
const CUT_NUMBERS = { "0": "T", "1": "A", "5": "E", "9": "N" };
|
|
43
56
|
class TemplateError extends Error {
|
package/docs/templates.md
CHANGED
|
@@ -34,7 +34,9 @@ about 2 µs each.
|
|
|
34
34
|
the namespaces are deliberately polo's. The syntax around them does not:
|
|
35
35
|
`{{#if}}` is `{% if %}{% endif %}`, `{{#each}}` is `{% for %}{% endfor %}`,
|
|
36
36
|
`{{> Partial}}` has no equivalent, and helpers are filters
|
|
37
|
-
(`{{ dash x }}` → `{{ x | dash }}`).
|
|
37
|
+
(`{{ dash x }}` → `{{ x | dash }}`). polo's
|
|
38
|
+
`{{#join op.refs separator=", " final=" & "}}{{or shortLabel label key}}{{/join}}`
|
|
39
|
+
is `{{ op.refs | refLabels | sentence }}`.
|
|
38
40
|
|
|
39
41
|
## What a template can name
|
|
40
42
|
|
|
@@ -122,7 +124,7 @@ with nothing to say it was invented.
|
|
|
122
124
|
|
|
123
125
|
All of Liquid's own (`date`, `downcase`, `upcase`, `strip`, `default`,
|
|
124
126
|
`join`, `size`, `first`, `last`, `round`, `truncate`, `replace`, `map`,
|
|
125
|
-
`where`, …), plus
|
|
127
|
+
`where`, …), plus six:
|
|
126
128
|
|
|
127
129
|
| filter | does | example |
|
|
128
130
|
|---|---|---|
|
|
@@ -130,12 +132,20 @@ All of Liquid's own (`date`, `downcase`, `upcase`, `strip`, `default`,
|
|
|
130
132
|
| `alnum` | strip to alphanumerics | `2026-07-27` → `20260727` |
|
|
131
133
|
| `pad: n` | zero-pad on the left to `n` characters (default 3); **blank stays blank** | `7` → `007` |
|
|
132
134
|
| `cut: "digits"` | CW cut numbers for the listed digits, of `0`→`T` `1`→`A` `5`→`E` `9`→`N`; default `"09"` | `599` → `5NN`, `{{ 9 \| pad: 3 \| cut }}` → `TTN` |
|
|
135
|
+
| `refLabels` | a list of refs → each one's `shortLabel`, else `label`, else `ref`; a ref with none of them is skipped — an operation's contest ref HAS a label (`CQ WPX CW`) and is listed | `op.refs` → `POTA US-1234`, `KFF-9999` |
|
|
136
|
+
| `sentence: "sep", "final"` | joins a list with a different LAST separator (defaults `", "` and `" & "`); blanks are dropped | `A, B & C`, `A & B` |
|
|
133
137
|
|
|
134
138
|
`pad` leaves a blank alone because a CW message can be keyed before the
|
|
135
139
|
serial field has a number, and `000` sent in that gap is a serial the log
|
|
136
140
|
will never agree with. Order matters with `cut`: pad first, or the padding
|
|
137
141
|
zeros go out uncut.
|
|
138
142
|
|
|
143
|
+
`refLabels` exists because `map` reads one field: `map: "shortLabel"` drops a
|
|
144
|
+
reference that resolved to nothing, since it carries no labels — an
|
|
145
|
+
operation at an unlisted park would print as though it had none. Liquid's own
|
|
146
|
+
`array_to_sentence_string` is the near miss for `sentence`: it always writes
|
|
147
|
+
the serial comma (`A, B, & C`).
|
|
148
|
+
|
|
139
149
|
`alnum` is app-polo's `compact` helper under a different name: Liquid already
|
|
140
150
|
has a `compact` (it drops nils from an **array**, and `op.refs`/`qso.refs` are
|
|
141
151
|
arrays), and `registerFilter` overwrites without warning, so taking that name
|