@fatcherjs/middleware-json 1.8.0 → 3.0.0-alpha-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +7 -19
- package/package.json +21 -20
- package/dist/json.d.ts +0 -12
- package/dist/json.esm.js +0 -21
- package/dist/json.js +0 -25
- package/dist/json.min.js +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
# @
|
|
2
|
-
|
|
3
|
-
A middleware for transform response to JSON
|
|
1
|
+
# @fatcher/middleware-json
|
|
4
2
|
|
|
5
3
|
## Install
|
|
6
4
|
|
|
@@ -13,30 +11,20 @@ A middleware for transform response to JSON
|
|
|
13
11
|
### CDN
|
|
14
12
|
|
|
15
13
|
```html
|
|
16
|
-
<script src="https://cdn.jsdelivr.net/npm/@fatcherjs/middleware-json/dist/
|
|
14
|
+
<script src="https://cdn.jsdelivr.net/npm/@fatcherjs/middleware-json/dist/index.min.js"></script>
|
|
17
15
|
```
|
|
18
16
|
|
|
19
17
|
## Usage
|
|
20
18
|
|
|
21
19
|
```ts
|
|
22
|
-
import { json } from '@fatcherjs/middleware-json';
|
|
23
20
|
import { fatcher } from 'fatcher';
|
|
21
|
+
import { json } from '@fatcherjs/middleware-json';
|
|
24
22
|
|
|
25
|
-
fatcher({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
payload: {
|
|
29
|
-
bar: 'foo',
|
|
30
|
-
},
|
|
31
|
-
})
|
|
32
|
-
.then(res => {
|
|
33
|
-
console.log(res);
|
|
34
|
-
})
|
|
35
|
-
.catch(err => {
|
|
36
|
-
console.error(error);
|
|
37
|
-
});
|
|
23
|
+
fatcher('https://foo.bar', {
|
|
24
|
+
middlewares: [json()],
|
|
25
|
+
});
|
|
38
26
|
```
|
|
39
27
|
|
|
40
28
|
## License
|
|
41
29
|
|
|
42
|
-
[
|
|
30
|
+
[MIT](https://github.com/fanhaoyuan/fatcher/blob/master/LICENSE)
|
package/package.json
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fatcherjs/middleware-json",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"middleware",
|
|
13
|
-
"json"
|
|
14
|
-
],
|
|
3
|
+
"homepage": "https://github.com/fanhaoyuan/fatcher",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/fanhaoyuan/fatcher.git"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"module": "dist/index.esm.js",
|
|
10
|
+
"browser": "dist/index.min.js",
|
|
11
|
+
"typings": "dist/index.d.ts",
|
|
15
12
|
"files": [
|
|
16
13
|
"dist"
|
|
17
14
|
],
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/fatcherjs/fatcher.git"
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"fatcher": "3.0.0-alpha-4"
|
|
22
17
|
},
|
|
23
18
|
"dependencies": {
|
|
24
|
-
"
|
|
19
|
+
"@fatcherjs/utils-shared": "3.0.0-alpha-4"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"fatcher": "3.0.0-alpha-4"
|
|
25
23
|
},
|
|
24
|
+
"version": "3.0.0-alpha-4",
|
|
26
25
|
"scripts": {
|
|
27
|
-
"
|
|
28
|
-
"build": "
|
|
29
|
-
"
|
|
26
|
+
"clean": "rimraf dist",
|
|
27
|
+
"build": "npm run clean && rollup -c rollup.config.ts",
|
|
28
|
+
"test": "jest",
|
|
29
|
+
"test:cov": "jest --coverage",
|
|
30
|
+
"tsc": "tsc --noEmit"
|
|
30
31
|
}
|
|
31
32
|
}
|
package/dist/json.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Middleware } from 'fatcher';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A middleware for transforming stream into json
|
|
5
|
-
*
|
|
6
|
-
* If response.body never used, will try to transform into json.
|
|
7
|
-
*
|
|
8
|
-
* But if transform error. Will return a origin response.
|
|
9
|
-
*/
|
|
10
|
-
declare function json(): Middleware;
|
|
11
|
-
|
|
12
|
-
export { json };
|
package/dist/json.esm.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { canActivate } from 'fatcher';
|
|
2
|
-
|
|
3
|
-
function json() {
|
|
4
|
-
return {
|
|
5
|
-
name: "fatcher-middleware-json",
|
|
6
|
-
async use(context, next) {
|
|
7
|
-
const result = await next();
|
|
8
|
-
if (canActivate(result.data)) {
|
|
9
|
-
const clonedResponse = result.data.clone();
|
|
10
|
-
try {
|
|
11
|
-
const data = await clonedResponse.json();
|
|
12
|
-
return Object.assign(result, { data });
|
|
13
|
-
} catch (e) {
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { json };
|
package/dist/json.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var fatcher = require('fatcher');
|
|
6
|
-
|
|
7
|
-
function json() {
|
|
8
|
-
return {
|
|
9
|
-
name: "fatcher-middleware-json",
|
|
10
|
-
async use(context, next) {
|
|
11
|
-
const result = await next();
|
|
12
|
-
if (fatcher.canActivate(result.data)) {
|
|
13
|
-
const clonedResponse = result.data.clone();
|
|
14
|
-
try {
|
|
15
|
-
const data = await clonedResponse.json();
|
|
16
|
-
return Object.assign(result, { data });
|
|
17
|
-
} catch (e) {
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
exports.json = json;
|
package/dist/json.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("fatcher")):typeof define=="function"&&define.amd?define(["exports","fatcher"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e.FatcherMiddlewareJson={},e.Fatcher))})(this,function(e,t){"use strict";function o(){return{name:"fatcher-middleware-json",async use(i,a){const n=await a();if(t.canActivate(n.data)){const c=n.data.clone();try{const s=await c.json();return Object.assign(n,{data:s})}catch(s){}}return n}}}e.json=o,Object.defineProperty(e,"__esModule",{value:!0})});
|