Socket
Socket
Sign inDemoInstall

riot-route

Package Overview
Dependencies
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

riot-route - npm Package Compare versions

Comparing version 2.3.0-beta to 2.3.0-beta.2

dist/amd.route.js

9

dist/riot.route.js

@@ -42,4 +42,6 @@ ;(function(riot) { if (!window) return;

function DEFAULT_SECOND_PARSER(path, filter) {
var re = new RegExp('^' + filter[REPLACE](/\*/g, '(\\w+)')[REPLACE](/\.\./, '.*') + '$')
if (args = path.match(re)) return args.slice(1)
var re = new RegExp('^' + filter[REPLACE](/\*/g, '(\\w+)')[REPLACE](/\.\./, '.*') + '$'),
args = path.match(re)
if (args) return args.slice(1)
}

@@ -252,2 +254,3 @@

riot.route = route })(riot)
riot.route = route
})(riot)
;(function() {
/** Browser global settings **/
var EXPORT_TO = 'route', MOD_MAP = { 'riot-observable': 'observable' }
'use strict'
/* istanbul ignore next */
/* istanbul ignore next */
var d = (typeof define === 'function' && define.amd) ? define : (function(f) {
var c = typeof exports === 'object' && !exports.nodeType,
r = c ? require : function(name) { return window[MOD_MAP[name] || name] },
m = c ? module : { _g: true }
f(r, 0, m)
})
d(function(require, exports, module) {
/**
var observable = function(el) {
/**
* Extend the original object or create a new empty one
* @type { Object }
*/
el = el || {}
/**
* Private variables and methods
*/
var callbacks = {},
onEachEvent = function(e, fn) { e.replace(/\S+/g, fn) }
/**
* Listen to the given space separated list of `events` and execute the `callback` each time an event is triggered.
* @param { String } events - events ids
* @param { Function } fn - callback function
* @returns { Object } el
*/
el.on = function(events, fn) {
if (typeof fn != 'function') return el
onEachEvent(events, function(name, pos) {
(callbacks[name] = callbacks[name] || []).push(fn)
fn.typed = pos > 0
})
return el
}
/**
* Removes the given space separated list of `events` listeners
* @param { String } events - events ids
* @param { Function } fn - callback function
* @returns { Object } el
*/
el.off = function(events, fn) {
if (events == '*') callbacks = {}
else {
onEachEvent(events, function(name) {
if (fn) {
var arr = callbacks[name]
for (var i = 0, cb; cb = arr && arr[i]; ++i) {
if (cb == fn) arr.splice(i--, 1)
}
} else delete callbacks[name]
})
}
return el
}
/**
* Listen to the given space separated list of `events` and execute the `callback` at most once
* @param { String } events - events ids
* @param { Function } fn - callback function
* @returns { Object } el
*/
el.one = function(events, fn) {
function on() {
el.off(events, on)
fn.apply(el, arguments)
}
return el.on(events, on)
}
/**
* Execute all callback functions that listen to the given space separated list of `events`
* @param { String } events - events ids
* @returns { Object } el
*/
el.trigger = function(events) {
var args = [].slice.call(arguments, 1)
onEachEvent(events, function(name) {
var fns = callbacks[name] || []
for (var i = 0, fn; fn = fns[i]; ++i) {
if (fn.busy) return
fn.busy = 1
fn.apply(el, fn.typed ? [name].concat(args) : args)
if (fns[i] !== fn) i--
fn.busy = 0
}
if (callbacks.all && name != 'all')
el.trigger.apply(el, ['all', name].concat(args))
})
return el
}
return el
}/**
* Simple client-side router

@@ -18,3 +112,2 @@ * @module riot-route

var observable = require('riot-observable')

@@ -54,4 +147,6 @@ var RE_ORIGIN = /^.+?\/+[^\/]+/,

function DEFAULT_SECOND_PARSER(path, filter) {
var re = new RegExp('^' + filter[REPLACE](/\*/g, '(\\w+)')[REPLACE](/\.\./, '.*') + '$')
if (args = path.match(re)) return args.slice(1)
var re = new RegExp('^' + filter[REPLACE](/\*/g, '(\\w+)')[REPLACE](/\.\./, '.*') + '$'),
args = path.match(re)
if (args) return args.slice(1)
}

@@ -264,5 +359,3 @@

module.exports = route
if (module._g) window[EXPORT_TO] = module.exports
})
window.route = route
})();

@@ -1,1 +0,1 @@

(function(){var t="route",e={"riot-observable":"observable"};var n=typeof define==="function"&&define.amd?define:function(t){var n=typeof exports==="object"&&!exports.nodeType,i=n?require:function(t){return window[e[t]||t]},r=n?module:{_g:true};t(i,0,r)};n(function(e,n,i){var r=e("riot-observable");var o=/^.+?\/+[^\/]+/,f="EventListener",s="remove"+f,u="add"+f,a="hasAttribute",c="replace",h="popstate",l="trigger",p=window,d=document,v=p.history.location||p.location,m=_.prototype,b=d&&d.ontouchstart?"touchstart":"click",w=false,g=r(),y,x,$,A;function K(t){return t.split(/[\/?#]/)}function N(t,e){var n=new RegExp("^"+e[c](/\*/g,"(\\w+)")[c](/\.\./,".*")+"$");if(args=t.match(n))return args.slice(1)}function _(){this.$=[];r(this);g.on("stop",this.s.bind(this));g.on("emit",this.e.bind(this))}function q(t){return t[c](/^\/|\/$/,"")}function E(t){return(t||v.href)[c](o,"")}function j(t){return y[0]=="#"?(t||v.href).split(y)[1]||"":E(t)[c](y,"")}function k(t){var e=j();if(t||e!=x){g[l]("emit",e);x=e}}function D(t){if(t.which!=1||t.metaKey||t.ctrlKey||t.shiftKey||t.defaultPrevented)return;var e=t.target;while(e&&e.nodeName!="A")e=e.parentNode;if(!e||e.nodeName!="A"||e[a]("download")||!e[a]("href")||e.target&&e.target!="_self"||e.href.indexOf(v.href.match(o)[0])==-1)return;if(e.href!=v.href){if(e.href.split("#")[0]==v.href.split("#")[0])return;L(j(e.href),e.title||d.title)}t.preventDefault()}function L(t,e){e=e||d.title;history.pushState(null,e,y+t);d.title=e;k()}m.m=function(t,e){if(t[0]&&(!e||e[0]))L(t,e);else if(e)this.r(t,e);else this.r("@",t)};m.s=function(){this.off("*");this.$=[]};m.e=function(t){this.$.concat("@").some(function(e){var n=(e=="@"?$:A)(q(t),q(e));if(n){this[l].apply(null,[e].concat(n));return true}},this)};m.r=function(t,e){if(t!="@")this.$.push(t);this.on(t,e)};var O=new _;var P=O.m.bind(O);P.create=function(){var t=new _;t.m.stop=t.s.bind(t);return t.m.bind(t)};P.base=function(t){y=t||"#";x=j()};P.exec=function(){k(true)};P.parser=function(t,e){if(!t&&!e){$=K;A=N}if(t)$=t;if(e)A=e};P.query=function(){var t={};v.href[c](/[?&](.+?)=([^&]*)/g,function(e,n,i){t[n]=i});return t};P.stop=function(){if(w){p[s](h,k);d[s](b,D);g[l]("stop");w=false}};P.start=function(){if(!w){p[u](h,k);d[u](b,D);w=true}};P.base();P.parser();P.start();i.exports=P;if(i._g)window[t]=i.exports})})();
(function(){"use strict";var t=function(t){t=t||{};var n={},e=function(t,n){t.replace(/\S+/g,n)};t.on=function(i,r){if(typeof r!="function")return t;e(i,function(t,e){(n[t]=n[t]||[]).push(r);r.typed=e>0});return t};t.off=function(i,r){if(i=="*")n={};else{e(i,function(t){if(r){var e=n[t];for(var i=0,f;f=e&&e[i];++i){if(f==r)e.splice(i--,1)}}else delete n[t]})}return t};t.one=function(n,e){function i(){t.off(n,i);e.apply(t,arguments)}return t.on(n,i)};t.trigger=function(i){var r=[].slice.call(arguments,1);e(i,function(e){var i=n[e]||[];for(var f=0,o;o=i[f];++f){if(o.busy)return;o.busy=1;o.apply(t,o.typed?[e].concat(r):r);if(i[f]!==o)f--;o.busy=0}if(n.all&&e!="all")t.trigger.apply(t,["all",e].concat(r))});return t};return t};var n=/^.+?\/+[^\/]+/,e="EventListener",i="remove"+e,r="add"+e,f="hasAttribute",o="replace",u="popstate",c="trigger",a=window,s=document,l=a.history.location||a.location,h=x.prototype,p=s&&s.ontouchstart?"touchstart":"click",d=false,v=t(),y,m,g,b;function w(t){return t.split(/[\/?#]/)}function $(t,n){var e=new RegExp("^"+n[o](/\*/g,"(\\w+)")[o](/\.\./,".*")+"$"),i=t.match(e);if(i)return i.slice(1)}function x(){this.$=[];t(this);v.on("stop",this.s.bind(this));v.on("emit",this.e.bind(this))}function A(t){return t[o](/^\/|\/$/,"")}function K(t){return(t||l.href)[o](n,"")}function N(t){return y[0]=="#"?(t||l.href).split(y)[1]||"":K(t)[o](y,"")}function E(t){var n=N();if(t||n!=m){v[c]("emit",n);m=n}}function S(t){if(t.which!=1||t.metaKey||t.ctrlKey||t.shiftKey||t.defaultPrevented)return;var e=t.target;while(e&&e.nodeName!="A")e=e.parentNode;if(!e||e.nodeName!="A"||e[f]("download")||!e[f]("href")||e.target&&e.target!="_self"||e.href.indexOf(l.href.match(n)[0])==-1)return;if(e.href!=l.href){if(e.href.split("#")[0]==l.href.split("#")[0])return;k(N(e.href),e.title||s.title)}t.preventDefault()}function k(t,n){n=n||s.title;history.pushState(null,n,y+t);s.title=n;E()}h.m=function(t,n){if(t[0]&&(!n||n[0]))k(t,n);else if(n)this.r(t,n);else this.r("@",t)};h.s=function(){this.off("*");this.$=[]};h.e=function(t){this.$.concat("@").some(function(n){var e=(n=="@"?g:b)(A(t),A(n));if(e){this[c].apply(null,[n].concat(e));return true}},this)};h.r=function(t,n){if(t!="@")this.$.push(t);this.on(t,n)};var q=new x;var D=q.m.bind(q);D.create=function(){var t=new x;t.m.stop=t.s.bind(t);return t.m.bind(t)};D.base=function(t){y=t||"#";m=N()};D.exec=function(){E(true)};D.parser=function(t,n){if(!t&&!n){g=w;b=$}if(t)g=t;if(n)b=n};D.query=function(){var t={};l.href[o](/[?&](.+?)=([^&]*)/g,function(n,e,i){t[e]=i});return t};D.stop=function(){if(d){a[i](u,E);s[i](p,S);v[c]("stop");d=false}};D.start=function(){if(!d){a[r](u,E);s[r](p,S);d=true}};D.base();D.parser();D.start();window.route=D})();

@@ -41,4 +41,6 @@ /**

function DEFAULT_SECOND_PARSER(path, filter) {
var re = new RegExp('^' + filter[REPLACE](/\*/g, '(\\w+)')[REPLACE](/\.\./, '.*') + '$')
if (args = path.match(re)) return args.slice(1)
var re = new RegExp('^' + filter[REPLACE](/\*/g, '(\\w+)')[REPLACE](/\.\./, '.*') + '$'),
args = path.match(re)
if (args) return args.slice(1)
}

@@ -45,0 +47,0 @@

{
"name": "riot-route",
"version": "2.3.0-beta",
"version": "2.3.0-beta.2",
"description": "Simple client-side router",
"main": "dist/route.js",
"main": "lib/index.js",
"directories": {

@@ -28,7 +28,8 @@ "lib": "lib",

"coveralls": "^2.11.4",
"eslint": "^1.3.1",
"eslint": "^1.4.1",
"expect.js": "^0.3.1",
"karma": "^0.13.9",
"karma-coverage": "^0.5.1",
"karma-coverage": "^0.5.2",
"karma-mocha": "^0.2.0",
"karma-mocha-reporter": "^1.1.1",
"karma-phantomjs-launcher": "^0.2.1",

@@ -35,0 +36,0 @@ "uglify-js": "latest"

@@ -10,12 +10,11 @@ [![Build Status][travis-image]][travis-url]

Router is a generic tool to take care of the URL and the back button. It's the smallest implementation you can find and it works on all browsers including IE9. It can do the following:
The Riot Router is the minimal router implementation with such technologies:
1. Change the hash part of the URL
2. Notify when the hash changes
3. Study the current hash
- pushState and history API
- multiple routing groups
- replacable parser
- compatible with IE9 and higher
You can place routing logic everywhere; in custom tags or non-UI modules. Some application frameworks make the router a central element that dispatches work to the other pieces of the application. Some take a milder approach where URL events are like keyboard events, not affecting the overall architecture.
A part of Riot.js, but it also works without Riot.js.
Every browser application needs routing since there is always an URL in the location bar.
## Documentation

@@ -30,2 +29,17 @@

## Downloads
We have 3 editions:
- **Standalone**:
- [route.js](https://raw.githubusercontent.com/riot/route/master/dist/route.js)
- [route.min.js](https://raw.githubusercontent.com/riot/route/master/dist/route.min.js)
- **AMD**:
- *for RequireJS*
- [amd.route.js](https://raw.githubusercontent.com/riot/route/master/dist/amd.route.js)
- [amd.route.min.js](https://raw.githubusercontent.com/riot/route/master/dist/amd.route.min.js)
- **CommonJS**
- *for Browserify, Webpack, ...etc*
- download via npm
## Installation

@@ -48,2 +62,3 @@

- [Page switching](http://riotjs.com/examples/plunker/?app=router-page-switcher)
- [Complex routings](http://riotjs.com/examples/plunker/?app=router-complex)

@@ -50,0 +65,0 @@ ## Development

var route = require('riot-route')
route.exec(function() {
route(function() {
console.log('Hello Browserify!')
})
route.exec()
module.exports = function(config) {
config.set({
basePath: '',
autoWatch: true,
frameworks: ['mocha'],
plugins: [
'karma-mocha',
'karma-mocha-reporter',
'karma-coverage',

@@ -13,5 +12,3 @@ 'karma-phantomjs-launcher'

files: [
'../node_modules/mocha/mocha.js',
'../node_modules/expect.js/index.js',
'../node_modules/riot-observable/dist/observable.js',
'polyfill.js',

@@ -21,10 +18,7 @@ '../dist/route.js',

],
browsers: ['PhantomJS'],
reporters: ['progress', 'coverage'],
reporters: ['mocha', 'coverage'],
preprocessors: {
'../dist/route.js': ['coverage']
},
coverageReporter: {

@@ -37,5 +31,4 @@ dir: '../coverage/',

},
singleRun: true
})
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc