core-js
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.
Array; // => [1, 2, 3]'*'; // => '**********'Promise; // => 32; // => 42
Without global namespace pollution:
var core = ; // With a modular system, otherwise use global `core`coreArray; // => [1, 2, 3]coreString; // => '**********'corePromise; // => 32core; // => 42
- Usage
- Supported engines
- Features
- Missing polyfills
- Changelog
Usage
Basic
npm i core-js
bower install core.js
// Default;// Without global namespace pollutionvar core = ;// Shim only;
If you need complete build for browser, use builds from core-js/client
path:
- default: Includes all features, standard and non-standard.
- as a library: Like "default", but does not pollute the global namespace (see 2nd example at the top).
- shim only: Only includes the standard methods.
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.
; // if you need support IE8-;;;Array; // => [1, 2, 3]1 2 NaN 3 4; // => 2 // or, w/o global namespace pollution: var core = ; // if you need support IE8-var Set = ;var from = ;var findIndex = ;; // => [1, 2, 3]; // => 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 upcore-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:
;; Array10::::; // => 4 // or ; Array10::::; // => 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
:
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;
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:
core-js(/library) <- all features
core-js(/library)/shim <- only polyfills
ECMAScript 5
Module es5
, nothing new - without examples.
Object
Some features moved to another modules / namespaces, but available as part of es5
namespace too:
Object -> object cap for ie8- -> object cap for ie8- -> object cap for ie8- -> bool cap for ie8- -> bool cap for ie8- -> bool cap for ie8-String # -> str
core-js(/library)/es5
ECMAScript 6
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 -> target -> bool -> -> var -> var -> var -> bool -> bool -> bool -> desc | undefined -> object | null -> array -> array # -> string ES6 fix: @@toStringTag support
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
var foo = q: 1 w: 2 bar = e: 3 r: 4 baz = t: 5 y: 6;Object; // => foo = {q: 1, w: 2, e: 3, r: 4, t: 5, y: 6} Object; // => trueObject; // => falseObject; // => trueObject; // => false {}{}Object; instanceof Child; // => true instanceof Parent; // => true var O = {};OSymboltoStringTag = 'Foo';'' + O; // => '[object Foo]' Object; // => ['0', '1', '2']Object === Stringprototype; // => true
ECMAScript 6: Function
Modules es6.function.name
and es6.function.has-instance
.
Function #name -> #@@ -> bool
core-js/es6/function
core-js/fn/function/name
core-js/fn/function/has-instance
{}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
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
Array; // => [1, 2, 3]Array; // => [1, 2, 3]Array; // => [1, 2, 3]Array; // => [1, 4, 9] Array; // => [1]Array; // => [1, 2, 3] var array = 'a' 'b' 'c'; forvar val of arrayconsole; // => 'a', 'b', 'c'forvar val of arrayconsole; // => 'a', 'b', 'c'forvar key of arrayconsole; // => 0, 1, 2forvar key val of array console; // => 0, 1, 2 console; // => 'a', 'b', 'c' { return val % 2;}4 8 15 16 23 42; // => 154 8 15 16 23 42; // => 24 8 15 16 23 42; // => undefined4 8 15 16 23 42; // => -1 Array5; // => [42, 42, 42, 42, 42] 1 2 3 4 5; // => [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 -> str -> str #
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
forvar val of 'a𠮷b' console; // => 'a', '𠮷', 'b' 'foobarbaz'; // => true'foobarbaz'; // => false'foobarbaz'; // => true'foobarbaz'; // => true'foobarbaz'; // => true'foobarbaz'; // => true 'string'; // => 'stringstringstring' '𠮷'; // => 134071String; // => 'a𠮷b' var name = 'Bob';Stringraw`Hi\n!`; // => 'Hi\\nBob!' (ES6 template string syntax)String; // => 't0e1s2t' 'foo'; // => '<b>foo</b>''bar'; // => '<a name="a"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
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
RegExp/./g 'm'; // => /./m /foo/flags; // => ''/foo/gimflags; // => 'gim' 'foo'; // => 1'foo'; // => 2'foo'; // => 3'foo'; // => 4
ECMAScript 6: Number
Module es6.number.constructor
. Number
constructor support binary and octal literals, example:
Number'0b1010101'; // => 85Number'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 Numbervar -> number | number object -> bool -> bool -> bool -> bool -> num -> int EPSILON -> num MAX_SAFE_INTEGER -> int MIN_SAFE_INTEGER -> int
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 -> num -> num -> num -> num -> uint -> num -> num -> num -> num -> int -> num -> num -> num -> 1 | -1 | 0 | -0 | NaN -> num -> num -> num
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 # -> str
core-js/es6/date
core-js/fn/date/to-string
NaN; // => 'Invalid Date'
ECMAScript 6: Promise
Module es6.promise
.
-> promise # -> promise #catch -> promise -> promise -> promise alliterable -> promise -> promise
core-js(/library)/es6/promise
core-js(/library)/fn/promise
Basic example:
{ return { ; };} console; // => Run; // => => Error: Irror!
Promise.resolve
and Promise.reject
example:
Promise; // => 42Promise; // => 42 Promise; // => ES6 promise
Promise.all
example:
Promiseall 'foo' // after 15 sec:; // => ['foo', 956, 85, 382]
Promise.race
example:
{ return Promise;} ; // => 853, after 5 sec.; // Error: Await > 10 sec
ECMAScript 7 async functions example:
var { await ; return 0 | Math * 1e3;};{ await ; throw Errormsg;}; async { try console; // => Run console; // => 936, after 5 sec. var a b c = await Promiseall ; console; // => 210 445 71, after 15 sec. await ; console; catche console; // => 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;process; var p = Promise;// unhandled 42 [object Promise] ;// 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 console;window console; var p = Promise;// unhandled 42 [object Promise] ;// 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
.
Symboldescription?) -> symbol hasInstance -> @@hasInstance isConcatSpreadable -> @@isConcatSpreadable iterator -> @@iterator match -> @@match replace -> @@replace search -> @@search species -> @@species split -> @@split toPrimitive -> @@toPrimitive toStringTag -> @@toStringTag unscopables -> @@unscopables -> symbol -> key -> void -> voidObject -> array
Also wrapped some methods for correct work with Symbol
polyfill.
Object
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
var Person = { var NAME = Symbol'name'; { thisNAME = name; } Personprototype{ return thisNAME; }; return Person;}; var person = 'Vasya';console; // => 'Vasya'console; // => undefinedconsole; // => undefined, symbols are uniqforvar key in personconsole; // => only 'getName', symbols are not enumerable
Symbol.for
& Symbol.keyFor
example:
var symbol = Symbol;symbol === Symbol; // trueSymbol; // 'key'
Example with methods for getting own object keys:
var O = a: 1;Object;OSymbol'c' = 3;Object; // => ['a']Object; // => ['a', 'b']Object; // => [Symbol(c)]Reflect; // => ['a', 'b', Symbol(c)]
Symbol
polyfill:
Caveats when using - We can't add new primitive type,
Symbol
returns object. Symbol.for
andSymbol.keyFor
can't be shimmed cross-realm.- By default, to hide the keys,
Symbol
polyfill defines setter inObject.prototype
. For this reason, uncontrolled creation of symbols can cause memory leak and thein
operator is not working correctly withSymbol
polyfill:Symbol() in {} // => true
.
You can disable defining setters in Object.prototype
. Example:
Symbol;var s1 = Symbol's1' o1 = {};o1s1 = true;forvar key in o1console; // => 'Symbol(s1)_t.qamkg9f3q', w/o native Symbol Symbol;var s2 = Symbol's2' o2 = {};o2s2 = true;forvar key in o2console; // nothing
- Currently,
core-js
not adds setters toObject.prototype
for well-known symbols for correct work something likeSymbol.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
.
?) -> map # -> void #deletekey -> bool # -> void # -> val # -> bool # -> @ #size -> uint # -> iterator # -> iterator # -> iterator #@@ ->
core-js(/library)/es6/map
core-js(/library)/fn/map
var a = 1; var map = 'a' 1 42 2;map; console; // => 4console; // => trueconsole; // => falseconsole; // => 3map;map;console; // => 3console; // => undefinedconsole; // => [['a', 1], [42, 2], [true, 4]] var map = 'a' 1 'b' 2 'c' 3; forvar key val of map console; // => 'a', 'b', 'c' console; // => 1, 2, 3forvar val of mapconsole; // => 1, 2, 3forvar key of mapconsole; // => 'a', 'b', 'c'forvar key val of map console; // => 'a', 'b', 'c' console; // => 1, 2, 3
Set
Module es6.set
.
iterable?) -> set # -> @ # -> void #deletekey -> bool # -> void # -> bool #size -> uint # -> iterator # -> iterator # -> iterator #@@ ->
core-js(/library)/es6/set
core-js(/library)/fn/set
var set = 'a' 'b' 'a' 'c';set;console; // => 5console; // => trueset;set;console; // => 4console; // => falseconsole; // => ['a', 'c', 'd', 'e'] var set = 1 2 3 2 1; forvar val of setconsole; // => 1, 2, 3forvar val of setconsole; // => 1, 2, 3forvar key of setconsole; // => 1, 2, 3forvar key val of set console; // => 1, 2, 3 console; // => 1, 2, 3
WeakMap
Module es6.weak-map
.
?) -> weakmap #deletekey -> bool # -> val # -> bool # -> @
core-js(/library)/es6/weak-map
core-js(/library)/fn/weak-map
var a = 1 b = 2 c = 3; var wmap = a 1 b 2;wmap;console; // => trueconsole; // => falseconsole; // => 1wmap;console; // => undefined // Private properties store:var Person = { var names = ; { names; } Personprototype{ return names; }; return Person;}; var person = 'Vasya';console; // => 'Vasya'forvar key in personconsole; // => only 'getName'
WeakSet
Module es6.weak-set
.
iterable?) -> weakset # -> @ #deletekey -> bool # -> bool
core-js(/library)/es6/weak-set
core-js(/library)/fn/weak-set
var a = 1 b = 2 c = 3; var wset = a b a;wset;console; // => trueconsole; // => falsewset;console; // => 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
.
length -> buffer -> bool # -> buffer #byteLength -> uint buffer byteOffset = 0 byteLength = bufferbyteLength - byteOffset -> view # -> int8 # -> uint8 # -> int16 # -> uint16 # -> int32 # -> uint32 # -> float32 # -> float64 # -> void # -> void # -> void # -> void # -> void # -> void # -> void # -> 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 = bufferbyteLength - byteOffset / @BYTES_PER_ELEMENT -> typed BYTES_PER_ELEMENT -> uint
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
4; // => [0, 0, 0, 0]1 2 3 666; // => [1, 2, 3, 255]1 2 3 2 1; // => [1, 2, 3] var buffer = 8;var view = buffer;view;buffer; // => [47, 221, 94, 64] Int8Array; // => [1, 1, 5, -23]Uint8Array; // => [1, 1, 5, 233] var typed = 1 2 3; var a = typed; // => [2, 3]typedbuffer === abuffer; // => falsevar b = typed; // => [2, 3]typedbuffer === bbuffer; // => true typed; // => [1, 3]typed; // => [1, 3, 4] forvar val of typedconsole; // => 1, 2, 3forvar val of typedconsole; // => 1, 2, 3forvar key of typedconsole; // => 0, 1, 2forvar key val of typed console; // => 0, 1, 2 console; // => 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 -> var
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
var O = a: 1;Object;OSymbol'c' = 3;Reflect; // => ['a', 'b', Symbol(c)] { thisc = a + b;} var instance = Reflect;instancec; // => 42
ECMAScript 7+ proposals
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:
{Array, %TypedArray%}#includes
proposal - modulees7.array.includes
,%TypedArray%
version in modules from this section.
core-
Stage 3:
Object.values
,Object.entries
proposal - moduleses7.object.values
,es7.object.entries
String#padStart
,String#padEnd
proposal - moduleses7.string.pad-left
,es7.string.pad-right
core-
Stage 2:
None.
core-
Stage 1:
String#trimLeft
,String#trimRight
/String#trimStart
,String#trimEnd
proposal - moduleses7.string.trim-left
,es7.string.trim-right
System.global
proposal - modulees7.system.global
core-
Stage 0:
String#at
proposal - modulees7.string.at
Object.getOwnPropertyDescriptors
proposal - modulees7.object.get-own-property-descriptors
Map#toJSON
,Set#toJSON
proposal - moduleses7.map.to-json
,es7.set.to-json
Error.isError
proposal - modulees7.error.is-error
Math.{iaddh, isubh, imulh, umulh}
proposal - moduleses7.math.iaddh
,es7.math.isubh
,es7.math.imulh
andes7.math.umulh
.
core-
Pre-stage 0 proposals:
None.
core-
Array #
1 2 3; // => true1 2 3; // => false1 2 3; // => false NaN; // => -1NaN; // => trueArray1; // => -1Array1; // => true 'a𠮷b'; // => '𠮷''a𠮷b'length; // => 2 'hello'; // => ' hello''hello'; // => '12341hello''hello'; // => 'hello ''hello'; // => 'hello12341' ' hello '; // => 'hello '' hello '; // => ' hello' Object; // => [1, 2, 3]Object; // => [['a', 1], ['b', 2], ['c', 3]] // Shallow object cloning with prototype and descriptors:var copy = Object;// Mixin:Object; JSON; // => '[["a","b"],["c","d"]]'JSON; // => '[1,2,3]' SystemglobalArray === Array; // => true Error; // => true
Web standards
core-
setTimeout / setInterval
Module web.timers
. Additional arguments fix for IE9-.
-> id -> id
core-
// Before:;// After:;
setImmediate
Module web.immediate
. setImmediate
proposal polyfill.
-> id -> void
core-
; ;
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 # -> iterator # -> iterator # -> iterator #@@ ->
core-
forvar id of document ifidconsole; forvar index id of document ifidconsole;
Non-standard
core-
Object
Modules core.object.is-object
, core.object.classof
, core.object.define
, core.object.make
.
Object -> bool -> string -> target
core-
Object classify examples:
Object; // => trueObject; // => trueObject; // => false var classof = Objectclassof; ; // => 'Null'; // => 'Undefined'; // => 'Number'; // => 'Boolean'; // => 'String'; // => 'Symbol' ; // => 'Number'; // => 'Boolean'; // => 'String' var {} list = {return arguments}1 2 3; ; // => 'Object'; // => 'Function'; // => 'Array'; // => 'Arguments'; // => 'RegExp'; // => 'Error' ; // => 'Set'; // => 'Map'; // => 'WeakSet'; // => 'WeakMap'; // => 'Promise' ; // => 'Array Iterator'; // => 'Set Iterator'; // => 'Map Iterator' ; // => 'Math'; // => 'JSON' {}ExampleprototypeSymboltoStringTag = 'Example'; ; // => 'Example'
Object.define
and Object.make
examples:
// Before:Object; // After:Object; // Shallow object cloning with prototype and descriptors:var copy = Object; // Simple inheritance:{ thisx = x; thisy = y;}Object;{ Vector2D; thisz = z;}Vector3Dprototype = Object; var vector = 9 12 20;console; // => 15console; // => 25vectory++;console; // => 15.811388300841896console; // => 25.495097567963924
Dict
Module core.dict
. Based on TC39 discuss / strawman.
new
core-
Dict
create object without prototype from iterable or simple object.
var map = 'a' 1 'b' 2 'c' 3; ; // => {__proto__: null}; // => {__proto__: null, a: 1, b: 2, c: 3}; // => {__proto__: null, a: 1, b: 2, c: 3}; // => {__proto__: null, 0: 1, 1: 2, 2: 3} var dict = ;dict instanceof Object; // => falsedicta; // => 42dicttoString; // => undefined'a' in dict; // => true'hasOwnProperty' in dict; // => false Dict; // => falseDict; // => true
Dict.keys
, Dict.values
and Dict.entries
returns iterators for objects.
var dict = a: 1 b: 2 c: 3; forvar key of Dictconsole; // => 'a', 'b', 'c' forvar val of Dictconsole; // => 1, 2, 3 forvar key val of Dict console; // => 'a', 'b', 'c' console; // => 1, 2, 3 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; // => trueDict; // => false q: 1'q'; // => 1{}toString; // => function toString(){ [native code] } Dict; // => 1Dict; // => undefined var O = {};O'q' = 1;O'q'; // => 1O'__proto__' = w: 2;O'__proto__'; // => {w: 2}O'w'; // => 2 var O = {};Dict;O'q'; // => 1Dict;O'__proto__'; // => {w: 2}O'w'; // => undefined
Other methods of Dict
module are static equialents of Array.prototype
methods for dictionaries.
var dict = a: 1 b: 2 c: 3; Dict;// => 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; // => {a: 1, b: 4, c: 9} Dict; // => {aa: 1, cc: 9} Dict; // => {a: 1, c: 3} Dict; // => true Dict; // => false Dict; // => 3Dict; // => undefined Dict; // => 'c'Dict; // => undefined Dict; // => 'b'Dict; // => undefined Dict; // => trueDict; // => false Dict; // => 6Dict; // => '123'
Partial application
Module core.function.part
.
Function # ->
core-js/core/
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
.
var fn1 = log;; // => 1, 2, 3, 4 var fn2 = log;; // => 1, 2, 3, 4 var fn3 = log;; // => 1, 2, 3, 4 ; // => 1, 2, 3, 4, 5; // => 1, 2, undefined, 4
Number Iterator
Module core.number.iterator
.
Number #@@ -> iterator
core-
forvar i of 3console; // => 0, 1, 2 ...10; // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Array; // => [0.9817775336559862, 0.02720663254149258, ...] Array; // => [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 -> strString # -> str # -> str
core-
RegExp; // => 'Hello, \[\]\{\}\(\)\*\+\?\.\\\^\$\|!' '<script>doSomething();</script>'; // => '<script>doSomething();</script>''<script>doSomething();</script>'; // => '<script>doSomething();</script>'
delay
Module core.delay
. Promise-returning delay function, esdiscuss.
-> promise
core-
; async { await ; console; whileawait console;};
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 -> bool -> iterator ->
core-
var list = { return arguments;}1 2 3; console; // true; var iter = core;console; // 1console; // 2console; // 3console; // undefined core; // TypeError: [object Object] is not iterable! var iterFn = core;console; // 'function'var iter = iterFn;console; // 1console; // 2console; // 3console; // undefined console; // undefined
Missing polyfills
- ES5
JSON
is missing now only in IE7- and never will it be added tocore-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 styleProxy
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 incore-js
. Looking at a large number of requests it maybe added in the future. Now you can use, for example, this polyfill.