# snail-helpers

> collection of snailreader client utils

Latest version **1.5.2** (published 2019-10-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install snail-helpers
pnpm add snail-helpers
yarn add snail-helpers
bun add snail-helpers
```

## 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 | 1.5.2 |
| Published | 2019-10-15 |
| First published | 2019-04-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | hzliushichuan@corp.netease.com |
| Maintainers | liushichuan |

## Links

- npm: https://www.npmjs.com/package/snail-helpers
- npm.io page: https://npm.io/package/snail-helpers

## Recent versions

- 1.5.2 (latest) — 2019-10-15
- 1.5.1 — 2019-10-15
- 1.5.0 — 2019-07-30
- 1.4.0 — 2019-07-29
- 1.3.0 — 2019-06-10
- 1.2.0 — 2019-06-05
- 1.1.0 — 2019-04-29

## README

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [isSnail][1]
-   [isIos][2]
-   [isIphone][3]
-   [isAndroid][4]
-   [isWechat][5]
-   [isQQ][6]
-   [isUpIos9][7]
-   [isUpIos11][8]
-   [isWeibo][9]
-   [getIosVersion][10]
-   [getEnv][11]
-   [getSnailType][12]
-   [formateVersion][13]
    -   [Parameters][14]
-   [getSnailVersion][15]
-   [isAppAfterVersion][16]
    -   [Parameters][17]
-   [parseUrl][18]
    -   [Parameters][19]
-   [getCookie][20]
    -   [Parameters][21]
-   [setCookie][22]
    -   [Parameters][23]
-   [getCsrfToken][24]
-   [encodeFormData][25]
    -   [Parameters][26]
-   [normalizeAvatar][27]
    -   [Parameters][28]

## isSnail

是否在蜗牛App内

## isIos

是否为iOS设备

## isIphone

是否为iPhone

## isAndroid

是否为Android

## isWechat

是否在微信内

## isQQ

是否为QQ内

## isUpIos9

是否为ios9及以上

## isUpIos11

是否为iOS11及以上

## isWeibo

是否为微博App内

## getIosVersion

获取给定ua对应的iOS系统版本号(Number类型)，如果非iOS系统或者匹配错误，返回值为-1

## getEnv

根据当前域名判断当前网页所处的环境, online线上、dev开发、test测试、pre预发

## getSnailType

获取当前蜗牛App的类型 normal普通、eink墨水屏、ipad、abroad海外版,非蜗牛App返回空

## formateVersion

转换App的版本为数字类型:1.7.0转换为10700

### Parameters

-   `version` **[string][29]** 版本号，必须符合'x.x.x'的格式，x为数字

## getSnailVersion

获取当前页面所处的蜗牛的App的版本号，并转换为Number类型，非蜗牛app或者ua设置错误时返回值为-1

## isAppAfterVersion

判断当前蜗牛app版本号是否大于等于给定版本号

### Parameters

-   `version` **[string][29]** 想要比较的版本号,必须符合'x.x.x'的格式，x为数字

## parseUrl

解析URL的查询参数

### Parameters

-   `url` **[string][29]** 传入的urlstring，为空则解析当前页的url查询部分

Returns **[object][30]** 查询url解析出的键值对没有则为空对象{}

## getCookie

获取cookie

### Parameters

-   `name` **[string][29]** 想要获取cookie值的name

## setCookie

设置cookie

### Parameters

-   `name` **[string][29]** cookie的名称 必须
-   `value` **[string][29]** cookie的值 必须
-   `days` **[number][31]** cookie的有效天数 可选

## getCsrfToken

从cookie中获取post请求所需的csrftoken,如果没有，则自行生成一个

## encodeFormData

将对象转换为formData

### Parameters

-   `oldData` **[Object][30]** 需要转换为formData形式的对象

## normalizeAvatar

规范化蜗牛的头像url，使其适合用于蜗牛ui中的圆形显示场景，并在为空时自动补充默认的头像

### Parameters

-   `url` **[string][29]** 想要被规范化的头像url

[1]: #issnail

[2]: #isios

[3]: #isiphone

[4]: #isandroid

[5]: #iswechat

[6]: #isqq

[7]: #isupios9

[8]: #isupios11

[9]: #isweibo

[10]: #getiosversion

[11]: #getenv

[12]: #getsnailtype

[13]: #formateversion

[14]: #parameters

[15]: #getsnailversion

[16]: #isappafterversion

[17]: #parameters-1

[18]: #parseurl

[19]: #parameters-2

[20]: #getcookie

[21]: #parameters-3

[22]: #setcookie

[23]: #parameters-4

[24]: #getcsrftoken

[25]: #encodeformdata

[26]: #parameters-5

[27]: #normalizeavatar

[28]: #parameters-6

[29]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[30]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[31]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

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