# mod-path

> encodeURIComponent decodeURIComponent

Latest version **0.0.6** (published 2021-11-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install mod-path
pnpm add mod-path
yarn add mod-path
bun add mod-path
```

## 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.0.6 |
| Published | 2021-11-10 |
| First published | 2020-12-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 1.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | enmotion |
| Maintainers | enmotion |
| Keywords | encodeURIComponent, decodeURIComponent |

## Links

- npm: https://www.npmjs.com/package/mod-path
- npm.io page: https://npm.io/package/mod-path

## Dependencies (2)

- [url](https://npm.io/package/url.md) ^0.11.0
- [ramda](https://npm.io/package/ramda.md) ^0.27.1

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.0.6 (latest) — 2021-11-10
- 0.0.5 — 2021-01-10
- 0.0.4 — 2020-12-30
- 0.0.3 — 2020-12-28
- 0.0.2 — 2020-12-27
- 0.0.1 — 2020-12-26

## README

# mod-path #

url地址操作工具。<br>

#### 功能说明：
1.可将JSON对象,作为参数拼接进地址,支持安全编码</br>
2.地址检查,比对地址的合法性</br>

#### install ####
npm安装命令
```
npm install --save mod-path
```

#### Usage ####

引入包
```
import P from "mod-path"
```

范例

```
import P from "../src/index.js";
//拼装Data
let data={
    name:"MOD",
    age:12,
    gender:"male",
    hobby:["videogame","tree",{new:"keep"}],
}
var strData = P.encodeData("")

console.log(strData);
console.log(P.encodeData(data))

var URL = P.encodeURL("www.baidu.com",data,{encode:true})
var URL2 = P.encodeURL("www.baidu.com#wechat",data,{encode:false})

console.log(URL,"\n",URL2);
console.log(P.decodeURL(URL,{encode:true}).query)
console.log(P.decodeURL(URL2,{encode:false}))

console.log(P.validURL('http://user:pass@host.com:8080/p/a/t/h?name=mod',"http://user:pass@host.com:8080/p/a/t/h?name=mod"));
console.log(P.validURL('http://user:pass@host.com:8080/p/a/t/h?name=mod',"http://user:pass@host.com:8080/p/a/t/h?name=ssse"));
console.log(P.validURL('https://user:pass@host.com:8080/p/a/t/h?name=mod',"http://user:pass@host.com:8080/p/a/t/h?name=mod"));

```
### PROP ###
[instance].encode 是否自动在生成地址时采用安全编码
默认 true ，启用安全编码 false 则取消安全编码
```
import P from "../src/index.js";

console.log(P.encode) // true
P.encode = false
console.log(P.encode) // false
```

### API ###

#### encodeURL(baseURL,data,config)<br> #### 
将地址拼接参数
baseURL:String,//需要拼接参数的地址
data:JSON Object,//参数JSON格式
config:Object,//同全局配置属性，可每次调用该方法时，灵活设置，如空则默认全局配置。

```
import P from "../src/index.js";

P.encodeURL('www.baiduc.com',{name:"MOD",age:12,gender:"male",hobby:["videogame","tree",{new:"keep"}]});
//www.baidu.com%3Fname%3DMOD%26age%3D12%26gender%3Dmale%26hobby%3D%5B%22videogame%22%2C%22tree%22%2C%7B%22new%22%3A%22keep%22%7D%5D

P.encodeURL('www.baiduc.com#wechat',{name:"MOD",age:12,gender:"male",hobby:["videogame","tree",{new:"keep"}]},{encode:false});
//www.baidu.com?name=MOD&age=12&gender=male&hobby=["videogame","tree",{"new":"keep"}]#wechat
```

#### decodeURL(locationURL,config)<br> #### 
可将携参地址的参数解析成对象
locationURL:String,//携参地址
config:Object,//同全局配置属性，可每次调用该方法时，灵活设置，如空则默认全局配置方式进行解析。

```
P.decodeURL('www.baidu.com%3Fname%3DMOD%26age%3D12%26gender%3Dmale%26hobby%3D%5B%22videogame%22%2C%22tree%22%2C%7B%22new%22%3A%22keep%22%7D%5D').query;
//{name:"MOD",age:12,gender:"male",hobby:["videogame","tree",{new:"keep"}]}
```

#### config
配置对象结构说明
```
{
    encode:true,//Boolean是否在本次调用时启用安全编码，如缺省 则依照全局配置
    hash:"wechat",//可添入哈希值
}
```

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