@fedify/vocab-tools 2.5.0-dev.2304 → 2.5.0-dev.2327

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/src/class.ts CHANGED
@@ -58,6 +58,7 @@ const RUNTIME_IMPORTS = [
58
58
  "isDecimal",
59
59
  "isGatewayUrl",
60
60
  "LanguageString",
61
+ "normalizeLanguageTag",
61
62
  "parseDecimal",
62
63
  "parseGatewayUrl",
63
64
  "parseIri",
@@ -325,7 +326,7 @@ function inspectIri(iri: URL): string {
325
326
  yield `
326
327
  function isValidLanguageTag(language: string): boolean {
327
328
  try {
328
- new Intl.Locale(language);
329
+ new Intl.Locale(normalizeLanguageTag(language));
329
330
  return true;
330
331
  } catch (error) {
331
332
  if (error instanceof RangeError) return false;
@@ -179,7 +179,7 @@ export async function* generateConstructor(
179
179
  if (Array.isArray(values.${property.pluralName}) &&
180
180
  values.${property.pluralName}.every(v => ${typeGuards})) {
181
181
  // @ts-ignore: type is checked above.
182
- this.${fieldName} = values.${property.pluralName};
182
+ this.${fieldName} = values.${property.pluralName}.slice();
183
183
  `;
184
184
  if (!allScalarTypes) {
185
185
  yield `
@@ -219,7 +219,8 @@ export async function* generateCloner(
219
219
  *
220
220
  * @param values The values to update the clone with.
221
221
  * @param options The options to use for cloning.
222
- * @returns The cloned instance.
222
+ * @returns The cloned instance with its own property arrays. Nested objects
223
+ * and URLs are shared with this instance.
223
224
  */
224
225
  ${emitOverride(typeUri, types)} clone(
225
226
  values:
@@ -258,7 +259,7 @@ export async function* generateCloner(
258
259
  const fieldName = await getFieldName(property.uri);
259
260
  const trustFieldName = await getFieldName(property.uri, "#_trust");
260
261
  const allScalarTypes = areAllScalarTypes(property.range, types);
261
- yield `clone.${fieldName} = this.${fieldName};`;
262
+ yield `clone.${fieldName} = this.${fieldName}.slice();`;
262
263
  if (!allScalarTypes) {
263
264
  yield `clone.${trustFieldName} = new Set(this.${trustFieldName});`;
264
265
  }
@@ -322,7 +323,7 @@ export async function* generateCloner(
322
323
  if (Array.isArray(values.${property.pluralName}) &&
323
324
  values.${property.pluralName}.every(v => ${typeGuards})) {
324
325
  // @ts-ignore: type is checked above.
325
- clone.${fieldName} = values.${property.pluralName};
326
+ clone.${fieldName} = values.${property.pluralName}.slice();
326
327
  `;
327
328
  if (!allScalarTypes) {
328
329
  yield `
package/src/type.ts CHANGED
@@ -310,7 +310,7 @@ const scalarTypes: Record<string, ScalarType> = {
310
310
  && typeof ${v}["@value"] === "string" && !("@language" in ${v})`;
311
311
  },
312
312
  decoder(v) {
313
- return `new Intl.Locale(${v}["@value"])`;
313
+ return `new Intl.Locale(normalizeLanguageTag(${v}["@value"]))`;
314
314
  },
315
315
  },
316
316
  "fedify:url": {