Comparing version 0.0.0 to 0.1.0
{ | ||
"name": "es6-set", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "ECMAScript6 Set polyfill", | ||
@@ -18,15 +18,16 @@ "author": "Mariusz Nowak <medyk@medikoo.com> (http://www.medikoo.com/)", | ||
}, | ||
"scripts": { | ||
"test": "node ./node_modules/tad/bin/tad" | ||
}, | ||
"dependencies": { | ||
"d": "git://github.com/medikoo/d.git", | ||
"es5-ext": "git://github.com/medikoo/es5-ext.git", | ||
"es6-iterator": "git://github.com/medikoo/es6-iterator.git", | ||
"event-emitter": "git://github.com/medikoo/event-emitter.git" | ||
"d": "~0.1.1", | ||
"es5-ext": "~0.10.2", | ||
"es6-iterator": "~0.1.1", | ||
"es6-symbol": "0.1.x", | ||
"event-emitter": "~0.3.1" | ||
}, | ||
"devDependencies": { | ||
"tad": "~0.1.19" | ||
"tad": "0.2.x" | ||
}, | ||
"scripts": { | ||
"test": "node ./node_modules/tad/bin/tad" | ||
}, | ||
"license": "MIT" | ||
} |
'use strict'; | ||
var callable = require('es5-ext/object/valid-callable') | ||
, d = require('d/d') | ||
, ee = require('event-emitter/lib/core') | ||
, getIterator = require('es6-iterator/get') | ||
, forOf = require('es6-iterator/for-of') | ||
, getSetData = require('./_get-set-data') | ||
, Iterator = require('./_iterator') | ||
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') | ||
, 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') | ||
, isArray = Array.isArray | ||
, call = Function.prototype.call, defineProperty = Object.defineProperty | ||
, Set, values; | ||
, SetPoly, getValues; | ||
module.exports = Set = function (/*iterable, comparator*/) { | ||
var iterable = arguments[0], comparator = arguments[1]; | ||
if (!(this instanceof Set)) return new Set(iterable, comparator); | ||
module.exports = SetPoly = function (/*iterable*/) { | ||
var iterable = arguments[0]; | ||
if (!(this instanceof SetPoly)) return new SetPoly(iterable); | ||
if (this.__setData__ !== undefined) { | ||
throw new TypeError(this + " cannot be reinitialized"); | ||
} | ||
if (iterable != null) { | ||
if (!isArray(iterable)) iterable = getIterator(iterable); | ||
} | ||
if (comparator != null) { | ||
if (comparator !== 'is') throw new RangeError("Unknown comparator"); | ||
} | ||
defineProperty(this, '__setData__', d('', getSetData(comparator))); | ||
if (iterable != null) iterator(iterable); | ||
defineProperty(this, '__setData__', d('c', [])); | ||
if (!iterable) return; | ||
forOf(iterable, function (value) { this.add(value); }, this); | ||
forOf(iterable, function (value) { | ||
if (eIndexOf.call(this, value) !== -1) return; | ||
this.push(value); | ||
}, this.__setData__); | ||
}; | ||
ee(Object.defineProperties(Set.prototype, { | ||
constructor: d(Set), | ||
if (isNative) { | ||
if (setPrototypeOf) setPrototypeOf(SetPoly, Set); | ||
SetPoly.prototype = Object.create(Set.prototype, { | ||
constructor: d(SetPoly) | ||
}); | ||
} | ||
ee(Object.defineProperties(SetPoly.prototype, { | ||
add: d(function (value) { | ||
if (this.has(value)) return this; | ||
this.emit('_add', this.__setData__.push(value) - 1); | ||
this.emit('_add', this.__setData__.push(value) - 1, value); | ||
return this; | ||
}), | ||
clear: d(function () { | ||
this.__setData__.clear(); | ||
if (!this.__setData__.length) return; | ||
clear.call(this.__setData__); | ||
this.emit('_clear'); | ||
}), | ||
delete: d(function (value) { | ||
var index = this.__setData__.eIndexOf(value); | ||
var index = eIndexOf.call(this.__setData__, value); | ||
if (index === -1) return false; | ||
this.__setData__.splice(index, 1); | ||
this.emit('_delete', index); | ||
this.emit('_delete', index, value); | ||
return true; | ||
@@ -52,19 +60,21 @@ }), | ||
forEach: d(function (cb/*, thisArg*/) { | ||
var thisArg = arguments[1], iterator, result; | ||
var thisArg = arguments[1], iterator, result, value; | ||
callable(cb); | ||
iterator = this.values(); | ||
result = iterator.next(); | ||
while (!result.done) { | ||
call.call(cb, thisArg, result.value, result.value, this); | ||
result = iterator.next(); | ||
result = iterator._next(); | ||
while (result !== undefined) { | ||
value = iterator._resolve(result); | ||
call.call(cb, thisArg, value, value, this); | ||
result = iterator._next(); | ||
} | ||
}), | ||
has: d(function (value) { | ||
return (this.__setData__.eIndexOf(value) !== -1); | ||
return (eIndexOf.call(this.__setData__, value) !== -1); | ||
}), | ||
keys: d(values = function () { return new Iterator(this); }), | ||
keys: d(getValues = function () { return this.values(); }), | ||
size: d.gs(function () { return this.__setData__.length; }), | ||
values: d(values), | ||
'@@iterator': d(values), | ||
values: d(function () { return new Iterator(this); }), | ||
toString: d(function () { return '[object Set]'; }) | ||
})); | ||
defineProperty(SetPoly.prototype, Symbol.iterator, d(getValues)); | ||
defineProperty(SetPoly.prototype, Symbol.toStringTag, d('c', 'Set')); |
@@ -24,2 +24,8 @@ # es6-set | ||
### Installation | ||
$ npm install es6-set | ||
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 | ||
@@ -48,3 +54,2 @@ | ||
// FF nightly only: | ||
@@ -66,15 +71,4 @@ for (value of set) { | ||
### Installation | ||
#### NPM | ||
In your project path: | ||
$ npm install es6-set | ||
##### Browser | ||
You can easily bundle _es6-set_ for browser with [modules-webmake](https://github.com/medikoo/modules-webmake) | ||
## Tests [![Build Status](https://travis-ci.org/medikoo/es6-set.png)](https://travis-ci.org/medikoo/es6-set) | ||
$ npm test |
'use strict'; | ||
var aFrom = require('es5-ext/array/from') | ||
, getIterator = require('es6-iterator/get') | ||
, toArray = require('es6-iterator/to-array'); | ||
var aFrom = require('es5-ext/array/from') | ||
, toArray = require('es5-ext/array/to-array'); | ||
@@ -39,3 +38,3 @@ module.exports = function (T, a) { | ||
a.deep(toArray(set.values()), ['dwa', 'trzy', x, 'cztery'], "Values"); | ||
a.deep(toArray(getIterator(set)), ['dwa', 'trzy', x, 'cztery'], "Iterator"); | ||
a.deep(toArray(set), ['dwa', 'trzy', x, 'cztery'], "Iterator"); | ||
@@ -45,3 +44,3 @@ set.clear(); | ||
a(set.has('trzy'), false, "Clear: has"); | ||
a.deep(toArray(set.values()), [], "Clear: Values"); | ||
a.deep(toArray(set), [], "Clear: Values"); | ||
}; |
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
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 4 instances in 1 package
24159
33
567
0
5
72
1
+ Addedes6-symbol@0.1.x
+ Addedd@0.1.11.0.2(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@0.1.32.0.3(transitive)
+ Addedes6-symbol@0.1.12.0.13.1.4(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedext@1.7.0(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addedtype@2.7.3(transitive)
Updatedd@~0.1.1
Updatedes5-ext@~0.10.2
Updatedes6-iterator@~0.1.1
Updatedevent-emitter@~0.3.1