@teamawesome/multi-dict
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -14,6 +14,2 @@ "use strict"; | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime/core-js/get-iterator")); | ||
var _iterator6 = _interopRequireDefault(require("@babel/runtime/core-js/symbol/iterator")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
@@ -23,6 +19,12 @@ | ||
var _weakSet = _interopRequireDefault(require("@babel/runtime/core-js/weak-set")); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime/core-js/get-iterator")); | ||
var _set = _interopRequireDefault(require("@babel/runtime/core-js/set")); | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread")); | ||
var _iterator7 = _interopRequireDefault(require("@babel/runtime/core-js/symbol/iterator")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
@@ -47,2 +49,3 @@ | ||
/** | ||
* @param {Iterable.<[*, *]>|object} entries Iterable of [...keys, value] entries, or the options object | ||
* @param {object} options | ||
@@ -53,4 +56,13 @@ * @param {Function} options.defaultType Constructor for the default type | ||
function _default() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var entries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
(0, _classCallCheck2.default)(this, _default); | ||
if (entries === null || entries === undefined) { | ||
entries = []; | ||
} else if (typeof entries[_iterator7.default] !== 'function') { | ||
options = entries; | ||
entries = []; | ||
} | ||
this.options = (0, _objectSpread2.default)({}, defaultOptions, options); | ||
@@ -68,7 +80,30 @@ var _this$options = this.options, | ||
/** | ||
* @type {WeakSet<Object>} | ||
* @type {Set<Object>} | ||
* @private | ||
*/ | ||
this._entries = new _weakSet.default(); | ||
this._entries = new _set.default(); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = (0, _getIterator2.default)(entries), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var entry = _step.value; | ||
this.set.apply(this, (0, _toConsumableArray2.default)(entry)); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
@@ -84,6 +119,2 @@ /** | ||
value: function set() { | ||
var _this$options2 = this.options, | ||
types = _this$options2.types, | ||
defaultType = _this$options2.defaultType; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -93,2 +124,9 @@ args[_key] = arguments[_key]; | ||
if (args.length < 2) { | ||
throw new TypeError('Specify at least one key and a value'); | ||
} | ||
var _this$options2 = this.options, | ||
types = _this$options2.types, | ||
defaultType = _this$options2.defaultType; | ||
var value = args.pop(); | ||
@@ -189,2 +227,4 @@ var lastKey = args.pop(); | ||
/** | ||
* Delete an entry | ||
* | ||
* @param {...*} keys | ||
@@ -217,3 +257,3 @@ * @return {boolean} | ||
/** | ||
* | ||
* Remove all entries | ||
*/ | ||
@@ -234,7 +274,7 @@ | ||
}, { | ||
key: _iterator6.default, | ||
key: _iterator7.default, | ||
value: | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function value() { | ||
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, entry; | ||
var _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, entry; | ||
@@ -245,10 +285,10 @@ return _regenerator.default.wrap(function value$(_context) { | ||
case 0: | ||
_iteratorNormalCompletion = true; | ||
_didIteratorError = false; | ||
_iteratorError = undefined; | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_context.prev = 3; | ||
_iterator = (0, _getIterator2.default)(this._entries); | ||
_iterator2 = (0, _getIterator2.default)(this._entries); | ||
case 5: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) { | ||
_context.next = 12; | ||
@@ -258,3 +298,3 @@ break; | ||
entry = _step.value; | ||
entry = _step2.value; | ||
_context.next = 9; | ||
@@ -264,3 +304,3 @@ return [entry.keys, entry.value]; | ||
case 9: | ||
_iteratorNormalCompletion = true; | ||
_iteratorNormalCompletion2 = true; | ||
_context.next = 5; | ||
@@ -276,4 +316,4 @@ break; | ||
_context.t0 = _context["catch"](3); | ||
_didIteratorError = true; | ||
_iteratorError = _context.t0; | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context.t0; | ||
@@ -284,4 +324,4 @@ case 18: | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
} | ||
@@ -292,3 +332,3 @@ | ||
if (!_didIteratorError) { | ||
if (!_didIteratorError2) { | ||
_context.next = 24; | ||
@@ -298,3 +338,3 @@ break; | ||
throw _iteratorError; | ||
throw _iteratorError2; | ||
@@ -324,3 +364,3 @@ case 24: | ||
_regenerator.default.mark(function entries() { | ||
var _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, entry; | ||
var _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, entry; | ||
@@ -331,10 +371,10 @@ return _regenerator.default.wrap(function entries$(_context2) { | ||
case 0: | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_iteratorNormalCompletion3 = true; | ||
_didIteratorError3 = false; | ||
_iteratorError3 = undefined; | ||
_context2.prev = 3; | ||
_iterator2 = (0, _getIterator2.default)(this._entries); | ||
_iterator3 = (0, _getIterator2.default)(this._entries); | ||
case 5: | ||
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) { | ||
if (_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done) { | ||
_context2.next = 12; | ||
@@ -344,3 +384,3 @@ break; | ||
entry = _step2.value; | ||
entry = _step3.value; | ||
_context2.next = 9; | ||
@@ -350,3 +390,3 @@ return [entry.keys, entry.value]; | ||
case 9: | ||
_iteratorNormalCompletion2 = true; | ||
_iteratorNormalCompletion3 = true; | ||
_context2.next = 5; | ||
@@ -362,4 +402,4 @@ break; | ||
_context2.t0 = _context2["catch"](3); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context2.t0; | ||
_didIteratorError3 = true; | ||
_iteratorError3 = _context2.t0; | ||
@@ -370,4 +410,4 @@ case 18: | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
if (!_iteratorNormalCompletion3 && _iterator3.return != null) { | ||
_iterator3.return(); | ||
} | ||
@@ -378,3 +418,3 @@ | ||
if (!_didIteratorError2) { | ||
if (!_didIteratorError3) { | ||
_context2.next = 24; | ||
@@ -384,3 +424,3 @@ break; | ||
throw _iteratorError2; | ||
throw _iteratorError3; | ||
@@ -410,3 +450,3 @@ case 24: | ||
_regenerator.default.mark(function keys() { | ||
var _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, entry; | ||
var _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, entry; | ||
@@ -417,10 +457,10 @@ return _regenerator.default.wrap(function keys$(_context3) { | ||
case 0: | ||
_iteratorNormalCompletion3 = true; | ||
_didIteratorError3 = false; | ||
_iteratorError3 = undefined; | ||
_iteratorNormalCompletion4 = true; | ||
_didIteratorError4 = false; | ||
_iteratorError4 = undefined; | ||
_context3.prev = 3; | ||
_iterator3 = (0, _getIterator2.default)(this._entries); | ||
_iterator4 = (0, _getIterator2.default)(this._entries); | ||
case 5: | ||
if (_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done) { | ||
if (_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done) { | ||
_context3.next = 12; | ||
@@ -430,3 +470,3 @@ break; | ||
entry = _step3.value; | ||
entry = _step4.value; | ||
_context3.next = 9; | ||
@@ -436,3 +476,3 @@ return entry.keys; | ||
case 9: | ||
_iteratorNormalCompletion3 = true; | ||
_iteratorNormalCompletion4 = true; | ||
_context3.next = 5; | ||
@@ -448,4 +488,4 @@ break; | ||
_context3.t0 = _context3["catch"](3); | ||
_didIteratorError3 = true; | ||
_iteratorError3 = _context3.t0; | ||
_didIteratorError4 = true; | ||
_iteratorError4 = _context3.t0; | ||
@@ -456,4 +496,4 @@ case 18: | ||
if (!_iteratorNormalCompletion3 && _iterator3.return != null) { | ||
_iterator3.return(); | ||
if (!_iteratorNormalCompletion4 && _iterator4.return != null) { | ||
_iterator4.return(); | ||
} | ||
@@ -464,3 +504,3 @@ | ||
if (!_didIteratorError3) { | ||
if (!_didIteratorError4) { | ||
_context3.next = 24; | ||
@@ -470,3 +510,3 @@ break; | ||
throw _iteratorError3; | ||
throw _iteratorError4; | ||
@@ -496,3 +536,3 @@ case 24: | ||
_regenerator.default.mark(function values() { | ||
var _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, entry; | ||
var _iteratorNormalCompletion5, _didIteratorError5, _iteratorError5, _iterator5, _step5, entry; | ||
@@ -503,10 +543,10 @@ return _regenerator.default.wrap(function values$(_context4) { | ||
case 0: | ||
_iteratorNormalCompletion4 = true; | ||
_didIteratorError4 = false; | ||
_iteratorError4 = undefined; | ||
_iteratorNormalCompletion5 = true; | ||
_didIteratorError5 = false; | ||
_iteratorError5 = undefined; | ||
_context4.prev = 3; | ||
_iterator4 = (0, _getIterator2.default)(this._entries); | ||
_iterator5 = (0, _getIterator2.default)(this._entries); | ||
case 5: | ||
if (_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done) { | ||
if (_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done) { | ||
_context4.next = 12; | ||
@@ -516,3 +556,3 @@ break; | ||
entry = _step4.value; | ||
entry = _step5.value; | ||
_context4.next = 9; | ||
@@ -522,3 +562,3 @@ return entry.value; | ||
case 9: | ||
_iteratorNormalCompletion4 = true; | ||
_iteratorNormalCompletion5 = true; | ||
_context4.next = 5; | ||
@@ -534,4 +574,4 @@ break; | ||
_context4.t0 = _context4["catch"](3); | ||
_didIteratorError4 = true; | ||
_iteratorError4 = _context4.t0; | ||
_didIteratorError5 = true; | ||
_iteratorError5 = _context4.t0; | ||
@@ -542,4 +582,4 @@ case 18: | ||
if (!_iteratorNormalCompletion4 && _iterator4.return != null) { | ||
_iterator4.return(); | ||
if (!_iteratorNormalCompletion5 && _iterator5.return != null) { | ||
_iterator5.return(); | ||
} | ||
@@ -550,3 +590,3 @@ | ||
if (!_didIteratorError4) { | ||
if (!_didIteratorError5) { | ||
_context4.next = 24; | ||
@@ -556,3 +596,3 @@ break; | ||
throw _iteratorError4; | ||
throw _iteratorError5; | ||
@@ -574,3 +614,3 @@ case 24: | ||
* @param {function(*, *[], this):undefined} callback | ||
* @param thisArg | ||
* @param {*} thisArg Option 'this' context for the callback | ||
*/ | ||
@@ -587,22 +627,22 @@ | ||
var _iteratorNormalCompletion5 = true; | ||
var _didIteratorError5 = false; | ||
var _iteratorError5 = undefined; | ||
var _iteratorNormalCompletion6 = true; | ||
var _didIteratorError6 = false; | ||
var _iteratorError6 = undefined; | ||
try { | ||
for (var _iterator5 = (0, _getIterator2.default)(this), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { | ||
var entry = _step5.value; | ||
for (var _iterator6 = (0, _getIterator2.default)(this), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { | ||
var entry = _step6.value; | ||
callback.call(thisArg, entry.value, entry.key, this); | ||
} | ||
} catch (err) { | ||
_didIteratorError5 = true; | ||
_iteratorError5 = err; | ||
_didIteratorError6 = true; | ||
_iteratorError6 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion5 && _iterator5.return != null) { | ||
_iterator5.return(); | ||
if (!_iteratorNormalCompletion6 && _iterator6.return != null) { | ||
_iterator6.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError5) { | ||
throw _iteratorError5; | ||
if (_didIteratorError6) { | ||
throw _iteratorError6; | ||
} | ||
@@ -609,0 +649,0 @@ } |
{ | ||
"name": "@teamawesome/multi-dict", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "", | ||
@@ -13,3 +13,10 @@ "main": "dist/index.js", | ||
"license": "MIT", | ||
"keywords": ["dict", "dictionary", "multiple", "cache", "store", "complex"], | ||
"keywords": [ | ||
"dict", | ||
"dictionary", | ||
"multiple", | ||
"cache", | ||
"store", | ||
"complex" | ||
], | ||
"devDependencies": { | ||
@@ -20,3 +27,7 @@ "@babel/cli": "^7.0.0-beta.49", | ||
"@babel/plugin-transform-runtime": "^7.0.0-beta.49", | ||
"@babel/preset-env": "^7.0.0-beta.49" | ||
"@babel/preset-env": "^7.0.0-beta.49", | ||
"mocha": "^5.2.0", | ||
"should": "^13.2.1", | ||
"should-sinon": "0.0.6", | ||
"sinon": "^6.0.0" | ||
}, | ||
@@ -23,0 +34,0 @@ "dependencies": { |
@@ -11,4 +11,13 @@ # Installation | ||
const dict = new MultiDict(); | ||
``` | ||
## Parameters | ||
* `entries` Optional. An iterable whose elements are in the shape of `[key1, ..., value]`. Each element is added to | ||
the dict. | ||
* `options` Optional. A hash of options as specified in the options paragraph. | ||
``` | ||
new Dict([ /* Entries */ ], { /* Options */ }); | ||
new Dict([ /* Entries */ ]); | ||
new Dict({ /* Options */ }); | ||
``` | ||
## Options | ||
@@ -33,8 +42,8 @@ By default, for each level of the dict a Map is used. However, you can specify a type for each level and/or a | ||
## Methods | ||
* `get` Get a value by it's path | ||
* `set` Set a value by a path of keys | ||
* `has` Check if a path of keys exists | ||
* `delete` Delete a path of keys | ||
* `get(...keys)` Get a value by it's path | ||
* `set(...keys, value)` Set a value by a path of keys | ||
* `has(...keys)` Check if a path of keys exists | ||
* `delete(...keys)` Delete a path of keys | ||
* `clear` Remove all entries in the dict | ||
* `forEach` Run a callback for each entry of the dict | ||
* `forEach(callback, thisArg)` Run a callback for each entry of the dict | ||
``` | ||
@@ -41,0 +50,0 @@ dict.set(key1, key2, value); |
@@ -11,2 +11,3 @@ import access from '@teamawesome/access'; | ||
/** | ||
* @param {Iterable.<[*, *]>|object} entries Iterable of [...keys, value] entries, or the options object | ||
* @param {object} options | ||
@@ -16,3 +17,10 @@ * @param {Function} options.defaultType Constructor for the default type | ||
*/ | ||
constructor(options = {}) { | ||
constructor(entries = [], options = {}) { | ||
if (entries === null || entries === undefined) { | ||
entries = []; | ||
} else if (typeof entries[Symbol.iterator] !== 'function') { | ||
options = entries; | ||
entries = []; | ||
} | ||
this.options = { | ||
@@ -32,6 +40,10 @@ ...defaultOptions, | ||
/** | ||
* @type {WeakSet<Object>} | ||
* @type {Set<Object>} | ||
* @private | ||
*/ | ||
this._entries = new WeakSet(); | ||
this._entries = new Set(); | ||
for (const entry of entries) { | ||
this.set(...entry); | ||
} | ||
} | ||
@@ -44,2 +56,6 @@ | ||
set(...args) { | ||
if (args.length < 2) { | ||
throw new TypeError('Specify at least one key and a value'); | ||
} | ||
const {types, defaultType} = this.options; | ||
@@ -116,2 +132,4 @@ const value = args.pop(); | ||
/** | ||
* Delete an entry | ||
* | ||
* @param {...*} keys | ||
@@ -138,3 +156,3 @@ * @return {boolean} | ||
/** | ||
* | ||
* Remove all entries | ||
*/ | ||
@@ -188,3 +206,3 @@ clear() { | ||
* @param {function(*, *[], this):undefined} callback | ||
* @param thisArg | ||
* @param {*} thisArg Option 'this' context for the callback | ||
*/ | ||
@@ -191,0 +209,0 @@ forEach(callback, thisArg = undefined) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28350
9
759
66
9