manner.js 0.0.47 → 0.0.48

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.
@@ -0,0 +1,34 @@
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 _clearCookie.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "filterNamespace", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _filterNamespace.default;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "readCookie", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _redCookie.default;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "setCookie", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _setCookie.default;
28
+ }
29
+ });
30
+ var _filterNamespace = _interopRequireDefault(require("./lib/filterNamespace"));
31
+ var _clearCookie = _interopRequireDefault(require("./lib/clearCookie"));
32
+ var _setCookie = _interopRequireDefault(require("./lib/setCookie"));
33
+ var _redCookie = _interopRequireDefault(require("./lib/redCookie"));
34
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,20 @@
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
+ }
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,38 @@
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
+ }
@@ -0,0 +1,25 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "manner.js",
3
- "version": "0.0.47",
3
+ "version": "0.0.48",
4
4
  "description": "Frontend mode project.",
5
5
  "repository": "git@github.com:leobrad/mode.git",
6
6
  "author": "Leo Ely",
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ class MultiFetch {
10
+ constructor(urls, options) {
11
+ this.index = 0;
12
+ this.dealParams(urls, options);
13
+ this.urls = urls;
14
+ this.options = options;
15
+ }
16
+ dealParams(urls, options) {
17
+ if (!Array.isArray(urls)) {
18
+ throw new Error('[Error] Param urls should be a array type.');
19
+ const {
20
+ length
21
+ } = urls;
22
+ if (length === 0) {
23
+ throw new Error('[Error] Param urls cannot have zero length.');
24
+ }
25
+ }
26
+ if (typeof options !== 'object') {
27
+ throw new Error('[Error] Param options should be a object type..');
28
+ }
29
+ }
30
+ async fetch() {
31
+ const {
32
+ urls,
33
+ options
34
+ } = this;
35
+ const {
36
+ length
37
+ } = urls;
38
+ if (this.index < length) {
39
+ this.index += 1;
40
+ } else {
41
+ this.index = 0;
42
+ }
43
+ return (0, _nodeFetch.default)(urls[index], options);
44
+ }
45
+ }
46
+ var _default = exports.default = MultiFetch;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "formatHttpDate", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _formatHttpDate.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "formatHttpKey", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _formatHttpKey.default;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "readCookie", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _readCookie.default;
22
+ }
23
+ });
24
+ var _readCookie = _interopRequireDefault(require("./lib/readCookie"));
25
+ var _formatHttpKey = _interopRequireDefault(require("./lib/formatHttpKey"));
26
+ var _formatHttpDate = _interopRequireDefault(require("./lib/formatHttpDate"));
27
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = formatHttpDate;
7
+ function formatHttpDate(ms) {
8
+ const date = new Date(ms);
9
+ let [week, month, day, year, time, zone] = date.toString().split(' ');
10
+ zone = zone.split('+')[0];
11
+ return week + ', ' + day + ' ' + month + ' ' + year + ' ' + time + ' ' + zone;
12
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = formatHttpKey;
7
+ function formatHttpKey(key) {
8
+ return key.split('-').map(v => {
9
+ return v.substring(0, 1).toUpperCase() + v.substring(1, v.length);
10
+ }).join('-');
11
+ }
@@ -0,0 +1,27 @@
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
+ }