# @deot/helper-route

> 处理 URL origin、path 和 query 的小型工具集，不依赖浏览器原生 `URL` 或 `URLSearchParams` 实例。

Latest version **1.1.9** (published 2026-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @deot/helper-route
pnpm add @deot/helper-route
yarn add @deot/helper-route
bun add @deot/helper-route
```

## Health

**Score 45/100 (D)** — status: active.

Positive: no vulnerabilities.

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

## Facts

| | |
|---|---|
| Version | 1.1.9 |
| Published | 2026-04-07 |
| First published | 2023-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | deot |

## Links

- npm: https://www.npmjs.com/package/@deot/helper-route
- npm.io page: https://npm.io/package/@deot/helper-route

## Recent versions

- 1.1.9 (latest) — 2026-04-07
- 1.1.8 — 2026-03-05
- 1.1.7 — 2026-03-02
- 1.1.6 — 2025-10-08
- 1.1.5 — 2025-01-10
- 1.1.4 — 2024-06-27
- 1.1.3 — 2023-11-22
- 1.1.2 — 2023-11-16
- 1.1.1 — 2023-08-25
- 1.1.0 — 2023-08-24
- 1.0.3 — 2023-08-21
- 1.0.2 — 2023-08-17
- 1.0.1 — 2023-07-13

## README

# @deot/helper-route

### `Route` 

```js
import * as Route from '@deot/helper-route';
```

```js
// or
import { Route } from '@deot/helper';
```

---

#### `merge`

`Route.merge(route: object, options: object)`

基于规则构建新的url

+ **route**: 路由规则
+ **options**: 可配置参数

*rule:* 规则:
+ **path**: *string, string[]* 路径
+ **query**: *object* 参数

**示例**
```js
Route.merge({
	// path: '/home',
	path: ['/', 'home'],
	query: { name: 'wya-team' }
});
```

---

#### `parse`

`Route.parse(url: string, options: object)`

解析当前路由 -> `{ query: {}, path: [] }`

+ **url**: 路径，默认值：当前路由
+ **options**: 可配置参数

**示例**
```js
Route.parse();
```

---

#### `get`

`Route.get(key: string, url: string, options: object)`

设置版本号

+ **key**: 参数键值
+ **url**: 路径，默认值：当前路由
+ **options**: 可配置参数

**示例**
```javascript
Route.get('name');
```

### 约定

```
let url = `?a=${encodeURIComponent('&')}`; // '?a=%26'

decodeURIComponent(url); // a=&

encodeURIComponent(url); // '%3Fa%3D%2526'
```

- 期望： `{ a: '&' }`
- 实际： `{ a: '' }`

为了避免该情况，内部对`url`不直接`decodeURIComponent`, 仅当对值进行`decodeURIComponent`. 所以`%3Fa%3D%2526`是无效的; 

`merge`调用时，`value`的值会被`decodeURIComponent`

```js
get('a', '?a=%26'); // &

merge({ query: { a: '&' } }); // ?a=%26

parse('?a=%26'); // query.a === '&' (true)
```

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