diff --git a/es6/index.js b/es6/index.js index fc5d5e0..c49fb98 100644 --- a/es6/index.js +++ b/es6/index.js @@ -1 +1 @@ -module.exports = require('..'); \ No newline at end of file +module.exports = require('../index'); \ No newline at end of file diff --git a/index.js b/index.js index 0ae9b84..86e16df 100644 --- a/index.js +++ b/index.js @@ -127,6 +127,30 @@ class InfiniteList { }; }; } + + if(typeof Proxy !== 'undefined') + return new Proxy(this, { + get: (obj, key) => { + if(key in obj) return obj[key]; + const index = ( + typeof key === 'string' && /^\d*$/g.test(key) + ) ? parseInt(key) : undefined; + if(index) return obj['get'](index); + }, + has: (obj, key) => { + const index = ( + typeof key === 'string' && /^\d*$/g.test(key) + ) ? parseInt(key) : undefined; + return ( + (key in obj) || + (areNumbers(index) && + (index % 1 === 0) && + (index >= 0)) + ) + }, + enumerate: obj => obj.keys(), + ownKeys: obj => obj.keys(), + }) } } diff --git a/spec/spec.js b/spec/spec.js index ce63182..8e2a1f3 100644 --- a/spec/spec.js +++ b/spec/spec.js @@ -1,6 +1,6 @@ 'use strict'; -const InfiniteList = require('../es5/infinity.min'); +const InfiniteList = require('../es6'); const { InfiniteListItem @@ -40,7 +40,7 @@ describe("InfiniteList", () => { it("Should be true", () => { const Infinite = new InfiniteList(0, x => x + 2); - expect(Infinite.get(5) instanceof InfiniteListItem).toBe(true); + expect((Infinite.get(5)) instanceof InfiniteListItem).toBe(true); }); it("Should be 22", () => {