Gathering detailed insights and metrics for @uraniadev/emailer
Gathering detailed insights and metrics for @uraniadev/emailer
Gathering detailed insights and metrics for @uraniadev/emailer
Gathering detailed insights and metrics for @uraniadev/emailer
npm install @uraniadev/emailer
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
8 Stars
28 Commits
1 Watching
1 Branches
1 Contributors
Updated on 29 Oct 2024
TypeScript (52.98%)
Svelte (35.94%)
JavaScript (7.21%)
HTML (3.01%)
CSS (0.86%)
Cumulative downloads
Total Downloads
Last day
0%
Compared to previous day
Last week
0%
0
Compared to previous week
Last month
0%
0
Compared to previous month
Last year
0%
0
Compared to previous year
3
1
This is a library for creating structured and styled HTML emails, intended as a transitional resource. Designed for convenience, it allows developers to build and customize emails quickly while encouraging best practices by illustrating the internal composition of emails through self-contained components. Inspired by Resend's @react-email.
This library takes a similar approach to the one applied by pilcrow's to The Copenhagen Book: this library is intended as a learning tool and a starting point. As developers become comfortable with the email structure and utilities provided, they are encouraged to transition toward standalone solutions.
To install the package, run:
1npm install @uraniadev/emailer
This library provides a set of unstyled, modular email components (e.g.,
Button
, Container
, Heading
) built with Svelte and styled with Tailwind
CSS. Components use inline
styling through tw-to-css
to ensure email
compatibility.
Create an email using the provided components:
1<!-- src/lib/email.svelte --> 2<script> 3 import { 4 Button, 5 Container, 6 Heading, 7 Image, 8 Paragraph 9 } from "@uraniadev/emailer"; 10</script> 11 12<Container> 13 <Image src="https://example.org/image-url.jpg" /> 14 <Heading level={2}>Lorem ipsum dolor sit</Heading> 15 <Paragraph> 16 Lorem ipsum dolor sit amet consectetur adipisicing elit. 17 Maiores veritatis earum, perspiciatis pariatur exercitationem 18 illum eligendi amet,deserunt provident ipsum dolore! 19 Voluptas mollitia earum temporibus, hic consequatur 20 aperiam recusandae. 21 </Paragraph> 22 <Button href="https://www.example.com">Deserunt</Button> 23</Container>
Then render this email in your server-side script:
1import Emailer from "@uraniadev/emailer"; 2import Email from "./email.svelte"; 3 4const emailer = new Emailer(); 5 6const html = emailer.render(Email, {/* props */}); 7sendMail(html); // Use your preferred email-sending method
tw-to-css
This library includes an inline
utility that merges Tailwind styles with
tw-to-css
to create compatible inline styles for emails:
1import { inline } from "@uraniadev/emailer"; 2 3<p style={inline("text-lg text-pink-500 font-bold")}> 4 This is a formatted text 5</p>;
1// inline() inherith shadcn cn an apply tw-to-css inline: 2 3import type { ClassValue } from "clsx"; 4 5import clsx from "clsx"; 6import { twMerge } from "tailwind-merge"; 7import { twi } from "tw-to-css"; 8 9export function inline(...inputs: ClassValue[]) { 10 return twi(twMerge(clsx(inputs))); 11}
Button
A link-styled button that accepts class
and href
attributes. *
1<Button class="bg-blue-500 text-white" href="https://example.com">Click Me</Button>
Card
A general-purpose card component for grouping content sections.
1<Card class="shadow-lg">This is a card</Card>
Container
A wrapper to align email content and provide consistent padding.
1<Container class="max-w-lg">Content goes here</Container>
Heading
A responsive heading element allowing level-based customization.
1<Heading level={2}>This is a Heading</Heading>
Image
An image wrapper with optional classes.
1<Image src="https://example.com/image.jpg" alt="Image description" />
Paragraph
For general text blocks, styled for readability.
1<Paragraph>This is a paragraph of text</Paragraph>
Preview
This is a text snippet that appears under the subject line in the inbox but is hidden from the main email content when it’s opened. *
1<Preview content="The preview of the content, to customize it from the actual mail" />
Repeatable
Generates repeated content, such as lists, from an array. itemsSnippet
can be
use to stylize the repeated item
1<Repeatable items={[1, 2, 3]}> 2 {#snippet itemsSnippet(item)} 3 <Container> 4 <Paragraph>{item.name}</Paragraph> 5 </Container> 6 {/snippet} 7</Repeatable>
Emailer
is the primary class used to render emails, taking in a Svelte
component and outputting an HTML template. It can be customized by passing
configuration options for props
, lang
, dir
, and style
.
1class Emailer { 2 render<T extends Component<any>>( 3 component: T, 4 props?: ComponentProps<T>, 5 config?: HTMLConfig, 6 ): string; 7}
The htmlBoilerplate
function in the Emailer
class generates the complete
HTML structure for email content, applying essential styles and configuration
for better rendering across email clients. This function wraps the main content
(children
) in an HTML template, ensuring consistency and compatibility.
html
, body
, and
container
elements, configurable via the HTMLConfig
type. Each property is
an array of style strings, providing styles like background color, text color,
and padding.<style>
tag.render
functionThe Emailer.render()
method uses htmlBoilerplate
to wrap the rendered body
of a Svelte component (provided in render
as component
). The function also
accepts:
<head>
section.HTMLConfig
object to override the default
properties, styles, direction, or language settings.Together, these properties and htmlBoilerplate
facilitate the creation of
highly customizable, visually consistent email templates with minimal setup.
1htmlBoilerplate = (children: string, head?: string, options?: HTMLConfig) => { 2 const { props, dir, lang, style } = options || 3 { props: this.props, dir: this.dir, lang: this.lang, style: this.style }; 4 return `<!doctype html> 5 <html ${props?.html.join(" ")} dir=${dir} lang=${lang}> 6 <head> 7 <style>*{box-sizing:border-box;text-decoration:none;border:0;padding:0;margin:0;}${style}</style> 8 ${head || this.head} 9 </head> 10 <body ${props?.body.join(" ")}> 11 <table ${props?.container.join(" ")}> 12 <tbody><tr><td>${children}</td></tr></tbody> 13 </table> 14 <body> 15 </html>`; 16};
The library is structured as an auto-deprecating toolkit for email composition, encouraging developers to understand and apply best practices for maintainable email templates in production. The following approaches are suggested:
Drawing inspiration from resources like The Copenhagen Book, this library advocates for transparency in development practices and empowers developers to confidently transition to self-maintained code structures.
The following references provide further information on creating HTML emails:
Note: This library is intended as a learning tool and a starting point. As developers become comfortable with the email structure and utilities provided, they are encouraged to transition toward standalone solutions.
No vulnerabilities found.
No security vulnerabilities found.