Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aminnairi/url
Utility functions to help you work with urls.
https://github.com/aminnairi/url
Last synced: about 5 hours ago
JSON representation
Utility functions to help you work with urls.
- Host: GitHub
- URL: https://github.com/aminnairi/url
- Owner: aminnairi
- License: gpl-3.0
- Created: 2022-07-08T22:42:52.000Z (over 2 years ago)
- Default Branch: development
- Last Pushed: 2022-07-10T19:05:21.000Z (over 2 years ago)
- Last Synced: 2024-10-12T22:49:31.607Z (about 1 month ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/@aminnairi/url
- Size: 35.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# @aminnairi/url
Utility functions to help you work with urls.
[![Continuous Integration](https://github.com/aminnairi/url/actions/workflows/continuous_integration.yaml/badge.svg)](https://github.com/aminnairi/url/actions/workflows/continuous_integration.yaml)
## Usage
### Node
#### ECMAScript Module
```bash
npm install @aminnairi/url
``````javascript
import {isMatchingPath, getMatchingPathParameters} from "@aminnairi/url";console.log(isMatchingPath("/users/:user", "/users/123"));
console.log(getMatchingPathParameters("/users/:user", "/users/123"));
// {user: "123"}
```#### CommonJS
```bash
npm install @aminnairi/url
``````javascript
const {isMatchingPath, getMatchingPathParameters} = require("@aminnairi/url");console.log(isMatchingPath("/users/:user", "/users/123"));
// trueconsole.log(getMatchingPathParameters("/users/:user", "/users/123"));
// {user: "123"}
```### Browser
#### ECMAScript Module
```html
@aminnairi/url
import {isMatchingPath, getMatchingPathParameters} from "https://unpkg.com/@aminnairi/url?module";console.log(isMatchingPath("/users/:user", "/users/123"));
console.log(getMatchingPathParameters("/users/:user", "/users/123"));
```
#### Script
```html
@aminnairi/url
const {isMatchingPath, getMatchingPathParameters} = window["@aminnairi/url"];console.log(isMatchingPath("/users/:user", "/users/123"));
console.log(getMatchingPathParameters("/users/:user", "/users/123"));
```
## Documentation
### isMatchingPath
#### Signature
```typescript
const isMatchingPath = (path: string, url: string) => boolean;
```#### Examples
```javascript
isMatchingPath(null, "/");
// falseisMatchingPath("/", null);
// falseisMatchingPath("/", "/");
// trueisMatchingPath("", "/");
// trueisMatchingPath("/", "");
// trueisMatchingPath("/", "/users");
// falseisMatchingPath("/users/:user", "/users/123");
// trueisMatchingPath("/users/:user", "/posts/123");
// falseisMatchingPath("/users/:user", "/users/123/posts");
// falseisMatchingPath("/users/:user/posts/:post", "/users/123/posts/456");
// true
```### getMatchingPathParameters
#### Signature
```typescript
const getMatchingPathParameters = (path: string, url: string) => Record;
```#### Examples
```javascript
getMatchingPathParameters(null, "/");
// {}getMatchingPathParameters("/", null);
// {}getMatchingPathParameters("/", "/");
// {}getMatchingPathParameters("", "/");
// {}getMatchingPathParameters("/", "");
// {}getMatchingPathParameters("/", "/users");
// {}getMatchingPathParameters("/users/:user", "/users/123");
// {user: "123"}getMatchingPathParameters("/users/:user", "/posts/123");
// {}getMatchingPathParameters("/users/:user", "/users/123/posts");
// {}getMatchingPathParameters("/users/:user/posts/:post", "/users/123/posts/456");
// {user: "123", post: "456"}
```## Changelog
See [`CHANGELOG.md`](https://github.com/aminnairi/url/blob/development/CHANGELOG.md).
## Contributing
See [`CONTRIBUTING.md`](https://github.com/aminnairi/url/blob/development/CONTRIBUTING.md).
## License
See [`LICENSE`](https://github.com/aminnairi/url/blob/development/LICENSE).