UNPKG

2.57 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
9function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
11/**
12 * Container for objects that may contain either string or array of string as
13 * values. Used to represent headers and query strings.
14 *
15 * @CLIENT-SERVER
16 */
17var Bucket = function () {
18 function Bucket() {
19 _classCallCheck(this, Bucket);
20
21 this._data = {};
22 }
23
24 /**
25 * @param {string} key
26 * @returns {boolean}
27 */
28
29 /**
30 * @type {{[key: string]: string | Array<string>}}
31 */
32
33
34 _createClass(Bucket, [{
35 key: 'has',
36 value: function has(key) {
37 return this._data.hasOwnProperty(key);
38 }
39
40 /**
41 * Returns
42 *
43 * @returns {{[key: string]: string | Array<string>}}
44 */
45
46 }, {
47 key: 'getAll',
48 value: function getAll() {
49 return this._data;
50 }
51
52 /**
53 * @param {string} key
54 * @returns {string | Array<string>}
55 */
56
57 }, {
58 key: 'get',
59 value: function get(key) {
60 return this._data[key];
61 }
62
63 /**
64 * Set value, overwrites the given value.
65 *
66 * @param {string} key
67 * @param {string | Array<string>} value
68 */
69
70 }, {
71 key: 'set',
72 value: function set(key, value) {
73 this._data[key] = value;
74 }
75
76 /**
77 * @param {string} key
78 * @param {string | Array<string>} value
79 */
80
81 }, {
82 key: 'add',
83 value: function add(key, value) {
84 if (!this._data.hasOwnProperty(key)) {
85 this._data[key] = value;
86 return;
87 }
88
89 if (Object.prototype.toString.call(this._data[key]) != '[object Array]') {
90 this._data[key] = [this._data[key]];
91 }
92
93 this._data[key] = this._data[key].concat(value);
94 }
95 }, {
96 key: 'remove',
97 value: function remove(key) {
98 delete this._data[key];
99 }
100 }]);
101
102 return Bucket;
103}();
104
105exports.default = Bucket;
106//# sourceMappingURL=Bucket.js.map
\No newline at end of file