Skip to content

Commit 4124c3c

Browse files
frenzzyblakeembrey
authored andcommitted
Add ES2015 module
1 parent cc0df28 commit 4124c3c

File tree

5 files changed

+87
-34
lines changed

5 files changed

+87
-34
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ node_modules
22
.nyc_output
33
coverage
44
components
5+
dist
6+
dist.es2015
57
typings

Readme.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ npm install path-to-regexp --save
2020
```javascript
2121
const pathToRegexp = require('path-to-regexp')
2222

23-
// pathToRegexp(path, keys?, options?)
23+
// pathToRegexp.pathToRegexp(path, keys?, options?)
2424
// pathToRegexp.match(path)
2525
// pathToRegexp.parse(path)
2626
// pathToRegexp.compile(path)
@@ -39,7 +39,7 @@ const pathToRegexp = require('path-to-regexp')
3939

4040
```javascript
4141
const keys = []
42-
const regexp = pathToRegexp('/foo/:bar', keys)
42+
const regexp = pathToRegexp.pathToRegexp('/foo/:bar', keys)
4343
// regexp = /^\/foo\/([^\/]+?)\/?$/i
4444
// keys = [{ name: 'bar', prefix: '/', delimiter: '/', optional: false, repeat: false, pattern: '[^\\/]+?' }]
4545
```
@@ -55,7 +55,7 @@ The path argument is used to define parameters and populate the list of keys.
5555
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. `[^/]+`).
5656

5757
```js
58-
const regexp = pathToRegexp('/:foo/:bar')
58+
const regexp = pathToRegexp.pathToRegexp('/:foo/:bar')
5959
// keys = [{ name: 'foo', prefix: '/', ... }, { name: 'bar', prefix: '/', ... }]
6060

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

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

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

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

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

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

109109
regexp.exec('/')
@@ -118,7 +118,7 @@ regexp.exec('/bar/baz')
118118
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.
119119

120120
```js
121-
const regexp = pathToRegexp('/:foo/(.*)')
121+
const regexp = pathToRegexp.pathToRegexp('/:foo/(.*)')
122122
// keys = [{ name: 'foo', ... }, { name: 0, ... }]
123123

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

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

136136
regexpNumbers.exec('/icon-123.png')
@@ -139,7 +139,7 @@ regexpNumbers.exec('/icon-123.png')
139139
regexpNumbers.exec('/icon-abc.png')
140140
//=> null
141141

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

145145
regexpWord.exec('/u')

package-lock.json

Lines changed: 57 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
"name": "path-to-regexp",
33
"description": "Express style path to RegExp utility",
44
"version": "3.2.0",
5-
"main": "index.js",
6-
"typings": "index.d.ts",
5+
"main": "dist/index.js",
6+
"typings": "dist/index.d.ts",
7+
"module": "dist.es2015/index.js",
8+
"sideEffects": false,
79
"files": [
8-
"index.js",
9-
"index.d.ts",
10-
"LICENSE"
10+
"dist/",
11+
"dist.es2015/"
1112
],
1213
"scripts": {
1314
"lint": "standard",
15+
"build": "rimraf dist/ dist.es2015/ && tsc && tsc -P tsconfig.es2015.json",
1416
"test-spec": "mocha --require ts-node/register -R spec --bail test.ts",
1517
"test-cov": "nyc --reporter=lcov mocha -- --require ts-node/register -R spec test.ts",
1618
"coverage": "nyc report --reporter=text-lcov",
17-
"test": "npm run lint && npm run test-cov"
19+
"test": "npm run build && npm run lint && npm run test-cov",
20+
"prepare": "npm run build"
1821
},
1922
"keywords": [
2023
"express",
@@ -39,6 +42,7 @@
3942
"chai": "^4.1.1",
4043
"mocha": "^6.2.0",
4144
"nyc": "^14.1.1",
45+
"rimraf": "^3.0.0",
4246
"standard": "^14.1.0",
4347
"ts-node": "^8.3.0",
4448
"typescript": "^3.7.2"

tsconfig.es2015.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist.es2015",
5+
"module": "es2015",
6+
"declaration": false
7+
},
8+
"files": ["index.ts"]
9+
}

0 commit comments

Comments
 (0)