### Install amazon-s3-url Source: https://github.com/zirkelc/amazon-s3-url/blob/main/README.md Installs the amazon-s3-url library using npm, yarn, or pnpm. ```bash # npm npm install amazon-s3-url # yarn yarn add amazon-s3-url # pnpm pnpm add amazon-s3-url ``` -------------------------------- ### Import formatS3Url Source: https://github.com/zirkelc/amazon-s3-url/blob/main/README.md Demonstrates how to import the formatS3Url function from the library using both ESM and CommonJS module systems. ```typescript // ESM import { formatS3Url } from 'amazon-s3-url'; // CommonJS const { formatS3Url } = require('amazon-s3-url'); ``` -------------------------------- ### S3Object Type Definition Source: https://github.com/zirkelc/amazon-s3-url/blob/main/README.md Defines the TypeScript type for an S3 object, including bucket, key, and an optional region. ```typescript type S3Object = { bucket: string; key: string; region?: string; }; const s3Object: S3Object = { bucket: 'bucket', key: 'key', region: 'us-west-1' }; ``` -------------------------------- ### Parse S3 URL with different formats Source: https://github.com/zirkelc/amazon-s3-url/blob/main/README.md The `parseS3Url` function takes an S3 URL string and an optional format to parse it into an S3Object. If no format is specified, it attempts to parse using all supported formats. Supported formats include 's3-global-path', 's3-legacy-path', 's3-legacy-virtual-host', 'https-legacy-path', 'https-legacy-virtual-host', 's3-region-path', 's3-region-virtual-host', 'https-region-path', and 'https-region-virtual-host'. ```typescript import { parseS3Url } from 'amazon-s3-url'; // s3-global-path const s3Object = parseS3Url('s3://bucket/key'); // s3-legacy-path const s3Object = parseS3Url('s3://s3.amazonaws.com/bucket/key'); // s3-legacy-virtual-host const s3Object = parseS3Url('s3://bucket.s3.amazonaws.com/key'); // https-legacy-path const s3Object = parseS3Url('https://s3.amazonaws.com/bucket/key'); // https-legacy-virtual-host const s3Object = parseS3Url('https://bucket.s3.amazonaws.com/key'); // s3-region-path const s3Object = parseS3Url('s3://s3.us-west-1.amazonaws.com/bucket/key'); // s3-region-virtual-host const s3Object = parseS3Url('s3://bucket.s3.us-west-1.amazonaws.com/bucket/key'); // https-region-path const s3Object = parseS3Url('https://s3.us-west-1.amazonaws.com/bucket/key'); // https-region-virtual-host const s3Object = parseS3Url('https://bucket.s3.us-west-1.amazonaws.com/bucket/key'); ``` -------------------------------- ### Format S3 URL with different formats Source: https://github.com/zirkelc/amazon-s3-url/blob/main/README.md The `formatS3Url` function takes an S3 object and an optional format string to generate a formatted S3 URL. It supports various formats like 's3-global-path', 's3-legacy-path', 's3-legacy-virtual-host', 'https-legacy-path', 'https-legacy-virtual-host', 's3-region-path', 's3-region-virtual-host', 'https-region-path', and 'https-region-virtual-host'. ```typescript import { formatS3Url, S3Object } from 'amazon-s3-url'; // s3://bucket/key const s3Url = formatS3Url(s3Object); // s3://bucket/key const s3Url = formatS3Url(s3Object, "s3-global-path"); // s3://s3.amazonaws.com/bucket/key const s3Url = formatS3Url(s3Object, "s3-legacy-path"); // s3://bucket.s3.amazonaws.com/key const s3Url = formatS3Url(s3Object, "s3-legacy-virtual-host"); // https://s3.amazonaws.com/bucket/key const s3Url = formatS3Url(s3Object, "https-legacy-path"); // https://bucket.s3.amazonaws.com/key const s3Url = formatS3Url(s3Object, "https-legacy-virtual-host"); // s3://s3.us-west-1.amazonaws.com/bucket/key const s3Url = formatS3Url(s3Object, "s3-region-path"); // s3://bucket.s3.us-west-1.amazonaws.com/key const s3Url = formatS3Url(s3Object, "s3-region-virtual-host"); // https://s3.us-west-1.amazonaws.com/bucket/key const s3Url = formatS3Url(s3Object, "https-region-path"); // https://bucket.s3.us-west-1.amazonaws.com/key const s3Url = formatS3Url(s3Object, "https-region-virtual-host"); ``` -------------------------------- ### Validate S3 URL with different formats Source: https://github.com/zirkelc/amazon-s3-url/blob/main/README.md The `isS3Url` function checks if a given string is a valid S3 URL, optionally validating against a specific format. If no format is provided, it checks against all supported formats. Supported formats include 's3-global-path', 's3-legacy-path', 's3-legacy-virtual-host', 'https-legacy-path', 'https-legacy-virtual-host', 's3-region-path', 's3-region-virtual-host', 'https-region-path', and 'https-region-virtual-host'. ```typescript import { isS3Url } from 'amazon-s3-url'; // s3-global-path isS3Url('s3://bucket/key'); // s3-legacy-path isS3Url('s3://s3.amazonaws.com/bucket/key'); // s3-legacy-virtual-host isS3Url('s3://bucket.s3.amazonaws.com/key'); // https-legacy-path isS3Url('https://s3.amazonaws.com/bucket/key'); // https-legacy-virtual-host isS3Url('https://bucket.s3.amazonaws.com/key'); // s3-region-path isS3Url('s3://s3.us-west-1.amazonaws.com/bucket/key'); // s3-region-virtual-host isS3Url('s3://bucket.s3.us-west-1.amazonaws.com/bucket/key'); // https-region-path isS3Url('https://s3.us-west-1.amazonaws.com/bucket/key'); // https-region-virtual-host isS3Url('https://bucket.s3.us-west-1.amazonaws.com/bucket/key'); ``` -------------------------------- ### S3UrlFormat Type Definition Source: https://github.com/zirkelc/amazon-s3-url/blob/main/README.md Defines the TypeScript type for S3 URL formats, specifying protocol, endpoint, and style combinations. ```typescript type S3UrlFormat = | "s3-global-path" | "s3-legacy-path" | "s3-legacy-virtual-host" | "https-legacy-path" | "https-legacy-virtual-host" | "s3-region-path" | "s3-region-virtual-host" | "https-region-path" | "https-region-virtual-host"; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.