# @trkm/http-url-ts

> Converts url parameters into a javascript object: the parameter name becomes the object property name.

Latest version **0.1.1** (published 2022-10-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @trkm/http-url-ts
pnpm add @trkm/http-url-ts
yarn add @trkm/http-url-ts
bun add @trkm/http-url-ts
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2022-10-30 |
| First published | 2022-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Eric Hosick |
| Maintainers | erichosick |
| Keywords | typescript, url parameters, trkm |

## Links

- npm: https://www.npmjs.com/package/@trkm/http-url-ts
- Repository: https://github.com/erichosick/trkm
- Homepage: https://github.com/erichosick/trkm/tree/main/packages/http-url-ts
- Issues: https://github.com/erichosick/trkm/issues
- npm.io page: https://npm.io/package/@trkm/http-url-ts

## 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

- 0.1.1 (latest) — 2022-10-30
- 0.1.0 — 2022-10-27

## README

# **@trkm/http-url-ts**

Support for converting information about an http url contained within the DOM windows and DOM documents, such as the url parameters, to javascript objects for easy consumption.

## Features

* 100% typescript.

## Usage

### `urlParamsToObj`

Converts a string of the format '?keyName01=keyValue01&keyName02=keyValue02` (the key/value pair format returned by window.location.search) to an object whose properties are the `keyName` and value is the `keyValue`. WARNING: Key names are case sensitive along with javascript object properties.

* @param keyValueString - A string containing zero or more key/value pairs of the format `?keyName01=keyValue01&`
* @param options:
  * mutateProperty - Lambda with a function signature of `(propertyName: string) => string;` used to convert the key name before using the key name as an object property.
* @returns - An object whose properties are the properties of all keys in the keyValueString and values are the value of the keyValueString.

```typescript
import { urlParamsToObj } from '@trkm/http-url-ts';

const urlParams = urlParamsToObj(window.location.search);

// convert url parameter name to lowercase

const toLowerCase = (input: string) => {
  return input.toLowerCase();
}

const urlParams2 = urlParamsToObj(
  '?ENABLED=true&updated=false',
  {
    mutateProperty: toLowerCase
  }
);

console.log(urlParams2);
// output
// {
//   enabled: true,
//   updated: false,
// }
```

## Intent

* No Emitted Javascript - The intent is to import this typescript library into a typescript project: compiling to Javascript occurring within the project.

## Development

See the [monorepo readme](https://www.github.com/erichosick/trkm).

## License

Licensed under [MIT](./LICENSE.md).

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