Removed GopherJS, basic frontend completed, need backend changes for

torrent storage
This commit is contained in:
2017-11-30 18:12:11 -05:00
parent 67fdef16b1
commit e98ad2cc88
69321 changed files with 5498914 additions and 337 deletions

View File

@@ -0,0 +1,13 @@
@root
module
indent 2
maxlen 100
tabs
ass
nomen
plusplus
predef+ Map

View File

@@ -0,0 +1,4 @@
.DS_Store
/node_modules
/npm-debug.log
/.lintcache

View File

@@ -0,0 +1,13 @@
sudo: 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"

View File

@@ -0,0 +1,33 @@
v0.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

View File

@@ -0,0 +1,19 @@
Copyright (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.

View File

@@ -0,0 +1,79 @@
# 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
Its safest to use *es6-map* as a [ponyfill](https://ponyfill.com) a polyfill which doesnt 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

View File

@@ -0,0 +1,7 @@
'use strict';
if (!require('./is-implemented')()) {
Object.defineProperty(require('es5-ext/global'), 'Map',
{ value: require('./polyfill'), configurable: true, enumerable: false,
writable: true });
}

View File

@@ -0,0 +1,3 @@
'use strict';
module.exports = require('./is-implemented')() ? Map : require('./polyfill');

View File

@@ -0,0 +1,32 @@
'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;
};

View File

@@ -0,0 +1,12 @@
'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;
};

View File

@@ -0,0 +1,9 @@
// 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]');
}());

View File

@@ -0,0 +1,4 @@
'use strict';
module.exports = require('es5-ext/object/primitive-set')('key',
'value', 'key+value');

View File

@@ -0,0 +1,38 @@
'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'));

View File

@@ -0,0 +1,57 @@
'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'));

View File

@@ -0,0 +1,77 @@
{
"_args": [
[
"es6-map@0.1.5",
"C:\\Users\\deranjer\\GoglandProjects\\torrent-project\\torrent-project"
]
],
"_from": "es6-map@0.1.5",
"_id": "es6-map@0.1.5",
"_inBundle": false,
"_integrity": "sha1-kTbgUD3MBqMBaQ8LsU/042TpSfA=",
"_location": "/webpack/es6-map",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "es6-map@0.1.5",
"name": "es6-map",
"escapedName": "es6-map",
"rawSpec": "0.1.5",
"saveSpec": null,
"fetchSpec": "0.1.5"
},
"_requiredBy": [
"/webpack/escope"
],
"_resolved": "https://registry.npmjs.org/es6-map/-/es6-map-0.1.5.tgz",
"_spec": "0.1.5",
"_where": "C:\\Users\\deranjer\\GoglandProjects\\torrent-project\\torrent-project",
"author": {
"name": "Mariusz Nowak",
"email": "medyk@medikoo.com",
"url": "http://www.medikoo.com/"
},
"bugs": {
"url": "https://github.com/medikoo/es6-map/issues"
},
"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"
},
"description": "ECMAScript6 Map polyfill",
"devDependencies": {
"tad": "~0.2.7",
"xlint": "~0.2.2",
"xlint-jslint-medikoo": "~0.1.4"
},
"homepage": "https://github.com/medikoo/es6-map#readme",
"keywords": [
"collection",
"es6",
"shim",
"harmony",
"list",
"hash",
"map",
"polyfill",
"ponyfill",
"ecmascript"
],
"license": "MIT",
"name": "es6-map",
"repository": {
"type": "git",
"url": "git://github.com/medikoo/es6-map.git"
},
"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"
},
"version": "0.1.5"
}

View File

@@ -0,0 +1,104 @@
'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'));

View File

@@ -0,0 +1,117 @@
'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'); })
});

View File

@@ -0,0 +1,3 @@
'use strict';
module.exports = function (t, a) { a(typeof Map, 'function'); };

View File

@@ -0,0 +1,5 @@
'use strict';
module.exports = function (T, a) {
a((new T([['raz', 1], ['dwa', 2]])).size, 2);
};

View File

@@ -0,0 +1,14 @@
'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;
};

View File

@@ -0,0 +1,16 @@
'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");
};

View File

@@ -0,0 +1,3 @@
'use strict';
module.exports = function (t, a) { a(typeof t, 'boolean'); };

View File

@@ -0,0 +1,5 @@
'use strict';
module.exports = function (t, a) {
a.deep(t, { key: true, value: true, 'key+value': true });
};

View File

@@ -0,0 +1,13 @@
'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");
};

View File

@@ -0,0 +1,130 @@
'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");
}
};
};

View File

@@ -0,0 +1,60 @@
'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');
};

View File

@@ -0,0 +1,59 @@
'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');
};

View File

@@ -0,0 +1,19 @@
'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");
};

View File

@@ -0,0 +1,8 @@
'use strict';
var isMap = require('./is-map');
module.exports = function (x) {
if (!isMap(x)) throw new TypeError(x + " is not a Map");
return x;
};