AI-powered ESM module generation service that creates JavaScript modules on-demand using Pollinations.ai.
🎯 No signup required
🎯 No API keys needed
🎯 No authentication
🎯 No rate limits for basic usage
🎯 Just import and code
Perfect for prototyping, learning, and production when you need modules fast.
unpkg.ai generates and serves ES modules dynamically based on URL-encoded prompts. Include full TypeScript-style type definitions in your prompts to get modules with precise JSDoc annotations.
GET /esm/{url-encoded-prompt}.js
GET /esm/{url-encoded-prompt}.js?model={model}&seed={seed}
Parameter | Description | Example | Required |
---|---|---|---|
model |
AI model to use for generation | gpt-4 , claude-3 , mistral |
No |
seed |
Random seed for deterministic output | 12345 |
No |
import { calculateTip } from 'https://unpkg.ai/esm/calculateTip(amount:number,percentage:number,people?:number):{tip:number,total:number,perPerson:number}.js';
const result = calculateTip(85.50, 18, 4);
console.log(result); // { tip: 15.39, total: 100.89, perPerson: 25.22 }
import { generatePassword } from 'https://unpkg.ai/esm/generatePassword(options?:{length?:number,symbols?:boolean,numbers?:boolean,uppercase?:boolean,lowercase?:boolean}):{password:string,strength:number,feedback:string[]}.js';
const result = generatePassword({ length: 16, symbols: true, numbers: true });
console.log(result); // { password: 'K#9m$L2pQ!7vX8nR', strength: 95, feedback: ['Very strong'] }
import { generatePalette } from 'https://unpkg.ai/esm/generatePalette(baseColor:string,count?:number,type?:'complementary'|'analogous'|'triadic'):{colors:{hex:string,rgb:string,hsl:string,name:string}[],scheme:string}.js';
const palette = generatePalette('#3B82F6', 5, 'complementary');
console.log(palette.colors); // Array of 5 complementary colors with multiple formats
import { initMinesweeper } from 'https://unpkg.ai/esm/initMinesweeper(container:string,options?:{width?:number,height?:number,mines?:number}):{start:()=>void,reset:()=>void,getStats:()=>{games:number,wins:number,time:number}}.js';
// Create container for the game
const gameContainer = document.createElement('div');
gameContainer.id = 'game-container';
document.body.appendChild(gameContainer);
// Creates a complete playable minesweeper game with UI
const game = initMinesweeper('#game-container', { width: 10, height: 10, mines: 15 });
console.log('Game initialized:', game);
game.start(); // Full game with click handlers, animations, timer, score tracking
import { createRichEditor } from 'https://unpkg.ai/esm/createRichEditor(container:string):{getContent:()=>string,setContent:(content:string)=>void,insertText:(text:string)=>void}|Rich+text+editor+with+bold+italic+lists+links+features.js';
// Create container for the editor
const editorContainer = document.createElement('div');
editorContainer.id = 'editor';
editorContainer.style.cssText = 'border: 1px solid #e5e7eb; border-radius: 8px; min-height: 200px; background: white;';
document.body.appendChild(editorContainer);
const editor = createRichEditor('#editor');
console.log('Editor created:', editor);
editor.setContent('# Welcome\\n\\nStart typing...');
import { createDashboard } from 'https://unpkg.ai/esm/createDashboard(containerSelector:string):{addChart:(id:string,type:string,data:{x:string,y:number}[])=>void,updateChart:(id:string,data:{x:string,y:number}[])=>void,addFilter:(name:string,callback:(data:{x:string,y:number}[])=>{x:string,y:number}[])=>void}|Interactive+dashboard+with+single+line+chart+and+filtering+that+preserves+data+order.js';
// Create container for the dashboard
const dashboardContainer = document.createElement('div');
dashboardContainer.id = 'dashboard';
dashboardContainer.style.cssText = 'border: 1px solid #e5e7eb; border-radius: 8px; min-height: 300px; background: white; padding: 1rem;';
document.body.appendChild(dashboardContainer);
const dashboard = createDashboard('#dashboard');
// Add interactive sales chart
dashboard.addChart('sales', 'line', [
{ x: 'Jan', y: 1000 }, { x: 'Feb', y: 1200 }, { x: 'Mar', y: 800 }, { x: 'Apr', y: 1500 }
]);
functionName(param1:type1,param2?:type2):ReturnType
{property1:type1,property2?:type2}
(param:string|number):boolean
param:array
param:{foo:string,bar:number}[]
For complex modules that need detailed documentation, append documentation after the type signature using |
:
functionName(param:type):ReturnType|Your documentation here describing the module behavior
GET /esm/{url-encoded-prompt}.js
- Generate and serve ES moduleGET /health
- Service health check
src/
├── server.js # Express server with /esm/* routing
├── generator.js # Module generation with TypeScript signature parsing
├── pollinations.js # Pollinations.ai API integration
└── cache.js # PostgreSQL caching layer
POLLINATIONS_API_KEY=your_api_key_here
PORT=3000
PG_URL=postgresql://user:pass@localhost:5432/unpkg_cache
CACHE_TTL=3600
NODE_ENV=production
CREATE TABLE module_cache (
id SERIAL PRIMARY KEY,
prompt_hash VARCHAR(64) UNIQUE NOT NULL,
query_params JSONB,
module_content TEXT NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE INDEX idx_prompt_hash ON module_cache(prompt_hash);
npm install
createdb unpkg_cache
npm run migrate
npm run dev # Development
npm start # Production
- PostgreSQL-based permanent caching
- Cache keys based on prompt hash and query parameters
- No expiration - modules cached indefinitely
MIT License