Skip to content

Commit

Permalink
Add ES2015 module
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzzy authored and blakeembrey committed Nov 11, 2019
1 parent cc0df28 commit 4124c3c
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ node_modules
.nyc_output
coverage
components
dist
dist.es2015
typings
18 changes: 9 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ npm install path-to-regexp --save
```javascript
const pathToRegexp = require('path-to-regexp')

// pathToRegexp(path, keys?, options?)
// pathToRegexp.pathToRegexp(path, keys?, options?)
// pathToRegexp.match(path)
// pathToRegexp.parse(path)
// pathToRegexp.compile(path)
Expand All @@ -39,7 +39,7 @@ const pathToRegexp = require('path-to-regexp')

```javascript
const keys = []
const regexp = pathToRegexp('/foo/:bar', keys)
const regexp = pathToRegexp.pathToRegexp('/foo/:bar', keys)
// regexp = /^\/foo\/([^\/]+?)\/?$/i
// keys = [{ name: 'bar', prefix: '/', delimiter: '/', optional: false, repeat: false, pattern: '[^\\/]+?' }]
```
Expand All @@ -55,7 +55,7 @@ The path argument is used to define parameters and populate the list of keys.
Named parameters are defined by prefixing a colon to the parameter name (`:foo`). By default, the parameter will match until the next prefix (e.g. `[^/]+`).

```js
const regexp = pathToRegexp('/:foo/:bar')
const regexp = pathToRegexp.pathToRegexp('/:foo/:bar')
// keys = [{ name: 'foo', prefix: '/', ... }, { name: 'bar', prefix: '/', ... }]

regexp.exec('/test/route')
Expand All @@ -71,7 +71,7 @@ regexp.exec('/test/route')
Parameters can be suffixed with a question mark (`?`) to make the parameter optional.

```js
const regexp = pathToRegexp('/:foo/:bar?')
const regexp = pathToRegexp.pathToRegexp('/:foo/:bar?')
// keys = [{ name: 'foo', ... }, { name: 'bar', delimiter: '/', optional: true, repeat: false }]

regexp.exec('/test')
Expand All @@ -88,7 +88,7 @@ regexp.exec('/test/route')
Parameters can be suffixed with an asterisk (`*`) to denote a zero or more parameter matches. The prefix is used for each match.

```js
const regexp = pathToRegexp('/:foo*')
const regexp = pathToRegexp.pathToRegexp('/:foo*')
// keys = [{ name: 'foo', delimiter: '/', optional: true, repeat: true }]

regexp.exec('/')
Expand All @@ -103,7 +103,7 @@ regexp.exec('/bar/baz')
Parameters can be suffixed with a plus sign (`+`) to denote a one or more parameter matches. The prefix is used for each match.

```js
const regexp = pathToRegexp('/:foo+')
const regexp = pathToRegexp.pathToRegexp('/:foo+')
// keys = [{ name: 'foo', delimiter: '/', optional: false, repeat: true }]

regexp.exec('/')
Expand All @@ -118,7 +118,7 @@ regexp.exec('/bar/baz')
It is possible to write an unnamed parameter that only consists of a matching group. It works the same as a named parameter, except it will be numerically indexed.

```js
const regexp = pathToRegexp('/:foo/(.*)')
const regexp = pathToRegexp.pathToRegexp('/:foo/(.*)')
// keys = [{ name: 'foo', ... }, { name: 0, ... }]

regexp.exec('/test/route')
Expand All @@ -130,7 +130,7 @@ regexp.exec('/test/route')
All parameters can have a custom regexp, which overrides the default match (`[^/]+`). For example, you can match digits or names in a path:

```js
const regexpNumbers = pathToRegexp('/icon-:foo(\\d+).png')
const regexpNumbers = pathToRegexp.pathToRegexp('/icon-:foo(\\d+).png')
// keys = [{ name: 'foo', ... }]

regexpNumbers.exec('/icon-123.png')
Expand All @@ -139,7 +139,7 @@ regexpNumbers.exec('/icon-123.png')
regexpNumbers.exec('/icon-abc.png')
//=> null

const regexpWord = pathToRegexp('/(user|u)')
const regexpWord = pathToRegexp.pathToRegexp('/(user|u)')
// keys = [{ name: 0, ... }]

regexpWord.exec('/u')
Expand Down
76 changes: 57 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
"name": "path-to-regexp",
"description": "Express style path to RegExp utility",
"version": "3.2.0",
"main": "index.js",
"typings": "index.d.ts",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"module": "dist.es2015/index.js",
"sideEffects": false,
"files": [
"index.js",
"index.d.ts",
"LICENSE"
"dist/",
"dist.es2015/"
],
"scripts": {
"lint": "standard",
"build": "rimraf dist/ dist.es2015/ && tsc && tsc -P tsconfig.es2015.json",
"test-spec": "mocha --require ts-node/register -R spec --bail test.ts",
"test-cov": "nyc --reporter=lcov mocha -- --require ts-node/register -R spec test.ts",
"coverage": "nyc report --reporter=text-lcov",
"test": "npm run lint && npm run test-cov"
"test": "npm run build && npm run lint && npm run test-cov",
"prepare": "npm run build"
},
"keywords": [
"express",
Expand All @@ -39,6 +42,7 @@
"chai": "^4.1.1",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
"rimraf": "^3.0.0",
"standard": "^14.1.0",
"ts-node": "^8.3.0",
"typescript": "^3.7.2"
Expand Down
9 changes: 9 additions & 0 deletions tsconfig.es2015.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist.es2015",
"module": "es2015",
"declaration": false
},
"files": ["index.ts"]
}

0 comments on commit 4124c3c

Please sign in to comment.