manner.js 0.0.31 → 0.0.32
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/package.json +1 -1
- package/client/index.js +0 -32
- package/client/lib/clearCookie.js +0 -20
- package/client/lib/filterNamespace.js +0 -15
- package/client/lib/readCookie.js +0 -38
- package/client/lib/setCookie.js +0 -25
- package/server/class/CommonHttp.js +0 -143
- package/server/index.js +0 -27
- package/server/lib/cacheOutput.js +0 -36
- package/server/lib/compressOutput.js +0 -28
- package/server/lib/formateHttpDate.js +0 -11
- package/server/lib/formateHttpKey.js +0 -11
- package/server/lib/getHtml.js +0 -32
- package/server/lib/parseDateString.js +0 -9
- package/server/lib/parseHttpDate.js +0 -11
- package/server/lib/parseOption.js +0 -70
- package/server/lib/readCookie.js +0 -27
package/package.json
CHANGED
package/client/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "clearCookie", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _setCookie.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "filterNamespace", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _filename.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "readCookie", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _setCookie.default;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "setCookie", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _setCookie.default;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
var _filename = _interopRequireDefault(require("./lib/filename"));
|
|
31
|
-
var _setCookie = _interopRequireDefault(require("./lib/setCookie"));
|
|
32
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = clearCookie;
|
|
7
|
-
function clearCookie(namespaces) {
|
|
8
|
-
Object.keys(namespaces).forEach(n => {
|
|
9
|
-
if (n.expires !== undefined) {
|
|
10
|
-
Object.keys(n).forEach(k => {
|
|
11
|
-
if (n === 'user') {
|
|
12
|
-
document.cookie[n + '_' + k] = '';
|
|
13
|
-
}
|
|
14
|
-
window.localStorage.removeItem(n + '_' + k);
|
|
15
|
-
});
|
|
16
|
-
delete namespaces[n];
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return namespaces;
|
|
20
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = filterNamespace;
|
|
7
|
-
function filterNamespace(namespace) {
|
|
8
|
-
const ans = {};
|
|
9
|
-
Object.keys(namespace).forEach(k => {
|
|
10
|
-
if (k !== 'expires') {
|
|
11
|
-
ans[k] = namespace[k];
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
return ans;
|
|
15
|
-
}
|
package/client/lib/readCookie.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = readCookie;
|
|
7
|
-
var _clearCookie = _interopRequireDefault(require("./clearCookie"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
function readCookie() {
|
|
10
|
-
const cookies = {};
|
|
11
|
-
document.cookie.split(';').forEach(i => {
|
|
12
|
-
const [key, value] = i.split('=');
|
|
13
|
-
cookies[key.trim()] = value;
|
|
14
|
-
});
|
|
15
|
-
const namespaces = {};
|
|
16
|
-
Object.keys(cookies).forEach(k => {
|
|
17
|
-
const result = k.split('_');
|
|
18
|
-
if (result.length === 2) {
|
|
19
|
-
const [namespace, key] = result;
|
|
20
|
-
if (namespaces[namespace] === undefined) {
|
|
21
|
-
namespaces[namespace] = {};
|
|
22
|
-
}
|
|
23
|
-
namespaces[namespace][key] = cookies[k];
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
for (let i = 0; i < window.localStorage.length; i += 1) {
|
|
27
|
-
const k = window.localStorage.key(i);
|
|
28
|
-
const result = k.split('_');
|
|
29
|
-
if (result.length === 2) {
|
|
30
|
-
const [namespace, key] = result;
|
|
31
|
-
if (namespaces[namespace] === undefined) {
|
|
32
|
-
namespaces[namespace] = {};
|
|
33
|
-
}
|
|
34
|
-
namespaces[namespace][key] = window.localStorage.getItem(k);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return (0, _clearCookie.default)(namespaces);
|
|
38
|
-
}
|
package/client/lib/setCookie.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = setCookie;
|
|
7
|
-
function setCookie(response) {
|
|
8
|
-
const cookie = response.headers.get('cookie');
|
|
9
|
-
if (cookie !== null) {
|
|
10
|
-
if (cookie === '') {
|
|
11
|
-
document.cookie.split(';').forEach(c => {
|
|
12
|
-
const [k, v] = c.split('=');
|
|
13
|
-
const [namespace] = k.split('_');
|
|
14
|
-
if (namespace === 'user') {
|
|
15
|
-
document.cookie = k + '=' + v;
|
|
16
|
-
}
|
|
17
|
-
window.localStorage.set(k, v);
|
|
18
|
-
});
|
|
19
|
-
} else {
|
|
20
|
-
cookie.split(';').forEach(c => {
|
|
21
|
-
document.cookie = c;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _path = _interopRequireDefault(require("path"));
|
|
8
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
-
var _zlib = _interopRequireDefault(require("zlib"));
|
|
10
|
-
var _getHtml = _interopRequireDefault(require("../lib/getHtml"));
|
|
11
|
-
var _parseDateString = _interopRequireDefault(require("../lib/parseDateString"));
|
|
12
|
-
var _formateHttpDate = _interopRequireDefault(require("../lib/formateHttpDate"));
|
|
13
|
-
var _formateHttpKey = _interopRequireDefault(require("../lib/formateHttpKey"));
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
function getLists(list) {
|
|
16
|
-
return list.join('|');
|
|
17
|
-
}
|
|
18
|
-
class CommonHttp {
|
|
19
|
-
constructor(options) {
|
|
20
|
-
this.time = new Date().getTime();
|
|
21
|
-
const {
|
|
22
|
-
fonts
|
|
23
|
-
} = options;
|
|
24
|
-
if (options.fonts === undefined) {
|
|
25
|
-
options.fonts = [];
|
|
26
|
-
}
|
|
27
|
-
this.time = new Date().getTime();
|
|
28
|
-
this.modify = {};
|
|
29
|
-
this.file = {};
|
|
30
|
-
this.raw = {};
|
|
31
|
-
this.compress = {};
|
|
32
|
-
this.options = options;
|
|
33
|
-
this.regexp = new RegExp(`\.(${getLists(options.fonts.concat(['html, ico', 'js']))})$`);
|
|
34
|
-
}
|
|
35
|
-
compressOutput(req, res, buffer, path) {
|
|
36
|
-
res.setHeader('Vary', 'Accept-Encoding');
|
|
37
|
-
let acceptEncoding = req.headers['accept-encoding'];
|
|
38
|
-
if (/gzip/.test(acceptEncoding)) {
|
|
39
|
-
res.writeHead(200, {
|
|
40
|
-
'Content-Encoding': 'gzip'
|
|
41
|
-
});
|
|
42
|
-
this.dealCompress(_zlib.default.gzipSync(buffer), path, res);
|
|
43
|
-
} else {
|
|
44
|
-
res.writeHead(200, {});
|
|
45
|
-
this.dealDirect(buffer, path, res);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
cacheOutput(req, res, path, file, ms) {
|
|
49
|
-
let ifModifiedSince = req.headers['If-Modified-Since'];
|
|
50
|
-
if (ifModifiedSince === undefined) {
|
|
51
|
-
if (this.modify[path] === undefined) {
|
|
52
|
-
this.modify[path] = new Date(ms).toString();
|
|
53
|
-
}
|
|
54
|
-
if (this.file[path] === undefined) {
|
|
55
|
-
this.file[path] = file;
|
|
56
|
-
}
|
|
57
|
-
res.setHeader('Last-Modified', (0, _formateHttpDate.default)(this.modify[path]));
|
|
58
|
-
this.compressOutput(req, res, this.file[path], path);
|
|
59
|
-
} else {
|
|
60
|
-
if (this.modify[path] === undefined) {
|
|
61
|
-
this.modify[path] = new Date(ms).toString();
|
|
62
|
-
}
|
|
63
|
-
if ((0, _parseDateString.default)(new Date().toString()) < (0, _parseDateString.default)(this.modify[path])) {
|
|
64
|
-
if (this.file[path] === undefined) {
|
|
65
|
-
this.file[path] = file;
|
|
66
|
-
}
|
|
67
|
-
res.setHeader('Last-Modified', (0, _formateHttpDate.default)(this.modify[path]));
|
|
68
|
-
this.compressOutput(req, res, this.file[path], path);
|
|
69
|
-
} else {
|
|
70
|
-
res.writeHead(304);
|
|
71
|
-
res.end();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
dealCompress(data, path, res) {
|
|
76
|
-
if (this.compress[path] === undefined) {
|
|
77
|
-
this.compress[path] = data;
|
|
78
|
-
}
|
|
79
|
-
res.end(this.compress[path]);
|
|
80
|
-
}
|
|
81
|
-
directDeal(data, path, res) {
|
|
82
|
-
if (this.raw[path] === undefined) {
|
|
83
|
-
this.compress[path] = data;
|
|
84
|
-
}
|
|
85
|
-
res.end(this.raw[path]);
|
|
86
|
-
}
|
|
87
|
-
async process(req, res) {
|
|
88
|
-
try {
|
|
89
|
-
const {
|
|
90
|
-
url
|
|
91
|
-
} = req;
|
|
92
|
-
if (url === '/update/time') {
|
|
93
|
-
const {
|
|
94
|
-
time
|
|
95
|
-
} = this;
|
|
96
|
-
res.end(time);
|
|
97
|
-
} else if (this.regexp.test(url)) {
|
|
98
|
-
const restPath = url.substring(1, url.length);
|
|
99
|
-
this.cacheOutput(req, res, restPath, _fs.default.readFileSync(_path.default.resolve('static', restPath)), parseInt(_fs.default.statSync(_path.default.resolve('static', restPath)).mtimeMs));
|
|
100
|
-
} else if (url.substring(0, 4) === '/api') {
|
|
101
|
-
const body = await new Promise((resolve, reject) => {
|
|
102
|
-
req.on('data', data => {
|
|
103
|
-
resolve(data.toString());
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
const {
|
|
107
|
-
location
|
|
108
|
-
} = this.options;
|
|
109
|
-
if (location !== undefined) {
|
|
110
|
-
const response = await fetch(location + url, {
|
|
111
|
-
method: 'POST',
|
|
112
|
-
body
|
|
113
|
-
});
|
|
114
|
-
for (const k of response.headers.keys()) {
|
|
115
|
-
res.setHeader((0, _formateHttpKey.default)(k), response.headers.get(k));
|
|
116
|
-
}
|
|
117
|
-
const data = await response.text();
|
|
118
|
-
res.end(JSON.stringify(data));
|
|
119
|
-
}
|
|
120
|
-
} else {
|
|
121
|
-
if (this.html === undefined) {
|
|
122
|
-
const {
|
|
123
|
-
title,
|
|
124
|
-
content
|
|
125
|
-
} = this.options;
|
|
126
|
-
this.html = (0, _getHtml.default)(title, content);
|
|
127
|
-
}
|
|
128
|
-
this.cacheOutput(req, res, '*html', this.html, this.time);
|
|
129
|
-
}
|
|
130
|
-
} catch (e) {
|
|
131
|
-
const {
|
|
132
|
-
develope
|
|
133
|
-
} = this.options;
|
|
134
|
-
if (develope === true) {
|
|
135
|
-
throw e;
|
|
136
|
-
} else {
|
|
137
|
-
res.writeHead(500);
|
|
138
|
-
res.end();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
exports.default = CommonHttp;
|
package/server/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "CommonHttp", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _CommonHttp.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "parseOption", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _parseOption.default;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "readCookie", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _readCookie.default;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
var _CommonHttp = _interopRequireDefault(require("./class/CommonHttp"));
|
|
25
|
-
var _parseOption = _interopRequireDefault(require("./lib/parseOption"));
|
|
26
|
-
var _readCookie = _interopRequireDefault(require("./lib/readCookie"));
|
|
27
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = cacheOutput;
|
|
7
|
-
var _formateHttpDate = _interopRequireDefault(require("./formateHttpDate"));
|
|
8
|
-
var _parseHttpDate = _interopRequireDefault(require("./parseHttpDate"));
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
function cacheOutput(req, res, path, file, ms) {
|
|
11
|
-
let ifModifiedSince = req.headers['If-Modified-Since'];
|
|
12
|
-
if (ifModifiedSince === undefined) {
|
|
13
|
-
if (this.modify[path] === undefined) {
|
|
14
|
-
this.modify[path] = new Date(ms).toString();
|
|
15
|
-
}
|
|
16
|
-
if (this.file[path] === undefined) {
|
|
17
|
-
this.file[path] = file;
|
|
18
|
-
}
|
|
19
|
-
res.setHeader('Last-Modified', (0, _formateHttpDate.default)(this.modify[path]));
|
|
20
|
-
this.compressOutput(req, res, this.file[path], path);
|
|
21
|
-
} else {
|
|
22
|
-
if (this.modify[path] === undefined) {
|
|
23
|
-
this.modify[path] = new Date(ms).toString();
|
|
24
|
-
}
|
|
25
|
-
if ((0, _parseHttpDate.default)(new Date().toString()) < (0, _parseHttpDate.default)(this.modify[path])) {
|
|
26
|
-
if (this.file[path] === undefined) {
|
|
27
|
-
this.file[path] = file;
|
|
28
|
-
}
|
|
29
|
-
res.setHeader('Last-Modified', (0, _formateHttpDate.default)(this.modify[path]));
|
|
30
|
-
this.compressOutput(req, res, this.file[path], path);
|
|
31
|
-
} else {
|
|
32
|
-
res.writeHead(304);
|
|
33
|
-
res.end();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = compressOutput;
|
|
7
|
-
var _zlib = _interopRequireDefault(require("zlib"));
|
|
8
|
-
var _stream = require("stream");
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
function onError(err) {
|
|
11
|
-
if (err) {
|
|
12
|
-
console.error('An error occurred:', err);
|
|
13
|
-
process.exitCode = 1;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function compressOutput(req, res, buffer, path) {
|
|
17
|
-
res.setHeader('Vary', 'Accept-Encoding');
|
|
18
|
-
let acceptEncoding = req.headers['accept-encoding'];
|
|
19
|
-
if (/gzip/.test(acceptEncoding)) {
|
|
20
|
-
res.writeHead(200, {
|
|
21
|
-
'Content-Encoding': 'gzip'
|
|
22
|
-
});
|
|
23
|
-
this.dealCompress(_zlib.default.gzipSync(buffer), path, res);
|
|
24
|
-
} else {
|
|
25
|
-
res.writeHead(200, {});
|
|
26
|
-
this.dealDirect(buffer, path, res);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = formateHttpDate;
|
|
7
|
-
function formateHttpDate(date) {
|
|
8
|
-
let [week, month, day, year, time, zone] = date.toString().split(' ');
|
|
9
|
-
zone = zone.split('+')[0];
|
|
10
|
-
return month + ', ' + day + ' ' + month + ' ' + year + ' ' + time + ' ' + zone;
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = formateHttpKey;
|
|
7
|
-
function formateHttpKey(key) {
|
|
8
|
-
return key.split('-').map(v => {
|
|
9
|
-
return v.substring(0, 1).toUpperCase() + v.substring(1, v.length);
|
|
10
|
-
}).join('-');
|
|
11
|
-
}
|
package/server/lib/getHtml.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = getHtml;
|
|
7
|
-
var _handlebars = _interopRequireDefault(require("handlebars"));
|
|
8
|
-
var _htmlMinifier = require("html-minifier");
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
function getHtml(title, content) {
|
|
11
|
-
const template = _handlebars.default.compile(`
|
|
12
|
-
<!doctype html>
|
|
13
|
-
<html lang="en">
|
|
14
|
-
<head>
|
|
15
|
-
<meta charset="utf-8" />
|
|
16
|
-
<title>{{title}}</title>
|
|
17
|
-
<meta name="description" content="{{content}}" />
|
|
18
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
19
|
-
</head>
|
|
20
|
-
<body>
|
|
21
|
-
<main id="root"></main>
|
|
22
|
-
<script src="main.bundle.js"></script>
|
|
23
|
-
</body>
|
|
24
|
-
</html>
|
|
25
|
-
`);
|
|
26
|
-
return (0, _htmlMinifier.minify)(template({
|
|
27
|
-
title,
|
|
28
|
-
content
|
|
29
|
-
}), {
|
|
30
|
-
collapseWhitespace: true
|
|
31
|
-
});
|
|
32
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = formateHttpDate;
|
|
7
|
-
function formateHttpDate(date) {
|
|
8
|
-
let [week, month, day, year, time, zone] = date.toString().split(' ');
|
|
9
|
-
zone = zone.split('+')[0];
|
|
10
|
-
return month + ', ' + day + ' ' + month + ' ' + year + ' ' + time + ' ' + zone;
|
|
11
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parseOption = parseOption;
|
|
7
|
-
function isOption(string) {
|
|
8
|
-
let ans = true;
|
|
9
|
-
if (typeof string === 'string') {
|
|
10
|
-
let i = 0;
|
|
11
|
-
for (i = 0; i < 1; i += 1) {
|
|
12
|
-
if (string.charAt(i) === '-') {
|
|
13
|
-
break;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
if (i === 0) {
|
|
17
|
-
ans = false;
|
|
18
|
-
}
|
|
19
|
-
} else {
|
|
20
|
-
ans = false;
|
|
21
|
-
}
|
|
22
|
-
return ans;
|
|
23
|
-
}
|
|
24
|
-
function transformOption(value) {
|
|
25
|
-
let ans;
|
|
26
|
-
const s = value.split('-');
|
|
27
|
-
if (s.length >= 1) {
|
|
28
|
-
ans = s.map((e, i) => {
|
|
29
|
-
if (i === 0) {
|
|
30
|
-
return e;
|
|
31
|
-
} else {
|
|
32
|
-
return e.charAt(0).toUpperCase() + e.substring(1, e.length);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
} else {
|
|
36
|
-
ans = value;
|
|
37
|
-
}
|
|
38
|
-
return ans.join('');
|
|
39
|
-
}
|
|
40
|
-
function parseOption(...params) {
|
|
41
|
-
const ans = {};
|
|
42
|
-
for (let i = 0; i < params.length; i += 1) {
|
|
43
|
-
const param = params[i];
|
|
44
|
-
if (param.charAt(0) === '-') {
|
|
45
|
-
const regexp = /^\-([a-z])$/;
|
|
46
|
-
if (regexp.test(param)) {
|
|
47
|
-
const [_, k] = param.match(regexp);
|
|
48
|
-
if (isOption(params[i + 1])) {
|
|
49
|
-
ans[k] = params[i + 1];
|
|
50
|
-
i += 1;
|
|
51
|
-
} else {
|
|
52
|
-
ans[k] = true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (param.charAt(1) === '-') {
|
|
56
|
-
const regexp = /^\-\-([a-z\-]+)$/;
|
|
57
|
-
if (regexp.test(param)) {
|
|
58
|
-
const [_, k] = param.match(regexp);
|
|
59
|
-
if (isOption(params[i + 1])) {
|
|
60
|
-
ans[transformOption(k)] = params[i + 1];
|
|
61
|
-
i += 1;
|
|
62
|
-
} else {
|
|
63
|
-
ans[k] = true;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return ans;
|
|
70
|
-
}
|
package/server/lib/readCookie.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.readCookie = readCookie;
|
|
7
|
-
function readCookie(cookie) {
|
|
8
|
-
const cookies = {};
|
|
9
|
-
if (typeof cookie === 'string') {
|
|
10
|
-
cookie.split(';').forEach(i => {
|
|
11
|
-
const [key, value] = i.split('=');
|
|
12
|
-
cookies[key.trim()] = value;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
const namespaces = {};
|
|
16
|
-
Object.keys(cookies).forEach(k => {
|
|
17
|
-
const result = k.split('_');
|
|
18
|
-
if (result.length === 2) {
|
|
19
|
-
const [namespace, key] = result;
|
|
20
|
-
if (namespaces[namespace] === undefined) {
|
|
21
|
-
namespaces[namespace] = {};
|
|
22
|
-
}
|
|
23
|
-
namespaces[namespace][key] = cookies[k];
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return namespaces;
|
|
27
|
-
}
|