# @ampproject/toolbox-cache-url

> Transform canonical URLs into AMP Cache URLs

Latest version **2.10.1** (published 2024-06-14) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @ampproject/toolbox-cache-url
pnpm add @ampproject/toolbox-cache-url
yarn add @ampproject/toolbox-cache-url
bun add @ampproject/toolbox-cache-url
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.10.1 |
| Published | 2024-06-14 |
| First published | 2019-06-10 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 75.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 459 |
| Author | AMPHTML Team |
| Maintainers | ampproject-admin, kristoferbaxter, jridgewell, choumx, amp-toolbox, fstanis, erwinmombay, samouri, caroqliu, rsimha, dvoytenko, patrickkettner, alanorozco, kdwan, ampprojectbot, esth |
| Keywords | amp, amp-toolbox, amp-url-api |

## Links

- npm: https://www.npmjs.com/package/@ampproject/toolbox-cache-url
- Repository: https://github.com/ampproject/amp-toolbox
- Homepage: https://github.com/ampproject/amp-toolbox/tree/main/packages/cache-url
- Issues: https://github.com/ampproject/amp-toolbox/issues
- npm.io page: https://npm.io/package/@ampproject/toolbox-cache-url

## Dependencies (2)

- [punycode](https://npm.io/package/punycode.md) 2.1.1
- [url-parse](https://npm.io/package/url-parse.md) ^1.5.10

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 2.10.1 (latest) — 2024-06-14
- 3.0.0-canary.2 (canary) — 2022-01-11
- 2.7.1-alpha.0 (alpha) — 2020-12-01
- 1.1.0-beta.0 (beta) — 2019-08-29
- 2.10.0 — 2024-06-13
- 2.9.0 — 2022-06-23
- 2.8.0 — 2021-05-31
- 2.8.0-canary.6 — 2021-03-18
- 2.8.0-canary.5 — 2021-03-12
- 2.8.0-canary.4 — 2021-03-02
- 2.8.0-canary.0 — 2021-02-12
- 2.7.2 — 2020-12-15
- 2.7.1 — 2020-12-02
- 2.7.0-alpha.1 — 2020-08-19
- 2.5.4 — 2020-06-22
- … 19 more at https://npm.io/package/@ampproject/toolbox-cache-url/versions

## README

# AMP-Toolbox Cache URL

[![npm version](https://badge.fury.io/js/%40ampproject%2Ftoolbox-cache-url.svg)](https://badge.fury.io/js/%40ampproject%2Ftoolbox-cache-url)

Translates an URL from the origin to the AMP Cache URL format, according to the specification
available in the [AMP documentation](https://developers.google.com/amp/cache/overview). This includes the SHA256 fallback URLs used by the AMP Cache on invalid human-readable cache urls.

## Usage

Install via:

```
$ npm install @ampproject/toolbox-cache-url
```

### Including the Module

#### ES Module (Browser)

```javascript
import {ampToolboxCacheUrl} from '@ampproject/toolbox-cache-url';
```

#### CommonJs (Node)

```javascript
const ampToolboxCacheUrl = require('@ampproject/toolbox-cache-url');
```


#### UMD (Node, Browser)

In the browser, include the UMD module in an HTML `<script>` tag. If using node, replace `window` with `global`.

```javascript
const {ampToolboxCacheUrl} = window.ToolboxCacheUrl;
```

### Using the module

```javascript
  // Get an AMP Cache URL from a cache domain, and a canonical URL
  ampToolboxCacheUrl.createCacheUrl('cdn.ampproject.org', 'https://www.example.com').then((cacheUrl) => {
    // This would log: 
    // 'https://www-example-com.cdn.ampproject.org/c/s/www.example.com/'
    console.log(cacheUrl);
  });

  // Transform a canonical URL to an AMP Cache subdomain
  ampToolboxCacheUrl.createCurlsSubdomain('https://www.example.com').then((curlsSubdomain) => {
    // This would log: 
    // 'www-example-com'
    console.log(curlsSubdomain);
  });
```

---
_Source: https://npm.io/package/@ampproject/toolbox-cache-url · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
