Skip to content

Commit 815dcea

Browse files
committed
refactor(root): 添加 typescript
1 parent 3a9413c commit 815dcea

28 files changed

+4343
-3260
lines changed

.babelrc

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
{
2-
"presets": [
3-
[
4-
"env",
5-
{
6-
"modules": false
7-
}
8-
]
9-
],
10-
"plugins": [
11-
"transform-runtime"
12-
]
2+
"presets": ["@babel/env", "@babel/typescript"],
3+
"plugins": ["@babel/proposal-class-properties", "@babel/proposal-object-rest-spread"]
134
}
14-

.eslintcache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"/Users/shiyi/github/callapp-lib/src/browser.ts":"1","/Users/shiyi/github/callapp-lib/src/evoke.ts":"2","/Users/shiyi/github/callapp-lib/src/generate.ts":"3","/Users/shiyi/github/callapp-lib/src/index.ts":"4","/Users/shiyi/github/callapp-lib/src/types.ts":"5"},{"size":1364,"mtime":1591692519227,"results":"6","hashOfConfig":"7"},{"size":2322,"mtime":1591692519227,"results":"8","hashOfConfig":"7"},{"size":2818,"mtime":1591692519227,"results":"9","hashOfConfig":"7"},{"size":3568,"mtime":1591692986922,"results":"10","hashOfConfig":"7"},{"size":916,"mtime":1591692519228,"results":"11","hashOfConfig":"7"},{"filePath":"12","messages":"13","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1k5k9j8",{"filePath":"14","messages":"15","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"16","messages":"17","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"18","messages":"19","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"20","messages":"21","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/shiyi/github/callapp-lib/src/browser.ts",[],"/Users/shiyi/github/callapp-lib/src/evoke.ts",[],"/Users/shiyi/github/callapp-lib/src/generate.ts",[],"/Users/shiyi/github/callapp-lib/src/index.ts",[],"/Users/shiyi/github/callapp-lib/src/types.ts",[]]

.eslintrc.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
module.exports = {
2-
"env": {
3-
"browser": true,
2+
extends: ['airbnb-base', 'plugin:import/typescript', 'plugin:unicorn/recommended', 'prettier'],
3+
plugins: ['prettier', 'unicorn'],
4+
env: {
5+
node: true,
6+
browser: true,
47
},
5-
"extends": "airbnb-base",
6-
'rules': {
7-
"import/no-extraneous-dependencies": ["error", {
8-
"devDependencies": true,
9-
}],
10-
}
11-
};
8+
rules: {
9+
'import/no-extraneous-dependencies': ['error', { peerDependencies: true }],
10+
'prettier/prettier': 'error',
11+
'unicorn/prevent-abbreviations': 'off',
12+
},
13+
overrides: [
14+
{
15+
files: ['*.ts'],
16+
parser: '@typescript-eslint/parser',
17+
plugins: ['@typescript-eslint'],
18+
extends: [
19+
'plugin:@typescript-eslint/eslint-recommended',
20+
'plugin:@typescript-eslint/recommended',
21+
'prettier/@typescript-eslint',
22+
],
23+
rules: {
24+
'@typescript-eslint/no-explicit-any': 'off',
25+
'no-param-reassign': 'off',
26+
// airbnb 配置导致 tsx 文件引用一直报错
27+
'import/extensions': ['error', 'ignorePackages', { ts: 'never' }],
28+
},
29+
},
30+
],
31+
};

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"endOfLine": "lf",
3+
"semi": true,
4+
"singleQuote": true,
5+
"tabWidth": 2,
6+
"printWidth": 100,
7+
"trailingComma": "es5"
8+
}

README.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
## callapp-lib
1+
# callapp-lib
22

33
callapp-lib 是一个 H5 唤起 APP 的解决方案,能够满足大部分唤起客户端的场景,也预留了扩展口,帮你实现一些定制化的功能。
44

5-
如果你想了解一些唤端的原理知识,或者阅读下面的文档有不理解的名词,可以访问这篇博客 [H5唤起APP指南](https://suanmei.github.io/2018/08/23/h5_call_app/)
5+
如果你想了解一些唤端的原理知识,或者阅读下面的文档有不理解的名词,可以访问这篇博客 [H5 唤起 APP 指南](https://suanmei.github.io/2018/08/23/h5_call_app/)
66

7-
如果你在使用 callapp-lib 的过程中,有好的想法或者发现了bug,提 Issue 就行,作者会及时跟进。
7+
如果你在使用 callapp-lib 的过程中,有好的想法或者发现了 bug,提 Issue 就行,作者会及时跟进。
88

99
## Install
1010

1111
Install with [npm](https://www.npmjs.com/):
1212

13-
``` sh
14-
$ npm install --save callapp-lib
13+
```sh
14+
npm install --save callapp-lib
1515
```
1616

1717
## Usage
1818

19-
``` js
19+
```js
2020
const CallApp = require('callapp-lib');
2121

22-
or
22+
or;
2323

2424
import CallApp from 'callapp-lib';
2525
```
2626

27-
callapp-lib 同样支持 `script` 加载,你可以使用下面的 **cdn文件(地址在下面的示例中)**,也可以下载 `dist/index.umd.js` 到你的项目中,`index.umd.js` 会暴露一个全局变量 `CallApp` ,这个全局变量和上面 `commonjs` 导入的 `CallApp` 内容是一致的,使用方法也是一致的。
27+
callapp-lib 同样支持 `script` 加载,你可以使用下面的 **cdn 文件(地址在下面的示例中)**,也可以下载 `dist/index.umd.js` 到你的项目中,`index.umd.js` 会暴露一个全局变量 `CallApp` ,这个全局变量和上面 `commonjs` 导入的 `CallApp` 内容是一致的,使用方法也是一致的。
2828

29-
``` html
29+
```html
3030
<!-- 及时下载未压缩的最新版本 Js -->
3131
<script src="https://unpkg.com/callapp-lib"></script>
3232

@@ -43,22 +43,22 @@ or
4343

4444
callapp-lib 中传递出来的是一个类,你需要将它实例化,然后才能去调用实例对象的方法。
4545

46-
``` js
46+
```js
4747
const options = {
4848
key1: 'xxx',
49-
key2: 'xxx'
49+
key2: 'xxx',
5050
};
5151
const callLib = new CallApp(options);
5252

5353
callLib.open({
5454
param: {},
55-
path: 'xxx'
55+
path: 'xxx',
5656
});
5757
```
5858

5959
## Demo
6060

61-
请访问[demo页面](https://raw.githack.com/suanmei/callapp-lib/master/example/index.html),或访问[demo文件](https://github.com/suanmei/callapp-lib/blob/master/example/index.html)
61+
请访问[demo 页面](https://raw.githack.com/suanmei/callapp-lib/master/example/index.html),或访问[demo 文件](https://github.com/suanmei/callapp-lib/blob/master/example/index.html)
6262

6363
如果你在使用移动端,可以扫描下方二维码:
6464

@@ -75,30 +75,30 @@ callLib.open({
7575
类型: `object`
7676
必填: ✅
7777

78-
用来配置 URL Scheme 所必须的那些v字段
78+
用来配置 URL Scheme 所必须的那些 v 字段
7979

80-
+ protocol
80+
- protocol
8181

8282
类型: `string`
8383
必填: ✅
8484

8585
APP 协议,URL Scheme 的 scheme 字段,就是你要打开的 APP 的标识。
8686

87-
+ host
87+
- host
8888

8989
类型: `string`
9090
必填: ❎
9191

9292
URL Scheme 的 host 字段。
9393

94-
+ port
94+
- port
9595

9696
类型: `string` | `number`
9797
必填: ❎
9898

9999
URL Scheme 的 port 字段。
100100

101-
### <s>protocol</s>
101+
### protocol
102102

103103
callapp-lib 2.0.0 版本已移除,原先的 protocol 移入到新增的 scheme 属性中
104104

@@ -111,45 +111,45 @@ callapp-lib 2.0.0 版本已移除,原先的 protocol 移入到新增的 scheme
111111

112112
例:`youku://ykshortvideo?url=xxx`
113113

114-
+ protocol (2.0.0 版本由原先的 protocal 修改为 protocol,原先的 protocal 是拼写错误)
114+
- protocol (2.0.0 版本由原先的 protocal 修改为 protocol,原先的 protocal 是拼写错误)
115115

116116
同 URL Scheme 的 scheme 字段,在你的 APP 就和上面的 protocol 属性值相同,在其他 APP 打开就传该 APP 的 scheme 标识。
117117

118-
+ path
118+
- path
119119

120120
参考 URL Scheme 的 path 字段,它代表了该 APP 的具体的某个功页面(功能),这里的 path 就是对应的中间页。
121121

122-
+ key
122+
- key
123123

124124
既然只是中间页,它自然要打开我们真正要打开的页面,所以我们需要把要打开的页面的 URL Scheme 传递过去。就像前端从 URL 的 query 字符串里面取值一样,客户端也是从 URL Scheme 里面来取。至于参数 key 定成什么,大家自己去协商吧,上面的示例中 `url` 也只是一个示例。
125125

126126
### intent
127127

128128
类型: `object`
129-
必填: ❎
129+
必填: ❎
130130

131131
安卓原生谷歌浏览器必须传递 Intent 协议地址,才能唤起 APP。
132132

133133
它支持以下五个属性,其中 scheme 和 上面的 protocal 一样,其他四个都是 apk 相关信息,其中 package 和 scheme 必传:
134134

135-
+ package
136-
+ action
137-
+ category
138-
+ component
139-
+ scheme
135+
- package
136+
- action
137+
- category
138+
- component
139+
- scheme
140140

141141
### universal
142142

143143
类型: `object`
144144
必填: ❎
145145

146-
如果你们的 ios 工程师没有做相应的配置来让 APP 支持 Universal Link,你可以不用传递, *callap-lib* 将会使用 URL Scheme 来替代它。
146+
如果你们的 ios 工程师没有做相应的配置来让 APP 支持 Universal Link,你可以不用传递, _callap-lib_ 将会使用 URL Scheme 来替代它。
147147

148-
+ host
148+
- host
149149

150150
你的 Universal Link 的域名,`apple-app-site-association` 文件就放在这个域名对应的服务器上。
151151

152-
+ pathKey
152+
- pathKey
153153

154154
pathKey 就和前面 Intent 的 key 属性一样,只是这里的 pathKey 是客户端用来提取 path 信息的,以便知道调用的是 APP 的哪个页面。这个值也是需要你和 ios 童鞋协商定下来的。
155155

@@ -200,41 +200,41 @@ url scheme 自定义拼接函数,内置的 buildScheme 函数是按照 uri 规
200200

201201
### open
202202

203-
唤端功能。接收一个对象作为参数,该对象支持以下属性:
203+
唤端功能。接收一个对象作为参数,该对象支持以下属性:
204+
205+
- path
204206

205-
+ path
207+
类型: `string`
208+
必填: ✅
206209

207-
类型: `string`
208-
必填: ✅
210+
需要打开的页面对应的值,URL Scheme 中的 path 部分,参照 [H5 唤起 APP 指南](https://suanmei.github.io/2018/08/23/h5_call_app/) 一文中的解释。
209211

210-
需要打开的页面对应的值,URL Scheme 中的 path 部分,参照 [H5唤起APP指南](https://suanmei.github.io/2018/08/23/h5_call_app/) 一文中的解释。
211-
212212
只想要直接打开 app ,不需要打开特定页面,path 传空字符串 `''` 就可以。
213213

214-
+ param
214+
- param
215215

216216
类型: `object`
217-
必填: ❎
217+
必填: ❎
218218

219219
打开 APP 某个页面,它需要接收的参数。
220220

221-
+ callback
222-
必填: ❎
221+
- callback
222+
必填: ❎
223223

224-
类型: `function`
224+
类型: `function`
225225

226-
自定义唤端失败回调函数。传递 `callback` 会覆盖 *callapp-lib* 库中默认的唤端失败处理逻辑。
226+
自定义唤端失败回调函数。传递 `callback` 会覆盖 _callapp-lib_ 库中默认的唤端失败处理逻辑。
227227

228228
### generateScheme
229229

230230
接收一个对象作为参数,该对象包含以下属性:
231231

232-
+ path
233-
+ param
232+
- path
233+
- param
234234

235235
属性含义和 `open` 方法参数的属性一致。
236236

237-
返回 URL Scheme。如果你觉得 *callapp-lib* 的唤端处理方式不符合你的需求,但你又不想费心费力的自己去拼凑 URL Scheme,可以利用这个方法直接生成。
237+
返回 URL Scheme。如果你觉得 _callapp-lib_ 的唤端处理方式不符合你的需求,但你又不想费心费力的自己去拼凑 URL Scheme,可以利用这个方法直接生成。
238238

239239
### generateIntent
240240

0 commit comments

Comments
 (0)