core-js-ie8

    2.0.3 • Public • Published

    core-js

    Gitter version npm downloads Build Status devDependency status

    Modular standard library for JavaScript. Includes polyfills for ECMAScript 5, ECMAScript 6: promises, symbols, collections, iterators, typed arrays, ECMAScript 7+ proposals, setImmediate, etc. Some additional features such as dictionaries or extended partial application. You can require only needed features or use it without global namespace pollution.

    Example:

    Array.from(new Set([1, 2, 3, 2, 1]));          // => [1, 2, 3]
    '*'.repeat(10);                                // => '**********'
    Promise.resolve(32).then(x => console.log(x)); // => 32
    setImmediate(x => console.log(x), 42);         // => 42

    Without global namespace pollution:

    var core = require('core-js/library'); // With a modular system, otherwise use global `core`
    core.Array.from(new core.Set([1, 2, 3, 2, 1]));     // => [1, 2, 3]
    core.String.repeat('*', 10);                        // => '**********'
    core.Promise.resolve(32).then(x => console.log(x)); // => 32
    core.setImmediate(x => console.log(x), 42);         // => 42

    Usage

    Basic

    npm i core-js
    bower install core.js
    
    // Default
    require('core-js');
    // Without global namespace pollution
    var core = require('core-js/library');
    // Shim only
    require('core-js/shim');

    If you need complete build for browser, use builds from core-js/client path:

    Warning: if you use core-js with the extension of native objects, require all needed core-js modules at the beginning of entry point of your application, otherwise, conflicts may occur.

    CommonJS

    You can require only needed modules.

    require('core-js/es5'); // if you need support IE8-
    require('core-js/fn/set');
    require('core-js/fn/array/from');
    require('core-js/fn/array/find-index');
    Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
    [1, 2, NaN, 3, 4].findIndex(isNaN);   // => 2
     
    // or, w/o global namespace pollution:
     
    var core      = require('core-js/library/es5'); // if you need support IE8-
    var Set       = require('core-js/library/fn/set');
    var from      = require('core-js/library/fn/array/from');
    var findIndex = require('core-js/library/fn/array/find-index');
    from(new Set([1, 2, 3, 2, 1]));      // => [1, 2, 3]
    findIndex([1, 2, NaN, 3, 4], isNaN); // => 2

    Available entry points for methods / constructors, as above examples, excluding features from es5 module (this module requires completely in ES3 environment before all other modules).

    Available namespaces: for example, core-js/es6/array (core-js/library/es6/array) contains all ES6 Array features, core-js/es6 (core-js/library/es6) contains all ES6 features.

    Caveats when using CommonJS API:
    • modules path is internal API, does not inject all required dependencies and can be changed in minor or patch releases. Use it only for a custom build and / or if you know what are you doing.
    • core-js is extremely modular and uses a lot of very tiny modules, because of that for usage in browsers bundle up core-js instead of usage loader for each file, otherwise, you will have hundreds of requests.

    CommonJS and prototype methods without global namespace pollution

    In the library version, we can't pollute prototypes of native constructors. Because of that, prototype methods transformed to static methods like in examples above. babel runtime transformer also can't transform them. But with transpilers we can use one more trick - bind operator and virtual methods. Special for that, available /virtual/ entry points. Example:

    import fill from 'core-js/library/fn/array/virtual/fill';
    import findIndex from 'core-js/library/fn/array/virtual/find-index';
     
    Array(10)::fill(0).map((a, b) => b * b)::findIndex(it => it && !(it % 8)); // => 4
     
    // or
     
    import {fill, findIndex} from 'core-js/library/fn/array/virtual';
     
    Array(10)::fill(0).map((a, b) => b * b)::findIndex(it => it && !(it % 8)); // => 4
     

    Custom build (from the command-line)

    npm i core-js && cd node_modules/core-js && npm i
    npm run grunt build:core.dict,es6 -- --blacklist=es6.promise,es6.math --library=on --path=custom uglify
    

    Where core.dict and es6 are modules (namespaces) names, which will be added to the build, es6.promise and es6.math are modules (namespaces) names, which will be excluded from the build, --library=on is flag for build without global namespace pollution and custom is target file name.

    Available namespaces: for example, es6.array contains ES6 Array features, es6 contains all modules whose names start with es6.

    Custom build (from external scripts)

    core-js-builder package exports a function that takes the same parameters as the build target from the previous section. This will conditionally include or exclude certain parts of core-js:

    require('core-js-builder')({
      modules: ['es6', 'core.dict'], // modules / namespaces
      blacklist: ['es6.reflect'],    // blacklist of modules / namespaces, by default - empty list
      library: false,                // flag for build without global namespace pollution, by default - false
    }).then(code => {
      // ...
    }).catch(error => {
      // ...
    });

    Supported engines

    Tested in:

    • Chrome 26+
    • Firefox 4+
    • Safari 5+
    • Opera 12+
    • Internet Explorer 6+ (sure, IE8- with ES3 limitations)
    • Edge
    • Android Browser 2.3+
    • iOS Safari 5.1+
    • PhantomJS 1.9
    • NodeJS 0.8+

    ...and it doesn't mean core-js will not work in other engines, they just have not been tested.

    Features:

    CommonJS entry points:

    core-js(/library)       <- all features
    core-js(/library)/shim  <- only polyfills
    

    ECMAScript 5

    Module es5, nothing new - without examples.

    Object
      .create(proto | null, descriptors?-> object
      .getPrototypeOf(object) -> proto | null
      .defineProperty(target, key, desc) -> target, cap for ie8-
      .defineProperties(target, descriptors) -> target, cap for ie8-
      .getOwnPropertyDescriptor(object, key) -> desc
      .getOwnPropertyNames(object) -> array
      .keys(object) -> array
    Array
      .isArray(var) -> bool
      #slice(start?, end?-> array, fix for ie7-
      #join(string = ',') -> string, fix for ie7-
      #indexOf(var, from?-> int
      #lastIndexOf(var, from?-> int
      #every(fn(val, index, @), that) -> bool
      #some(fn(val, index, @), that) -> bool
      #forEach(fn(val, index, @), that) -> void
      #map(fn(val, index, @), that) -> array
      #filter(fn(val, index, @), that) -> array
      #reduce(fn(memo, val, index, @), memo?-> var
      #reduceRight(fn(memo, val, index, @), memo?-> var
    Function
      #bind(object, ...args) -> boundFn(...args)
    Date
      .now() -> int
      #toISOString() -> string

    Some features moved to another modules / namespaces, but available as part of es5 namespace too:

    Object
      .seal(object) -> object, cap for ie8-
      .freeze(object) -> object, cap for ie8-
      .preventExtensions(object) -> object, cap for ie8-
      .isSealed(object) -> bool, cap for ie8-
      .isFrozen(object) -> bool, cap for ie8-
      .isExtensible(object) -> bool, cap for ie8-
    String
      #trim() -> str

    CommonJS entry points:

    core-js(/library)/es5
    

    ECMAScript 6

    CommonJS entry points:

    core-js(/library)/es6
    

    ECMAScript 6: Object

    Modules es6.object.assign, es6.object.is, es6.object.set-prototype-of and es6.object.to-string.

    In ES6 most Object static methods should work with primitives. Modules es6.object.freeze, es6.object.seal, es6.object.prevent-extensions, es6.object.is-frozen, es6.object.is-sealed, es6.object.is-extensible, es6.object.get-own-property-descriptor, es6.object.get-prototype-of, es6.object.keys, es6.object.get-own-property-names.

    Object
      .assign(target, ...src) -> target
      .is(a, b) -> bool
      .setPrototypeOf(target, proto | null) -> target (required __proto__ - IE11+)
      .freeze(var) -> var
      .seal(var) -> var
      .preventExtensions(var) -> var
      .isFrozen(var) -> bool
      .isSealed(var) -> bool
      .isExtensible(var) -> bool
      .getOwnPropertyDescriptor(var, key) -> desc | undefined
      .getPrototypeOf(var) -> object | null
      .keys(var) -> array
      .getOwnPropertyNames(var) -> array
      #toString() -> string, ES6 fix: @@toStringTag support

    CommonJS entry points:

    core-js(/library)/es6/object
    core-js(/library)/fn/object/assign
    core-js(/library)/fn/object/is
    core-js(/library)/fn/object/set-prototype-of
    core-js(/library)/fn/object/freeze
    core-js(/library)/fn/object/seal
    core-js(/library)/fn/object/prevent-extensions
    core-js(/library)/fn/object/is-frozen
    core-js(/library)/fn/object/is-sealed
    core-js(/library)/fn/object/is-extensible
    core-js(/library)/fn/object/get-own-property-descriptor
    core-js(/library)/fn/object/get-prototype-of
    core-js(/library)/fn/object/keys
    core-js(/library)/fn/object/get-own-property-names
    core-js/fn/object/to-string
    

    Examples:

    var foo = {q: 1, w: 2}
      , bar = {e: 3, r: 4}
      , baz = {t: 5, y: 6};
    Object.assign(foo, bar, baz); // => foo = {q: 1, w: 2, e: 3, r: 4, t: 5, y: 6}
     
    Object.is(NaN, NaN); // => true
    Object.is(0, -0);    // => false
    Object.is(42, 42);   // => true
    Object.is(42, '42'); // => false
     
    function Parent(){}
    function Child(){}
    Object.setPrototypeOf(Child.prototype, Parent.prototype);
    new Child instanceof Child;  // => true
    new Child instanceof Parent; // => true
     
    var O = {};
    O[Symbol.toStringTag] = 'Foo';
    '' + O; // => '[object Foo]'
     
    Object.keys('qwe'); // => ['0', '1', '2']
    Object.getPrototypeOf('qwe') === String.prototype; // => true

    ECMAScript 6: Function

    Modules es6.function.name and es6.function.has-instance.

    Function
      #name -> string (IE9+)
      #@@hasInstance(var) -> bool

    CommonJS entry points:

    core-js/es6/function
    core-js/fn/function/name
    core-js/fn/function/has-instance
    

    Example:

    (function foo(){}).name // => 'foo'

    ECMAScript 6: Array

    Modules es6.array.from, es6.array.of, es6.array.copy-within, es6.array.fill, es6.array.find, es6.array.find-index and es6.array.iterator.

    Array
      .from(iterable | array-like, mapFn(val, index)?, that) -> array
      .of(...args) -> array
      #copyWithin(target = 0, start = 0, end = @length) -> @
      #fill(val, start = 0, end = @length) -> @
      #find(fn(val, index, @), that) -> val
      #findIndex(fn(val, index, @), that) -> index
      #values() -> iterator
      #keys() -> iterator
      #entries() -> iterator
      #@@iterator() -> iterator (values)
      #@@unscopables -> object (cap)
    Arguments
      #@@iterator() -> iterator (values, available only in core-js methods)

    CommonJS entry points:

    core-js(/library)/es6/array
    core-js(/library)/fn/array/from
    core-js(/library)/fn/array/of
    core-js(/library)/fn/array/copy-within
    core-js(/library)/fn/array/fill
    core-js(/library)/fn/array/find
    core-js(/library)/fn/array/find-index
    core-js(/library)/fn/array/values
    core-js(/library)/fn/array/keys
    core-js(/library)/fn/array/entries
    core-js(/library)/fn/array/iterator
    core-js(/library)/fn/array/virtual/copy-within
    core-js(/library)/fn/array/virtual/fill
    core-js(/library)/fn/array/virtual/find
    core-js(/library)/fn/array/virtual/find-index
    core-js(/library)/fn/array/virtual/values
    core-js(/library)/fn/array/virtual/keys
    core-js(/library)/fn/array/virtual/entries
    core-js(/library)/fn/array/virtual/iterator
    

    Examples:

    Array.from(new Set([1, 2, 3, 2, 1]));      // => [1, 2, 3]
    Array.from({0: 1, 1: 2, 2: 3, length: 3}); // => [1, 2, 3]
    Array.from('123', Number);                 // => [1, 2, 3]
    Array.from('123', function(it){
      return it * it;
    });                                        // => [1, 4, 9]
     
    Array.of(1);       // => [1]
    Array.of(1, 2, 3); // => [1, 2, 3]
     
    var array = ['a', 'b', 'c'];
     
    for(var val of array)console.log(val);          // => 'a', 'b', 'c'
    for(var val of array.values())console.log(val); // => 'a', 'b', 'c'
    for(var key of array.keys())console.log(key);   // => 0, 1, 2
    for(var [key, val] of array.entries()){
      console.log(key);                             // => 0, 1, 2
      console.log(val);                             // => 'a', 'b', 'c'
    }
     
    function isOdd(val){
      return val % 2;
    }
    [4, 8, 15, 16, 23, 42].find(isOdd);      // => 15
    [4, 8, 15, 16, 23, 42].findIndex(isOdd); // => 2
    [4, 8, 15, 16, 23, 42].find(isNaN);      // => undefined
    [4, 8, 15, 16, 23, 42].findIndex(isNaN); // => -1
     
    Array(5).fill(42); // => [42, 42, 42, 42, 42]
     
    [1, 2, 3, 4, 5].copyWithin(0, 3); // => [4, 5, 3, 4, 5]

    ECMAScript 6: String

    Modules es6.string.from-code-point, es6.string.raw, es6.string.iterator, es6.string.code-point-at, es6.string.ends-with, es6.string.includes, es6.string.repeat, es6.string.starts-with and es6.string.trim.

    Annex B HTML methods. Ugly, but it's also the part of the spec. Modules es6.string.anchor, es6.string.big, es6.string.blink, es6.string.bold, es6.string.fixed, es6.string.fontcolor, es6.string.fontsize, es6.string.italics, es6.string.link, es6.string.small, es6.string.strike, es6.string.sub and es6.string.sup.

    String
      .fromCodePoint(...codePoints) -> str
      .raw({raw}, ...substitutions) -> str
      #includes(str, from?-> bool
      #startsWith(str, from?-> bool
      #endsWith(str, from?-> bool
      #repeat(num) -> str
      #codePointAt(pos) -> uint
      #trim() -> str, ES6 fix
      #anchor(name)     -> str
      #big()            -> str
      #blink()          -> str
      #bold()           -> str
      #fixed()          -> str
      #fontcolor(color) -> str
      #fontsize(size)   -> str
      #italics()        -> str
      #link(url)        -> str
      #small()          -> str
      #strike()         -> str
      #sub()            -> str
      #sup()            -> str
      #@@iterator() -> iterator (code points)

    CommonJS entry points:

    core-js(/library)/es6/string
    core-js(/library)/fn/string/from-code-point
    core-js(/library)/fn/string/raw
    core-js(/library)/fn/string/includes
    core-js(/library)/fn/string/starts-with
    core-js(/library)/fn/string/ends-with
    core-js(/library)/fn/string/repeat
    core-js(/library)/fn/string/code-point-at
    core-js(/library)/fn/string/trim
    core-js(/library)/fn/string/anchor
    core-js(/library)/fn/string/big
    core-js(/library)/fn/string/blink
    core-js(/library)/fn/string/bold
    core-js(/library)/fn/string/fixed
    core-js(/library)/fn/string/fontcolor
    core-js(/library)/fn/string/fontsize
    core-js(/library)/fn/string/italics
    core-js(/library)/fn/string/link
    core-js(/library)/fn/string/small
    core-js(/library)/fn/string/strike
    core-js(/library)/fn/string/sub
    core-js(/library)/fn/string/sup
    core-js(/library)/fn/string/iterator
    core-js(/library)/fn/string/virtual/includes
    core-js(/library)/fn/string/virtual/starts-with
    core-js(/library)/fn/string/virtual/ends-with
    core-js(/library)/fn/string/virtual/repeat
    core-js(/library)/fn/string/virtual/code-point-at
    core-js(/library)/fn/string/virtual/trim
    core-js(/library)/fn/string/virtual/anchor
    core-js(/library)/fn/string/virtual/big
    core-js(/library)/fn/string/virtual/blink
    core-js(/library)/fn/string/virtual/bold
    core-js(/library)/fn/string/virtual/fixed
    core-js(/library)/fn/string/virtual/fontcolor
    core-js(/library)/fn/string/virtual/fontsize
    core-js(/library)/fn/string/virtual/italics
    core-js(/library)/fn/string/virtual/link
    core-js(/library)/fn/string/virtual/small
    core-js(/library)/fn/string/virtual/strike
    core-js(/library)/fn/string/virtual/sub
    core-js(/library)/fn/string/virtual/sup
    core-js(/library)/fn/string/virtual/iterator
    

    Examples:

    for(var val of 'a𠮷b'){
      console.log(val); // => 'a', '𠮷', 'b'
    }
     
    'foobarbaz'.includes('bar');      // => true
    'foobarbaz'.includes('bar', 4);   // => false
    'foobarbaz'.startsWith('foo');    // => true
    'foobarbaz'.startsWith('bar', 3); // => true
    'foobarbaz'.endsWith('baz');      // => true
    'foobarbaz'.endsWith('bar', 6);   // => true
     
    'string'.repeat(3); // => 'stringstringstring'
     
    '𠮷'.codePointAt(0); // => 134071
    String.fromCodePoint(97, 134071, 98); // => 'a𠮷b'
     
    var name = 'Bob';
    String.raw`Hi\n${name}!`;           // => 'Hi\\nBob!' (ES6 template string syntax)
    String.raw({raw: 'test'}, 0, 1, 2); // => 't0e1s2t'
     
    'foo'.bold();                     // => '<b>foo</b>'
    'bar'.anchor('a"b');              // => '<a name="a&quot;b">bar</a>'
    'baz'.link('http://example.com'); // => '<a href="http://example.com">baz</a>'

    ECMAScript 6: RegExp

    Modules es6.regexp.constructor and es6.regexp.flags.

    Support well-known symbols @@match, @@replace, @@search and @@split, modules es6.regexp.match, es6.regexp.replace, es6.regexp.search and es6.regexp.split.

    [new] RegExp(pattern, flags?) -> regexp, ES6 fix: can alter flags (IE9+)
      #flags -> str (IE9+)
      #@@match(str)             -> array | null
      #@@replace(str, replacer) -> string
      #@@search(str)            -> index
      #@@split(str, limit)      -> array
    String
      #match(tpl)             -> var, ES6 fix for support @@match
      #replace(tpl, replacer) -> var, ES6 fix for support @@replace
      #search(tpl)            -> var, ES6 fix for support @@search
      #split(tpl, limit)      -> var, ES6 fix for support @@split
    

    CommonJS entry points:

    core-js/es6/regexp
    core-js/fn/regexp/constructor
    core-js(/library)/fn/regexp/flags
    core-js/fn/regexp/match
    core-js/fn/regexp/replace
    core-js/fn/regexp/search
    core-js/fn/regexp/split
    

    Examples:

    RegExp(/./g, 'm'); // => /./m
     
    /foo/.flags;    // => ''
    /foo/gim.flags; // => 'gim'
     
    'foo'.match({[Symbol.match]: _ => 1});     // => 1
    'foo'.replace({[Symbol.replace]: _ => 2}); // => 2
    'foo'.search({[Symbol.search]: _ => 3});   // => 3
    'foo'.split({[Symbol.split]: _ => 4});     // => 4

    ECMAScript 6: Number

    Module es6.number.constructor. Number constructor support binary and octal literals, example:

    Number('0b1010101'); // => 85
    Number('0o7654321'); // => 2054353

    Number: modules es6.number.epsilon, es6.number.is-finite, es6.number.is-integer, es6.number.is-nan, es6.number.is-safe-integer, es6.number.max-safe-integer, es6.number.min-safe-integer, es6.number.parse-float, es6.number.parse-int.

    [new] Number(var) -> number | number object
      .isFinite(num) -> bool
      .isNaN(num)    -> bool
      .isInteger(num)     -> bool
      .isSafeInteger(num) -> bool
      .parseFloat(str) -> num
      .parseInt(str)   -> int
      .EPSILON          -> num
      .MAX_SAFE_INTEGER -> int
      .MIN_SAFE_INTEGER -> int

    CommonJS entry points:

    core-js(/library)/es6/number
    core-js(/library)/fn/number/is-finite
    core-js(/library)/fn/number/is-nan
    core-js(/library)/fn/number/is-integer
    core-js(/library)/fn/number/is-safe-integer
    core-js(/library)/fn/number/parse-float
    core-js(/library)/fn/number/parse-int
    core-js(/library)/fn/number/epsilon
    core-js(/library)/fn/number/max-safe-integer
    core-js(/library)/fn/number/min-safe-integer
    core-js/es6/number/constructor
    

    ECMAScript 6: Math

    Math: modules es6.math.acosh, es6.math.asinh, es6.math.atanh, es6.math.cbrt, es6.math.clz32, es6.math.cosh, es6.math.expm1, es6.math.fround, es6.math.hypot, es6.math.imul, es6.math.log10, es6.math.log1p, es6.math.log2, es6.math.sign, es6.math.sinh, es6.math.tanh, es6.math.trunc.

    Math
      .acosh(num)     -> num
      .asinh(num)     -> num
      .atanh(num)     -> num
      .cbrt(num)      -> num
      .clz32(num)     -> uint
      .cosh(num)      -> num
      .expm1(num)     -> num
      .fround(num)    -> num
      .hypot(...args) -> num
      .imul(num, num) -> int
      .log1p(num)     -> num
      .log10(num)     -> num
      .log2(num)      -> num
      .sign(num)      -> 1 | -1 | 0 | -0 | NaN
      .sinh(num)      -> num
      .tanh(num)      -> num
      .trunc(num)     -> num

    CommonJS entry points:

    core-js(/library)/es6/math
    core-js(/library)/fn/math/acosh
    core-js(/library)/fn/math/asinh
    core-js(/library)/fn/math/atanh
    core-js(/library)/fn/math/cbrt
    core-js(/library)/fn/math/clz32
    core-js(/library)/fn/math/cosh
    core-js(/library)/fn/math/expm1
    core-js(/library)/fn/math/fround
    core-js(/library)/fn/math/hypot
    core-js(/library)/fn/math/imul
    core-js(/library)/fn/math/log1p
    core-js(/library)/fn/math/log10
    core-js(/library)/fn/math/log2
    core-js(/library)/fn/math/sign
    core-js(/library)/fn/math/sinh
    core-js(/library)/fn/math/tanh
    core-js(/library)/fn/math/trunc
    

    ECMAScript 6: Date

    Currently - only one little fix for Date#toString. Module es6.date.to-string:

    Date
      #toString() -> str

    CommonJS entry points:

    core-js/es6/date
    core-js/fn/date/to-string
    

    Example:

    new Date(NaN).toString(); // => 'Invalid Date'

    ECMAScript 6: Promise

    Module es6.promise.

    new Promise(executor(resolve(var), reject(var))) -> promise
      #then(resolved(var), rejected(var)) -> promise
      #catch(rejected(var)) -> promise
      .resolve(var || promise) -> promise
      .reject(var) -> promise
      .all(iterable) -> promise
      .race(iterable) -> promise

    CommonJS entry points:

    core-js(/library)/es6/promise
    core-js(/library)/fn/promise
    

    Basic example:

    function sleepRandom(time){
      return new Promise(function(resolve, reject){
        setTimeout(resolve, time * 1e3, 0 | Math.random() * 1e3);
      });
    }
     
    console.log('Run');                    // => Run
    sleepRandom(5).then(function(result){
      console.log(result);                 // => 869, after 5 sec.
      return sleepRandom(10);
    }).then(function(result){
      console.log(result);                 // => 202, after 10 sec.
    }).then(function(){
      console.log('immediately after');    // => immediately after
      throw Error('Irror!');
    }).then(function(){
      console.log('will not be displayed');
    }).catch(x => console.log(x));         // => => Error: Irror!

    Promise.resolve and Promise.reject example:

    Promise.resolve(42).then(x => console.log(x)); // => 42
    Promise.reject(42).catch(x => console.log(x)); // => 42
     
    Promise.resolve($.getJSON('/data.json')); // => ES6 promise

    Promise.all example:

    Promise.all([
      'foo',
      sleepRandom(5),
      sleepRandom(15),
      sleepRandom(10)             // after 15 sec:
    ]).then(x => console.log(x)); // => ['foo', 956, 85, 382]

    Promise.race example:

    function timeLimit(promise, time){
      return Promise.race([promise, new Promise(function(resolve, reject){
        setTimeout(reject, time * 1e3, Error('Await > ' + time + ' sec'));
      })]);
    }
     
    timeLimit(sleepRandom(5), 10).then(x => console.log(x));   // => 853, after 5 sec.
    timeLimit(sleepRandom(15), 10).catch(x => console.log(x)); // Error: Await > 10 sec

    ECMAScript 7 async functions example:

    var delay = time => new Promise(resolve => setTimeout(resolve, time))
     
    async function sleepRandom(time){
      await delay(time * 1e3);
      return 0 | Math.random() * 1e3;
    };
    async function sleepError(time, msg){
      await delay(time * 1e3);
      throw Error(msg);
    };
     
    (async () => {
      try {
        console.log('Run');                // => Run
        console.log(await sleepRandom(5)); // => 936, after 5 sec.
        var [a, b, c] = await Promise.all([
          sleepRandom(5),
          sleepRandom(15),
          sleepRandom(10)
        ]);
        console.log(a, b, c);              // => 210 445 71, after 15 sec.
        await sleepError(5, 'Irror!');
        console.log('Will not be displayed');
      } catch(e){
        console.log(e);                    // => Error: 'Irror!', after 5 sec.
      }
    })();
    Unhandled rejection tracking

    core-js Promise supports (but not adds to native implementations) unhandled rejection tracking.

    In Node.js, like in native implementation, available events unhandledRejection and rejectionHandled:

    process.on('unhandledRejection', (reason, promise) => console.log('unhandled', reason, promise));
    process.on('rejectionHandled', (promise) => console.log('handled', promise));
     
    var p = Promise.reject(42);
    // unhandled 42 [object Promise]
     
    setTimeout(() => p.catch(_ => _), 1e3);
    // handled [object Promise]

    In a browser on rejection, by default, you will see notify in the console, or you can add a custom handler and a handler on handling unhandled, example:

    window.onunhandledrejection = e => console.log('unhandled', e.reason, e.promise);
    window.onrejectionhandled = e => console.log('handled', e.reason, e.promise);
     
    var p = Promise.reject(42);
    // unhandled 42 [object Promise]
     
    setTimeout(() => p.catch(_ => _), 1e3);
    // handled 42 [object Promise]

    Warning: The problem here - we can't add it to native Promise implementations, but by idea core-js should use enough correct native implementation if it's available. Currently, most native implementations are buggy and core-js uses polyfill, but the situation will be changed. If someone wanna use this hook everywhere - he should delete window.Promise before inclusion core-js.

    ECMAScript 6: Symbol

    Module es6.symbol.

    Symbol(description?-> symbol
      .hasInstance -> @@hasInstance
      .isConcatSpreadable -> @@isConcatSpreadable
      .iterator -> @@iterator
      .match -> @@match
      .replace -> @@replace
      .search -> @@search
      .species -> @@species
      .split -> @@split
      .toPrimitive -> @@toPrimitive
      .toStringTag -> @@toStringTag
      .unscopables -> @@unscopables
      .for(key) -> symbol
      .keyFor(symbol) -> key
      .useSimple() -> void
      .useSetter() -> void
    Object
      .getOwnPropertySymbols(object) -> array

    Also wrapped some methods for correct work with Symbol polyfill.

    Object
      .create(proto | null, descriptors?-> object
      .defineProperty(target, key, desc) -> target
      .defineProperties(target, descriptors) -> target
      .getOwnPropertyDescriptor(var, key) -> desc | undefined
      .getOwnPropertyNames(var) -> array
      #propertyIsEnumerable(key) -> bool
    JSON
      .stringify(target, replacer?, space?-> string | undefined

    CommonJS entry points:

    core-js(/library)/es6/symbol
    core-js(/library)/fn/symbol
    core-js(/library)/fn/symbol/has-instance
    core-js(/library)/fn/symbol/is-concat-spreadable
    core-js(/library)/fn/symbol/iterator
    core-js(/library)/fn/symbol/match
    core-js(/library)/fn/symbol/replace
    core-js(/library)/fn/symbol/search
    core-js(/library)/fn/symbol/species
    core-js(/library)/fn/symbol/split
    core-js(/library)/fn/symbol/to-primitive
    core-js(/library)/fn/symbol/to-string-tag
    core-js(/library)/fn/symbol/unscopables
    core-js(/library)/fn/symbol/for
    core-js(/library)/fn/symbol/key-for
    

    Basic example:

    var Person = (function(){
      var NAME = Symbol('name');
      function Person(name){
        this[NAME] = name;
      }
      Person.prototype.getName = function(){
        return this[NAME];
      };
      return Person;
    })();
     
    var person = new Person('Vasya');
    console.log(person.getName());          // => 'Vasya'
    console.log(person['name']);            // => undefined
    console.log(person[Symbol('name')]);    // => undefined, symbols are uniq
    for(var key in person)console.log(key); // => only 'getName', symbols are not enumerable

    Symbol.for & Symbol.keyFor example:

    var symbol = Symbol.for('key');
    symbol === Symbol.for('key'); // true
    Symbol.keyFor(symbol);        // 'key'

    Example with methods for getting own object keys:

    var O = {a: 1};
    Object.defineProperty(O, 'b', {value: 2});
    O[Symbol('c')] = 3;
    Object.keys(O);                  // => ['a']
    Object.getOwnPropertyNames(O);   // => ['a', 'b']
    Object.getOwnPropertySymbols(O); // => [Symbol(c)]
    Reflect.ownKeys(O);              // => ['a', 'b', Symbol(c)]
    Caveats when using Symbol polyfill:
    • We can't add new primitive type, Symbol returns object.
    • Symbol.for and Symbol.keyFor can't be shimmed cross-realm.
    • By default, to hide the keys, Symbol polyfill defines setter in Object.prototype. For this reason, uncontrolled creation of symbols can cause memory leak and the in operator is not working correctly with Symbol polyfill: Symbol() in {} // => true.

    You can disable defining setters in Object.prototype. Example:

    Symbol.useSimple();
    var s1 = Symbol('s1')
      , o1 = {};
    o1[s1] = true;
    for(var key in o1)console.log(key); // => 'Symbol(s1)_t.qamkg9f3q', w/o native Symbol
     
    Symbol.useSetter();
    var s2 = Symbol('s2')
      , o2 = {};
    o2[s2] = true;
    for(var key in o2)console.log(key); // nothing
    • Currently, core-js not adds setters to Object.prototype for well-known symbols for correct work something like Symbol.iterator in foo. It can cause problems with their enumerability.

    ECMAScript 6: Collections

    core-js uses native collections in most case, just fixes methods / constructor, if it's required, and in old environment uses fast polyfill (O(1) lookup).

    Map

    Module es6.map.

    new Map(iterable (entries) ?-> map
      #clear() -> void
      #delete(key) -> bool
      #forEach(fn(val, key, @), that) -> void
      #get(key) -> val
      #has(key) -> bool
      #set(key, val) -> @
      #size -> uint
      #values() -> iterator
      #keys() -> iterator
      #entries() -> iterator
      #@@iterator() -> iterator (entries)

    CommonJS entry points:

    core-js(/library)/es6/map
    core-js(/library)/fn/map
    

    Examples:

    var a = [1];
     
    var map = new Map([['a', 1], [42, 2]]);
    map.set(a, 3).set(true, 4);
     
    console.log(map.size);        // => 4
    console.log(map.has(a));      // => true
    console.log(map.has([1]));    // => false
    console.log(map.get(a));      // => 3
    map.forEach(function(val, key){
      console.log(val);           // => 1, 2, 3, 4
      console.log(key);           // => 'a', 42, [1], true
    });
    map.delete(a);
    console.log(map.size);        // => 3
    console.log(map.get(a));      // => undefined
    console.log(Array.from(map)); // => [['a', 1], [42, 2], [true, 4]]
     
    var map = new Map([['a', 1], ['b', 2], ['c', 3]]);
     
    for(var [key, val] of map){
      console.log(key);                           // => 'a', 'b', 'c'
      console.log(val);                           // => 1, 2, 3
    }
    for(var val of map.values())console.log(val); // => 1, 2, 3
    for(var key of map.keys())console.log(key);   // => 'a', 'b', 'c'
    for(var [key, val] of map.entries()){
      console.log(key);                           // => 'a', 'b', 'c'
      console.log(val);                           // => 1, 2, 3
    }

    Set

    Module es6.set.

    new Set(iterable?-> set
      #add(key) -> @
      #clear() -> void
      #delete(key) -> bool
      #forEach(fn(el, el, @), that) -> void
      #has(key) -> bool
      #size -> uint
      #values() -> iterator
      #keys() -> iterator
      #entries() -> iterator
      #@@iterator() -> iterator (values)

    CommonJS entry points:

    core-js(/library)/es6/set
    core-js(/library)/fn/set
    

    Examples:

    var set = new Set(['a', 'b', 'a', 'c']);
    set.add('d').add('b').add('e');
    console.log(set.size);        // => 5
    console.log(set.has('b'));    // => true
    set.forEach(function(it){
      console.log(it);            // => 'a', 'b', 'c', 'd', 'e'
    });
    set.delete('b');
    console.log(set.size);        // => 4
    console.log(set.has('b'));    // => false
    console.log(Array.from(set)); // => ['a', 'c', 'd', 'e']
     
    var set = new Set([1, 2, 3, 2, 1]);
     
    for(var val of set)console.log(val);          // => 1, 2, 3
    for(var val of set.values())console.log(val); // => 1, 2, 3
    for(var key of set.keys())console.log(key);   // => 1, 2, 3
    for(var [key, val] of set.entries()){
      console.log(key);                           // => 1, 2, 3
      console.log(val);                           // => 1, 2, 3
    }

    WeakMap

    Module es6.weak-map.

    new WeakMap(iterable (entries) ?-> weakmap
      #delete(key) -> bool
      #get(key) -> val
      #has(key) -> bool
      #set(key, val) -> @

    CommonJS entry points:

    core-js(/library)/es6/weak-map
    core-js(/library)/fn/weak-map
    

    Examples:

    var a = [1]
      , b = [2]
      , c = [3];
     
    var wmap = new WeakMap([[a, 1], [b, 2]]);
    wmap.set(c, 3).set(b, 4);
    console.log(wmap.has(a));   // => true
    console.log(wmap.has([1])); // => false
    console.log(wmap.get(a));   // => 1
    wmap.delete(a);
    console.log(wmap.get(a));   // => undefined
     
    // Private properties store:
    var Person = (function(){
      var names = new WeakMap;
      function Person(name){
        names.set(this, name);
      }
      Person.prototype.getName = function(){
        return names.get(this);
      };
      return Person;
    })();
     
    var person = new Person('Vasya');
    console.log(person.getName());          // => 'Vasya'
    for(var key in person)console.log(key); // => only 'getName'

    WeakSet

    Module es6.weak-set.

    new WeakSet(iterable?-> weakset
      #add(key) -> @
      #delete(key) -> bool
      #has(key) -> bool

    CommonJS entry points:

    core-js(/library)/es6/weak-set
    core-js(/library)/fn/weak-set
    

    Examples:

    var a = [1]
      , b = [2]
      , c = [3];
     
    var wset = new WeakSet([a, b, a]);
    wset.add(c).add(b).add(c);
    console.log(wset.has(b));   // => true
    console.log(wset.has([2])); // => false
    wset.delete(b);
    console.log(wset.has(b));   // => false
    Caveats when using collections polyfill:
    • Weak-collections polyfill stores values as hidden properties of keys. It works correct and not leak in most cases. However, it is desirable to store a collection longer than its keys.

    ECMAScript 6: Typed Arrays

    Implementations and fixes ArrayBuffer, DataView, typed arrays constructors, static and prototype methods. Typed Arrays work only in environments with support descriptors (IE9+), ArrayBuffer and DataView should work anywhere.

    Modules es6.typed.array-buffer, es6.typed.data-view, es6.typed.int8-array, es6.typed.uint8-array, es6.typed.uint8-clamped-array, es6.typed.int16-array, es6.typed.uint16-array, es6.typed.int32-array, es6.typed.uint32-array, es6.typed.float32-array and es6.typed.float64-array.

    new ArrayBuffer(length) -> buffer
      .isView(var) -> bool
      #slice(start = 0, end = @length) -> buffer
      #byteLength -> uint
     
    new DataView(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) -> view
      #getInt8(offset)                          -> int8
      #getUint8(offset)                         -> uint8
      #getInt16(offset, littleEndian = false)   -> int16
      #getUint16(offset, littleEndian = false)  -> uint16
      #getInt32(offset, littleEndian = false)   -> int32
      #getUint32(offset, littleEndian = false)  -> uint32
      #getFloat32(offset, littleEndian = false) -> float32
      #getFloat64(offset, littleEndian = false) -> float64
      #setInt8(offset, value)                          -> void
      #setUint8(offset, value)                         -> void
      #setInt16(offset, value, littleEndian = false)   -> void
      #setUint16(offset, value, littleEndian = false)  -> void
      #setInt32(offset, value, littleEndian = false)   -> void
      #setUint32(offset, value, littleEndian = false)  -> void
      #setFloat32(offset, value, littleEndian = false) -> void
      #setFloat64(offset, value, littleEndian = false) -> void
      #buffer     -> buffer
      #byteLength -> uint
      #byteOffset -> uint
     
    {
      Int8Array,
      Uint8Array,
      Uint8ClampedArray,
      Int16Array,
      Uint16Array,
      Int32Array,
      Uint32Array,
      Float32Array,
      Float64Array
    }
      new %TypedArray%(length)    -> typed
      new %TypedArray%(typed)     -> typed
      new %TypedArray%(arrayLike) -> typed
      new %TypedArray%(iterable)  -> typed
      new %TypedArray%(buffer, byteOffset = 0, length = (buffer.byteLength - byteOffset) / @BYTES_PER_ELEMENT) -> typed
      .BYTES_PER_ELEMENT -> uint
      .from(arrayLike | iterable, mapFn(val, index)?, that) -> typed
      .of(...args) -> typed
      #BYTES_PER_ELEMENT -> uint
      #copyWithin(target = 0, start = 0, end = @length) -> @
      #every(fn(val, index, @), that) -> bool
      #fill(val, start = 0, end = @length) -> @
      #filter(fn(val, index, @), that) -> typed
      #find(fn(val, index, @), that) -> val
      #findIndex(fn(val, index, @), that) -> index
      #forEach(fn(val, index, @), that) -> void
      #indexOf(var, from?-> int
      #includes(var, from?-> bool
      #join(string = ',') -> string
      #lastIndexOf(var, from?-> int
      #map(fn(val, index, @), that) -> typed
      #reduce(fn(memo, val, index, @), memo?-> var
      #reduceRight(fn(memo, val, index, @), memo?-> var
      #reverse() -> @
      #set(arrayLike, offset = 0) -> void
      #slice(start = 0, end = @length) -> typed
      #some(fn(val, index, @), that) -> bool
      #sort(fn(a, b)?-> @
      #subarray(start = 0, end = @length) -> typed
      #toString() -> string
      #toLocaleString() -> string
      #values()     -> iterator
      #keys()       -> iterator
      #entries()    -> iterator
      #@@iterator() -> iterator (values)
      #buffer     -> buffer
      #byteLength -> uint
      #byteOffset -> uint
      #length     -> uint

    CommonJS entry points:

    core-js(/library)/es6/typed
    core-js(/library)/fn/typed
    core-js(/library)/fn/typed/array-buffer
    core-js(/library)/fn/typed/data-view
    core-js(/library)/fn/typed/int8-array
    core-js(/library)/fn/typed/uint8-array
    core-js(/library)/fn/typed/uint8-clamped-array
    core-js(/library)/fn/typed/int16-array
    core-js(/library)/fn/typed/uint16-array
    core-js(/library)/fn/typed/int32-array
    core-js(/library)/fn/typed/uint32-array
    core-js(/library)/fn/typed/float32-array
    core-js(/library)/fn/typed/float64-array
    

    Examples:

    new Int32Array(4);                          // => [0, 0, 0, 0]
    new Uint8ClampedArray([1, 2, 3, 666]);      // => [1, 2, 3, 255]
    new Float32Array(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
     
    var buffer = new ArrayBuffer(8);
    var view   = new DataView(buffer);
    view.setFloat64(0, 123.456, true);
    new Uint8Array(buffer.slice(4)); // => [47, 221, 94, 64]
     
    Int8Array.of(1, 1.5, 5.7, 745);      // => [1, 1, 5, -23]
    Uint8Array.from([1, 1.5, 5.7, 745]); // => [1, 1, 5, 233]
     
    var typed = new Uint8Array([1, 2, 3]);
     
    var a = typed.slice(1);    // => [2, 3]
    typed.buffer === a.buffer; // => false
    var b = typed.subarray(1); // => [2, 3]
    typed.buffer === b.buffer; // => true
     
    typed.filter(it => it % 2); // => [1, 3]
    typed.map(it => it * 1.5);  // => [1, 3, 4]
     
    for(var val of typed)console.log(val);          // => 1, 2, 3
    for(var val of typed.values())console.log(val); // => 1, 2, 3
    for(var key of typed.keys())console.log(key);   // => 0, 1, 2
    for(var [key, val] of typed.entries()){
      console.log(key);                             // => 0, 1, 2
      console.log(val);                             // => 1, 2, 3
    }
    Caveats when using typed arrays:
    • Typed Arrays polyfills works completely how should work by the spec, but because of internal use getter / setters on each instance, is slow and consumes significant memory. However, typed arrays polyfills required mainly for IE9 (and for Uint8ClampedArray in IE10 and early IE11), all modern engines have native typed arrays and requires only constructors fixes and methods.
    • The current version hasn't special entry points for methods, they can be added only with constructors. It can be added in the future.
    • In the library version we can't pollute native prototypes, so prototype methods available as constructors static.

    ECMAScript 6: Reflect

    Modules es6.reflect.apply, es6.reflect.construct, es6.reflect.define-property, es6.reflect.delete-property, es6.reflect.enumerate, es6.reflect.get, es6.reflect.get-own-property-descriptor, es6.reflect.get-prototype-of, es6.reflect.has, es6.reflect.is-extensible, es6.reflect.own-keys, es6.reflect.prevent-extensions, es6.reflect.set, es6.reflect.set-prototype-of.

    Reflect
      .apply(target, thisArgument, argumentsList) -> var
      .construct(target, argumentsList, newTarget?-> object
      .defineProperty(target, propertyKey, attributes) -> bool
      .deleteProperty(target, propertyKey) -> bool
      .enumerate(target) -> iterator
      .get(target, propertyKey, receiver?-> var
      .getOwnPropertyDescriptor(target, propertyKey) -> desc
      .getPrototypeOf(target) -> object | null
      .has(target, propertyKey) -> bool
      .isExtensible(target) -> bool
      .ownKeys(target) -> array
      .preventExtensions(target) -> bool
      .set(target, propertyKey, V, receiver?-> bool
      .setPrototypeOf(target, proto) -> bool (required __proto__ - IE11+)

    CommonJS entry points:

    core-js(/library)/es6/reflect
    core-js(/library)/fn/reflect
    core-js(/library)/fn/reflect/apply
    core-js(/library)/fn/reflect/construct
    core-js(/library)/fn/reflect/define-property
    core-js(/library)/fn/reflect/delete-property
    core-js(/library)/fn/reflect/enumerate
    core-js(/library)/fn/reflect/get
    core-js(/library)/fn/reflect/get-own-property-descriptor
    core-js(/library)/fn/reflect/get-prototype-of
    core-js(/library)/fn/reflect/has
    core-js(/library)/fn/reflect/is-extensible
    core-js(/library)/fn/reflect/own-keys
    core-js(/library)/fn/reflect/prevent-extensions
    core-js(/library)/fn/reflect/set
    core-js(/library)/fn/reflect/set-prototype-of
    

    Examples:

    var O = {a: 1};
    Object.defineProperty(O, 'b', {value: 2});
    O[Symbol('c')] = 3;
    Reflect.ownKeys(O); // => ['a', 'b', Symbol(c)]
     
    function C(a, b){
      this.c = a + b;
    }
     
    var instance = Reflect.construct(C, [20, 22]);
    instance.c; // => 42

    ECMAScript 7+ proposals

    The TC39 process.

    CommonJS entry points:

    core-js(/library)/es7
    core-js(/library)/es7/array
    core-js(/library)/es7/string
    core-js(/library)/es7/map
    core-js(/library)/es7/set
    core-js(/library)/es7/math
    core-js(/library)/es7/system
    core-js(/library)/es7/error
    

    core-js/stage/4 entry point contains only stage 4 proposals, core-js/stage/3 - stage 3 and stage 4, etc.

    Stage 4:

    CommonJS entry points:

    core-js(/library)/stage/4
    core-js(/library)/fn/array/includes
    Stage 3:

    CommonJS entry points:

    core-js(/library)/stage/3
    core-js(/library)/fn/object/values
    core-js(/library)/fn/object/entries
    core-js(/library)/fn/string/pad-start
    core-js(/library)/fn/string/pad-end
    core-js(/library)/fn/string/virtual/pad-start
    core-js(/library)/fn/string/virtual/pad-end
    Stage 2:

    None.

    CommonJS entry points:

    core-js(/library)/stage/2
    Stage 1:

    CommonJS entry points:

    core-js(/library)/stage/1
    core-js(/library)/fn/string/trim-start
    core-js(/library)/fn/string/trim-end
    core-js(/library)/fn/string/trim-left
    core-js(/library)/fn/string/trim-right
    core-js(/library)/fn/string/virtual/trim-start
    core-js(/library)/fn/string/virtual/trim-end
    core-js(/library)/fn/string/virtual/trim-left
    core-js(/library)/fn/string/virtual/trim-right
    core-js(/library)/fn/system/global
    Stage 0:

    CommonJS entry points:

    core-js(/library)/stage/0
    core-js(/library)/fn/string/at
    core-js(/library)/fn/string/virtual/at
    core-js(/library)/fn/object/get-own-property-descriptors
    core-js(/library)/fn/map
    core-js(/library)/fn/set
    core-js(/library)/fn/error/is-error
    core-js(/library)/fn/math/iaddh
    core-js(/library)/fn/math/isubh
    core-js(/library)/fn/math/imulh
    core-js(/library)/fn/math/umulh
    Pre-stage 0 proposals:

    None.

    CommonJS entry points:

    core-js(/library)/stage/pre
    Array
      #includes(var, from?-> bool
    String
      #at(index) -> string
      #padStart(length, fillStr = ' ') -> string
      #padEnd(length, fillStr = ' ') -> string
      #trimLeft() -> string
      #trimRight() -> string
      #trimStart() -> string
      #trimEnd() -> string
    Object
      .values(object) -> array
      .entries(object) -> array
      .getOwnPropertyDescriptors(object) -> object
    RegExp
      .escape(str) -> str
    Map
      #toJSON() -> array
    Set
      #toJSON() -> array
    System
      .global -> object
    Error
      .isError(it) -> bool
    Math
      .iaddh(lo0, hi0, lo1, hi1) -> int32
      .isubh(lo0, hi0, lo1, hi1) -> int32
      .imulh(a, b) -> int32
      .umulh(a, b) -> uint32

    Examples:

    [1, 2, 3].includes(2);        // => true
    [1, 2, 3].includes(4);        // => false
    [1, 2, 3].includes(2, 2);     // => false
     
    [NaN].indexOf(NaN);           // => -1
    [NaN].includes(NaN);          // => true
    Array(1).indexOf(undefined);  // => -1
    Array(1).includes(undefined); // => true
     
    'a𠮷b'.at(1);        // => '𠮷'
    'a𠮷b'.at(1).length; // => 2
     
    'hello'.padStart(10);         // => '     hello'
    'hello'.padStart(10, '1234'); // => '12341hello'
    'hello'.padEnd(10);           // => 'hello     '
    'hello'.padEnd(10, '1234');   // => 'hello12341'
     
    '   hello   '.trimLeft();  // => 'hello   '
    '   hello   '.trimRight(); // => '   hello'
     
    Object.values({a: 1, b: 2, c: 3});  // => [1, 2, 3]
    Object.entries({a: 1, b: 2, c: 3}); // => [['a', 1], ['b', 2], ['c', 3]]
     
    // Shallow object cloning with prototype and descriptors:
    var copy = Object.create(Object.getPrototypeOf(O), Object.getOwnPropertyDescriptors(O));
    // Mixin:
    Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
     
    JSON.stringify(new Map([['a', 'b'], ['c', 'd']])); // => '[["a","b"],["c","d"]]'
    JSON.stringify(new Set([1, 2, 3, 2, 1]));          // => '[1,2,3]'
     
    System.global.Array === Array; // => true
     
    Error.isError(new TypeError); // => true

    Web standards

    CommonJS entry points:

    core-js(/library)/web

    setTimeout / setInterval

    Module web.timers. Additional arguments fix for IE9-.

    setTimeout(fn(...args), time, ...args) -> id
    setInterval(fn(...args), time, ...args) -> id

    CommonJS entry points:

    core-js(/library)/web/timers
    core-js(/library)/fn/set-timeout
    core-js(/library)/fn/set-interval
    // Before:
    setTimeout(log.bind(null, 42), 1000);
    // After:
    setTimeout(log, 1000, 42);

    setImmediate

    Module web.immediate. setImmediate proposal polyfill.

    setImmediate(fn(...args), ...args) -> id
    clearImmediate(id) -> void

    CommonJS entry points:

    core-js(/library)/web/immediate
    core-js(/library)/fn/set-immediate
    core-js(/library)/fn/clear-immediate

    Examples:

    setImmediate(function(arg1, arg2){
      console.log(arg1, arg2); // => Message will be displayed with minimum delay
    }, 'Message will be displayed', 'with minimum delay');
     
    clearImmediate(setImmediate(function(){
      console.log('Message will not be displayed');
    }));

    Iterable DOM collections

    Some DOM collections should have iterable interface or should be inherited from Array. That mean they should have keys, values, entries and @@iterator methods for iteration. So add them. Module web.dom.iterable:

    {
      NodeList,
      DOMTokenList,
      MediaList,
      StyleSheetList,
      CSSRuleList
    }
      #values()     -> iterator
      #keys()       -> iterator
      #entries()    -> iterator
      #@@iterator() -> iterator (values)

    CommonJS entry points:

    core-js(/library)/web/dom-collections
    core-js(/library)/fn/dom-collections/iterator

    Examples:

    for(var {id} of document.querySelectorAll('*')){
      if(id)console.log(id);
    }
     
    for(var [index, {id}] of document.querySelectorAll('*').entries()){
      if(id)console.log(index, id);
    }

    Non-standard

    CommonJS entry points:

    core-js(/library)/core

    Object

    Modules core.object.is-object, core.object.classof, core.object.define, core.object.make.

    Object
      .isObject(var) -> bool
      .classof(var) -> string
      .define(target, mixin) -> target
      .make(proto | null, mixin?-> object

    CommonJS entry points:

    core-js(/library)/core/object
    core-js(/library)/fn/object/is-object
    core-js(/library)/fn/object/define
    core-js(/library)/fn/object/make

    Object classify examples:

    Object.isObject({});    // => true
    Object.isObject(isNaN); // => true
    Object.isObject(null);  // => false
     
    var classof = Object.classof;
     
    classof(null);                 // => 'Null'
    classof(undefined);            // => 'Undefined'
    classof(1);                    // => 'Number'
    classof(true);                 // => 'Boolean'
    classof('string');             // => 'String'
    classof(Symbol());             // => 'Symbol'
     
    classof(new Number(1));        // => 'Number'
    classof(new Boolean(true));    // => 'Boolean'
    classof(new String('string')); // => 'String'
     
    var fn   = function(){}
      , list = (function(){return arguments})(1, 2, 3);
     
    classof({});                   // => 'Object'
    classof(fn);                   // => 'Function'
    classof([]);                   // => 'Array'
    classof(list);                 // => 'Arguments'
    classof(/./);                  // => 'RegExp'
    classof(new TypeError);        // => 'Error'
     
    classof(new Set);              // => 'Set'
    classof(new Map);              // => 'Map'
    classof(new WeakSet);          // => 'WeakSet'
    classof(new WeakMap);          // => 'WeakMap'
    classof(new Promise(fn));      // => 'Promise'
     
    classof([].values());          // => 'Array Iterator'
    classof(new Set().values());   // => 'Set Iterator'
    classof(new Map().values());   // => 'Map Iterator'
     
    classof(Math);                 // => 'Math'
    classof(JSON);                 // => 'JSON'
     
    function Example(){}
    Example.prototype[Symbol.toStringTag] = 'Example';
     
    classof(new Example);          // => 'Example'

    Object.define and Object.make examples:

    // Before:
    Object.defineProperty(target, 'c', {
      enumerable: true,
      configurable: true,
      get: function(){
        return this.a + this.b;
      }
    });
     
    // After:
    Object.define(target, {
      get c(){
        return this.a + this.b;
      }
    });
     
    // Shallow object cloning with prototype and descriptors:
    var copy = Object.make(Object.getPrototypeOf(src), src);
     
    // Simple inheritance:
    function Vector2D(x, y){
      this.x = x;
      this.y = y;
    }
    Object.define(Vector2D.prototype, {
      get xy(){
        return Math.hypot(this.x, this.y);
      }
    });
    function Vector3D(x, y, z){
      Vector2D.apply(this, arguments);
      this.z = z;
    }
    Vector3D.prototype = Object.make(Vector2D.prototype, {
      constructor: Vector3D,
      get xyz(){
        return Math.hypot(this.x, this.y, this.z);
      }
    });
     
    var vector = new Vector3D(9, 12, 20);
    console.log(vector.xy);  // => 15
    console.log(vector.xyz); // => 25
    vector.y++;
    console.log(vector.xy);  // => 15.811388300841896
    console.log(vector.xyz); // => 25.495097567963924

    Dict

    Module core.dict. Based on TC39 discuss / strawman.

    [new] Dict(iterable (entries) | object ?-> dict
      .isDict(var) -> bool
      .values(object) -> iterator
      .keys(object) -> iterator
      .entries(object) -> iterator (entries)
      .has(object, key) -> bool
      .get(object, key) -> val
      .set(object, key, value) -> object
      .forEach(object, fn(val, key, @), that) -> void
      .map(object, fn(val, key, @), that) -> new @
      .mapPairs(object, fn(val, key, @), that) -> new @
      .filter(object, fn(val, key, @), that) -> new @
      .some(object, fn(val, key, @), that) -> bool
      .every(object, fn(val, key, @), that) -> bool
      .find(object, fn(val, key, @), that) -> val
      .findKey(object, fn(val, key, @), that) -> key
      .keyOf(object, var) -> key
      .includes(object, var) -> bool
      .reduce(object, fn(memo, val, key, @), memo?-> var

    CommonJS entry points:

    core-js(/library)/core/dict
    core-js(/library)/fn/dict

    Dict create object without prototype from iterable or simple object.

    Examples:

    var map = new Map([['a', 1], ['b', 2], ['c', 3]]);
     
    Dict();                    // => {__proto__: null}
    Dict({a: 1, b: 2, c: 3});  // => {__proto__: null, a: 1, b: 2, c: 3}
    Dict(map);                 // => {__proto__: null, a: 1, b: 2, c: 3}
    Dict([1, 2, 3].entries()); // => {__proto__: null, 0: 1, 1: 2, 2: 3}
     
    var dict = Dict({a: 42});
    dict instanceof Object;   // => false
    dict.a;                   // => 42
    dict.toString;            // => undefined
    'a' in dict;              // => true
    'hasOwnProperty' in dict; // => false
     
    Dict.isDict({});     // => false
    Dict.isDict(Dict()); // => true

    Dict.keys, Dict.values and Dict.entries returns iterators for objects.

    Examples:

    var dict = {a: 1, b: 2, c: 3};
     
    for(var key of Dict.keys(dict))console.log(key); // => 'a', 'b', 'c'
     
    for(var val of Dict.values(dict))console.log(val); // => 1, 2, 3
     
    for(var [key, val] of Dict.entries(dict)){
      console.log(key); // => 'a', 'b', 'c'
      console.log(val); // => 1, 2, 3
    }
     
    new Map(Dict.entries(dict)); // => Map {a: 1, b: 2, c: 3}

    Basic dict operations for objects with prototype examples:

    'q' in {q: 1};            // => true
    'toString' in {};         // => true
     
    Dict.has({q: 1}, 'q');    // => true
    Dict.has({}, 'toString'); // => false
     
    ({q: 1})['q'];            // => 1
    ({}).toString;            // => function toString(){ [native code] }
     
    Dict.get({q: 1}, 'q');    // => 1
    Dict.get({}, 'toString'); // => undefined
     
    var O = {};
    O['q'] = 1;
    O['q'];         // => 1
    O['__proto__'] = {w: 2};
    O['__proto__']; // => {w: 2}
    O['w'];         // => 2
     
    var O = {};
    Dict.set(O, 'q', 1);
    O['q'];         // => 1
    Dict.set(O, '__proto__', {w: 2});
    O['__proto__']; // => {w: 2}
    O['w'];         // => undefined

    Other methods of Dict module are static equialents of Array.prototype methods for dictionaries.

    Examples:

    var dict = {a: 1, b: 2, c: 3};
     
    Dict.forEach(dict, console.log, console);
    // => 1, 'a', {a: 1, b: 2, c: 3}
    // => 2, 'b', {a: 1, b: 2, c: 3}
    // => 3, 'c', {a: 1, b: 2, c: 3}
     
    Dict.map(dict, function(it){
      return it * it;
    }); // => {a: 1, b: 4, c: 9}
     
    Dict.mapPairs(dict, function(val, key){
      if(key != 'b')return [key + key, val * val];
    }); // => {aa: 1, cc: 9}
     
    Dict.filter(dict, function(it){
      return it % 2;
    }); // => {a: 1, c: 3}
     
    Dict.some(dict, function(it){
      return it === 2;
    }); // => true
     
    Dict.every(dict, function(it){
      return it === 2;
    }); // => false
     
    Dict.find(dict, function(it){
      return it > 2;
    }); // => 3
    Dict.find(dict, function(it){
      return it > 4;
    }); // => undefined
     
    Dict.findKey(dict, function(it){
      return it > 2;
    }); // => 'c'
    Dict.findKey(dict, function(it){
      return it > 4;
    }); // => undefined
     
    Dict.keyOf(dict, 2);    // => 'b'
    Dict.keyOf(dict, 4);    // => undefined
     
    Dict.includes(dict, 2); // => true
    Dict.includes(dict, 4); // => false
     
    Dict.reduce(dict, function(memo, it){
      return memo + it;
    });     // => 6
    Dict.reduce(dict, function(memo, it){
      return memo + it;
    }, ''); // => '123'

    Partial application

    Module core.function.part.

    Function
      #part(...args | _) -> fn(...args)

    CommonJS entry points:

    core-js/core/function
    core-js(/library)/fn/function/part
    core-js(/library)/fn/function/virtual/part
    core-js(/library)/fn/_

    Function#part partial apply function without this binding. Uses global variable _ (core._ for builds without global namespace pollution) as placeholder and not conflict with Underscore / LoDash.

    Examples:

    var fn1 = log.part(1, 2);
    fn1(3, 4);    // => 1, 2, 3, 4
     
    var fn2 = log.part(_, 2, _, 4);
    fn2(1, 3);    // => 1, 2, 3, 4
     
    var fn3 = log.part(1, _, _, 4);
    fn3(2, 3);    // => 1, 2, 3, 4
     
    fn2(1, 3, 5); // => 1, 2, 3, 4, 5
    fn2(1);       // => 1, 2, undefined, 4

    Number Iterator

    Module core.number.iterator.

    Number
      #@@iterator() -> iterator

    CommonJS entry points:

    core-js(/library)/core/number
    core-js(/library)/fn/number/iterator
    core-js(/library)/fn/number/virtual/iterator

    Examples:

    for(var i of 3)console.log(i); // => 0, 1, 2
     
    [...10]; // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     
    Array.from(10, Math.random); // => [0.9817775336559862, 0.02720663254149258, ...]
     
    Array.from(10, function(it){
      return this + it * it;
    }, .42); // => [0.42, 1.42, 4.42, 9.42, 16.42, 25.42, 36.42, 49.42, 64.42, 81.42]

    Escaping strings

    Modules core.regexp.escape, core.string.escape-html and core.string.unescape-html.

    RegExp
      .escape(str) -> str
    String
      #escapeHTML() -> str
      #unescapeHTML() -> str

    CommonJS entry points:

    core-js(/library)/core/regexp
    core-js(/library)/core/string
    core-js(/library)/fn/regexp/escape
    core-js(/library)/fn/string/escape-html
    core-js(/library)/fn/string/unescape-html
    core-js(/library)/fn/string/virtual/escape-html
    core-js(/library)/fn/string/virtual/unescape-html

    Examples:

    RegExp.escape('Hello, []{}()*+?.\\^$|!'); // => 'Hello, \[\]\{\}\(\)\*\+\?\.\\\^\$\|!'
     
    '<script>doSomething();</script>'.escapeHTML(); // => '&lt;script&gt;doSomething();&lt;/script&gt;'
    '&lt;script&gt;doSomething();&lt;/script&gt;'.unescapeHTML(); // => '<script>doSomething();</script>'

    delay

    Module core.delay. Promise-returning delay function, esdiscuss.

    delay(ms) -> promise

    CommonJS entry points:

    core-js(/library)/core/delay
    core-js(/library)/fn/delay

    Examples:

    delay(1e3).then(() => console.log('after 1 sec'));
     
    (async () => {
      await delay(3e3);
      console.log('after 3 sec');
      
      while(await delay(3e3))console.log('each 3 sec');
    })();

    Helpers for iterators

    Modules core.is-iterable, core.get-iterator, core.get-iterator-method - helpers for check iterability / get iterator in the library version or, for example, for arguments object:

    core
      .isIterable(var) -> bool
      .getIterator(iterable) -> iterator
      .getIteratorMethod(var) -> function | undefined

    CommonJS entry points:

    core-js(/library)/fn/is-iterable
    core-js(/library)/fn/get-iterator
    core-js(/library)/fn/get-iterator-method

    Examples:

    var list = (function(){
      return arguments;
    })(1, 2, 3);
     
    console.log(core.isIterable(list)); // true;
     
    var iter = core.getIterator(list);
    console.log(iter.next().value); // 1
    console.log(iter.next().value); // 2
    console.log(iter.next().value); // 3
    console.log(iter.next().value); // undefined
     
    core.getIterator({});   // TypeError: [object Object] is not iterable!
     
    var iterFn = core.getIteratorMethod(list);
    console.log(typeof iterFn);     // 'function'
    var iter = iterFn.call(list);
    console.log(iter.next().value); // 1
    console.log(iter.next().value); // 2
    console.log(iter.next().value); // 3
    console.log(iter.next().value); // undefined
     
    console.log(core.getIteratorMethod({})); // undefined

    Missing polyfills

    • ES5 JSON is missing now only in IE7- and never will it be added to core-js, if you need it in these old browsers, many implementations are available, for example, json3.
    • ES6 String#normalize is not a very useful feature, but this polyfill will be very large. If you need it, you can use unorm.
    • ES6 Proxy can't be polyfilled, but for Node.js / Chromium with additional flags you can try harmony-reflect for adapt old style Proxy API to final ES6 version.
    • ES6 logic for @@isConcatSpreadable and @@species (in most places) can be polyfilled without problems, but it will cause a serious slowdown in popular cases in some engines. It will be polyfilled when it will be implemented in modern engines.
    • ES7 SIMD. core-js doesn't add polyfill of this feature because of large size and some other reasons. You can use this polyfill.
    • window.fetch is not a cross-platform feature, in some environments it make no sense. For this reason, I don't think it should be in core-js. Looking at a large number of requests it maybe added in the future. Now you can use, for example, this polyfill.

    Install

    npm i core-js-ie8

    DownloadsWeekly Downloads

    1

    Version

    2.0.3

    License

    MIT

    Last publish

    Collaborators

    • cchamberlain