2.4.0 • Published 3 months ago

@zthun/webigail-url v2.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 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);
2.4.0

3 months ago

2.3.0

3 months ago

2.1.1

3 months ago

2.0.2

5 months ago

2.1.0

3 months ago

2.0.1

5 months ago

2.0.0

5 months ago

1.2.0

6 months ago

1.0.2

9 months ago

1.1.0

9 months ago

0.2.0

9 months ago

0.1.0

1 year ago