can-route
Advanced tools
Comparing version 3.2.1 to 3.2.2
{ | ||
"name": "can-route", | ||
"version": "3.2.1", | ||
"version": "3.2.2", | ||
"description": "", | ||
"homepage": "", | ||
"license": "MIT", | ||
"repository": { | ||
@@ -27,3 +28,2 @@ "type": "git", | ||
"build": "node build.js", | ||
"document": "bit-docs", | ||
"develop": "done-serve --static --develop --port 8080" | ||
@@ -45,3 +45,3 @@ }, | ||
"can-deparam": "^1.0.1", | ||
"can-event": "^3.5.0-pre.2", | ||
"can-event": "^3.6.0", | ||
"can-namespace": "1.0.0", | ||
@@ -51,11 +51,11 @@ "can-observation": "^3.3.1", | ||
"can-reflect": "^1.2.1", | ||
"can-simple-map": "^3.3.0-pre.2", | ||
"can-symbol": "^1.0.0-pre.1", | ||
"can-types": "^1.1.0-pre.3", | ||
"can-util": "^3.9.0-pre.7" | ||
"can-simple-map": "^3.3.0", | ||
"can-symbol": "^1.0.0", | ||
"can-types": "^1.1.0", | ||
"can-util": "^3.9.0" | ||
}, | ||
"devDependencies": { | ||
"can-stache-key": "^0.0.2", | ||
"can-define": "^1.3.0-pre.1", | ||
"can-list": "^3.2.0-pre.1", | ||
"can-stache-key": "^0.0.4", | ||
"can-define": "^1.3.3", | ||
"can-list": "^3.2.0", | ||
"can-map": "^3.3.1", | ||
@@ -67,20 +67,4 @@ "done-serve": "^0.2.0", | ||
"steal-tools": "^1.1.2", | ||
"testee": "^0.6.1" | ||
}, | ||
"bit-docs": { | ||
"dependencies": { | ||
"bit-docs-glob-finder": "^0.0.5", | ||
"bit-docs-dev": "^0.0.3", | ||
"bit-docs-js": "^0.0.3", | ||
"bit-docs-generate-readme": "^0.0.8" | ||
}, | ||
"glob": { | ||
"pattern": "**/*.{js,md}", | ||
"ignore": "node_modules/**/*" | ||
}, | ||
"readme": { | ||
"apis": "./docs/apis.json" | ||
}, | ||
"parent": "can-route" | ||
"testee": "^0.7.0" | ||
} | ||
} |
198
readme.md
# can-route | ||
[![Build Status](https://travis-ci.org/canjs/can-route.png?branch=master)](https://travis-ci.org/canjs/can-route) | ||
[![Join the chat at https://gitter.im/canjs/canjs](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/canjs/canjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/canjs/can-route/blob/master/LICENSE.md) | ||
[![npm version](https://badge.fury.io/js/can-route.svg)](https://www.npmjs.com/package/can-route) | ||
[![Travis build status](https://travis-ci.org/canjs/can-route.svg?branch=master)](https://travis-ci.org/canjs/can-route) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/canjs/can-route.svg)](https://greenkeeper.io/) | ||
> __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. | ||
- <code>[route(template [, defaults])](#routetemplate--defaults)</code> | ||
- <code>[route.map(MapConstructor)](#routemapmapconstructor)</code> | ||
- <code>[route.map(mapInstance)](#routemapmapinstance)</code> | ||
- <code>[route.param(data)](#routeparamdata)</code> | ||
- <code>[route.deparam(url)](#routedeparamurl)</code> | ||
- <code>[route.ready()](#routeready)</code> | ||
- <code>[route.url(data [, merge])](#routeurldata--merge)</code> | ||
- <code>[route.link(innerText, data, props [, merge])](#routelinkinnertext-data-props--merge)</code> | ||
## API | ||
## <code>route(template [, defaults])</code> | ||
Create a route matching rule. Optionally provide defaults that will be applied to the [can-map] when the route matches. | ||
```js | ||
route(":page", { page: "home" }); | ||
``` | ||
## Documentation | ||
Will apply **cart** when the url is `#cart` and **home** when the url is `#`. | ||
Read the [can-route API docs on CanJS.com](https://canjs.com/doc/can-route.html). | ||
## Changelog | ||
1. __template__ <code>{String}</code>: | ||
the fragment identifier to match. The fragment identifier | ||
should start with either a character (a-Z) or colon (:). Examples: | ||
```js | ||
route(":foo") | ||
route("foo/:bar") | ||
``` | ||
1. __defaults__ <code>{Object}</code>: | ||
An object of default values. | ||
See the [latest releases on GitHub](https://github.com/canjs/can-route/releases). | ||
- __returns__ <code>{can.route}</code>: | ||
### <code>route.map(MapConstructor)</code> | ||
Binds can-route to an instance based on a constructor. A new instance will be created and bound to: | ||
```js | ||
var ViewModel = Map.attr({ | ||
define: { | ||
page: { | ||
set: function(page){ | ||
if(page === "user") { | ||
this.verifyLoggedIn(); | ||
} | ||
return page; | ||
} | ||
} | ||
} | ||
}); | ||
route.map(ViewModel); | ||
``` | ||
1. __MapConstructor__ <code>{can-map}</code>: | ||
A can-map constructor function. A new can-map instance will be created and used as the can-map internal to can-route. | ||
### <code>route.map(mapInstance)</code> | ||
Bind can-route to an instance of a map. | ||
```js | ||
var map = new Map({ | ||
page: "home" | ||
}); | ||
route.map(map); | ||
map.attr("page", "user"); | ||
// location.hash -> "#user" | ||
``` | ||
1. __mapInstance__ <code>{can-map}</code>: | ||
A can-map instance, used as the can-map internal to can-route. | ||
### <code>route.param(data)</code> | ||
1. __object__ <code>{data}</code>: | ||
The data to populate the route with. | ||
- __returns__ <code>{String}</code>: | ||
The route, with the data populated in it. | ||
### <code>route.deparam(url)</code> | ||
Extract data from a url, creating an object representing its values. | ||
```js | ||
route(":page"); | ||
var result = route.deparam("page=home"); | ||
console.log(result.page); // -> "home" | ||
``` | ||
1. __url__ <code>{String}</code>: | ||
A route fragment to extract data from. | ||
- __returns__ <code>{Object}</code>: | ||
An object containing the extracted data. | ||
### <code>route.ready()</code> | ||
Sets up the two-way binding between the hash and the can-route observable | ||
map and sets the route map to its initial values. | ||
```js | ||
route(":page", { page: "home" })); | ||
route.ready(); | ||
route.attr("page"); // -> "home" | ||
``` | ||
- __returns__ <code>{canRoute}</code>: | ||
The can-route object. | ||
### <code>route.url(data [, merge])</code> | ||
Make a URL fragment that when set to window.location.hash will update can-route's properties | ||
to match those in `data`. | ||
```js | ||
route.url({ page: "home" }); | ||
// -> "#!page=home" | ||
``` | ||
1. __data__ <code>{Object}</code>: | ||
The data to populate the route with. | ||
1. __merge__ <code>{Boolean}</code>: | ||
Whether the given options should be merged into the current state of the route. | ||
- __returns__ <code>{String}</code>: | ||
The route URL and query string. | ||
### <code>route.link(innerText, data, props [, merge])</code> | ||
Make an anchor tag (`<A>`) that when clicked on will updatecanRoute's properties | ||
to match those in `data`. | ||
1. __innerText__ <code>{Object}</code>: | ||
The text inside the link. | ||
1. __data__ <code>{Object}</code>: | ||
The data to populate the route with. | ||
1. __props__ <code>{Object}</code>: | ||
Properties for the anchor other than `href`. | ||
1. __merge__ <code>{Boolean}</code>: | ||
Whether the given options should be merged into the current state of the route. | ||
- __returns__ <code>{String}</code>: | ||
A string with an anchor tag that points to the populated route. | ||
## Contributing | ||
### Making a Build | ||
The [contribution guide](https://github.com/canjs/can-route/blob/master/CONTRIBUTING.md) has information on getting help, reporting bugs, developing locally, and more. | ||
To make a build of the distributables into `dist/` in the cloned repository run | ||
## License | ||
``` | ||
npm install | ||
node build | ||
``` | ||
[MIT](https://github.com/canjs/can-route/blob/master/LICENSE.md) | ||
### Running the tests | ||
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 | ||
``` | ||
npm test | ||
``` |
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
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
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
99268
20
29
1
Updatedcan-event@^3.6.0
Updatedcan-simple-map@^3.3.0
Updatedcan-symbol@^1.0.0
Updatedcan-types@^1.1.0
Updatedcan-util@^3.9.0