Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zanonnicola/pathname-matcher
Match a given path name against a URL
https://github.com/zanonnicola/pathname-matcher
es6-modules javascript javascript-library matcher path regex
Last synced: 26 days ago
JSON representation
Match a given path name against a URL
- Host: GitHub
- URL: https://github.com/zanonnicola/pathname-matcher
- Owner: zanonnicola
- Created: 2018-01-01T17:28:38.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-01T18:36:47.000Z (almost 7 years ago)
- Last Synced: 2024-11-18T22:02:11.347Z (about 1 month ago)
- Topics: es6-modules, javascript, javascript-library, matcher, path, regex
- Language: JavaScript
- Size: 54.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# pathname-matcher
Match a given path name against a URL
## :package: Installation
```bash
npm install pathname-matcher --save
```## :rocket: Load
```js
// using es modules
import pathnameMatcher from 'pathname-matcher'// common.js
const pathnameMatcher = require('pathname-matcher')```
Or use script tags and globals.
```html
```
And then grab it off the global like so:
```js
const isPath = pathnameMatcher.default;
```## :bulb: Usage
Let's assume you want to run a function if a user navigate to a specific path
```javascript
// www.site.com/hello/search
if (pathnameMatcher(document.location.pathname, 'search')) {
console.log('Hello!!');
}// www.site.com/search/myPage
if (pathnameMatcher(document.location.pathname, 'search/myPage')) {
console.log('Hello!!');
}
```> You can provide any path or url as long as it is provided as a string
## API
#### `pathnameMatcher(URL: String, pathname: String)` [required]
Returns `true` if pathname matches the given URL (no trailing slash)
OR `false` when no match.
**pathname** should be passed without `/` at the beginning of the string. See examples above.
## Legal
Released under MIT license.