# url-wrapper

> Minimal wrapper for URL type

Latest version **1.0.7** (published 2021-04-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install url-wrapper
pnpm add url-wrapper
yarn add url-wrapper
bun add url-wrapper
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2021-04-07 |
| First published | 2021-04-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | gp |
| Maintainers | garypeterson |
| Keywords | url, minimal |

## Links

- npm: https://www.npmjs.com/package/url-wrapper
- Repository: https://github.com/gary-peterson/api-wrapper
- Homepage: https://github.com/gary-peterson/api-wrapper#readme
- npm.io page: https://npm.io/package/url-wrapper

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.7 (latest) — 2021-04-07
- 1.0.6 — 2021-04-07
- 1.0.5 — 2021-04-07
- 1.0.4 — 2021-04-07
- 1.0.3 — 2021-04-07
- 1.0.2 — 2021-04-07
- 1.0.1 — 2021-04-07
- 1.0.0 — 2021-04-07

## README

# URL Wrapper

## Overview

A little wrapper on the URL global object, to ease the interface when only interested in url path and query params.

Given full url of:

	- https://foo.com/shapes/rectangle?width=10&height=5

Wrapper will provide:

	- url path, e.g., /shapes/rectangle
	- query params e.g., width=10&height=5
		(as string, array of pairs, or plain object / map

## Usage

```
//-----------------------
//Abbreviated (pseudo)

UrlWrapper = require('url-wrapper').UrlWrapper;
urlw = UrlWrapper.fromRequest(req),
path = urlw.path();
query = urlw.query();
width = query.width;
height = query['height'];

//-----------------------
//Detailed

//rec-form-server

const
	http = require('http'),
	httpStatusCodes = require('http-status-codes'),	
	UrlWrapper = require('url-wrapper').UrlWrapper,
	port = 3000,
	startupFct = () => console.log(`Server started on port: ${port}`),
	br = '<br>';
	
const requestHandlerFct = (req, res) => {
	res.writeHead(httpStatusCodes.OK, {'Content-Type': 'text/html'});		
	const 
		urlw = UrlWrapper.fromRequest(req),
		path = urlw.path(),
		query = urlw.query();
	res.write('received request ' + req.url + br);	
	res.write('URL Path: ' + path + br);
	res.write('URL Query Param Pairs: ' + JSON.stringify(query) + br);
	res.write('Width: ' + query.width + br);
	res.write('Height: ' + query['height'] + br);
	res.end();
}	

const server = http.createServer(requestHandlerFct);
server.listen(port, startupFct);	

```

---
_Source: https://npm.io/package/url-wrapper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
