UNPKG

object-iterable

Version:

Create a new object containing the same properties (through assignment) of another object along with an @@iterator method can make use of the default iteration behavior (such as for-of) that built-in iterables like Array or Map have.

27 lines (19 loc) 640 B
"use strict"; function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function objectIterator(obj) { var iterableObj = _defineProperty({}, Symbol.iterator, function () { var _this = this; var keys = Object.keys(this); var i = 0; return { next: function next() { return { value: _this[keys[i++]], done: i > keys.length }; } }; }); return Object.assign(iterableObj, obj); } module.exports = objectIterator;