# hrefjs-lite

> 根据提供的href地址链接，解析出location结构数据，包括hash参数，及参数与json互转

Latest version **2.1.10** (published 2024-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install hrefjs-lite
pnpm add hrefjs-lite
yarn add hrefjs-lite
bun add hrefjs-lite
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.10 |
| Published | 2024-05-14 |
| First published | 2020-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 176.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wilderliu |
| Maintainers | wilderliu |
| Keywords | location, search, href, hash, json |

## Links

- npm: https://www.npmjs.com/package/hrefjs-lite
- Repository: https://gitee.com/orz365/hrefjs-lite
- Issues: https://gitee.com/orz365/hrefjs-lite/issues
- npm.io page: https://npm.io/package/hrefjs-lite

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.1.10 (latest) — 2024-05-14
- 2.1.9 — 2023-11-16
- 2.1.8 — 2023-11-10
- 2.1.4 — 2023-11-09
- 2.1.3 — 2023-11-09
- 2.1.2 — 2023-09-07
- 2.1.1 — 2023-09-07
- 2.1.0 — 2023-09-07
- 2.0.4 — 2023-09-06
- 2.0.3 — 2023-09-06
- 2.0.2 — 2023-09-04
- 2.0.1 — 2023-08-04
- 2.0.0 — 2023-07-31
- 1.0.8 — 2022-04-12
- 1.0.7 — 2022-03-29
- … 6 more at https://npm.io/package/hrefjs-lite/versions

## README

# hrefjs-lite

根据提供的href地址链接，解析出location结构数据，
参数与json互转，hash参数解析转换。

### 安装

```bash
npm i hrefjs-lite
```

### 使用

```js
import Hrefjs from "hrefjs-lite"
const url = 'https://www.cssjs.cn:92/tt/bb/#/fly?a=10&a=20&a=30'
const location = new Hrefjs(url)
console.log(location)
// 返回结果
{
  href: 'https://www.cssjs.cn:92/tt/bb/#/fly?a=10&a=20&a=30',
  origin: 'https://www.cssjs.cn:92',
  protocol: 'https:',
  username: '',
  password: '',
  host: 'www.cssjs.cn:92',
  hostname: 'www.cssjs.cn',
  port: '92',
  pathname: '/tt/bb/',
  search: '',
  searchParams: r {},
  hash: '#/fly?a=10&a=20&a=30',
  hashPath: '/fly',
  hashSearch: 'a=10&a=20&a=30',
  hashSearchParams: r { 'a' => '10', 'a' => '20', 'a' => '30' },
  hashSearchJson: r { 'a' => '10', 'a' => '20', 'a' => '30' }
}
```

```js
import Hrefjs from 'hrefjs-lite'
var json = {
  a: 10,
  b: 20
}
var param = Hrefjs.json2param(json)
console.log(param)
// a=10&b=20

param = 'a=10&b=20'
json = Hrefjs.param2json(param)
console.log(json)
//{ a: '10', b: '20' }
```

### 修改URL参数和hash参数

```js
import Hrefjs from 'hrefjs-lite'
const url = 'https://www.cssjs.cn:92/tt/bb/#/fly?a=10&a=20&a=30'
const location = new Hrefjs(url)

// 增加参数
location.searchParams.set('name', 'Tom')
console.log(location.toString())
// https://www.cssjs.cn:92/tt/bb/?name=Tom#/fly?a=10&a=20&a=30

// 增加hash的参数信息
location.hashSearchParams.set('age', 40)
console.log(location.toString())
// https://www.cssjs.cn:92/tt/bb/?name=Tom#/fly?a=10&a=20&a=30&age=40

// 修改path路径
location.pathname = '/new/path'
console.log(location.toString())
// https://www.cssjs.cn:92/new/path?name=Tom#/fly?a=10&a=20&a=30&age=40

// 修改hash路径
location.hashPath = '/new/path'
console.log(location.toString())
// https://www.cssjs.cn:92/tt/bb/?name=Tom#/new/path?a=10&a=20&a=30&age=40
```

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