UNPKG

thank-you-tweet-button-003

Version:

Easy-to-use tweet button for saying thank you to @oluwatobiss.

32 lines (27 loc) 1.25 kB
import { generateStarIcons } from "./generateStarIcons.js"; import { showError } from "./showError.js"; export function tweetButton(rating, bestNPMPackage, quantity) { const tweetButtonContainer = document.createElement("section"); const anchorElement = document.createElement("a"); const anchorElementContent = document.createTextNode( "Post a thank you message", ); const tweetUrl = `https://twitter.com/intent/tweet?text=Thank+you,+ %40oluwatobiss.+Your+book+helped+me+create,+test,+and+publish+${ quantity && quantity > 1 ? quantity : "an" }+NPM+${ quantity && quantity > 1 ? "packages" : "package" }.%0A%0AMy+Favorite:+${bestNPMPackage}%0A%0ABook's+Rating:+${rating}- star+rating!+${generateStarIcons( rating, )}+%0A%0ACreating%20NPM%20Package%0A%0Ahttps%3A%2F%2Famzn.to/4lifL3n`; tweetButtonContainer.setAttribute("id", "tweet-btn-container"); anchorElement.setAttribute("class", "tweet-button"); anchorElement.setAttribute("target", "_blank"); anchorElement.setAttribute("href", tweetUrl); anchorElement.appendChild(anchorElementContent); tweetButtonContainer.appendChild(anchorElement); return typeof rating === "number" && bestNPMPackage ? tweetButtonContainer : showError(); }