Giter VIP home page Giter VIP logo

flash's Introduction

flash

NPM version Build status Test coverage Dependency Status License Downloads

The simplest flash implementation for Express.

Usage

npm i flash
app.use(session()); // session middleware
app.use(require('flash')());

app.use(function (req, res) {
  // flash a message
  req.flash('info', 'hello!');
  next();
})
for message in flash
  a.alert(class='alert-' + message.type)
    p= message.message
while message = flash.shift() // consume messages as jade reads them
  a.alert(class='alert-' + message.type)
    p= message.message

API

req.flash([type], msg)

Flash a message defaulting the type to info.

res.locals.flash

An array of flash messages of the form:

{
  "type": "info",
  "message": "message"
}

flash's People

Contributors

gluxon avatar jonathanong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flash's Issues

The value of a little advice

use while message = flash.shift() get value too cumbersome。
Some values are not my concern
I just want error_message value
Whether this can be req.flash('message') ?

I modified code
after flash('message') the 'message' be delete, no need to manually shift.

function push(type, msg) {
  var res = this.res || this;
  var locals = res.locals.flash;
  if(!msg){
      if(typeof type === 'string' && locals.length){
          for(var i = 0, l = locals.length; i < l; i++){
              if(locals[i]['type'] === type){
                  msg = locals[i]['message'];
                  locals.splice(i, 1);
                  return msg;
              }
          }
      }
      return;
  }
  msg = {
    message: msg,
    type: type
  }

  var messages = res.locals.flash
  // do not allow duplicate flash messages
  for (var i = 0; i < messages.length; i++) {
    var message = messages[i]
    if (msg.type === message.type && msg.message === message.message) return this
  }
  messages.push(msg)
  return this
}

Flashes in twig

Hi, I have a problem with flashes in twig. I want pop stack of flash and write messages to template. For pop stack i use shift() like written in doc. But it's not works. Twig not support while loop, only for with syntax for <i> in <source>. Useless for pop flash stack.

{% for alert in flash.shift() %}
    <div class="alert alert-{{alert.type}} alert-dismissible fade show general-alert" role="alert">
      {{alert.message}}
      <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
      </button>
    </div>
{% endfor %}

How I solve this problem?

the flash session not to be expired

Hello,
I have this session

app.use(session({ secret: 'changeme' , cookie: { secure: false,  maxAge: new Date(Date.now() + 3600000), } , resave:false, saveUninitialized:false, store: new SkinStore(db)  }));

when using flash it will stuck on the session and not to be expired !
should I destory the flash session manually

Feature request: TypeScript support

Hello world,

I would like to request a feature: TypeScript support.

I am going to to try to pull together a pull request if I can.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.