es6-weak-map
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -1,7 +0,11 @@ | ||
'use strict'; | ||
"use strict"; | ||
if (!require('./is-implemented')()) { | ||
Object.defineProperty(require('es5-ext/global'), 'WeakMap', | ||
{ value: require('./polyfill'), configurable: true, enumerable: false, | ||
writable: true }); | ||
if (!require("./is-implemented")()) { | ||
Object.defineProperty(require("es5-ext/global"), "WeakMap", | ||
{ | ||
value: require("./polyfill"), | ||
configurable: true, | ||
enumerable: false, | ||
writable: true | ||
}); | ||
} |
@@ -1,3 +0,3 @@ | ||
'use strict'; | ||
"use strict"; | ||
module.exports = require('./is-implemented')() ? WeakMap : require('./polyfill'); | ||
module.exports = require("./is-implemented")() ? WeakMap : require("./polyfill"); |
@@ -1,20 +0,21 @@ | ||
'use strict'; | ||
"use strict"; | ||
module.exports = function () { | ||
var weakMap, x; | ||
if (typeof WeakMap !== 'function') return false; | ||
var weakMap, obj; | ||
if (typeof WeakMap !== "function") return false; | ||
try { | ||
// WebKit doesn't support arguments and crashes | ||
weakMap = new WeakMap([[x = {}, 'one'], [{}, 'two'], [{}, 'three']]); | ||
weakMap = new WeakMap([[obj = {}, "one"], [{}, "two"], [{}, "three"]]); | ||
} catch (e) { | ||
return false; | ||
} | ||
if (String(weakMap) !== '[object WeakMap]') return false; | ||
if (typeof weakMap.set !== 'function') return false; | ||
if (String(weakMap) !== "[object WeakMap]") return false; | ||
if (typeof weakMap.set !== "function") return false; | ||
if (weakMap.set({}, 1) !== weakMap) return false; | ||
if (typeof weakMap.delete !== 'function') return false; | ||
if (typeof weakMap.has !== 'function') return false; | ||
if (weakMap.get(x) !== 'one') return false; | ||
if (typeof weakMap.delete !== "function") return false; | ||
if (typeof weakMap.has !== "function") return false; | ||
if (weakMap.get(obj) !== "one") return false; | ||
return true; | ||
}; |
// Exports true if environment provides native `WeakMap` implementation, whatever that is. | ||
'use strict'; | ||
"use strict"; | ||
module.exports = (function () { | ||
if (typeof WeakMap !== 'function') return false; | ||
return (Object.prototype.toString.call(new WeakMap()) === '[object WeakMap]'); | ||
if (typeof WeakMap !== "function") return false; | ||
return Object.prototype.toString.call(new WeakMap()) === "[object WeakMap]"; | ||
}()); |
@@ -1,13 +0,13 @@ | ||
'use strict'; | ||
"use strict"; | ||
var toStringTagSymbol = require('es6-symbol').toStringTag | ||
var toStringTagSymbol = require("es6-symbol").toStringTag | ||
, toString = Object.prototype.toString | ||
, id = '[object WeakMap]' | ||
, Global = (typeof WeakMap === 'undefined') ? null : WeakMap; | ||
, objToString = Object.prototype.toString | ||
, id = "[object WeakMap]" | ||
, Global = typeof WeakMap === "undefined" ? null : WeakMap; | ||
module.exports = function (x) { | ||
return (x && ((Global && (x instanceof Global)) || | ||
(toString.call(x) === id) || (x[toStringTagSymbol] === 'WeakMap'))) || | ||
module.exports = function (value) { | ||
return (value && ((Global && (value instanceof Global)) || | ||
(objToString.call(value) === id) || (value[toStringTagSymbol] === "WeakMap"))) || | ||
false; | ||
}; |
{ | ||
"name": "es6-weak-map", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "ECMAScript6 WeakMap polyfill", | ||
@@ -23,17 +23,23 @@ "author": "Mariusz Nowak <medyk@medikoo.com> (http://www.medikoo.com/)", | ||
"d": "1", | ||
"es5-ext": "^0.10.14", | ||
"es6-iterator": "^2.0.1", | ||
"es5-ext": "^0.10.46", | ||
"es6-iterator": "^2.0.3", | ||
"es6-symbol": "^3.1.1" | ||
}, | ||
"devDependencies": { | ||
"tad": "^0.2.7", | ||
"xlint": "^0.2.2", | ||
"xlint-jslint-medikoo": "^0.1.4" | ||
"eslint": "^5.5", | ||
"eslint-config-medikoo-es5": "^1.7", | ||
"tad": "^0.2.8" | ||
}, | ||
"eslintConfig": { | ||
"extends": "medikoo-es5", | ||
"root": true, | ||
"globals": { | ||
"WeakMap": true | ||
} | ||
}, | ||
"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", | ||
"lint": "eslint --ignore-path=.gitignore .", | ||
"test": "node ./node_modules/tad/bin/tad" | ||
}, | ||
"license": "MIT" | ||
"license": "ISC" | ||
} |
@@ -1,32 +0,32 @@ | ||
'use strict'; | ||
"use strict"; | ||
var setPrototypeOf = require('es5-ext/object/set-prototype-of') | ||
, object = require('es5-ext/object/valid-object') | ||
, value = require('es5-ext/object/valid-value') | ||
, randomUniq = require('es5-ext/string/random-uniq') | ||
, d = require('d') | ||
, getIterator = require('es6-iterator/get') | ||
, forOf = require('es6-iterator/for-of') | ||
, toStringTagSymbol = require('es6-symbol').toStringTag | ||
, isNative = require('./is-native-implemented') | ||
var isValue = require("es5-ext/object/is-value") | ||
, setPrototypeOf = require("es5-ext/object/set-prototype-of") | ||
, object = require("es5-ext/object/valid-object") | ||
, ensureValue = require("es5-ext/object/valid-value") | ||
, randomUniq = require("es5-ext/string/random-uniq") | ||
, d = require("d") | ||
, getIterator = require("es6-iterator/get") | ||
, forOf = require("es6-iterator/for-of") | ||
, toStringTagSymbol = require("es6-symbol").toStringTag | ||
, isNative = require("./is-native-implemented") | ||
, isArray = Array.isArray, defineProperty = Object.defineProperty | ||
, hasOwnProperty = Object.prototype.hasOwnProperty, getPrototypeOf = Object.getPrototypeOf | ||
, objHasOwnProperty = Object.prototype.hasOwnProperty, getPrototypeOf = Object.getPrototypeOf | ||
, WeakMapPoly; | ||
module.exports = WeakMapPoly = function (/*iterable*/) { | ||
module.exports = WeakMapPoly = function (/* Iterable*/) { | ||
var iterable = arguments[0], self; | ||
if (!(this instanceof WeakMapPoly)) throw new TypeError('Constructor requires \'new\''); | ||
if (isNative && setPrototypeOf && (WeakMap !== WeakMapPoly)) { | ||
self = setPrototypeOf(new WeakMap(), getPrototypeOf(this)); | ||
} else { | ||
self = this; | ||
} | ||
if (iterable != null) { | ||
if (!(this instanceof WeakMapPoly)) throw new TypeError("Constructor requires 'new'"); | ||
self = isNative && setPrototypeOf && (WeakMap !== WeakMapPoly) | ||
? setPrototypeOf(new WeakMap(), getPrototypeOf(this)) : this; | ||
if (isValue(iterable)) { | ||
if (!isArray(iterable)) iterable = getIterator(iterable); | ||
} | ||
defineProperty(self, '__weakMapData__', d('c', '$weakMap$' + randomUniq())); | ||
defineProperty(self, "__weakMapData__", d("c", "$weakMap$" + randomUniq())); | ||
if (!iterable) return self; | ||
forOf(iterable, function (val) { | ||
value(val); | ||
ensureValue(val); | ||
self.set(val[0], val[1]); | ||
@@ -39,5 +39,3 @@ }); | ||
if (setPrototypeOf) setPrototypeOf(WeakMapPoly, WeakMap); | ||
WeakMapPoly.prototype = Object.create(WeakMap.prototype, { | ||
constructor: d(WeakMapPoly) | ||
}); | ||
WeakMapPoly.prototype = Object.create(WeakMap.prototype, { constructor: d(WeakMapPoly) }); | ||
} | ||
@@ -47,3 +45,3 @@ | ||
delete: d(function (key) { | ||
if (hasOwnProperty.call(object(key), this.__weakMapData__)) { | ||
if (objHasOwnProperty.call(object(key), this.__weakMapData__)) { | ||
delete key[this.__weakMapData__]; | ||
@@ -55,15 +53,16 @@ return true; | ||
get: d(function (key) { | ||
if (hasOwnProperty.call(object(key), this.__weakMapData__)) { | ||
return key[this.__weakMapData__]; | ||
} | ||
if (!objHasOwnProperty.call(object(key), this.__weakMapData__)) return undefined; | ||
return key[this.__weakMapData__]; | ||
}), | ||
has: d(function (key) { | ||
return hasOwnProperty.call(object(key), this.__weakMapData__); | ||
return objHasOwnProperty.call(object(key), this.__weakMapData__); | ||
}), | ||
set: d(function (key, value) { | ||
defineProperty(object(key), this.__weakMapData__, d('c', value)); | ||
defineProperty(object(key), this.__weakMapData__, d("c", value)); | ||
return this; | ||
}), | ||
toString: d(function () { return '[object WeakMap]'; }) | ||
toString: d(function () { | ||
return "[object WeakMap]"; | ||
}) | ||
}); | ||
defineProperty(WeakMapPoly.prototype, toStringTagSymbol, d('c', 'WeakMap')); | ||
defineProperty(WeakMapPoly.prototype, toStringTagSymbol, d("c", "WeakMap")); |
@@ -0,2 +1,8 @@ | ||
[![Build status][nix-build-image]][nix-build-url] | ||
[![Windows status][win-build-image]][win-build-url] | ||
![Transpilation status][transpilation-image] | ||
[![npm version][npm-image]][npm-url] | ||
# es6-weak-map | ||
## WeakMap collection as specified in ECMAScript6 | ||
@@ -7,13 +13,14 @@ | ||
Differences are: | ||
- Assumes compliant ES5 environment (no weird ES3 workarounds or hacks) | ||
- Well modularized CJS style | ||
- Based on one solution. | ||
- Assumes compliant ES5 environment (no weird ES3 workarounds or hacks) | ||
- Well modularized CJS style | ||
- Based on one solution. | ||
### Limitations | ||
- Will fail on non extensible objects provided as keys | ||
- Will fail on non extensible objects provided as keys | ||
### Installation | ||
$ npm install es6-weak-map | ||
$ npm install es6-weak-map | ||
@@ -27,3 +34,3 @@ 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/) | ||
```javascript | ||
require('es6-weak-map/implement'); | ||
require("es6-weak-map/implement"); | ||
``` | ||
@@ -34,3 +41,3 @@ | ||
```javascript | ||
var WeakMap = require('es6-weak-map'); | ||
var WeakMap = require("es6-weak-map"); | ||
``` | ||
@@ -41,3 +48,3 @@ | ||
```javascript | ||
var WeakMap = require('es6-weak-map/polyfill'); | ||
var WeakMap = require("es6-weak-map/polyfill"); | ||
``` | ||
@@ -50,3 +57,3 @@ | ||
```javascript | ||
var WeakMap = require('es6-weak-map'); | ||
var WeakMap = require("es6-weak-map"); | ||
@@ -56,14 +63,22 @@ var map = new WeakMap(); | ||
map.set(obj, 'foo'); // map | ||
map.get(obj); // 'foo' | ||
map.has(obj); // true | ||
map.delete(obj); // true | ||
map.get(obj); // undefined | ||
map.has(obj); // false | ||
map.set(obj, 'bar'); // map | ||
map.has(obj); // false | ||
map.set(obj, "foo"); // map | ||
map.get(obj); // 'foo' | ||
map.has(obj); // true | ||
map.delete(obj); // true | ||
map.get(obj); // undefined | ||
map.has(obj); // false | ||
map.set(obj, "bar"); // map | ||
map.has(obj); // false | ||
``` | ||
## Tests [![Build Status](https://travis-ci.org/medikoo/es6-weak-map.svg)](https://travis-ci.org/medikoo/es6-weak-map) | ||
## Tests | ||
$ npm test | ||
$ npm test | ||
[nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/es6-weak-map/branches/master/shields_badge.svg | ||
[nix-build-url]: https://semaphoreci.com/medikoo-org/es6-weak-map | ||
[win-build-image]: https://ci.appveyor.com/api/projects/status/1c73c57pg4s6lwmu?svg=true | ||
[win-build-url]: https://ci.appveyor.com/project/medikoo/es6-weak-map | ||
[transpilation-image]: https://img.shields.io/badge/transpilation-free-brightgreen.svg | ||
[npm-image]: https://img.shields.io/npm/v/es6-weak-map.svg | ||
[npm-url]: https://www.npmjs.com/package/es6-weak-map |
@@ -1,3 +0,5 @@ | ||
'use strict'; | ||
"use strict"; | ||
module.exports = function (t, a) { a(typeof WeakMap, 'function'); }; | ||
module.exports = function (t, a) { | ||
a(typeof WeakMap, "function"); | ||
}; |
@@ -1,6 +0,7 @@ | ||
'use strict'; | ||
"use strict"; | ||
module.exports = function (T, a) { | ||
var x = {}; | ||
a((new T([[x, 'foo']])).get(x), 'foo'); | ||
var obj = {}; | ||
a((new T([[obj, "foo"]])).get(obj), "foo"); | ||
}; |
@@ -1,14 +0,15 @@ | ||
'use strict'; | ||
"use strict"; | ||
var global = require('es5-ext/global') | ||
, polyfill = require('../polyfill'); | ||
var globalObj = require("es5-ext/global") | ||
, polyfill = require("../polyfill"); | ||
module.exports = function (t, a) { | ||
var cache; | ||
a(typeof t(), 'boolean'); | ||
cache = global.WeakMap; | ||
global.WeakMap = polyfill; | ||
a(typeof t(), "boolean"); | ||
cache = globalObj.WeakMap; | ||
globalObj.WeakMap = polyfill; | ||
a(t(), true); | ||
if (cache === undefined) delete global.WeakMap; | ||
else global.WeakMap = cache; | ||
if (cache === undefined) delete globalObj.WeakMap; | ||
else globalObj.WeakMap = cache; | ||
}; |
@@ -1,3 +0,5 @@ | ||
'use strict'; | ||
"use strict"; | ||
module.exports = function (t, a) { a(typeof t, 'boolean'); }; | ||
module.exports = function (t, a) { | ||
a(typeof t, "boolean"); | ||
}; |
@@ -1,4 +0,4 @@ | ||
'use strict'; | ||
"use strict"; | ||
var WeakMapPoly = require('../polyfill'); | ||
var WeakMapPoly = require("../polyfill"); | ||
@@ -9,6 +9,6 @@ module.exports = function (t, a) { | ||
a(t(true), false, "Primitive"); | ||
a(t('raz'), false, "String"); | ||
a(t("raz"), false, "String"); | ||
a(t({}), false, "Object"); | ||
a(t([]), false, "Array"); | ||
if (typeof WeakMap !== 'undefined') { | ||
if (typeof WeakMap !== "undefined") { | ||
a(t(new WeakMap()), true, "Native"); | ||
@@ -15,0 +15,0 @@ } |
@@ -1,23 +0,23 @@ | ||
'use strict'; | ||
"use strict"; | ||
module.exports = function (T, a) { | ||
var x = {}, y = {}, z = {}, arr = [[x, 'raz'], [y, 'dwa']], map = new T(arr); | ||
var obj1 = {}, obj2 = {}, obj3 = {}, arr = [[obj1, "raz"], [obj2, "dwa"]], map = new T(arr); | ||
a(map instanceof T, true, "WeakMap"); | ||
a(map.has(x), true, "Has: true"); | ||
a(map.get(x), 'raz', "Get: contains"); | ||
a(map.has(z), false, "Has: false"); | ||
a(map.get(z), undefined, "Get: doesn't contain"); | ||
a(map.set(z, 'trzy'), map, "Set: return"); | ||
a(map.has(z), true, "Add"); | ||
a(map.has(obj1), true, "Has: true"); | ||
a(map.get(obj1), "raz", "Get: contains"); | ||
a(map.has(obj3), false, "Has: false"); | ||
a(map.get(obj3), undefined, "Get: doesn't contain"); | ||
a(map.set(obj3, "trzy"), map, "Set: return"); | ||
a(map.has(obj3), true, "Add"); | ||
a(map.delete({}), false, "Delete: false"); | ||
a(map.delete(x), true, "Delete: true"); | ||
a(map.get(x), undefined, "Get: after delete"); | ||
a(map.has(x), false, "Has: after delete"); | ||
a(map.delete(obj1), true, "Delete: true"); | ||
a(map.get(obj1), undefined, "Get: after delete"); | ||
a(map.has(obj1), false, "Has: after delete"); | ||
a.h1("Empty initialization"); | ||
map = new T(); | ||
map.set(x, 'bar'); | ||
a(map.get(x), 'bar'); | ||
map.set(obj1, "bar"); | ||
a(map.get(obj1), "bar"); | ||
}; |
@@ -1,14 +0,27 @@ | ||
'use strict'; | ||
"use strict"; | ||
var WeakMapPoly = require('../polyfill'); | ||
var WeakMapPoly = 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 WeakMap !== 'undefined') { | ||
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 WeakMap !== "undefined") { | ||
map = new WeakMap(); | ||
@@ -15,0 +28,0 @@ a(t(map), map, "Native"); |
@@ -1,8 +0,8 @@ | ||
'use strict'; | ||
"use strict"; | ||
var isWeakMap = require('./is-weak-map'); | ||
var isWeakMap = require("./is-weak-map"); | ||
module.exports = function (x) { | ||
if (!isWeakMap(x)) throw new TypeError(x + " is not a WeakMap"); | ||
return x; | ||
module.exports = function (value) { | ||
if (!isWeakMap(value)) throw new TypeError(value + " is not a WeakMap"); | ||
return value; | ||
}; |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
12458
197
79
20
1
Updatedes5-ext@^0.10.46
Updatedes6-iterator@^2.0.3