How to use the core-js-pure/features/map 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.map.find-key.js View on Github external
QUnit.test('Map#findKey', assert => {
  const { findKey } = Map.prototype;

  assert.isFunction(findKey);
  assert.arity(findKey, 1);
  assert.nonEnumerable(Map.prototype, 'findKey');

  const set = new Map([[1, 2]]);
  const context = {};
  set.findKey(function (value, key, that) {
    assert.same(arguments.length, 3, 'correct number of callback arguments');
    assert.same(value, 2, '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 Map([[1, 2], [2, 3], [3, 4]]).findKey(it => it % 2), 2);
  assert.same(new Map().findKey(it => it === 42), undefined);

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

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

  const set = new Map([[1, 2]]);
  const context = {};
  set.find(function (value, key, that) {
    assert.same(arguments.length, 3, 'correct number of callback arguments');
    assert.same(value, 2, '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 Map([[1, 2], [2, 3], [3, 4]]).find(it => it % 2), 3);
  assert.same(new Map().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.map.delete-all.js View on Github external
assert.arity(deleteAll, 0);
  assert.nonEnumerable(Map.prototype, 'deleteAll');

  let set = new Map([[1, 2], [2, 3], [3, 4]]);
  assert.same(set.deleteAll(1, 2), true);
  assert.deepEqual(from(set), [[3, 4]]);

  set = new Map([[1, 2], [2, 3], [3, 4]]);
  assert.same(set.deleteAll(3, 4), false);
  assert.deepEqual(from(set), [[1, 2], [2, 3]]);

  set = new Map([[1, 2], [2, 3], [3, 4]]);
  assert.same(set.deleteAll(4, 5), false);
  assert.deepEqual(from(set), [[1, 2], [2, 3], [3, 4]]);

  set = new Map([[1, 2], [2, 3], [3, 4]]);
  assert.same(set.deleteAll(), true);
  assert.deepEqual(from(set), [[1, 2], [2, 3], [3, 4]]);

  assert.notThrows(() => !deleteAll.call({ delete() { /* empty */ } }, 1, 2, 3));
  assert.throws(() => deleteAll.call({}, 1, 2, 3), TypeError);
  assert.throws(() => deleteAll.call(undefined, 1, 2, 3), TypeError);
  assert.throws(() => deleteAll.call(null, 1, 2, 3), TypeError);
});
github zloirock / core-js / tests / pure / esnext.map.some.js View on Github external
const { some } = Map.prototype;
  assert.isFunction(some);
  assert.arity(some, 1);
  assert.name(some, 'some');
  assert.nonEnumerable(Map.prototype, 'some');

  let map = new Map([[9, 1]]);
  const context = {};
  map.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, 9, 'correct index in callback');
    assert.same(that, map, 'correct link to map in callback');
    assert.same(this, context, 'correct callback context');
  }, context);
  map = new Map([[0, 1], [1, '2'], [2, 3]]);
  assert.ok(map.some(it => typeof it === 'number'));
  assert.ok(map.some(it => it < 3));
  assert.ok(!map.some(it => it < 0));
  assert.ok(map.some(it => typeof it === 'string'));
  assert.ok(!map.some(function () {
    return +this !== 1;
  }, 1));
  let result = '';
  map.some((value, key) => {
    result += key;
    return false;
  });
  assert.same(result, '012');
  assert.ok(map.some((value, key, that) => that === map));

  assert.throws(() => some.call({}, () => { /* empty */ }), TypeError);
github zloirock / core-js / tests / pure / esnext.map.upsert.js View on Github external
}, () => {
    assert.ok(false, 'should not be called');
    return 3;
  }), 4, 'returns a correct value');
  assert.same(map.upsert('b', value => {
    assert.ok(false, 'should not be called');
    return value ** 2;
  }, function () {
    assert.same(arguments.length, 0, 'correct number of callback arguments');
    return 3;
  }), 3, 'returns a correct value');
  assert.same(map.size, 2, 'correct size');
  assert.same(map.get('a'), 4, 'correct result #1');
  assert.same(map.get('b'), 3, 'correct result #2');

  assert.same(new Map([['a', 2]]).upsert('b', null, () => 3), 3);
  assert.same(new Map([['a', 2]]).upsert('a', value => value ** 2), 4);

  assert.throws(() => new Map().upsert('a'), TypeError);
  assert.throws(() => upsert.call({}, 'a', () => { /* empty */ }, () => { /* empty */ }), TypeError);
  assert.throws(() => upsert.call([], 'a', () => { /* empty */ }, () => { /* empty */ }), TypeError);
  assert.throws(() => upsert.call(undefined, 'a', () => { /* empty */ }, () => { /* empty */ }), TypeError);
  assert.throws(() => upsert.call(null, 'a', () => { /* empty */ }, () => { /* empty */ }), TypeError);
});
github zloirock / core-js / tests / pure / esnext.map.update.js View on Github external
  assert.throws(() => new Map().update(9, () => { /* empty */ }), TypeError);
github zloirock / core-js / tests / pure / esnext.map.some.js View on Github external
QUnit.test('Map#some', assert => {
  const { some } = Map.prototype;
  assert.isFunction(some);
  assert.arity(some, 1);
  assert.name(some, 'some');
  assert.nonEnumerable(Map.prototype, 'some');

  let map = new Map([[9, 1]]);
  const context = {};
  map.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, 9, 'correct index in callback');
    assert.same(that, map, 'correct link to map in callback');
    assert.same(this, context, 'correct callback context');
  }, context);
  map = new Map([[0, 1], [1, '2'], [2, 3]]);
  assert.ok(map.some(it => typeof it === 'number'));
  assert.ok(map.some(it => it < 3));
  assert.ok(!map.some(it => it < 0));
  assert.ok(map.some(it => typeof it === 'string'));
  assert.ok(!map.some(function () {
    return +this !== 1;
  }, 1));
github zloirock / core-js / tests / pure / esnext.map.update.js View on Github external
QUnit.test('Map#update', assert => {
  const { update } = Map.prototype;
  assert.isFunction(update);
  assert.arity(update, 2);
  assert.name(update, 'update');
  assert.nonEnumerable(Map.prototype, 'update');

  let map = new Map([[9, 2]]);
  assert.same(map.update(9, function (value, key, that) {
    assert.same(arguments.length, 3, 'correct number of callback arguments');
    assert.same(value, 2, 'correct value in callback');
    assert.same(key, 9, 'correct key in callback');
    assert.same(that, map, 'correct link to map in callback');
    return value * 2;
  }), map, 'returns this');
  assert.same(map.size, 1, 'correct size');
  assert.same(map.get(9), 4, 'correct result');
  map = new Map([[4, 5]]);
  map.update(9, function (value, key, that) {
    assert.same(arguments.length, 3, 'correct number of callback arguments');
    assert.same(value, 2, 'correct value in callback');
    assert.same(key, 9, 'correct key in callback');
    assert.same(that, map, 'correct link to map in callback');
    return value * 2;
github zloirock / core-js / tests / pure / esnext.map.reduce.js View on Github external
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, 'a', 'correct index in callback');
    assert.same(that, set, 'correct link to set in callback');
  }, accumulator);

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

  new Map([
    ['a', 1],
    ['b', 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, 'b', 'correct start index without initial accumulator');
  });

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

  let values = '';
  let keys = '';
github zloirock / core-js / tests / pure / esnext.map.reduce.js View on Github external
assert.same(new Map([
    ['a', 1],
    ['b', 2],
    ['c', 3],
  ]).reduce(((a, b) => a + b), 1), 7, 'works with initial accumulator');

  new Map([
    ['a', 1],
    ['b', 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, 'b', 'correct start index without initial accumulator');
  });

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

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