Registry / storage / amp-toolbox-cache-url

amp-toolbox-cache-url

JSON →
library1.2.0-alpha.2jsnpmunverified

Translates canonical URLs into AMP Cache URL format according to the AMP Cache URL specification. Version 1.2.0-alpha.2 is the latest pre-release; the package is stable but not actively developed. It supports multiple module formats (ESM, CommonJS, UMD) and includes both human-readable and SHA256 fallback cache URLs. Key differentiators: official AMP project tooling, support for cache URL creation and subdomain transformation, and handling of invalid URLs via SHA256.

npm install amp-toolbox-cache-url
INSTALL
IMPORT
SIG · AMP-TOOLBOX-CACHE-
A
amp-toolbox-cache-url
storagejavascriptv1.2.0-alpha.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ampToolboxCacheUrl
import {ampToolboxCacheUrl} from 'amp-toolbox-cache-url'
const ampToolboxCacheUrl = require('amp-toolbox-cache-url')
ESM import yields an object with methods. CommonJS require with default gives an object; use require().createCacheUrl to get the function.
createCacheUrl
import {createCacheUrl} from 'amp-toolbox-cache-url'
const {createCacheUrl} = require('amp-toolbox-cache-url').createCacheUrl
CommonJS: const createCacheUrl = require('amp-toolbox-cache-url').createCacheUrl;
createCurlsSubdomain
import {createCurlsSubdomain} from 'amp-toolbox-cache-url'
const {createCurlsSubdomain} = require('amp-toolbox-cache-url').createCurlsSubdomain
CommonJS: const createCurlsSubdomain = require('amp-toolbox-cache-url').createCurlsSubdomain;
UMD global
const {ampToolboxCacheUrl} = window.AmpToolboxCacheUrl
const {ampToolboxCacheUrl} = window.ampToolboxCacheUrl
UMD bundle exposes global `AmpToolboxCacheUrl` object.

Shows how to transform a canonical URL into an AMP Cache URL and create a curls subdomain using the library's main functions.

import { createCacheUrl, createCurlsSubdomain } from 'amp-toolbox-cache-url'; // Create an AMP Cache URL createCacheUrl('cdn.ampproject.org', 'https://www.example.com').then(cacheUrl => { console.log('Cache URL:', cacheUrl); // Logs: https://www-example-com.cdn.ampproject.org/c/s/www.example.com/ }); // Create a subdomain for curls createCurlsSubdomain('https://www.example.com').then(subdomain => { console.log('Curls subdomain:', subdomain); // Logs: www-example-com });
Debug
Known issues
breakingThe CommonJS require() returns an object with methods, not the function directly.
fix
Use const {createCacheUrl} = require('amp-toolbox-cache-url'); or const ampToolboxCacheUrl = require('amp-toolbox-cache-url'); ampToolboxCacheUrl.createCacheUrl(...).
affects: >=1.0.0
deprecatedThe UMD bundle is deprecated in favor of ES modules.
fix
Use ESM imports: import {createCacheUrl} from 'amp-toolbox-cache-url';
affects: >=1.1.0
gotchaThe callback style (success, error) is not supported; only Promises are returned.
fix
Use .then()/.catch() or async/await.
affects: >=1.0.0
gotchaThe npm package name is 'amp-toolbox-cache-url', not 'amp-toolbox'.
fix
Install: npm install amp-toolbox-cache-url
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: ampToolboxCacheUrl is not a function
CommonJS require() returns an object; calling it as a function fails.
fix
Use require('amp-toolbox-cache-url').createCacheUrl(...) instead.
Cannot find module 'amp-toolbox-cache-url'
Package not installed or wrong installation path.
fix
Run: npm install amp-toolbox-cache-url
window.AmpToolboxCacheUrl is undefined
UMD bundle not loaded or script tag missing.
fix
Include a script tag: <script src="node_modules/amp-toolbox-cache-url/dist/amp-toolbox-cache-url.umd.js"></script>
Upgrade
Version history
1.2.0-alpha.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
45 hits · last 30 days
node
42
Resources
amp-toolbox-cache-url — npm install amp-toolbox-cache-url · libregistry