Skip to content

Commit fe210f2

Browse files
committed
Init
0 parents  commit fe210f2

File tree

9 files changed

+5496
-0
lines changed

9 files changed

+5496
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coverage
2+
node_modules
3+
*.tgz
4+
dist

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Node URL Path
2+
3+
Simple utility class to help join URLs and add query parameters to URLs similar to how Python's pathlib Path object works with file paths.
4+
5+
## Installation
6+
7+
Install the latest version using `npm` with:
8+
9+
```bash
10+
npm install node-url-path
11+
```
12+
13+
## Usage
14+
15+
Using the `URLPath` class makes working with URLs simple. You can add paths to a URL that already has query parameters added to it and add additional query parameters if needed with the call of a method.
16+
17+
All `URLPath` methods return a `URLPath` instance so you can chain them together.
18+
19+
Get the final URL from a `URLPath` instance by retrieving the public `href` property.
20+
21+
```typescript
22+
import { URLPath } from 'node-url-path';
23+
24+
const urlPath = new URLPath('https://google.com/api/')
25+
.joinPath('/query')
26+
.addQueryParams({
27+
query: 'How to make URLs easier when working with Node',
28+
apiKey: '1234567890',
29+
});
30+
31+
console.log(urlPath.href);
32+
33+
// Outputs:
34+
// https://google.com/api/query?query=How%20to%20make%20URLs%20easier%20when%20working%20with%20Node&apiKey=1234567890
35+
```
36+
37+
or a more complex example:
38+
39+
```typescript
40+
import { URLPath } from 'node-url-path';
41+
42+
const urlPath = new URLPath('https://google.com/api/?someExistingParams=1')
43+
.joinPath('/query')
44+
.addQueryParams({
45+
query: 'How to make URLs easier when working with Node',
46+
apiKey: '1234567890',
47+
});
48+
49+
console.log(urlPath.href);
50+
51+
// Outputs:
52+
// https://google.com/api/query?someExistingParams=1&query=How%20to%20make%20URLs%20easier%20when%20working%20with%20Node&apiKey=1234567890
53+
```

babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
3+
};

0 commit comments

Comments
 (0)