Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
snd committed Mar 21, 2012
0 parents commit e801163
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (C) 2012 by Maximilian Krüger

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
45 changes: 45 additions & 0 deletions README.md
@@ -0,0 +1,45 @@
# url-pattern

match urls to patterns and extract named url segments

## Installation

```
npm install git://github.com/snd/url-pattern.git
```

## Usage

### make a pattern from a string

```coffeescript
pattern = new Pattern '/users/:id'
```

### match a pattern against a url

```coffeescript
pattern.match '/projects/5' # => null
pattern.match '/users/5' # => {id: 5}
```

match returns either `null` if there was no match or an object with the named parameters.

## Pattern examples

`/users` will match only exactly the url `/users`.

`/projects/:projectId/supporters/:supporterId` will match any url where the first
segment (url part delimited by `/`) is exactly `projects`, the second segment is not empty, the third segment is exactly
`supporters` and the fourth segment is not empty. the second and fourth segments will be bound
to `projectId` and `supporterId`.

`/projects/*` will match any url which begins with `/projects/`.

`*/projects` will match any url which ends with `/projects/`.

`/users/*/projects` will match any url which starts with `/users` and ends with `/projects/`.

## License

url-pattern is released under the MIT License (see LICENSE for details).
16 changes: 16 additions & 0 deletions package.json
@@ -0,0 +1,16 @@
{
"name": "url-pattern",
"description": "match urls to patterns and extract named url segments",
"author": "Maximilian Krüger <kruemaxi@googlemail.com> (http://github.com/snd)",
"version": "0.1.0",
"repository": {
"type": "git",
"url": "git://github.com/snd/url-pattern.git"
},
"dependencies": {
"underscore": "*"
},
"devDependencies": {
"nodeunit": "*"
}
}

0 comments on commit e801163

Please sign in to comment.