Skip to content

Commit 1342fa7

Browse files
author
winddies
committed
type definition
1 parent 92961c6 commit 1342fa7

25 files changed

+15836
-9691
lines changed

.eslintignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/src/__mock__
22
/src/__tests__
3-
/test/*
3+
/test/*
4+
dist
5+
*.js

.eslintrc.js

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,13 @@
11
module.exports = {
2-
"extends": "eslint:recommended",
3-
"env": {
4-
"browser": true,
5-
"node": true,
6-
"commonjs": true,
7-
"amd": true,
8-
"worker":true,
9-
"es6":true,
10-
"mocha":true
11-
},
12-
"parserOptions": {
13-
"sourceType": "module",//module
14-
// 想使用的额外的语言特性:
15-
"ecmaFeatures": {
16-
// 允许在全局作用域下使用 return 语句
17-
"globalReturn":true,
18-
// impliedStric
19-
"impliedStrict":true,
20-
"experimentalObjectRestSpread": true
2+
extends: [
3+
'@qiniu'
4+
],
5+
settings: {
6+
"import/resolver": {
7+
node: {
8+
extensions: ['.js', '.ts'],
9+
moduleDirectory: ['node_modules', 'src/']
10+
}
2111
}
22-
},
23-
"rules": {
24-
"no-console": "off",
25-
"no-redeclare": 2,
26-
"keyword-spacing": 1,
27-
"prefer-spread": 0,
28-
"indent":[
29-
0,
30-
2
31-
],
32-
"array-bracket-spacing": [1, "never"],
33-
"comma-spacing": [1, { "before": false, "after": true }],
34-
"no-var": 1,
35-
"eqeqeq": 0,
36-
"brace-style": 1,
37-
"camelcase": 0,
38-
"space-infix-ops": 1,
39-
"no-unused-vars": [1, { "vars": "all", "args": "none" }],
40-
"spaced-comment": [1, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!"] }],
41-
"quotes": [
42-
"error",
43-
"double"
44-
],
45-
"no-shadow": 0,
46-
"semi": [
47-
1,
48-
"always"
49-
]
50-
},
51-
}
12+
}
13+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ deploy.sh
66
npm-debug.log
77
dist
88
test/config.json
9+
coverage
10+
.tmp

README.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Qiniu-JavaScript-SDK 的示例 [Demo](http://jssdk-v2.demo.qiniu.io) 中的服
8888
npm install qiniu-js
8989
```
9090
```Javascript
91-
var qiniu = require('qiniu-js')
91+
const qiniu = require('qiniu-js')
9292
// or
9393
import * as qiniu from 'qiniu-js'
9494
```
@@ -109,31 +109,31 @@ Qiniu-JavaScript-SDK 的示例 [Demo](http://jssdk-v2.demo.qiniu.io) 中的服
109109

110110
```JavaScript
111111

112-
var observable = qiniu.upload(file, key, token, putExtra, config)
112+
const observable = qiniu.upload(file, key, token, putExtra, config)
113113

114-
var subscription = observable.subscribe(observer) // 上传开始
114+
const subscription = observable.subscribe(observer) // 上传开始
115115
// or
116-
var subscription = observable.subscribe(next, error, complete) // 这样传参形式也可以
116+
const subscription = observable.subscribe(next, error, complete) // 这样传参形式也可以
117117

118118
subscription.unsubscribe() // 上传取消
119119
```
120120
图片上传前压缩:
121121

122122
```JavaScript
123-
let options = {
123+
const options = {
124124
quality: 0.92,
125125
noCompressIfLarger: true
126126
// maxWidth: 1000,
127127
// maxHeight: 618
128128
}
129129
qiniu.compressImage(file, options).then(data => {
130-
var observable = qiniu.upload(data.dist, key, token, putExtra, config)
131-
var subscription = observable.subscribe(observer) // 上传开始
130+
const observable = qiniu.upload(data.dist, key, token, putExtra, config)
131+
const subscription = observable.subscribe(observer) // 上传开始
132132
})
133133
```
134134
## API Reference Interface
135135

136-
### qiniu.upload(file: blob, key: string, token: string, putExtra: object, config: object): observable
136+
### qiniu.upload(file: File, key: string, token: string, putExtra: object, config: object): observable
137137

138138
* **observable**: 为一个带有 subscribe 方法的类实例
139139

@@ -142,7 +142,7 @@ qiniu.compressImage(file, options).then(data => {
142142
* observer: `observer` 为一个 `object`,用来设置上传过程的监听函数,有三个属性 `next``error``complete`:
143143

144144
```JavaScript
145-
var observer = {
145+
const observer = {
146146
next(res){
147147
// ...
148148
},
@@ -169,13 +169,13 @@ qiniu.compressImage(file, options).then(data => {
169169

170170
* subscription: 为一个带有 `unsubscribe` 方法的类实例,通过调用 `subscription.unsubscribe()` 停止当前文件上传。
171171

172-
* **file**: `Blob` 对象,上传的文件
172+
* **file**: `File` 对象,上传的文件
173173
* **key**: 文件资源名
174174
* **token**: 上传验证信息,前端通过接口请求后端获得
175175
* **config**: `object`
176176

177177
```JavaScript
178-
var config = {
178+
const config = {
179179
useCdnDomain: true,
180180
region: qiniu.region.z2
181181
};
@@ -193,15 +193,15 @@ qiniu.compressImage(file, options).then(data => {
193193
* **putExtra**:
194194

195195
```JavaScript
196-
var putExtra = {
196+
const putExtra = {
197197
fname: "",
198198
params: {},
199199
mimeType: [] || null
200200
};
201201
```
202202

203203
* fname: `string`,文件原文件名
204-
* params: `object`,用来放置自定义变量,自定义变量格式请参考[文档](https://developer.qiniu.com/kodo/manual/1235/vars)
204+
* params: `object`,用来放置自定义变量,变量名必须以 `x:` 开始,自定义变量格式及说明请参考[文档](https://developer.qiniu.com/kodo/manual/1235/vars)
205205
* mimeType: `null || array`,用来限制上传文件类型,为 `null` 时表示不对文件类型限制;限制类型放到数组里:
206206
`["image/png", "image/jpeg", "image/gif"]`
207207

@@ -215,11 +215,11 @@ qiniu.compressImage(file, options).then(data => {
215215
* **putExtra**: 同上
216216

217217
```JavaScript
218-
var requestUrl = qiniu.createMkFileUrl(
219-
  uploadUrl,
220-
  file.size,
221-
  key,
222-
  putExtra
218+
const requestUrl = qiniu.createMkFileUrl(
219+
uploadUrl,
220+
file.size,
221+
key,
222+
putExtra
223223
);
224224
```
225225

@@ -245,45 +245,45 @@ qiniu.compressImage(file, options).then(data => {
245245
* **token**: 后端返回的上传验证信息
246246

247247
```JavaScript
248-
var headers = qiniu.getHeadersForChunkUpload(token)
248+
const headers = qiniu.getHeadersForChunkUpload(token)
249249
```
250250

251251
### qiniu.getHeadersForMkFile(token: string): object
252252

253253
返回 `object`,包含用来获得文件创建的头信息,参数为 `token` 字符串;当分片上传完需要把 ctx 信息传给七牛用来创建文件时,请求需要带该函数返回的头信息
254254

255255
```JavaScript
256-
var headers = qiniu.getHeadersForMkFile(token)
256+
const headers = qiniu.getHeadersForMkFile(token)
257257
```
258258

259-
### qiniu.getResumeUploadedSize(file: blob): number
259+
### qiniu.getResumeUploadedSize(file: File): number
260260
断点续传时返回文件之前已上传的字节数,为 0 代表当前并无该文件的断点信息
261261

262262
### qiniu.filterParams(params: object): array
263263

264264
返回[[k, v],...]格式的数组,k 为自定义变量 `key` 名,v 为自定义变量值,用来提取 `putExtra.params` 包含的自定义变量
265265

266266
```JavaScript
267-
var customVarList = qiniu.filterParams(putExtra.params)
267+
const customVarList = qiniu.filterParams(putExtra.params)
268268
269-
for (var i = 0; i < customVarList.length; i++) {
270-
var k = customVarList[i]
269+
for (let i = 0; i < customVarList.length; i++) {
270+
const k = customVarList[i]
271271
multipart_params_obj[k[0]] = k[1]
272272
}
273273
```
274-
### qiniu.compressImage(file: blob, options: object) : Promise (上传前图片压缩)
274+
### qiniu.compressImage(file: File, options: object) : Promise (上传前图片压缩)
275275

276276
```JavaScript
277-
var imgLink = qiniu.compressImage(file, options).then(res => {
277+
const imgLink = qiniu.compressImage(file, options).then(res => {
278278
// res : {
279-
// dist: 压缩后输出的 blob 对象,或原始的 file,具体看下面的 options 配置
279+
// dist: 压缩后输出的 File 对象,或原始的 file,具体看下面的 options 配置
280280
// width: 压缩后的图片宽度
281281
// height: 压缩后的图片高度
282282
// }
283283
}
284284
})
285285
```
286-
* file: 要压缩的源图片,为 `blob` 对象,支持 `image/png``image/jpeg``image/bmp``image/webp` 这几种图片类型
286+
* file: 要压缩的源图片,为 `File` 对象,支持 `image/png``image/jpeg``image/bmp``image/webp` 这几种图片类型
287287
* options: `object`
288288
* options.quality: `number`,图片压缩质量,在图片格式为 `image/jpeg``image/webp` 的情况下生效,其他格式不会生效,可以从 01 的区间内选择图片的质量。默认值 0.92
289289
* options.maxWidh: `number`,压缩图片的最大宽度值
@@ -299,7 +299,7 @@ qiniu.compressImage(file, options).then(data => {
299299

300300
```JavaScript
301301
302-
var imgLink = qiniu.watermark({
302+
const imgLink = qiniu.watermark({
303303
mode: 1, // 图片水印
304304
image: 'http://www.b1.qiniudn.com/images/logo-2.png', // 图片水印的Url,mode = 1 时 **必需**
305305
dissolve: 50, // 透明度,取值范围1-100,非必需,下同
@@ -316,7 +316,7 @@ qiniu.compressImage(file, options).then(data => {
316316
317317
// 或者
318318
319-
var imgLink = qiniu.watermark({
319+
const imgLink = qiniu.watermark({
320320
mode: 2, // 文字水印
321321
text: 'hello world !', // 水印文字,mode = 2 时 **必需**
322322
dissolve: 50, // 透明度,取值范围1-100,非必需,下同
@@ -336,7 +336,7 @@ qiniu.compressImage(file, options).then(data => {
336336
返回处理后的图片url
337337

338338
```JavaScript
339-
var imgLink = qiniu.imageView2({
339+
const imgLink = qiniu.imageView2({
340340
mode: 3, // 缩略模式,共6种[0-5]
341341
w: 100, // 具体含义由缩略模式决定
342342
h: 100, // 具体含义由缩略模式决定
@@ -352,7 +352,7 @@ qiniu.compressImage(file, options).then(data => {
352352
返回处理后的图片url
353353

354354
```JavaScript
355-
var imgLink = qiniu.imageMogr2({
355+
const imgLink = qiniu.imageMogr2({
356356
"auto-orient": true, // 布尔值,是否根据原图EXIF信息自动旋正,便于后续处理,建议放在首位。
357357
strip: true, // 布尔值,是否去除图片中的元信息
358358
thumbnail: '1000x1000' // 缩放操作参数
@@ -386,7 +386,7 @@ qiniu.compressImage(file, options).then(data => {
386386
### qiniu.pipeline(fopArr: array, key: string, domain: string): string
387387

388388
```JavaScript
389-
var fopArr = [{
389+
const fopArr = [{
390390
fop: 'watermark', // 指定watermark操作
391391
mode: 2, // 此参数同watermark函数的参数,下同。
392392
text: 'hello world !',
@@ -419,7 +419,7 @@ qiniu.compressImage(file, options).then(data => {
419419
420420
// fopArr 可以为三种类型'watermark'、'imageMogr2'、'imageView2'中的任意1-3个
421421
// 例如只对'watermark'、'imageMogr2'进行管道操作,则如下即可
422-
// var fopArr = [{
422+
// const fopArr = [{
423423
// fop: 'watermark', // 指定watermark操作
424424
// mode: 2, // 此参数同watermark函数的参数,下同。
425425
// text: 'hello world !',
@@ -443,7 +443,7 @@ qiniu.compressImage(file, options).then(data => {
443443
// blur:'3x5'
444444
// }];
445445
446-
var imgLink = qiniu.pipeline(fopArr, key, domain))
446+
const imgLink = qiniu.pipeline(fopArr, key, domain))
447447
```
448448

449449
fopArr包含的具体管道操作解释见[管道操作](https://developer.qiniu.com/dora/manual/processing-mechanism)

0 commit comments

Comments
 (0)