{"_id":"@boris93/whatsapp-compose","_rev":"2-148f06f49581fd34f68761adccd107e0","name":"@boris93/whatsapp-compose","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@boris93/whatsapp-compose","version":"0.1.0","keywords":["whatsapp","typescript","esm","nextjs","messaging","compose"],"author":{"url":"https://borisaghajanyan.github.io/","name":"Boris Aghajanyan"},"license":"MIT","_id":"@boris93/whatsapp-compose@0.1.0","maintainers":[{"name":"boris93","email":"boris.aghajanyan@gmail.com"}],"homepage":"https://github.com/borisaghajanyan/whatsapp-compose#readme","bugs":{"url":"https://github.com/borisaghajanyan/whatsapp-compose/issues"},"dist":{"shasum":"645d356fcacd4bf2c864994a97b6e8d81e38cb00","tarball":"https://registry.npmjs.org/@boris93/whatsapp-compose/-/whatsapp-compose-0.1.0.tgz","fileCount":5,"integrity":"sha512-wtSHOSdvk+B3QK0B6HgcLBbgamI+bJXJof7BwqOJgToGys0ATy80Xg269yd6TSgQoYVgh/Qnt9Z7c5PToplS6w==","signatures":[{"sig":"MEQCIDp8IEr7Zn3MuQ/uUc4YqY7WeAkH2BtGQWJ4hnH9H/mvAiB4mjVdrjBWqaGiI3YXTYf98IeS+ar7Ci2HBJ4K17n/0g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":6712},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"dev":"tsup src/index.ts --watch --format esm --dts --tsconfig tsconfig.build.json","test":"vitest run","build":"tsup src/index.ts --format esm --dts --tsconfig tsconfig.build.json"},"_npmUser":{"name":"boris93","email":"boris.aghajanyan@gmail.com"},"repository":{"url":"git+https://github.com/borisaghajanyan/whatsapp-compose.git","type":"git"},"_npmVersion":"11.7.0","description":"Compose WhatsApp messages in modern TypeScript apps","directories":{},"sideEffects":false,"_nodeVersion":"25.3.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.0","vitest":"^4.1.2","typescript":"^6.0.0"},"_npmOperationalInternal":{"tmp":"tmp/whatsapp-compose_0.1.0_1775505691856_0.3113845373116506","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@boris93/whatsapp-compose","version":"0.1.1","description":"Build WhatsApp wa.me links with prefilled text and optional recipient numbers","author":{"name":"Boris Aghajanyan","url":"https://borisaghajanyan.github.io/"},"repository":{"type":"git","url":"git+https://github.com/borisaghajanyan/whatsapp-compose.git"},"homepage":"https://github.com/borisaghajanyan/whatsapp-compose#readme","type":"module","publishConfig":{"access":"public"},"main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"build":"tsup src/index.ts --format esm --dts --tsconfig tsconfig.build.json","dev":"tsup src/index.ts --watch --format esm --dts --tsconfig tsconfig.build.json","test":"vitest run"},"sideEffects":false,"keywords":["whatsapp","wa.me","deep-link","url-builder","typescript","esm","nextjs","messaging","compose"],"license":"MIT","devDependencies":{"tsup":"^8.5.0","typescript":"^6.0.0","vitest":"^4.1.2"},"_id":"@boris93/whatsapp-compose@0.1.1","bugs":{"url":"https://github.com/borisaghajanyan/whatsapp-compose/issues"},"_nodeVersion":"25.3.0","_npmVersion":"11.7.0","dist":{"integrity":"sha512-qUIgNByq2SK8IVZ/+e68xgM5lqCHP99zUwjvnsZfbUBjN1227fJgIaFIpQ0iAeWjocRCzPyShFntRxN+CXUgAQ==","shasum":"a17e3095cb3353d86664c2734433b16418fbc457","tarball":"https://registry.npmjs.org/@boris93/whatsapp-compose/-/whatsapp-compose-0.1.1.tgz","fileCount":5,"unpackedSize":7099,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC8oka29GP1mPc3pVQp8YsAZ0jlmOEUZz1GNCDwoHyKswIhAL9QgpQxRwMokSanY6flptAIYYSL32AHauLoqzC4hcir"}]},"_npmUser":{"name":"boris93","email":"boris.aghajanyan@gmail.com"},"directories":{},"maintainers":[{"name":"boris93","email":"boris.aghajanyan@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/whatsapp-compose_0.1.1_1775505977852_0.3483561613932946"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-06T20:01:31.660Z","modified":"2026-04-06T20:06:18.107Z","0.1.0":"2026-04-06T20:01:32.010Z","0.1.1":"2026-04-06T20:06:17.978Z"},"bugs":{"url":"https://github.com/borisaghajanyan/whatsapp-compose/issues"},"author":{"name":"Boris Aghajanyan","url":"https://borisaghajanyan.github.io/"},"license":"MIT","homepage":"https://github.com/borisaghajanyan/whatsapp-compose#readme","keywords":["whatsapp","wa.me","deep-link","url-builder","typescript","esm","nextjs","messaging","compose"],"repository":{"type":"git","url":"git+https://github.com/borisaghajanyan/whatsapp-compose.git"},"description":"Build WhatsApp wa.me links with prefilled text and optional recipient numbers","maintainers":[{"name":"boris93","email":"boris.aghajanyan@gmail.com"}],"readme":"# whatsapp-compose\n\nBuild WhatsApp `wa.me` links with prefilled message text and an optional recipient phone number.\n\nThis package does one thing: it returns a WhatsApp URL string. You can use that URL in browser apps, React or Next.js event handlers, or anywhere else you need to generate a WhatsApp deep link.\n\n## Installation\n\n```bash\nnpm install @boris93/whatsapp-compose\n```\n\n## API\n\n### `composeWhatsappMessage(options)`\n\nBuilds a WhatsApp deep link with prefilled text and an optional recipient phone number.\n\n```ts\nimport { composeWhatsappMessage } from \"@boris93/whatsapp-compose\";\n\nconst url = composeWhatsappMessage({\n  text: \"Hello from my app\",\n  phoneNumber: \"+491701234567\",\n});\n```\n\n#### Parameters\n\n```ts\ntype WhatsappComposeOptions = {\n  text: string;\n  phoneNumber?: string;\n};\n```\n\n- `text`: The message to prefill in WhatsApp. It is URL-encoded automatically.\n- `phoneNumber`: Optional recipient phone number in international format. Non-digit characters such as `+`, spaces, dashes, and parentheses are stripped before the URL is built.\n\n#### Returns\n\nReturns a `string` WhatsApp URL in one of these forms:\n\n- `https://wa.me/?text=...`\n- `https://wa.me/<phone>?text=...`\n\n#### Throws\n\n- Throws an error if `phoneNumber` is provided but does not contain any digits after normalization.\n\nThe function does not open WhatsApp, navigate the browser, or send a message. It only returns the URL.\n\n## Usage Examples\n\n### Prefill a message without a phone number\n\n```ts\nimport { composeWhatsappMessage } from \"@boris93/whatsapp-compose\";\n\nconst url = composeWhatsappMessage({\n  text: \"Hello there\",\n});\n\n// https://wa.me/?text=Hello%20there\n```\n\n### Prefill a message for a specific recipient\n\n```ts\nimport { composeWhatsappMessage } from \"@boris93/whatsapp-compose\";\n\nconst url = composeWhatsappMessage({\n  text: \"Can we talk later?\",\n  phoneNumber: \"+49 170 123 4567\",\n});\n\n// https://wa.me/491701234567?text=Can%20we%20talk%20later%3F\n```\n\n### Open WhatsApp in the browser\n\n```ts\nimport { composeWhatsappMessage } from \"@boris93/whatsapp-compose\";\n\ntry {\n  const url = composeWhatsappMessage({\n    text: \"Hello from the browser\",\n    phoneNumber: \"+491701234567\",\n  });\n\n  window.open(url, \"_blank\", \"noopener,noreferrer\");\n} catch (error) {\n  console.error(\"Could not create WhatsApp link\", error);\n}\n```\n\n### Use inside a Next.js or React click handler\n\n```ts\nimport { composeWhatsappMessage } from \"@boris93/whatsapp-compose\";\n\nexport function ContactButton() {\n  const handleClick = () => {\n    try {\n      const url = composeWhatsappMessage({\n        text: \"Hi, I want to learn more about your service.\",\n        phoneNumber: \"+491701234567\",\n      });\n\n      window.location.href = url;\n    } catch (error) {\n      console.error(\"Invalid WhatsApp link options\", error);\n    }\n  };\n\n  return <button onClick={handleClick}>Chat on WhatsApp</button>;\n}\n```\n\n### Handle invalid phone numbers\n\n```ts\nimport { composeWhatsappMessage } from \"@boris93/whatsapp-compose\";\n\ntry {\n  const url = composeWhatsappMessage({\n    text: \"Hello\",\n    phoneNumber: \"invalid-number\",\n  });\n\n  console.log(url);\n} catch (error) {\n  console.error(\"Please provide a valid international phone number\", error);\n}\n```\n\n## Notes\n\n- `phoneNumber` should include the country code.\n- The function only builds a WhatsApp URL string. It does not send messages or open WhatsApp by itself.\n- If you need to validate phone numbers beyond basic digit extraction, do that before calling the function.\n","readmeFilename":"README.md"}