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

notify-io

v0.1.2

Published

Notify-IO gives you an easy to use interface for defining and calling your own custom notifications.

Downloads

2

Readme

Notify-IO

Introduction

Notify-IO gives you an easy to use interface for defining and calling your own custom notifications.

1. Geting Started

The steps below will walk you through setting up a basic project to get started with notify-io

step 0: NPM install notify-io

$ npm i notify-io

step 1: Require in Notify and SchemaBuilder

const { Notify, SchemaBuilder } = require('notify-io')

step 2: Create new SchemaBuilder object

const schema = new SchemaBuilder()

step 3: Define Schema with the create function

schema.create('welcome', {
    en: (noun) => `welcome back ${noun}`, 
    zh: (noun) => `欢迎回来 ${noun}`,
})

step 4: Use Notify in your project

const notify = new Notify(schema)
notify.stateTo('info') // info is the default state, so only call stateTo() if you need another state.

const msg = notify.message('welcome', 'some-username', 'username')

console.log(msg)

step 5: The output of step 4

{
  lang: 'en',
  state: 'validation',
  messages: [
    {
      key: 'username',
      state: 'info',
      code: 'welcome',
      message: 'welcome back some-username'
    }
  ]
}

Schema Definition Types

Schemas are at the core of Notify-IO. Here we will take a look at the three types of Schemas, specifically how they are defined and when what type is used. Schema types are distinguished based on the mount of arguments the schema function takes.

The three types are:

  • Constant Schema Definition (CSD)
  • Unary Schema Definition (USD)
  • Multidimensional Schema Definition (MSD)

Note: keys must be valid ISO 639-1 lang codes e.g. "en"

Constant Schema Definition (CSD)

schema.create('already_registered', {
    en: () => `please try loggin in!`, 
    zh: () => `请登陆`,
})

Unary Schema Definition (USD)

schema.create('welcome', {
    en: (noun) => `welcome back ${noun}`, 
    zh: (noun) => `欢迎回来 ${noun}`,
})

Multidimensional Schema Definition (MSD)

schema.create('should_match', {
    en: (data) => `${data.noun1} and ${data.noun2} should match!`,
    zh: (data) => `${data.noun1} 和 ${data.noun2} 应该相同!`
})

API Documentation

.message()

The message method has three parameters. The first is required and the other two are optional. Notify-IO-Instance.message(schema-name, schema-data, message-key). The message method renders handles schema rendering for you.

const notify = new Notify('validation')
notify
    .message('any.required', 'password', 'password')

.load()

The load method has three parameters. The first is required and the other two are optional. Notify-IO-Instance.load(schema-name, schema-data, message-key). The load method only loads your Schema to a queue. When you are done loading messages you can call the render method which will render all Schema in the queue.

const notify = new Notify('validation')
notify
    .load('any.required', 'password', 'password')
    .load('string.empty', 'password', 'password')
    .render()

.render()

The render method takes no parameters. It renders all Schema in the queue.

const notify = new Notify('validation')
notify
    .load('any.required', 'password', 'password')
    .load('string.empty', 'password', 'password')
    // call load as many times as you need ...
    .render()