# @yangguoxin/mini-shim

> 小程序webview垫片

Latest version **1.0.5** (published 2021-07-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install @yangguoxin/mini-shim
pnpm add @yangguoxin/mini-shim
yarn add @yangguoxin/mini-shim
bun add @yangguoxin/mini-shim
```

## 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.5 |
| Published | 2021-07-13 |
| First published | 2021-07-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | 无线中心 |
| Maintainers | ygx763123 |

## Links

- npm: https://www.npmjs.com/package/@yangguoxin/mini-shim
- npm.io page: https://npm.io/package/@yangguoxin/mini-shim

## Recent versions

- 1.0.5 (latest) — 2021-07-13

## README

# 小程序webview垫片

主要解决将url上`__bf_params`基础参数解析出来，自动存入`cookie`

将`env`字段存入`sessionStorage`，方便同步判断小程序环境

## 使用

```js
import miniShim from '@blackfish/mini-shim'
// 解析并写cookie
miniShim.init()

// 解析的key值
console.log(miniShim.getKeys()) // ['token', 'phoneNumber', 'env', 'pValue',
//  'appId', 'appName', 'appVersion', 'wxVersion', 'fingerPrint', 'normalId']

// 是否在小程序环境
miniShim.isMini() // true of false
```

## 小程序webview使用
```js
let params = {
  token: app.globalData.loginInfo.token, // 当前用户token
  userId: 'userId', // 用户id
  phoneNumber: app.globalData.accessInfo.memberPhone, // 当前用户手机号
  env: 'miniprogram', // 运行环境标识，由于小程序api是异步，最好url直接标识
  pValue: 'p值',
  appId: 'appId',
  wxAppId: '微信小程序appId', // 如果 appId 传的是小程序appId，此字段可以不传
  appName: 'app名称',
  appVersion: 'app版本',
  wxVersion: '微信版本',
  openId: 'openId',
  normalId: 'normalId',
  fingerPrint: '设备指纹'
}
 
let url = `${h5URL}?__bf_params=${encodeURIComponent(JSON.stringify(params))}`
 
this.setData({
  url: url
})
```

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