shelving 1.187.2 → 1.187.3

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.
@@ -3,7 +3,7 @@ import { REACT_ELEMENT_TYPE } from "../util/internal.js";
3
3
  import { getWordRegExp } from "../util/regexp.js";
4
4
  import { getMarkupRule } from "../util/rule.js";
5
5
  /** Map characters, e.g. `*`, to their coresponding HTML tag, e.g. `strong` */
6
- const INLINE_CHARS = { "-": "del", "~": "del", "+": "ins", "*": "strong", _: "em", "=": "mark", ":": "mark" }; // Hyphen must be first so it works when we use the keys as a character class.
6
+ const INLINE_CHARS = { "-": "del", "~": "del", "+": "ins", "*": "strong", _: "em", "=": "mark" }; // Hyphen must be first so it works when we use the keys as a character class.
7
7
  const INLINE_REGEXP = getWordRegExp(`(?<wrap>(?<char>[${Object.keys(INLINE_CHARS).join("")}])+)(?<text>(?!\\k<char>)\\S(?:[\\s\\S]*?(?!\\k<char>)\\S)?)\\k<wrap>`);
8
8
  /**
9
9
  * Inline strong, emphasis, insert, delete, highlight.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shelving",
3
- "version": "1.187.2",
3
+ "version": "1.187.3",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "@types/bun": "^1.3.12",
15
15
  "@types/react": "^19.2.14",
16
16
  "@types/react-dom": "^19.2.3",
17
- "@typescript/native-preview": "^7.0.0-dev.20260417.1",
17
+ "@typescript/native-preview": "^7.0.0-dev.20260418.1",
18
18
  "firebase": "^12.12.0",
19
19
  "react": "^19.2.5",
20
20
  "react-dom": "^19.2.5",
@@ -1,4 +1,4 @@
1
- import type { ImmutableArray } from "./array.js";
1
+ import { type ImmutableArray } from "./array.js";
2
2
  import { type ImmutableDictionary } from "./dictionary.js";
3
3
  import { type AnyCaller } from "./function.js";
4
4
  import { type NotString, type PossibleString } from "./string.js";
package/util/template.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { RequiredError } from "../error/RequiredError.js";
2
2
  import { ValueError } from "../error/ValueError.js";
3
+ import { isArray } from "./array.js";
4
+ import { getDataProp, isData } from "./data.js";
3
5
  import { EMPTY_DICTIONARY } from "./dictionary.js";
4
6
  import { isFunction } from "./function.js";
5
7
  import { setMapItem } from "./map.js";
6
- import { isObject } from "./object.js";
7
8
  import { getString } from "./string.js";
8
9
  // RegExp to find named variables in several formats e.g. `:a`, `${b}`, `{{c}}` or `{d}`
9
10
  const R_PLACEHOLDERS = /(\*\*?|:[a-z][a-z0-9]*|\$\{[a-z][a-z0-9]*\}|\{\{[a-z][a-z0-9]*\}\}|\{[a-z][a-z0-9]*\})/i;
@@ -114,24 +115,32 @@ export function renderTemplate(template, values, caller = renderTemplate) {
114
115
  if (!chunks.length)
115
116
  return template;
116
117
  let output = template;
117
- for (const { name, placeholder } of chunks)
118
- output = output.replace(placeholder, _replaceTemplateKey(name, values, caller));
119
- return output;
120
- }
121
- function _replaceTemplateKey(key, values, caller) {
122
- if (isFunction(values))
123
- return values(key);
124
- if (isObject(values)) {
125
- // Dictionary or array of values.
126
- const v = getString(values[key]);
127
- if (v !== undefined)
128
- return v;
118
+ if (isFunction(values)) {
119
+ for (const { name, placeholder } of chunks)
120
+ output = output.replace(placeholder, values(name));
121
+ }
122
+ else if (isData(values)) {
123
+ for (const { name, placeholder } of chunks) {
124
+ const v = getString(getDataProp(values, name));
125
+ if (v === undefined)
126
+ throw new RequiredError(`Template placeholder "${name}" not found in object`, { received: values, name, caller });
127
+ output = output.replace(placeholder, v);
128
+ }
129
+ }
130
+ else if (isArray(values)) {
131
+ for (const { name, placeholder } of chunks) {
132
+ const v = getString(values[Number(name)]);
133
+ if (v === undefined)
134
+ throw new RequiredError(`Template placeholder "${name}" not found in array`, { received: values, name, caller });
135
+ output = output.replace(placeholder, v);
136
+ }
129
137
  }
130
138
  else {
131
- // Single value for all placeholders.
132
139
  const v = getString(values);
133
- if (v !== undefined)
134
- return v;
140
+ if (v === undefined)
141
+ throw new RequiredError(`Template value must be string`, { received: values, caller });
142
+ for (const { placeholder } of chunks)
143
+ output = output.replace(placeholder, v);
135
144
  }
136
- throw new RequiredError(`Template value for "${key}" must be string`, { received: values, key, caller });
145
+ return output;
137
146
  }