pax_global_header00006660000000000000000000000064130630056520014512gustar00rootroot0000000000000052 comment=901fee71166dd5bc4b515b619521ae403a95472e es6-map-0.1.5/000077500000000000000000000000001306300565200127655ustar00rootroot00000000000000es6-map-0.1.5/.gitignore000066400000000000000000000000631306300565200147540ustar00rootroot00000000000000.DS_Store /node_modules /npm-debug.log /.lintcache es6-map-0.1.5/.lint000066400000000000000000000001111306300565200137250ustar00rootroot00000000000000@root module indent 2 maxlen 100 tabs ass nomen plusplus predef+ Map es6-map-0.1.5/.travis.yml000066400000000000000000000003521306300565200150760ustar00rootroot00000000000000sudo: false # http://docs.travis-ci.com/user/workers/container-based-infrastructure/ language: node_js node_js: - 0.12 - 4 - 6 - 7 notifications: email: - medikoo+es6-map@medikoo.com script: "npm test && npm run lint" es6-map-0.1.5/CHANGES000066400000000000000000000015231306300565200137610ustar00rootroot00000000000000v0.1.5 -- 2017.03.17 * Update dependencies * Improve documentation v0.1.4 -- 2016.06.03 * Update dependencies v0.1.3 -- 2015.11.18 * Relax validation of native implementation (do not require proper stringification of Map.prototype) v0.1.2 -- 2015.10.15 * Improve native detection * Ensure proper inheritance * Update up to specification * Fix spelling of LICENSE * Update dependencies v0.1.1 -- 2014.10.07 * Fix isImplemented so native Maps are detected properly * Configure lint scripts v0.1.0 -- 2014.04.29 * Assure strictly npm hosted dependencies * Update to use latest versions of dependencies v0.0.1 -- 2014.04.25 * Provide @@toStringTag symbol, and use other ES 6 symbols * Fix iterators handling * Fix isImplemented so it doesn't crash * Update up to changes in dependencies v0.0.0 -- 2013.11.10 - Initial (dev) version es6-map-0.1.5/LICENSE000066400000000000000000000020631306300565200137730ustar00rootroot00000000000000Copyright (C) 2013 Mariusz Nowak (www.medikoo.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. es6-map-0.1.5/README.md000066400000000000000000000042761306300565200142550ustar00rootroot00000000000000# es6-map ## Map collection as specified in ECMAScript6 __Warning: v0.1 version does not ensure O(1) algorithm complexity (but O(n)). This shortcoming will be addressed in v1.0__ ### Usage It’s safest to use *es6-map* as a [ponyfill](https://ponyfill.com) – a polyfill which doesn’t touch global objects: ```javascript var Map = require('es6-map'); ``` If you want to make sure your environment implements `Map` globally, do: ```javascript require('es6-map/implement'); ``` If you strictly want to use the polyfill even if the native `Map` exists, do: ```javascript var Map = require('es6-map/polyfill'); ``` ### Installation $ npm install es6-map To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/) #### API Best is to refer to [specification](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-map-objects). Still if you want quick look, follow examples: ```javascript var Map = require('es6-map'); var x = {}, y = {}, map = new Map([['raz', 'one'], ['dwa', 'two'], [x, y]]); map.size; // 3 map.get('raz'); // 'one' map.get(x); // y map.has('raz'); // true map.has(x); // true map.has('foo'); // false map.set('trzy', 'three'); // map map.size // 4 map.get('trzy'); // 'three' map.has('trzy'); // true map.has('dwa'); // true map.delete('dwa'); // true map.size; // 3 map.forEach(function (value, key) { // { 'raz', 'one' }, { x, y }, { 'trzy', 'three' } iterated }); // FF nightly only: for (value of map) { // ['raz', 'one'], [x, y], ['trzy', 'three'] iterated } var iterator = map.values(); iterator.next(); // { done: false, value: 'one' } iterator.next(); // { done: false, value: y } iterator.next(); // { done: false, value: 'three' } iterator.next(); // { done: true, value: undefined } map.clear(); // undefined map.size; // 0 ``` ## Tests [![Build Status](https://travis-ci.org/medikoo/es6-map.png)](https://travis-ci.org/medikoo/es6-map) $ npm test es6-map-0.1.5/implement.js000066400000000000000000000003171306300565200153160ustar00rootroot00000000000000'use strict'; if (!require('./is-implemented')()) { Object.defineProperty(require('es5-ext/global'), 'Map', { value: require('./polyfill'), configurable: true, enumerable: false, writable: true }); } es6-map-0.1.5/index.js000066400000000000000000000001351306300565200144310ustar00rootroot00000000000000'use strict'; module.exports = require('./is-implemented')() ? Map : require('./polyfill'); es6-map-0.1.5/is-implemented.js000066400000000000000000000020631306300565200162400ustar00rootroot00000000000000'use strict'; module.exports = function () { var map, iterator, result; if (typeof Map !== 'function') return false; try { // WebKit doesn't support arguments and crashes map = new Map([['raz', 'one'], ['dwa', 'two'], ['trzy', 'three']]); } catch (e) { return false; } if (String(map) !== '[object Map]') return false; if (map.size !== 3) return false; if (typeof map.clear !== 'function') return false; if (typeof map.delete !== 'function') return false; if (typeof map.entries !== 'function') return false; if (typeof map.forEach !== 'function') return false; if (typeof map.get !== 'function') return false; if (typeof map.has !== 'function') return false; if (typeof map.keys !== 'function') return false; if (typeof map.set !== 'function') return false; if (typeof map.values !== 'function') return false; iterator = map.entries(); result = iterator.next(); if (result.done !== false) return false; if (!result.value) return false; if (result.value[0] !== 'raz') return false; if (result.value[1] !== 'one') return false; return true; }; es6-map-0.1.5/is-map.js000066400000000000000000000006061306300565200145130ustar00rootroot00000000000000'use strict'; var toStringTagSymbol = require('es6-symbol').toStringTag , toString = Object.prototype.toString , id = '[object Map]' , Global = (typeof Map === 'undefined') ? null : Map; module.exports = function (x) { return (x && ((Global && ((x instanceof Global) || (x === Global.prototype))) || (toString.call(x) === id) || (x[toStringTagSymbol] === 'Map'))) || false; }; es6-map-0.1.5/is-native-implemented.js000066400000000000000000000004071306300565200175240ustar00rootroot00000000000000// Exports true if environment provides native `Map` implementation, // whatever that is. 'use strict'; module.exports = (function () { if (typeof Map === 'undefined') return false; return (Object.prototype.toString.call(new Map()) === '[object Map]'); }()); es6-map-0.1.5/lib/000077500000000000000000000000001306300565200135335ustar00rootroot00000000000000es6-map-0.1.5/lib/iterator-kinds.js000066400000000000000000000001471306300565200170320ustar00rootroot00000000000000'use strict'; module.exports = require('es5-ext/object/primitive-set')('key', 'value', 'key+value'); es6-map-0.1.5/lib/iterator.js000066400000000000000000000024121306300565200157210ustar00rootroot00000000000000'use strict'; var setPrototypeOf = require('es5-ext/object/set-prototype-of') , d = require('d') , Iterator = require('es6-iterator') , toStringTagSymbol = require('es6-symbol').toStringTag , kinds = require('./iterator-kinds') , defineProperties = Object.defineProperties , unBind = Iterator.prototype._unBind , MapIterator; MapIterator = module.exports = function (map, kind) { if (!(this instanceof MapIterator)) return new MapIterator(map, kind); Iterator.call(this, map.__mapKeysData__, map); if (!kind || !kinds[kind]) kind = 'key+value'; defineProperties(this, { __kind__: d('', kind), __values__: d('w', map.__mapValuesData__) }); }; if (setPrototypeOf) setPrototypeOf(MapIterator, Iterator); MapIterator.prototype = Object.create(Iterator.prototype, { constructor: d(MapIterator), _resolve: d(function (i) { if (this.__kind__ === 'value') return this.__values__[i]; if (this.__kind__ === 'key') return this.__list__[i]; return [this.__list__[i], this.__values__[i]]; }), _unBind: d(function () { this.__values__ = null; unBind.call(this); }), toString: d(function () { return '[object Map Iterator]'; }) }); Object.defineProperty(MapIterator.prototype, toStringTagSymbol, d('c', 'Map Iterator')); es6-map-0.1.5/lib/primitive-iterator.js000066400000000000000000000037701306300565200177370ustar00rootroot00000000000000'use strict'; var clear = require('es5-ext/array/#/clear') , assign = require('es5-ext/object/assign') , setPrototypeOf = require('es5-ext/object/set-prototype-of') , toStringTagSymbol = require('es6-symbol').toStringTag , d = require('d') , autoBind = require('d/auto-bind') , Iterator = require('es6-iterator') , kinds = require('./iterator-kinds') , defineProperties = Object.defineProperties, keys = Object.keys , unBind = Iterator.prototype._unBind , PrimitiveMapIterator; PrimitiveMapIterator = module.exports = function (map, kind) { if (!(this instanceof PrimitiveMapIterator)) { return new PrimitiveMapIterator(map, kind); } Iterator.call(this, keys(map.__mapKeysData__), map); if (!kind || !kinds[kind]) kind = 'key+value'; defineProperties(this, { __kind__: d('', kind), __keysData__: d('w', map.__mapKeysData__), __valuesData__: d('w', map.__mapValuesData__) }); }; if (setPrototypeOf) setPrototypeOf(PrimitiveMapIterator, Iterator); PrimitiveMapIterator.prototype = Object.create(Iterator.prototype, assign({ constructor: d(PrimitiveMapIterator), _resolve: d(function (i) { if (this.__kind__ === 'value') return this.__valuesData__[this.__list__[i]]; if (this.__kind__ === 'key') return this.__keysData__[this.__list__[i]]; return [this.__keysData__[this.__list__[i]], this.__valuesData__[this.__list__[i]]]; }), _unBind: d(function () { this.__keysData__ = null; this.__valuesData__ = null; unBind.call(this); }), toString: d(function () { return '[object Map Iterator]'; }) }, autoBind({ _onAdd: d(function (key) { this.__list__.push(key); }), _onDelete: d(function (key) { var index = this.__list__.lastIndexOf(key); if (index < this.__nextIndex__) return; this.__list__.splice(index, 1); }), _onClear: d(function () { clear.call(this.__list__); this.__nextIndex__ = 0; }) }))); Object.defineProperty(PrimitiveMapIterator.prototype, toStringTagSymbol, d('c', 'Map Iterator')); es6-map-0.1.5/package.json000066400000000000000000000020121306300565200152460ustar00rootroot00000000000000{ "name": "es6-map", "version": "0.1.5", "description": "ECMAScript6 Map polyfill", "author": "Mariusz Nowak (http://www.medikoo.com/)", "keywords": [ "collection", "es6", "shim", "harmony", "list", "hash", "map", "polyfill", "ponyfill", "ecmascript" ], "repository": { "type": "git", "url": "git://github.com/medikoo/es6-map.git" }, "dependencies": { "d": "1", "es5-ext": "~0.10.14", "es6-iterator": "~2.0.1", "es6-set": "~0.1.5", "es6-symbol": "~3.1.1", "event-emitter": "~0.3.5" }, "devDependencies": { "tad": "~0.2.7", "xlint": "~0.2.2", "xlint-jslint-medikoo": "~0.1.4" }, "scripts": { "lint": "node node_modules/xlint/bin/xlint --linter=node_modules/xlint-jslint-medikoo/index.js --no-cache --no-stream", "lint-console": "node node_modules/xlint/bin/xlint --linter=node_modules/xlint-jslint-medikoo/index.js --watch", "test": "node ./node_modules/tad/bin/tad" }, "license": "MIT" } es6-map-0.1.5/polyfill.js000066400000000000000000000066461306300565200151710ustar00rootroot00000000000000'use strict'; var clear = require('es5-ext/array/#/clear') , eIndexOf = require('es5-ext/array/#/e-index-of') , setPrototypeOf = require('es5-ext/object/set-prototype-of') , callable = require('es5-ext/object/valid-callable') , validValue = require('es5-ext/object/valid-value') , d = require('d') , ee = require('event-emitter') , Symbol = require('es6-symbol') , iterator = require('es6-iterator/valid-iterable') , forOf = require('es6-iterator/for-of') , Iterator = require('./lib/iterator') , isNative = require('./is-native-implemented') , call = Function.prototype.call , defineProperties = Object.defineProperties, getPrototypeOf = Object.getPrototypeOf , MapPoly; module.exports = MapPoly = function (/*iterable*/) { var iterable = arguments[0], keys, values, self; if (!(this instanceof MapPoly)) throw new TypeError('Constructor requires \'new\''); if (isNative && setPrototypeOf && (Map !== MapPoly)) { self = setPrototypeOf(new Map(), getPrototypeOf(this)); } else { self = this; } if (iterable != null) iterator(iterable); defineProperties(self, { __mapKeysData__: d('c', keys = []), __mapValuesData__: d('c', values = []) }); if (!iterable) return self; forOf(iterable, function (value) { var key = validValue(value)[0]; value = value[1]; if (eIndexOf.call(keys, key) !== -1) return; keys.push(key); values.push(value); }, self); return self; }; if (isNative) { if (setPrototypeOf) setPrototypeOf(MapPoly, Map); MapPoly.prototype = Object.create(Map.prototype, { constructor: d(MapPoly) }); } ee(defineProperties(MapPoly.prototype, { clear: d(function () { if (!this.__mapKeysData__.length) return; clear.call(this.__mapKeysData__); clear.call(this.__mapValuesData__); this.emit('_clear'); }), delete: d(function (key) { var index = eIndexOf.call(this.__mapKeysData__, key); if (index === -1) return false; this.__mapKeysData__.splice(index, 1); this.__mapValuesData__.splice(index, 1); this.emit('_delete', index, key); return true; }), entries: d(function () { return new Iterator(this, 'key+value'); }), forEach: d(function (cb/*, thisArg*/) { var thisArg = arguments[1], iterator, result; callable(cb); iterator = this.entries(); result = iterator._next(); while (result !== undefined) { call.call(cb, thisArg, this.__mapValuesData__[result], this.__mapKeysData__[result], this); result = iterator._next(); } }), get: d(function (key) { var index = eIndexOf.call(this.__mapKeysData__, key); if (index === -1) return; return this.__mapValuesData__[index]; }), has: d(function (key) { return (eIndexOf.call(this.__mapKeysData__, key) !== -1); }), keys: d(function () { return new Iterator(this, 'key'); }), set: d(function (key, value) { var index = eIndexOf.call(this.__mapKeysData__, key), emit; if (index === -1) { index = this.__mapKeysData__.push(key) - 1; emit = true; } this.__mapValuesData__[index] = value; if (emit) this.emit('_add', index, key); return this; }), size: d.gs(function () { return this.__mapKeysData__.length; }), values: d(function () { return new Iterator(this, 'value'); }), toString: d(function () { return '[object Map]'; }) })); Object.defineProperty(MapPoly.prototype, Symbol.iterator, d(function () { return this.entries(); })); Object.defineProperty(MapPoly.prototype, Symbol.toStringTag, d('c', 'Map')); es6-map-0.1.5/primitive/000077500000000000000000000000001306300565200147755ustar00rootroot00000000000000es6-map-0.1.5/primitive/index.js000066400000000000000000000077041306300565200164520ustar00rootroot00000000000000'use strict'; var clear = require('es5-ext/object/clear') , setPrototypeOf = require('es5-ext/object/set-prototype-of') , validValue = require('es5-ext/object/valid-value') , callable = require('es5-ext/object/valid-callable') , d = require('d') , iterator = require('es6-iterator/valid-iterable') , forOf = require('es6-iterator/for-of') , isNative = require('../is-native-implemented') , MapPolyfill = require('../polyfill') , Iterator = require('../lib/primitive-iterator') , call = Function.prototype.call , create = Object.create, defineProperty = Object.defineProperty , defineProperties = Object.defineProperties, getPrototypeOf = Object.getPrototypeOf , hasOwnProperty = Object.prototype.hasOwnProperty , PrimitiveMap; module.exports = PrimitiveMap = function (/*iterable, serialize*/) { var iterable = arguments[0], serialize = arguments[1], self; if (!(this instanceof PrimitiveMap)) throw new TypeError('Constructor requires \'new\''); if (isNative && setPrototypeOf && (Map !== MapPolyfill)) { self = setPrototypeOf(new Map(), getPrototypeOf(this)); } else { self = this; } if (iterable != null) iterator(iterable); if (serialize !== undefined) { callable(serialize); defineProperty(self, '_serialize', d('', serialize)); } defineProperties(self, { __mapKeysData__: d('c', create(null)), __mapValuesData__: d('c', create(null)), __size__: d('w', 0) }); if (!iterable) return self; forOf(iterable, function (value) { var key = validValue(value)[0], sKey = self._serialize(key); if (sKey == null) throw new TypeError(key + " cannot be serialized"); value = value[1]; if (hasOwnProperty.call(self.__mapKeysData__, sKey)) { if (self.__mapValuesData__[sKey] === value) return; } else { ++self.__size__; } self.__mapKeysData__[sKey] = key; self.__mapValuesData__[sKey] = value; }); return self; }; if (setPrototypeOf) setPrototypeOf(PrimitiveMap, MapPolyfill); PrimitiveMap.prototype = create(MapPolyfill.prototype, { constructor: d(PrimitiveMap), _serialize: d(function (value) { if (value && (typeof value.toString !== 'function')) return null; return String(value); }), clear: d(function () { if (!this.__size__) return; clear(this.__mapKeysData__); clear(this.__mapValuesData__); this.__size__ = 0; this.emit('_clear'); }), delete: d(function (key) { var sKey = this._serialize(key); if (sKey == null) return false; if (!hasOwnProperty.call(this.__mapKeysData__, sKey)) return false; delete this.__mapKeysData__[sKey]; delete this.__mapValuesData__[sKey]; --this.__size__; this.emit('_delete', sKey); return true; }), entries: d(function () { return new Iterator(this, 'key+value'); }), forEach: d(function (cb/*, thisArg*/) { var thisArg = arguments[1], iterator, result, sKey; callable(cb); iterator = this.entries(); result = iterator._next(); while (result !== undefined) { sKey = iterator.__list__[result]; call.call(cb, thisArg, this.__mapValuesData__[sKey], this.__mapKeysData__[sKey], this); result = iterator._next(); } }), get: d(function (key) { var sKey = this._serialize(key); if (sKey == null) return; return this.__mapValuesData__[sKey]; }), has: d(function (key) { var sKey = this._serialize(key); if (sKey == null) return false; return hasOwnProperty.call(this.__mapKeysData__, sKey); }), keys: d(function () { return new Iterator(this, 'key'); }), size: d.gs(function () { return this.__size__; }), set: d(function (key, value) { var sKey = this._serialize(key); if (sKey == null) throw new TypeError(key + " cannot be serialized"); if (hasOwnProperty.call(this.__mapKeysData__, sKey)) { if (this.__mapValuesData__[sKey] === value) return this; } else { ++this.__size__; } this.__mapKeysData__[sKey] = key; this.__mapValuesData__[sKey] = value; this.emit('_add', sKey); return this; }), values: d(function () { return new Iterator(this, 'value'); }) }); es6-map-0.1.5/test/000077500000000000000000000000001306300565200137445ustar00rootroot00000000000000es6-map-0.1.5/test/implement.js000066400000000000000000000001201306300565200162650ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { a(typeof Map, 'function'); }; es6-map-0.1.5/test/index.js000066400000000000000000000001441306300565200154100ustar00rootroot00000000000000'use strict'; module.exports = function (T, a) { a((new T([['raz', 1], ['dwa', 2]])).size, 2); }; es6-map-0.1.5/test/is-implemented.js000066400000000000000000000004601306300565200172160ustar00rootroot00000000000000'use strict'; var global = require('es5-ext/global') , polyfill = require('../polyfill'); module.exports = function (t, a) { var cache; a(typeof t(), 'boolean'); cache = global.Map; global.Map = polyfill; a(t(), true); if (cache === undefined) delete global.Map; else global.Map = cache; }; es6-map-0.1.5/test/is-map.js000066400000000000000000000006061306300565200154720ustar00rootroot00000000000000'use strict'; var MapPoly = require('../polyfill'); module.exports = function (t, a) { a(t(undefined), false, "Undefined"); a(t(null), false, "Null"); a(t(true), false, "Primitive"); a(t('raz'), false, "String"); a(t({}), false, "Object"); a(t([]), false, "Array"); if (typeof Map !== 'undefined') { a(t(new Map()), true, "Native"); } a(t(new MapPoly()), true, "Polyfill"); }; es6-map-0.1.5/test/is-native-implemented.js000066400000000000000000000001151306300565200204770ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { a(typeof t, 'boolean'); }; es6-map-0.1.5/test/lib/000077500000000000000000000000001306300565200145125ustar00rootroot00000000000000es6-map-0.1.5/test/lib/iterator-kinds.js000066400000000000000000000001601306300565200200040ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { a.deep(t, { key: true, value: true, 'key+value': true }); }; es6-map-0.1.5/test/lib/iterator.js000066400000000000000000000006741306300565200167100ustar00rootroot00000000000000'use strict'; var Map = require('../../polyfill') , toArray = require('es5-ext/array/to-array'); module.exports = function (T, a) { var arr = [['raz', 'one'], ['dwa', 'two']], map = new Map(arr); a.deep(toArray(new T(map)), arr, "Default"); a.deep(toArray(new T(map, 'key+value')), arr, "Key & Value"); a.deep(toArray(new T(map, 'value')), ['one', 'two'], "Value"); a.deep(toArray(new T(map, 'key')), ['raz', 'dwa'], "Value"); }; es6-map-0.1.5/test/lib/primitive-iterator.js000066400000000000000000000073061306300565200207150ustar00rootroot00000000000000'use strict'; var iteratorSymbol = require('es6-symbol').iterator , toArray = require('es5-ext/array/to-array') , Map = require('../../primitive') , compare, mapToResults; compare = function (a, b) { if (!a.value) return -1; if (!b.value) return 1; return a.value[0].localeCompare(b.value[0]); }; mapToResults = function (arr) { return arr.sort().map(function (value) { return { done: false, value: value }; }); }; module.exports = function (T) { return { "": function (a) { var arr, it, y, z, map, result = []; arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'], ['cztery', 'four'], ['pięć', 'five']]; map = new Map(arr); it = new T(map); a(it[iteratorSymbol](), it, "@@iterator"); y = it.next(); result.push(y); z = it.next(); a.not(y, z, "Recreate result"); result.push(z); result.push(it.next()); result.push(it.next()); result.push(it.next()); a.deep(result.sort(compare), mapToResults(arr)); a.deep(y = it.next(), { done: true, value: undefined }, "End"); a.not(y, it.next(), "Recreate result on dead"); }, Emited: function (a) { var arr, it, map, result = []; arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'], ['cztery', 'four'], ['pięć', 'five']]; map = new Map(arr); it = new T(map); result.push(it.next()); result.push(it.next()); map.set('sześć', 'six'); arr.push(['sześć', 'six']); result.push(it.next()); map.delete('pięć'); arr.splice(4, 1); result.push(it.next()); result.push(it.next()); a.deep(result.sort(compare), mapToResults(arr)); a.deep(it.next(), { done: true, value: undefined }, "End"); }, "Emited #2": function (a) { var arr, it, map, result = []; arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'], ['cztery', 'four'], ['pięć', 'five'], ['sześć', 'six']]; map = new Map(arr); it = new T(map); result.push(it.next()); result.push(it.next()); map.set('siedem', 'seven'); map.delete('siedem'); result.push(it.next()); result.push(it.next()); map.delete('pięć'); arr.splice(4, 1); result.push(it.next()); a.deep(result.sort(compare), mapToResults(arr)); a.deep(it.next(), { done: true, value: undefined }, "End"); }, "Emited: Clear #1": function (a) { var arr, it, map, result = []; arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'], ['cztery', 'four'], ['pięć', 'five'], ['sześć', 'six']]; map = new Map(arr); it = new T(map); result.push(it.next()); result.push(it.next()); arr = [['raz', 'one'], ['dwa', 'two']]; map.clear(); a.deep(result.sort(compare), mapToResults(arr)); a.deep(it.next(), { done: true, value: undefined }, "End"); }, "Emited: Clear #2": function (a) { var arr, it, map, result = []; arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'], ['cztery', 'four'], ['pięć', 'five'], ['sześć', 'six']]; map = new Map(arr); it = new T(map); result.push(it.next()); result.push(it.next()); map.clear(); map.set('foo', 'bru'); map.set('bar', 'far'); arr = [['raz', 'one'], ['dwa', 'two'], ['foo', 'bru'], ['bar', 'far']]; result.push(it.next()); result.push(it.next()); a.deep(result.sort(compare), mapToResults(arr)); a.deep(it.next(), { done: true, value: undefined }, "End"); }, Kinds: function (a) { var arr = [['raz', 'one'], ['dwa', 'two']], map = new Map(arr); a.deep(toArray(new T(map)).sort(), arr.sort(), "Default"); a.deep(toArray(new T(map, 'key+value')).sort(), arr.sort(), "Key + Value"); a.deep(toArray(new T(map, 'value')).sort(), ['one', 'two'].sort(), "Value"); a.deep(toArray(new T(map, 'key')).sort(), ['raz', 'dwa'].sort(), "Key"); } }; }; es6-map-0.1.5/test/polyfill.js000066400000000000000000000034071306300565200161400ustar00rootroot00000000000000'use strict'; var aFrom = require('es5-ext/array/from') , toArray = require('es5-ext/array/to-array'); module.exports = function (T, a) { var arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three']] , map = new T(arr), x = {}, y = {}, i = 0; a(map instanceof T, true, "Map"); a(map.size, 3, "Size"); a(map.get('raz'), 'one', "Get: contained"); a(map.get(x), undefined, "Get: not contained"); a(map.has('raz'), true, "Has: contained"); a(map.has(x), false, "Has: not contained"); a(map.set(x, y), map, "Set: return"); a(map.has(x), true, "Set: has"); a(map.get(x), y, "Set: get"); a(map.size, 4, "Set: Size"); map.set('dwa', x); a(map.get('dwa'), x, "Overwrite: get"); a(map.size, 4, "Overwrite: size"); a(map.delete({}), false, "Delete: false"); arr.push([x, y]); arr[1][1] = x; map.forEach(function () { a.deep(aFrom(arguments), [arr[i][1], arr[i][0], map], "ForEach: Arguments: #" + i); a(this, y, "ForEach: Context: #" + i); if (i === 0) { a(map.delete('raz'), true, "Delete: true"); a(map.has('raz'), false, "Delete"); a(map.size, 3, "Delete: size"); map.set('cztery', 'four'); arr.push(['cztery', 'four']); } i++; }, y); arr.splice(0, 1); a.deep(toArray(map.entries()), [['dwa', x], ['trzy', 'three'], [x, y], ['cztery', 'four']], "Entries"); a.deep(toArray(map.keys()), ['dwa', 'trzy', x, 'cztery'], "Keys"); a.deep(toArray(map.values()), [x, 'three', y, 'four'], "Values"); a.deep(toArray(map), [['dwa', x], ['trzy', 'three'], [x, y], ['cztery', 'four']], "Iterator"); map.clear(); a(map.size, 0, "Clear: size"); a(map.has('trzy'), false, "Clear: has"); a.deep(toArray(map), [], "Clear: Values"); a.h1("Empty initialization"); map = new T(); map.set('foo', 'bar'); a(map.size, 1); a(map.get('foo'), 'bar'); }; es6-map-0.1.5/test/primitive/000077500000000000000000000000001306300565200157545ustar00rootroot00000000000000es6-map-0.1.5/test/primitive/index.js000066400000000000000000000034261306300565200174260ustar00rootroot00000000000000'use strict'; var aFrom = require('es5-ext/array/from') , getIterator = require('es6-iterator/get') , toArray = require('es5-ext/array/to-array'); module.exports = function (T, a) { var arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three']] , map = new T(arr), x = 'other', y = 'other2' , i = 0, result = []; a(map instanceof T, true, "Map"); a(map.size, 3, "Size"); a(map.get('raz'), 'one', "Get: contained"); a(map.get(x), undefined, "Get: not contained"); a(map.has('raz'), true, "Has: true"); a(map.has(x), false, "Has: false"); a(map.set(x, y), map, "Add: return"); a(map.has(x), true, "Add"); a(map.size, 4, "Add: Size"); map.set('dwa', x); a(map.get('dwa'), x, "Overwrite: get"); a(map.size, 4, "Overwrite: size"); a(map.delete('else'), false, "Delete: false"); arr.push([x, y]); arr[1][1] = x; map.forEach(function () { result.push(aFrom(arguments)); a(this, y, "ForEach: Context: #" + i); }, y); a.deep(result.sort(function (a, b) { return String([a[1], a[0]]).localeCompare([b[1], b[0]]); }), arr.sort().map(function (val) { return [val[1], val[0], map]; }), "ForEach: Arguments"); a.deep(toArray(map.entries()).sort(), [['dwa', x], ['trzy', 'three'], [x, y], ['raz', 'one']].sort(), "Entries"); a.deep(toArray(map.keys()).sort(), ['dwa', 'trzy', x, 'raz'].sort(), "Keys"); a.deep(toArray(map.values()).sort(), [x, 'three', y, 'one'].sort(), "Values"); a.deep(toArray(getIterator(map)).sort(), [['dwa', x], ['trzy', 'three'], [x, y], ['raz', 'one']].sort(), "Iterator"); map.clear(); a(map.size, 0, "Clear: size"); a(map.has('trzy'), false, "Clear: has"); a.deep(toArray(map.values()), [], "Clear: Values"); a.h1("Empty initialization"); map = new T(); map.set('foo', 'bar'); a(map.size, 1); a(map.get('foo'), 'bar'); }; es6-map-0.1.5/test/valid-map.js000066400000000000000000000011171306300565200161540ustar00rootroot00000000000000'use strict'; var MapPoly = require('../polyfill'); module.exports = function (t, a) { var map; a.throws(function () { t(undefined); }, TypeError, "Undefined"); a.throws(function () { t(null); }, TypeError, "Null"); a.throws(function () { t(true); }, TypeError, "Primitive"); a.throws(function () { t('raz'); }, TypeError, "String"); a.throws(function () { t({}); }, TypeError, "Object"); a.throws(function () { t([]); }, TypeError, "Array"); if (typeof Map !== 'undefined') { map = new Map(); a(t(map), map, "Native"); } map = new MapPoly(); a(t(map), map, "Polyfill"); }; es6-map-0.1.5/valid-map.js000066400000000000000000000002311306300565200151710ustar00rootroot00000000000000'use strict'; var isMap = require('./is-map'); module.exports = function (x) { if (!isMap(x)) throw new TypeError(x + " is not a Map"); return x; };