JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 21
  • Score
    100M100P100Q41882F
  • License MIT

Flash messaging. Minimal dependencies.

Package Exports

  • kisapmata

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (kisapmata) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

kisapmata

npm version

"o kay bilis naman maglaho"

Install

Choose 1 of 3 options:

Install from NPM:

npm install kisapmata

Install latest from GitHub:

npm install github:kosinix/kisapmata

Tied to a specific version/release from GitHub:

npm install github:kosinix/kisapmata#1.1.0

Quickstart

Include it:

const flash = require('kisapmata');

In Express:

Note: This assumes that you have registered the express-session middleware

const session = require('express-session');
router.use(session());

In routes:

router.post('/edit-profile', async (req, res, next) => {
    try {

        flash.set(req, 'success', 'Changes saved.') // Create flash message. Pass Express's req variable. Assign to key "success". Message is "Changes saved."

        res.redirect('/edit-profile')
    } catch (err) {
        next(err);
    }
});

router.get('/edit-profile', async (req, res, next) => {
    try {
        
        let okMessage = flash.get(req, 'success') // Get message with key 'success'
        res.render('edit-profile.html', {  
            okMessage: okMessage
        }) // Pass flash message to template
        
    } catch (err) {
        next(err);
    }
});

Advanced Usage

Its meant to be used with express sessions so the default path is 'session.flash.${id}'.

Change the path to something and use it outside express apps:

flash.set(myCustomVariable, 'success', 'Changes saved.', 'path.custom.${id}') // Here ${id} becomes 'success'

let x = flash.get(myCustomVariable, 'success', 'path.custom.${id}') // Make sure the path matches the one used in flash.set