can-route
Advanced tools
Comparing version 0.3.0 to 3.0.0-pre.1
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" | ||
} | ||
} |
118
readme.md
# 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
49774
13
1479
0
5
10
2
75
2
+ Addedcan-event@^3.0.0-pre.2
+ Addedcan-list@^3.0.0-pre.1
+ Addedcan-map@^3.0.0-pre.1
+ Addedcan-util@^3.0.0-pre.2
+ Addedcan-ajax@1.4.1(transitive)
+ Addedcan-assign@1.3.3(transitive)
+ Addedcan-cid@1.3.1(transitive)
+ Addedcan-compute@3.3.10(transitive)
+ Addedcan-construct@3.5.7(transitive)
+ Addedcan-deparam@1.2.3(transitive)
+ Addedcan-dom-data-state@0.2.0(transitive)
+ Addedcan-dom-events@1.3.13(transitive)
+ Addedcan-event@3.7.7(transitive)
+ Addedcan-event-dom-enter@1.0.4(transitive)
+ Addedcan-event-dom-radiochange@1.0.5(transitive)
+ Addedcan-globals@1.2.2(transitive)
+ Addedcan-key-tree@1.2.2(transitive)
+ Addedcan-list@3.2.2(transitive)
+ Addedcan-log@1.0.2(transitive)
+ Addedcan-map@3.6.1(transitive)
+ Addedcan-namespace@1.0.0(transitive)
+ Addedcan-observation@3.3.6(transitive)
+ Addedcan-observe-info@3.0.0(transitive)
+ Addedcan-param@1.2.0(transitive)
+ Addedcan-parse-uri@1.2.2(transitive)
+ Addedcan-reflect@1.19.2(transitive)
+ Addedcan-reflect-promise@1.1.5(transitive)
+ Addedcan-stache-key@0.1.4(transitive)
+ Addedcan-string@1.1.0(transitive)
+ Addedcan-symbol@1.7.0(transitive)
+ Addedcan-types@1.4.0(transitive)
+ Addedcan-util@3.14.0(transitive)
- Removedcollapse-array@~1.0.1
- Removedmethods@~0.1.0
- Removednamed-regexp@~0.1.1
- Removedcollapse-array@1.0.1(transitive)
- Removedmethods@0.1.0(transitive)
- Removednamed-regexp@0.1.1(transitive)