How to use the core-js-pure/features/set function in core-js-pure

To help you get started, we’ve selected a few core-js-pure examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zloirock / core-js / tests / pure / esnext.set.filter.js View on Github external
QUnit.test('Set#filter', assert => {
  const { filter } = Set.prototype;

  assert.isFunction(filter);
  assert.arity(filter, 1);
  assert.name(filter, 'filter');
  assert.nonEnumerable(Set.prototype, 'filter');

  const set = new Set([1]);
  const context = {};
  set.filter(function (value, key, that) {
    assert.same(arguments.length, 3, 'correct number of callback arguments');
    assert.same(value, 1, 'correct value in callback');
    assert.same(key, 1, 'correct key in callback');
    assert.same(that, set, 'correct link to set in callback');
    assert.same(this, context, 'correct callback context');
  }, context);

  assert.ok(new Set().filter(it => it) instanceof Set);

  assert.deepEqual(from(new Set([1, 2, 3, 'q', {}, 4, true, 5]).filter(it => typeof it === 'number')), [1, 2, 3, 4, 5]);

  assert.throws(() => filter.call({}, () => { /* empty */ }), TypeError);
  assert.throws(() => filter.call(undefined, () => { /* empty */ }), TypeError);
  assert.throws(() => filter.call(null, () => { /* empty */ }), TypeError);
github zloirock / core-js / tests / pure / esnext.set.add-all.js View on Github external
QUnit.test('Set#addAll', assert => {
  const { addAll } = Set.prototype;

  assert.isFunction(addAll);
  assert.arity(addAll, 0);
  assert.name(addAll, 'addAll');
  assert.nonEnumerable(Set.prototype, 'addAll');

  const set = new Set([1]);
  assert.same(set.addAll(2), set);

  assert.deepEqual(from(new Set([1, 2, 3]).addAll(4, 5)), [1, 2, 3, 4, 5]);
  assert.deepEqual(from(new Set([1, 2, 3]).addAll(3, 4)), [1, 2, 3, 4]);
  assert.deepEqual(from(new Set([1, 2, 3]).addAll()), [1, 2, 3]);

  assert.notThrows(() => addAll.call({ add() { /* empty */ } }, 1, 2, 3));
  assert.throws(() => addAll.call({}, 1, 2, 3), TypeError);
  assert.throws(() => addAll.call(undefined, 1, 2, 3), TypeError);
  assert.throws(() => addAll.call(null, 1, 2, 3), TypeError);
});
github zloirock / core-js / tests / pure / esnext.set.some.js View on Github external
QUnit.test('Set#some', assert => {
  const { some } = Set.prototype;

  assert.isFunction(some);
  assert.arity(some, 1);
  assert.name(some, 'some');
  assert.nonEnumerable(Set.prototype, 'some');

  const set = new Set([1]);
  const context = {};
  set.some(function (value, key, that) {
    assert.same(arguments.length, 3, 'correct number of callback arguments');
    assert.same(value, 1, 'correct value in callback');
    assert.same(key, 1, 'correct key in callback');
    assert.same(that, set, 'correct link to set in callback');
    assert.same(this, context, 'correct callback context');
  }, context);

  assert.same(new Set([1, 2, 3]).some(it => typeof it === 'number'), true);
  assert.same(new Set(['1', '2', '3']).some(it => typeof it === 'number'), false);
  assert.same(new Set([1, '2', 3]).some(it => typeof it === 'number'), true);
  assert.same(new Set().some(it => typeof it === 'number'), false);

  assert.throws(() => some.call({}, () => { /* empty */ }), TypeError);
  assert.throws(() => some.call(undefined, () => { /* empty */ }), TypeError);
github zloirock / core-js / tests / pure / esnext.set.find.js View on Github external
QUnit.test('Set#find', assert => {
  const { find } = Set.prototype;

  assert.isFunction(find);
  assert.arity(find, 1);
  assert.name(find, 'find');
  assert.nonEnumerable(Set.prototype, 'find');

  const set = new Set([1]);
  const context = {};
  set.find(function (value, key, that) {
    assert.same(arguments.length, 3, 'correct number of callback arguments');
    assert.same(value, 1, 'correct value in callback');
    assert.same(key, 1, 'correct key in callback');
    assert.same(that, set, 'correct link to set in callback');
    assert.same(this, context, 'correct callback context');
  }, context);

  assert.same(new Set([2, 3, 4]).find(it => it % 2), 3);
  assert.same(new Set().find(it => it === 42), undefined);

  assert.throws(() => find.call({}, () => { /* empty */ }), TypeError);
  assert.throws(() => find.call(undefined, () => { /* empty */ }), TypeError);
  assert.throws(() => find.call(null, () => { /* empty */ }), TypeError);
});
github zloirock / core-js / tests / pure / esnext.set.filter.js View on Github external
assert.name(filter, 'filter');
  assert.nonEnumerable(Set.prototype, 'filter');

  const set = new Set([1]);
  const context = {};
  set.filter(function (value, key, that) {
    assert.same(arguments.length, 3, 'correct number of callback arguments');
    assert.same(value, 1, 'correct value in callback');
    assert.same(key, 1, 'correct key in callback');
    assert.same(that, set, 'correct link to set in callback');
    assert.same(this, context, 'correct callback context');
  }, context);

  assert.ok(new Set().filter(it => it) instanceof Set);

  assert.deepEqual(from(new Set([1, 2, 3, 'q', {}, 4, true, 5]).filter(it => typeof it === 'number')), [1, 2, 3, 4, 5]);

  assert.throws(() => filter.call({}, () => { /* empty */ }), TypeError);
  assert.throws(() => filter.call(undefined, () => { /* empty */ }), TypeError);
  assert.throws(() => filter.call(null, () => { /* empty */ }), TypeError);
});
github zloirock / core-js / tests / pure / esnext.set.difference.js View on Github external
QUnit.test('Set#difference', assert => {
  const { difference } = Set.prototype;

  assert.isFunction(difference);
  assert.arity(difference, 1);
  assert.name(difference, 'difference');
  assert.nonEnumerable(Set.prototype, 'difference');

  const set = new Set([1]);
  assert.ok(set.difference([2]) !== set);

  assert.deepEqual(from(new Set([1, 2, 3]).difference([4, 5])), [1, 2, 3]);
  assert.deepEqual(from(new Set([1, 2, 3]).difference([3, 4])), [1, 2]);
  assert.deepEqual(from(new Set([1, 2, 3]).difference(createIterable([3, 4]))), [1, 2]);

  assert.throws(() => new Set([1, 2, 3]).difference(), TypeError);

  assert.throws(() => difference.call({}, [1, 2, 3]), TypeError);
  assert.throws(() => difference.call(undefined, [1, 2, 3]), TypeError);
  assert.throws(() => difference.call(null, [1, 2, 3]), TypeError);
});
github zloirock / core-js / tests / pure / esnext.set.union.js View on Github external
QUnit.test('Set#union', assert => {
  const { union } = Set.prototype;

  assert.isFunction(union);
  assert.arity(union, 1);
  assert.name(union, 'union');
  assert.nonEnumerable(Set.prototype, 'union');

  const set = new Set([1]);
  assert.ok(set.union([2]) !== set);

  assert.deepEqual(from(new Set([1, 2, 3]).union([4, 5])), [1, 2, 3, 4, 5]);
  assert.deepEqual(from(new Set([1, 2, 3]).union([3, 4])), [1, 2, 3, 4]);
  assert.deepEqual(from(new Set([1, 2, 3]).union(createIterable([3, 4]))), [1, 2, 3, 4]);

  assert.throws(() => new Set([1, 2, 3]).union(), TypeError);

  assert.throws(() => union.call({}, [1, 2, 3]), TypeError);
  assert.throws(() => union.call(undefined, [1, 2, 3]), TypeError);
  assert.throws(() => union.call(null, [1, 2, 3]), TypeError);
});
github zloirock / core-js / tests / pure / esnext.set.is-superset-of.js View on Github external
QUnit.test('Set#isSupersetOf', assert => {
  const { isSupersetOf } = Set.prototype;

  assert.isFunction(isSupersetOf);
  assert.arity(isSupersetOf, 1);
  assert.name(isSupersetOf, 'isSupersetOf');
  assert.nonEnumerable(Set.prototype, 'isSupersetOf');

  assert.ok(new Set([1, 2, 3]).isSupersetOf([1]));
  assert.ok(!new Set([2, 3, 4]).isSupersetOf([1]));
  assert.ok(new Set([5, 4, 3, 2, 1]).isSupersetOf([1, 2, 3]));
  assert.ok(!new Set([5, 4, 3, 2]).isSupersetOf([1, 2, 3]));

  assert.ok(new Set([1, 2, 3]).isSupersetOf(createIterable([1])));
  assert.ok(!new Set([2, 3, 4]).isSupersetOf(createIterable([1])));

  assert.throws(() => new Set([1, 2, 3]).isSupersetOf(), TypeError);
  assert.throws(() => isSupersetOf.call({}, [1, 2, 3]), TypeError);
  assert.throws(() => isSupersetOf.call(undefined, [1, 2, 3]), TypeError);
  assert.throws(() => isSupersetOf.call(null, [1, 2, 3]), TypeError);
});
github zloirock / core-js / tests / pure / esnext.set.symmetric-difference.js View on Github external
  assert.throws(() => new Set([1, 2, 3]).symmetricDifference(), TypeError);
github zloirock / core-js / tests / pure / esnext.set.reduce.js View on Github external
assert.isFunction(reduce);
  assert.arity(reduce, 1);
  assert.name(reduce, 'reduce');
  assert.nonEnumerable(Set.prototype, 'reduce');

  const set = new Set([1]);
  const accumulator = {};
  set.reduce(function (memo, value, key, that) {
    assert.same(arguments.length, 4, 'correct number of callback arguments');
    assert.same(memo, accumulator, 'correct callback accumulator');
    assert.same(value, 1, 'correct value in callback');
    assert.same(key, 1, 'correct index in callback');
    assert.same(that, set, 'correct link to set in callback');
  }, accumulator);

  assert.same(new Set([1, 2, 3]).reduce(((a, b) => a + b), 1), 7, 'works with initial accumulator');

  new Set([1, 2]).reduce((memo, value, key) => {
    assert.same(memo, 1, 'correct default accumulator');
    assert.same(value, 2, 'correct start value without initial accumulator');
    assert.same(key, 2, 'correct start index without initial accumulator');
  });

  assert.same(new Set([1, 2, 3]).reduce((a, b) => a + b), 6, 'works without initial accumulator');

  let values = '';
  let keys = '';
  new Set([1, 2, 3]).reduce((memo, value, key, s) => {
    s.delete(2);
    values += value;
    keys += key;
  }, 0);