@zthun/webigail-url 0.2.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Webigail URL
|
|
2
|
+
|
|
3
|
+
It's easy to make mistakes when making REST invocations and public API calls. Webigail solves this by using the builder
|
|
4
|
+
pattern to construct a full URL given different parts of a URI.
|
|
5
|
+
|
|
6
|
+
## Build Status
|
|
7
|
+
|
|
8
|
+
[](https://dl.circleci.com/status-badge/redirect/gh/zthun/webigail/tree/latest)
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
Webigail is built in TypeScript and it exports both ESM and CJS modules.
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
# NPM
|
|
16
|
+
npm install @zthun/webigail-url
|
|
17
|
+
# Yarn
|
|
18
|
+
yarn add @zthun/webigail-url
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { ZUrlBuilder } from '@zthun/webigail-url';
|
|
23
|
+
|
|
24
|
+
const url = new ZUrlBuilder().protocol('https').hostname('zthunworks.com').subdomain('webigail').build();
|
|
25
|
+
|
|
26
|
+
// Outputs https://webigail.zthunworks.com
|
|
27
|
+
console.log(url);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
There are also some utility functions for common use cases.
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { ZUrlBuilder } from '@zthun/webigail-url';
|
|
34
|
+
|
|
35
|
+
// Note: Browser only unless you're using jsdom in node. Outputs the current
|
|
36
|
+
// browser location with /api appended to it.
|
|
37
|
+
const locationUrl = new ZUrlBuilder().location(location).path('/api').build();
|
|
38
|
+
console.log(url);
|
|
39
|
+
|
|
40
|
+
// Url for a persons gravatar if one exists.
|
|
41
|
+
const avatar = new ZUrlBuilder().gravatar(md5('john-doe@gmail.com'), 256).build();
|
|
42
|
+
console.log(avatar);
|
|
43
|
+
|
|
44
|
+
// Outputs the existing pieces of the url.
|
|
45
|
+
const existingInfo = new ZUrlBuilder().parse('https://webigail.zthunworks.com/api/path?filter=hello').info();
|
|
46
|
+
console.log(existingInfo);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Data URLs
|
|
50
|
+
|
|
51
|
+
Webigail also supports building and parsing data urls as well.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { ZDataUrlBuilder, ZMimeTypeApplication } from '@zthun/webigail-url';
|
|
55
|
+
|
|
56
|
+
const raw = require('my-data.json');
|
|
57
|
+
const mimeType = ZMimeTypeApplication.JSON;
|
|
58
|
+
const url = new ZDataUrlBuilder().mimeType(mimeType).buffer(Buffer.from(raw)).encode('base64').build();
|
|
59
|
+
console.log(url);
|
|
60
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zthun/webigail-url",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Url parsing and building.",
|
|
5
5
|
"author": "Anthony Bonta",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"url-parse": "^1.5.10"
|
|
32
32
|
},
|
|
33
33
|
"sideEffects": false,
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "4dbd684a60c4303d13d28c1c7a53fd02bb494f22"
|
|
35
35
|
}
|