@fedify/vocab-tools 2.3.11-dev.2280 → 2.3.11

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
@@ -206,6 +206,7 @@ export async function* generateClasses(
206
206
  "importPem",
207
207
  "isDecimal",
208
208
  "LanguageString",
209
+ "normalizeLanguageTag",
209
210
  "parseDecimal",
210
211
  "type RemoteDocument",
211
212
  ];
@@ -235,7 +236,7 @@ function decodeIri(iri: string): URL {
235
236
  yield `
236
237
  function isValidLanguageTag(language: string): boolean {
237
238
  try {
238
- new Intl.Locale(language);
239
+ new Intl.Locale(normalizeLanguageTag(language));
239
240
  return true;
240
241
  } catch (error) {
241
242
  if (error instanceof RangeError) return false;
@@ -177,7 +177,7 @@ export async function* generateConstructor(
177
177
  if (Array.isArray(values.${property.pluralName}) &&
178
178
  values.${property.pluralName}.every(v => ${typeGuards})) {
179
179
  // @ts-ignore: type is checked above.
180
- this.${fieldName} = values.${property.pluralName};
180
+ this.${fieldName} = values.${property.pluralName}.slice();
181
181
  `;
182
182
  if (!allScalarTypes) {
183
183
  yield `
@@ -210,7 +210,8 @@ export async function* generateCloner(
210
210
  * Clones this instance, optionally updating it with the given values.
211
211
  * @param values The values to update the clone with.
212
212
  * @param options The options to use for cloning.
213
- * @returns The cloned instance.
213
+ * @returns The cloned instance with its own property arrays. Nested objects
214
+ * and URLs are shared with this instance.
214
215
  */
215
216
  ${emitOverride(typeUri, types)} clone(
216
217
  values:
@@ -247,7 +248,7 @@ export async function* generateCloner(
247
248
  const fieldName = await getFieldName(property.uri);
248
249
  const trustFieldName = await getFieldName(property.uri, "#_trust");
249
250
  const allScalarTypes = areAllScalarTypes(property.range, types);
250
- yield `clone.${fieldName} = this.${fieldName};`;
251
+ yield `clone.${fieldName} = this.${fieldName}.slice();`;
251
252
  if (!allScalarTypes) {
252
253
  yield `clone.${trustFieldName} = new Set(this.${trustFieldName});`;
253
254
  }
@@ -311,7 +312,7 @@ export async function* generateCloner(
311
312
  if (Array.isArray(values.${property.pluralName}) &&
312
313
  values.${property.pluralName}.every(v => ${typeGuards})) {
313
314
  // @ts-ignore: type is checked above.
314
- clone.${fieldName} = values.${property.pluralName};
315
+ clone.${fieldName} = values.${property.pluralName}.slice();
315
316
  `;
316
317
  if (!allScalarTypes) {
317
318
  yield `
package/src/type.ts CHANGED
@@ -323,7 +323,7 @@ const scalarTypes: Record<string, ScalarType> = {
323
323
  && typeof ${v}["@value"] === "string" && !("@language" in ${v})`;
324
324
  },
325
325
  decoder(v) {
326
- return `new Intl.Locale(${v}["@value"])`;
326
+ return `new Intl.Locale(normalizeLanguageTag(${v}["@value"]))`;
327
327
  },
328
328
  },
329
329
  "fedify:url": {