Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

can-route

Package Overview
Dependencies
Maintainers
4
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-route - npm Package Compare versions

Comparing version 0.3.0 to 3.0.0-pre.1

.editorconfig

103

package.json
{
"name": "can-route",
"version": "0.3.0",
"description": "A simple regexp router that returns false when it can’t handle a request.",
"main": "index.js",
"browser": "browser.js",
"directories": {
"test": "test"
"version": "3.0.0-pre.1",
"description": "",
"homepage": "",
"repository": {
"type": "git",
"url": "git://github.com/canjs/can-route.git"
},
"dependencies": {
"methods": "~0.1.0",
"collapse-array": "~1.0.1",
"named-regexp": "~0.1.1"
"author": {
"name": "Bitovi",
"email": "contact@bitovi.com",
"url": "http://bitovi.com"
},
"devDependencies": {
"tape": "~2.1.0"
},
"scripts": {
"test": "tape test/server.js"
"preversion": "npm test && npm run build",
"version": "git commit -am \"Update dist for release\" && git checkout -b release && git add -f dist/",
"postversion": "git push --tags && git checkout master && git branch -D release && git push",
"testee": "testee test/test.html --browsers firefox",
"test": "npm run jshint && npm run testee",
"jshint": "jshint ./*.js --config",
"release:pre": "npm version prerelease && npm publish",
"release:patch": "npm version patch && npm publish",
"release:minor": "npm version minor && npm publish",
"release:major": "npm version major && npm publish",
"build": "node build.js",
"document": "documentjs",
"develop": "done-serve --static --develop --port 8080"
},
"testling": {
"files": "test/browser.js",
"browsers": {
"ie": [6, 7, 8, 9, 10],
"chrome": [20, 25, 29],
"firefox": [3, 4, 7, 19, 24],
"safari": [5.1, 6],
"opera": [10, 12, 15],
"iphone": [6],
"android": [4.2]
}
"main": "dist/cjs/can-route",
"browser": {
"transform": [
"cssify"
]
},
"repository": {
"type": "git",
"url": "git@github.com:michaelrhodes/can-route.git"
"browserify": {
"transform": [
"cssify"
]
},
"keywords": [
"simple",
"router",
"regex",
"regexp"
],
"author": "Michael Rhodes",
"license": "MIT",
"bugs": {
"url": "https://github.com/michaelrhodes/can-route/issues"
"keywords": [],
"system": {
"main": "can-route",
"configDependencies": [
"live-reload"
],
"npmIgnore": [
"documentjs",
"testee",
"generator-donejs",
"donejs-cli",
"steal-tools"
],
"npmAlgorithm": "flat"
},
"dependencies": {
"can-map": "^3.0.0-pre.1",
"can-list": "^3.0.0-pre.1",
"can-event": "^3.0.0-pre.2",
"can-observe-info": "^3.0.0-pre.1",
"can-util": "^3.0.0-pre.2"
},
"devDependencies": {
"documentjs": "^0.4.2",
"jshint": "^2.9.1",
"cssify": "^0.6.0",
"steal": "^0.16.0",
"steal-qunit": "^0.1.1",
"steal-tools": "^0.16.0",
"testee": "^0.2.4",
"generator-donejs": "^0.9.0",
"donejs-cli": "^0.8.0",
"done-serve": "^0.2.0"
}
}
# can-route
can-route is a simple router that returns false when it can’t handle a request. Its routes are defined with [named regular expressions](https://npm.im/named-regexp).
[![Build status](https://travis-ci.org/michaelrhodes/can-route.png?branch=master)](https://travis-ci.org/michaelrhodes/can-route)
[![Build Status](https://travis-ci.org/canjs/can-route.png?branch=master)](https://travis-ci.org/canjs/can-route)
[![Browser support](https://ci.testling.com/michaelrhodes/can-route.png)](https://ci.testling.com/michaelrhodes/can-route)
> __Note:__ This is the CanJS [can-route](https://github.com/canjs/can-route) module. The old `can-route` has been renamed to [did-route](https://www.npmjs.com/package/did-route). Many thanks to [@michaelrhodes](https://github.com/michaelrhodes) for letting us use the `can-route` module name.
## Install
## Usage
### ES6 use
With StealJS, you can import this module directly in a template that is autorendered:
```js
import plugin from 'can-route';
```
npm install can-route
### CommonJS use
Use `require` to load `can-route` and everything else
needed to create a template that uses `can-route`:
```js
var plugin = require("can-route");
```
### Example
``` js
var http = require('http')
var can = require('can-route')()
## AMD use
// Home
can.get(/^\/$/,
function(req, res) {
res.end('Welcome to the homepage\n')
}
)
Configure the `can` and `jquery` paths and the `can-route` package:
// Item
can.patch(/^\/(:<id>[a-f0-9]{16})\/?$/i,
function(req, res, params) {
res.end(params.id + '\n')
}
)
```html
<script src="require.js"></script>
<script>
require.config({
paths: {
"jquery": "node_modules/jquery/dist/jquery",
"can": "node_modules/canjs/dist/amd/can"
},
packages: [{
name: 'can-route',
location: 'node_modules/can-route/dist/amd',
main: 'lib/can-route'
}]
});
require(["main-amd"], function(){});
</script>
```
http.createServer(function(req, res) {
// No route has not been registered for
// this URI + HTTP method.
if (!can.route(req, res)) {
### Standalone use
// A route *has* been registered for this
// URI, but not for this HTTP method.
if (can.match(req, res)) {
res.statusCode = 405
res.end()
return
}
Load the `global` version of the plugin:
res.statusCode = 404
res.end()
}
}).listen(8080)
```html
<script src='./node_modules/can-route/dist/global/can-route.js'></script>
```
#### Browser
can-route also works in the browser with basically the same API:
## Contributing
``` js
var can = require('can-route')()
### Making a Build
can.get(/^\/$/, function() {
// No arguments for routes without parameters.
})
To make a build of the distributables into `dist/` in the cloned repository run
can.get(/^\/(:<name>[a-z]+)\/?$/i, function(params) {
// The only possible argument is the param object.
})
```
npm install
node build
```
can.get(/#\/(:<name>[a-z]+)\/$/i, function(params) {
// It's possible to define routes based on
// the value of location.hash.
})
### Running the tests
window.onpopstate = function() {
var path = window.location || '/path/to/page'
if (!can.route(path)) {
// Handle 404
}
}
Tests can run in the browser by opening a webserver and visiting the `test.html` page.
Automated tests that run the tests from the command line in Firefox can be run with
window.onhashchange = function() {
var includeQueryAndHash = true
if (!can.route(window.location, includeQueryAndHash)) {
// Handle 404
}
}
```
### License
[MIT](http://opensource.org/licenses/MIT)
npm test
```

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