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

notifme-template

v1.0.0

Published

A Node.js library to easily handle all your notification templates

Downloads

3,786

Readme

Features

  • All your notifications in one place — Define all your email, sms, push, and webpush templates in one folder :thumbsup:

  • Choose your template enginefacebook/react, pug (formerly jade), mozilla/nunjucks, handlebars.js, mustache.js, lodash, underscore, marko, doT, swig, linkedin/dustjs, twig.js, ejs... and many more. Literally the one you want :dancer:

  • Complete control — No magic: you define all the behaviours you need (layouts, CSS preprocessor...) :rocket:

  • No dependencies — Lightning fast installation :zap:

  • Localization — Easily implement i18n/l10n for all your notifications :globe_with_meridians:

  • CSS inlining — Add Juice to your dependencies and the CSS in your emails will automatically be inlined :ribbon:

  • MIT license — Use it like you want.

Getting Started

$ yarn add notifme-template
// Example with nunjucks template engine ($ yarn add nunjucks)
const nunjucks = require('nunjucks')
const getRenderer = require('notifme-template')

const render = getRenderer(nunjucks.renderString, './templates')

const data = {user: {firstname: 'John', email: '[email protected]'}}
render('welcome', data, 'en-US').then((notification) => {
  // Send the notification on its channels
})
// ./templates/welcome.js
module.exports = () => ({
  name: 'welcome',
  title: 'Welcome {{user.firstname}}',
  version: 1,
  channels: {
    sms: {
      from: '{{smsFrom}}',
      to: '{{user.phone}}',
      text: "Hi {{user.firstname}}, we're very happy to welcome you on board!"
    },
    email: {
      from: '{{emailFrom}}',
      to: '{{user.email}}',
      subject: 'Welcome {{user.firstname}}',
      html: `{% extends "templates/_layouts/email-transactional.html" %}
        {% block content %}
        Hi {{user.firstname}},<br><br>
        We're very happy to welcome you on board.<br><br>
        See you soon!
        {% endblock %}`
    },
    push: {
      registrationToken: '{{user.pushToken}}',
      title: 'Welcome {{user.firstname}}',
      body: "Hi {{user.firstname}}, we're very happy to welcome you on board"
    }
  },
  sampleData: {
    smsFrom: 'Notifme',
    emailFrom: '"David, Notif.me team" <[email protected]>',
    user: {
      firstname: 'John',
      email: '[email protected]',
      phone: '+15000000001',
      pushToken: 'xxxxx'
    }
  }
})

See a complete working example for more details.

How to use

Constructor options

const getRenderer = require('notifme-template')

const render = getRenderer(/* renderer, folder, options */)

| Argument name | Type | Required | Description | | --- | --- | --- | --- | | renderer | Function | true | Template engine function to use. It must implement (templateName: string, data: Object) => string | Promise<string>. | | folder | string | true | The path to the folder containing all your templates. | | options | Object | false | See options definition. |

This returns the render function documented below.

Template declaration

project/
│
└───templates/    <= you can place this folder where you want and choose its name
    │   template1.js
    │
    └───template2/
        │   index.js

With the structure above, you will have two templates template1 and template2. notifme-template makes a dynamic require require(`${path.resolve(folder, templateName)}`) the first time you call them.

Each template must export a function implementing: (lang: string) => TemplateType | Promise<TemplateType>. See TemplateType definition and examples for more details.

render method

render(/* templateName, data, lang */).then((notification) => {
  // Send the notification on its channels
})

| Argument name | Type | Required | Description | | --- | --- | --- | --- | | templateName | string | true | The template name to use. | | data | Object | true | Data to use when rendering the notification. | | lang | string | false | User language. |

This returns a Promise resolving with the rendered template.

Contributing

js-standard-style flow-typed

Contributions are very welcome!

To get started: fork this repository to your own GitHub account and then clone it to your local device.

$ git clone [email protected]:[YOUR_USERNAME]/notifme-template.git && cd notifme-template
$ yarn install

Need Help? Found a bug?

Submit an issue to the project Github if you need any help. And, of course, feel free to submit pull requests with bug fixes or changes.