3.2.0 • Published 10 months ago

@zthun/webigail-url v3.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Webigail URL

It's easy to make mistakes when making REST invocations and public API calls. Webigail solves this by using the builder pattern to construct a full URL given different parts of a URI.

Build Status

CircleCI

Usage

Webigail is built in TypeScript and it exports both ESM and CJS modules.

# NPM
npm install @zthun/webigail-url
# Yarn
yarn add @zthun/webigail-url
import { ZUrlBuilder } from '@zthun/webigail-url';

const url = new ZUrlBuilder().protocol('https').hostname('zthunworks.com').subdomain('webigail').build();

// Outputs https://webigail.zthunworks.com
console.log(url);

There are also some utility functions for common use cases.

import { ZUrlBuilder } from '@zthun/webigail-url';

// Note: Browser only unless you're using jsdom in node.  Outputs the current
// browser location with /api appended to it.
const locationUrl = new ZUrlBuilder().location(location).path('/api').build();
console.log(url);

// Url for a persons gravatar if one exists.
const avatar = new ZUrlBuilder().gravatar(md5('john-doe@gmail.com'), 256).build();
console.log(avatar);

// Outputs the existing pieces of the url.
const existingInfo = new ZUrlBuilder().parse('https://webigail.zthunworks.com/api/path?filter=hello').info();
console.log(existingInfo);

Data URLs

Webigail also supports building and parsing data urls as well.

import { ZDataUrlBuilder, ZMimeTypeApplication } from '@zthun/webigail-url';

const raw = require('my-data.json');
const mimeType = ZMimeTypeApplication.JSON;
const url = new ZDataUrlBuilder().mimeType(mimeType).buffer(Buffer.from(raw)).encode('base64').build();
console.log(url);
3.1.3

11 months ago

3.2.0

10 months ago

3.0.2

11 months ago

3.0.0

1 year ago

2.4.2

1 year ago

2.4.1

1 year ago

2.4.0

2 years ago

2.3.0

2 years ago

2.1.1

2 years ago

2.0.2

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.0

2 years ago

1.0.2

2 years ago

1.1.0

2 years ago

0.2.0

2 years ago

0.1.0

3 years ago