npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@push.rocks/smartntml

v2.0.8

Published

Provides lit-html rendering capabilities for backend applications.

Downloads

331

Readme

@push.rocks/smartntml

lit-html for the backend

Install

To install @push.rocks/smartntml, you need Node.js and npm installed on your machine. If you have them ready, open your terminal and run the following command:

npm install @push.rocks/smartntml --save

This will add @push.rocks/smartntml as a dependency to your project and you're ready to use lit-html in your backend applications.

Usage

The core idea behind @push.rocks/smartntml is to bring the convenience and developer experience of lit-html to server-side rendering. This package leverages the power of lit-html's syntax and data-binding capabilities in a Node.js environment, especially focusing on backend applications that require rendering HTML.

To start using @push.rocks/smartntml, you need to familiarize yourself with TypeScript and ESM syntax, as this module is designed to offer the best experience within this ecosystem.

Setting Up Your Project with TypeScript and ESM

First and foremost, ensure your project is set up to use TypeScript and ECMAScript Modules (ESM). Your tsconfig.json should have the following settings:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
  }
}

Basic Usage

@push.rocks/smartntml simplifies the process of creating and rendering templates. The following example demonstrates how to create a template and render it:

  1. Import the necessary modules

First, import Smartntml and any other module you wish to use:

import { Smartntml, deesElement } from '@push.rocks/smartntml';

deesElement is leveraged for its TemplateResult type and html tag function, allowing us to define our templates with ease.

  1. Create an instance of Smartntml
const smartNTML = new Smartntml();
  1. Define a Template

You can define a template using the html function provided by deesElement. This function allows you to embed dynamic content in a concise and readable manner.

const myTemplate = deesElement.html`
<div>Welcome to Smartntml!</div>
`;
  1. Render the Template

With a template defined, you can render it to a string. This string can then be sent as a response to a client in a web application or stored for later use.

async function renderMyTemplate() {
  const renderedString = await smartNTML.renderTemplateResult(myTemplate);
  console.log(renderedString);
}
renderMyTemplate();

Working with Dynamic Content

@push.rocks/smartntml excels in rendering dynamic content. Assume you have an array of items that you want to display in a list:

const items = ['Apple', 'Banana', 'Cherry'];
const listTemplate = deesElement.html`
<ul>
  ${items.map(item => deesElement.html`<li>${item}</li>`)}
</ul>
`;

You can dynamically render arrays or any functional JavaScript within your templates, making it incredibly powerful for generating dynamic HTML content.

Advanced Usage

@push.rocks/smartntml can also integrate with other backend services and capabilities. For instance, using it alongside your server-side logic to render user-specific data, handling form submissions, or creating email templates.

Note: Always sanitize any user input before rendering it with smartntml to prevent XSS (Cross-Site Scripting) attacks.

Support and Contribution

@push.rocks/smartntml is an open-source project and welcomes contributions from the community. Whether it's improving the documentation, adding new features, or reporting bugs, every contribution helps make smartntml better for everyone.

Before contributing to the project, make sure to discuss your ideas or issues on the repository's issue tracker. This ensures that your contributions align with the project's goals and don't overlap with existing efforts.

Final Thoughts

@push.rocks/smartntml provides a streamlined and efficient way to use lit-html-like syntax for server-rendered templates in Node.js applications. It offers a blend of simplicity and power, enabling developers to create dynamic, data-driven HTML content on the backend with minimal effort. By integrating @push.rocks/smartntml into your project, you embrace modern JavaScript practices and significantly enhance your server-side rendering capabilities.

For more detailed usage examples and advanced features, make sure to check out the official documentation and explore the @push.rocks/smartntml codebase. Happy coding!

License and Legal Information

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at [email protected].

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.