@stll/agent-input 0.4.4 → 0.5.0

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 CHANGED
@@ -42,6 +42,10 @@ type EliOptions = {
42
42
  readCitation?: ((text: string) => string | undefined) | undefined;
43
43
  /** The corrective call when the input is not an ELI. */
44
44
  hint?: string | undefined;
45
+ /** Prefixes of the URNs that name works of publishers without ELIs
46
+ * (`"urn:hu:magyar-kozlony:"`). A work URN is one lower-case slug after
47
+ * its prefix; it is read in any case, as written otherwise. */
48
+ urnPrefixes?: readonly string[] | undefined;
45
49
  };
46
50
  /**
47
51
  * Read an ELI an agent spelled its own way, as the canonical work identifier
package/dist/index.js CHANGED
@@ -223,6 +223,7 @@ const normalizeDateFormatSpec = (input) => {
223
223
  };
224
224
  // src/eli.ts
225
225
  const ELI_EXPECTED = "an ELI";
226
+ const URN_SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
226
227
  const ELI_HINT = "Pass the eli a search result returned.";
227
228
  /** An origin with a scheme, or a bare host a model pasted without one; a bare
228
229
  * host needs a dot so `cz/sb/...` is never taken for one. */
@@ -287,6 +288,13 @@ const normalizeEli = (input, options) => {
287
288
  });
288
289
  if (typeof input !== "string") return notAnEli();
289
290
  const trimmed = input.trim();
291
+ const lowered = trimmed.toLowerCase();
292
+ const urnPrefix = options.urnPrefixes?.find((prefix) => lowered.startsWith(prefix.toLowerCase()));
293
+ if (urnPrefix !== void 0) return URN_SLUG_RE.test(lowered.slice(urnPrefix.length)) ? readValueAs(input, lowered) : askForFix({
294
+ input,
295
+ expected: "the URN of a work",
296
+ hint: options.hint ?? ELI_HINT
297
+ });
290
298
  const parsed = parseEli(trimmed);
291
299
  if (parsed === null) {
292
300
  const cited = options.readCitation?.(trimmed);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/agent-input",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "Lenient readers for values agents write: dates, date bounds, date-format specs, numbers, booleans, locales, countries, enum and vocabulary values, ids, ELIs, string lists",
5
5
  "keywords": [
6
6
  "agent",
@@ -70,7 +70,7 @@
70
70
  "dependencies": {
71
71
  "@stll/country-codes": "^0.2.0",
72
72
  "@stll/fuzzy-search": "1.4.2",
73
- "@stll/template-conditions": "^0.6.6",
73
+ "@stll/template-conditions": "^0.7.0",
74
74
  "@stll/text-normalize": "^0.8.0",
75
75
  "@stll/time": "0.4.2",
76
76
  "better-result": "3.0.1"