Unverified Commit 66f5c864 authored by Hong Minhee's avatar Hong Minhee
Browse files

Replace @std/text with es-toolkit

parent c864a217
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
import { toPascalCase } from "@std/text/to-pascal-case";
import { pascalCase } from "@es-toolkit/es-toolkit";
import metadata from "../deno.json" with { type: "json" };
import { getFieldName } from "./field.ts";
import type { PropertySchema, TypeSchema } from "./schema.ts";
@@ -56,7 +56,7 @@ async function* generateProperty(
    }
  } else {
    yield `
    async #fetch${toPascalCase(property.singularName)}(
    async #fetch${pascalCase(property.singularName)}(
      url: URL,
      options: {
        documentLoader?: DocumentLoader,
@@ -165,7 +165,7 @@ async function* generateProperty(
      yield `
      /**
       * Similar to
       * {@link ${type.name}.get${toPascalCase(property.singularName)}},
       * {@link ${type.name}.get${pascalCase(property.singularName)}},
       * but returns its \`@id\` URL instead of the object itself.
       */
      ${override} get ${property.singularName}Id(): URL | null {
@@ -183,7 +183,7 @@ async function* generateProperty(
      `;
      yield doc;
      yield `
      ${override} async get${toPascalCase(property.singularName)}(
      ${override} async get${pascalCase(property.singularName)}(
        options: {
          documentLoader?: DocumentLoader,
          contextLoader?: DocumentLoader,
@@ -201,7 +201,7 @@ async function* generateProperty(
        const v = this.${await getFieldName(property.uri)}[0];
        if (v instanceof URL) {
          const fetched =
            await this.#fetch${toPascalCase(property.singularName)}(v, options);
            await this.#fetch${pascalCase(property.singularName)}(v, options);
          if (fetched == null) return null;
          this.${await getFieldName(property.uri)}[0] = fetched;
          this._cachedJsonLd = undefined;
@@ -234,7 +234,7 @@ async function* generateProperty(
      yield `
      /**
       * Similar to
       * {@link ${type.name}.get${toPascalCase(property.pluralName)}},
       * {@link ${type.name}.get${pascalCase(property.pluralName)}},
       * but returns their \`@id\`s instead of the objects themselves.
       */
      ${override} get ${property.singularName}Ids(): URL[] {
@@ -251,7 +251,7 @@ async function* generateProperty(
      `;
      yield doc;
      yield `
      ${override} async* get${toPascalCase(property.pluralName)}(
      ${override} async* get${pascalCase(property.pluralName)}(
        options: {
          documentLoader?: DocumentLoader,
          contextLoader?: DocumentLoader,
@@ -270,7 +270,7 @@ async function* generateProperty(
          const v = vs[i];
          if (v instanceof URL) {
            const fetched =
              await this.#fetch${toPascalCase(property.singularName)}(
              await this.#fetch${pascalCase(property.singularName)}(
                v, options);
            if (fetched == null) continue;
            vs[i] = fetched;
+0 −1
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@
    "@std/encoding": "jsr:@std/encoding@1.0.7",
    "@std/http": "jsr:@std/http@^1.0.6",
    "@std/testing": "jsr:@std/testing@^0.224.0",
    "@std/text": "jsr:@std/text@^1.0.6",
    "@std/url": "jsr:@std/url@^0.225.1",
    "@std/yaml": "jsr:@std/yaml@^0.224.3",
    "asn1js": "npm:asn1js@^3.0.5",
+12 −13
Original line number Diff line number Diff line
import { isDeno } from "@david/which-runtime";
import { pascalCase } from "@es-toolkit/es-toolkit";
import { parseLanguageTag } from "@phensley/language-tag";
import {
  assertEquals,
@@ -9,7 +10,6 @@ import {
  assertThrows,
} from "@std/assert";
import { assertSnapshot } from "@std/testing/snapshot";
import { toPascalCase } from "@std/text/to-pascal-case";
import { decode } from "../runtime/multibase/index.ts";
import {
  loadSchemaFiles,
@@ -898,7 +898,7 @@ for (const typeUri in types) {
      } else {
        if (property.functional || property.singularAccessor) {
          assertEquals(
            await instance[`get${toPascalCase(property.singularName)}`].call(
            await instance[`get${pascalCase(property.singularName)}`].call(
              instance,
              { documentLoader: mockDocumentLoader },
            ),
@@ -912,7 +912,7 @@ for (const typeUri in types) {
        if (!property.functional) {
          assertEquals(
            await Array.fromAsync(
              instance[`get${toPascalCase(property.pluralName)}`].call(
              instance[`get${pascalCase(property.pluralName)}`].call(
                instance,
                { documentLoader: mockDocumentLoader },
              ),
@@ -940,7 +940,7 @@ for (const typeUri in types) {
        } else {
          if (property.functional || property.singularAccessor) {
            assertEquals(
              await empty[`get${toPascalCase(property.singularName)}`].call(
              await empty[`get${pascalCase(property.singularName)}`].call(
                empty,
                { documentLoader: mockDocumentLoader },
              ),
@@ -951,7 +951,7 @@ for (const typeUri in types) {
          if (!property.functional) {
            assertEquals(
              await Array.fromAsync(
                empty[`get${toPascalCase(property.pluralName)}`].call(
                empty[`get${pascalCase(property.pluralName)}`].call(
                  empty,
                  { documentLoader: mockDocumentLoader },
                ),
@@ -1071,12 +1071,11 @@ for (const typeUri in types) {
    };

    if (property.functional || property.singularAccessor) {
      test(`${type.name}.get${toPascalCase(property.singularName)}() [auto]`, async () => {
      test(`${type.name}.get${pascalCase(property.singularName)}() [auto]`, async () => {
        const instance = new cls({
          [property.singularName]: new URL("https://example.com/test"),
        });
        const value =
          await instance[`get${toPascalCase(property.singularName)}`]
        const value = await instance[`get${pascalCase(property.singularName)}`]
          .call(instance, { documentLoader: docLoader });
        assertEquals(value, sampleValues[property.range[0]]);

@@ -1086,7 +1085,7 @@ for (const typeUri in types) {
        });
        await assertRejects(
          () =>
            wrongRef[`get${toPascalCase(property.singularName)}`].call(
            wrongRef[`get${pascalCase(property.singularName)}`].call(
              wrongRef,
              {
                documentLoader: mockDocumentLoader,
@@ -1097,11 +1096,11 @@ for (const typeUri in types) {
      });
    }
    if (!property.functional) {
      test(`${type.name}.get${toPascalCase(property.pluralName)}() [auto]`, async () => {
      test(`${type.name}.get${pascalCase(property.pluralName)}() [auto]`, async () => {
        const instance = new cls({
          [property.pluralName]: [new URL("https://example.com/test")],
        });
        const value = instance[`get${toPascalCase(property.pluralName)}`].call(
        const value = instance[`get${pascalCase(property.pluralName)}`].call(
          instance,
          { documentLoader: docLoader },
        );
@@ -1116,7 +1115,7 @@ for (const typeUri in types) {
        await assertRejects(
          () =>
            Array.fromAsync(
              wrongRef[`get${toPascalCase(property.pluralName)}`].call(
              wrongRef[`get${pascalCase(property.pluralName)}`].call(
                wrongRef,
                {
                  documentLoader: mockDocumentLoader,