[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Type](https://evolu.dev/docs/api-reference/common/Type) › UrlFromString

```ts
const UrlFromString: transform(
  "UrlFromString",
  String,
  Url,
  {
    from: (value: string): Result<string, UrlFromStringError> => {
      const canonical = canonicalizeUrl(value);
      return canonical === undefined
        ? err({ type: "UrlFromString", value })
        : ok(canonical);
    },
    to: (value: Url) => value,
  },
  formatUrlFromStringError,
);
```

Defined in: [packages/common/src/Type.ts:9764](https://github.com/evoluhq/evolu/blob/aa223771feea747ffb1b0f5f3271574455633e37/packages/common/src/Type.ts#L9764)

Transforms an absolute URL into its canonical [Url](https://evolu.dev/docs/api-reference/common/Type/variables/Url).

Accepts what the platform's `URL` parses without a base URL, as Url
describes, and returns its `href`. Encoding returns the canonical spelling,
not the original one.

### Example

```ts
import { assertEqual, assertErr, assertOk, UrlFromString } from "@evolu/common";

// Lowercases the scheme and host, removes 443, the default port of https:,
// and resolves /a/../b to /b.
assertOk(
  UrlFromString.fromUnknown("HTTPS://Example.com:443/a/../b"),
  "https://example.com/b",
);

const invalid = UrlFromString.fromUnknown("/b");
assertErr(invalid, { type: "UrlFromString", value: "/b" });
assertEqual(
  UrlFromString.formatError(invalid.error),
  'The value "/b" is not a valid URL.',
);
```