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

remit-route

v1.4.6

Published

remit an easy way to manage routes with javascript supports optencion of parameters, with the latest version released can validate a form and simulate methods such as GET, POST, PUT, PATCH, DELETE, OPTIONS

Downloads

3

Readme

#remit remit an easy way to manage routes with javascript supports optencion of parameters, with the latest version released can validate a form and simulate methods such as GET, POST, PUT, PATCH, DELETE, OPTIONS


Download/Installation

Download Source:

production development

install with npm

for install you should use the following command

npm install remit-route


##routes

configured to display the error page that is displayed by default and an example of how to use a route

var app = new remit({
	/*showPageNotFount: true,
    showAccessError: true,*/
    viewPath: '/default_dir_view/'
})

var route = new app.Route({
	registerMiddleware: {
		'user': function(req, res, next) {
			if (req.params.id == 1){
				return next(res)
			}
			res.redirect('/')
		}
	}
})

route.get('/', function(req, res) {
    alert('home')
})

to obtain the parameters

route.get('/user/{id}', function(req, res, id){
	alert(id) // or req.params.id 
})

among the options of this url:

  • / user/{name}
  • / user/{id: number}
  • / user/{name: string}
  • / user/{name: upper}
  • / user/{name: lower}
  • / user/(?P<id>[\d+|\D+|otherOptions])

if you want to submit a form by post method and validate the second parameter an object is passed

route.get('/user/login', {
	validation: ['#idForm', {'name': 'required', 'pass': 'required'}],
	render: function(req, res) {
		console.log('via get');
   }
};

When running a view, the key is changed

route.get('/user/login', {
	asyncValidation: ['#idForm', {'name': 'required', 'pass': 'required'}],
	render: function(req, res) {
		res.view('login.html');
   }
};

run the post method

route.post('/user/login', function() {
	console.log('post')
})

or do so through the method options

route.options('/user/login', {
	validation: ['#idForm', {'name': 'required', 'pass': 'required'}],
	render: function(req, res) {
		console.log('OPTIONS method')
   }
}

create groups

route.group('/user', function(route) {
    route.get('/login', function() {
    	console.log('login')
    })
    
    route.get('/register', function() {
    	console.log('register')
    })
})

render and pass data to the view

route.get('/view', function(req, res) {
	res.view('index.html', {
	    welcome: 'welcome!'
	})
})

routes method

  • group
  • get
  • post
  • put
  • patch
  • delete
  • options

#middleware

use the middleware that is registered, or pass as a function

route.get('/verify/user/{id}', {
	middleware: 'user',
	render: function(req, res, id) {
		console.log(id);
   }
};

##validation

options available to validate

  • required
  • min:min_value
  • max:max_value
var validator = new app.validation('#idForm', {
	'inputName': 'required|min:6|max:20'
}).ifNotSubmit()

##local storage and session storage

using localData function to store data, by default uses the localStorage, you can specify that you want to use session specifying in the last parameter

app.localData('key', 'value');

or

app.localData.set('key', 'value');

to add session

app.localData('key', 'value', 'session');

the same to obtain or remove

app.localData.delete('key' /*, null or 'session'*/);

get value

app.localData.get('key' /*, null or 'session'*/);

##Cookie

add Cookie

app.Cookie('key', 'value'/*, options {} */);

or

app.Cookie.assign('key', 'value'/*, options {} */);

static methods

app.Cookie.assign('key', 'value'/*, options {}  */);
app.Cookie.all(); // return an array
app.Cookie.delete('key');
app.Cookie.get ('key') // return a string

when the browser is reloaded, methods post, put, patch and delete is executed once