- module es7.string.at
js
String
#at(index) -> string
CommonJS entry points:
js
core-js(/library)/fn/string/at
core-js(/library)/fn/string/virtual/at
Examples:
js
'a𠮷b'.at(1); // => '𠮷'
'a𠮷b'.at(1).length; // => 2
Map#toJSON
, Set#toJSON
proposal - modules es7.map.to-json
, es7.set.to-json
(rejected and will be removed from core-js@3
)
js
Map
#toJSON() -> array (rejected and will be removed from core-js@3)
Set
#toJSON() -> array (rejected and will be removed from core-js@3)
CommonJS entry points:
js
core-js(/library)/fn/map
core-js(/library)/fn/set
Error.isError
proposal - module es7.error.is-error
(withdrawn and will be removed from core-js@3
)
js
Error
.isError(it) -> bool (withdrawn and will be removed from core-js@3)
CommonJS entry points:
js
core-js(/library)/fn/error/is-error
Math.{iaddh, isubh, imulh, umulh}
proposal - modules es7.math.iaddh
, es7.math.isubh
, es7.math.imulh
and es7.math.umulh
js
Math
.iaddh(lo0, hi0, lo1, hi1) -> int32
.isubh(lo0, hi0, lo1, hi1) -> int32
.imulh(a, b) -> int32
.umulh(a, b) -> uint32
CommonJS entry points:
js
core-js(/library)/fn/math/iaddh
core-js(/library)/fn/math/isubh
core-js(/library)/fn/math/imulh
core-js(/library)/fn/math/umulh
global.asap
, TC39 discussion, module es7.asap
js
asap(fn) -> void
CommonJS entry points:
js
core-js(/library)/fn/asap
Examples:
js
asap(() => console.log('called as microtask'));
core-js(/library)/stage/pre
Reflect
metadata proposal - modules es7.reflect.define-metadata
, es7.reflect.delete-metadata
, es7.reflect.get-metadata
, es7.reflect.get-metadata-keys
, es7.reflect.get-own-metadata
, es7.reflect.get-own-metadata-keys
, es7.reflect.has-metadata
, es7.reflect.has-own-metadata
and es7.reflect.metadata
.
js
Reflect
.defineMetadata(metadataKey, metadataValue, target, propertyKey?) -> void
.getMetadata(metadataKey, target, propertyKey?) -> var
.getOwnMetadata(metadataKey, target, propertyKey?) -> var
.hasMetadata(metadataKey, target, propertyKey?) -> bool
.hasOwnMetadata(metadataKey, target, propertyKey?) -> bool
.deleteMetadata(metadataKey, target, propertyKey?) -> bool
.getMetadataKeys(target, propertyKey?) -> array
.getOwnMetadataKeys(target, propertyKey?) -> array
.metadata(metadataKey, metadataValue) -> decorator(target, targetKey?) -> void
CommonJS entry points:
js
core-js(/library)/fn/reflect/define-metadata
core-js(/library)/fn/reflect/delete-metadata
core-js(/library)/fn/reflect/get-metadata
core-js(/library)/fn/reflect/get-metadata-keys
core-js(/library)/fn/reflect/get-own-metadata
core-js(/library)/fn/reflect/get-own-metadata-keys
core-js(/library)/fn/reflect/has-metadata
core-js(/library)/fn/reflect/has-own-metadata
core-js(/library)/fn/reflect/metadata
Examples:
js
var O = {};
Reflect.defineMetadata('foo', 'bar', O);
Reflect.ownKeys(O); // => []
Reflect.getOwnMetadataKeys(O); // => ['foo']
Reflect.getOwnMetadata('foo', O); // => 'bar'
core-js(/library)/web
Module web.timers
. Additional arguments fix for IE9-.
setTimeout(fn(...args), time, ...args) -> id
setInterval(fn(...args), time, ...args) -> id
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);
Module web.immediate
. setImmediate
proposal polyfill.
setImmediate(fn(...args), ...args) -> id
clearImmediate(id) -> void
core-js(/library)/web/immediate
core-js(/library)/fn/set-immediate
core-js(/library)/fn/clear-immediate
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');
}));
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
:
{
CSSRuleList,
CSSStyleDeclaration,
CSSValueList,
ClientRectList,
DOMRectList,
DOMStringList,
DOMTokenList,
DataTransferItemList,
FileList,
HTMLAllCollection,
HTMLCollection,
HTMLFormElement,
HTMLSelectElement,
MediaList,
MimeTypeArray,
NamedNodeMap,
NodeList,
PaintRequestList,
Plugin,
PluginArray,
SVGLengthList,
SVGNumberList,
SVGPathSegList,
SVGPointList,
SVGStringList,
SVGTransformList,
SourceBufferList,
StyleSheetList,
TextTrackCueList,
TextTrackList,
TouchList
}
#@@iterator() -> iterator (values)
{
DOMTokenList,
NodeList
}
#values() -> iterator
#keys() -> iterator
#entries() -> iterator
core-js(/library)/web/dom-collections
core-js(/library)/fn/dom-collections/iterator
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);
}
core-js(/library)/core
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
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
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
core-js(/library)/core/dict
core-js(/library)/fn/dict
Dict
create object without prototype from iterable or simple object.
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.
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 equivalents of Array.prototype
methods for dictionaries.
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'
Module core.function.part
.
Function
#part(...args | _) -> fn(...args)
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
.
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
Module core.number.iterator
.
Number
#@@iterator() -> iterator
core-js(/library)/core/number
core-js(/library)/fn/number/iterator
core-js(/library)/fn/number/virtual/iterator
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]
Modules core.regexp.escape
, core.string.escape-html
and core.string.unescape-html
.
RegExp
.escape(str) -> str
String
#escapeHTML() -> str
#unescapeHTML() -> str
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
RegExp.escape('Hello, []{}()*+?.\\^$|!'); // => 'Hello, \[\]\{\}\(\)\*\+\?\.\\\^\$\|!'
'<script>doSomething();</script>'.escapeHTML(); // => '<script>doSomething();</script>'
'<script>doSomething();</script>'.unescapeHTML(); // => '<script>doSomething();</script>'
Module core.delay
. Promise-returning delay function, esdiscuss.
delay(ms) -> promise
core-js(/library)/core/delay
core-js(/library)/fn/delay
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');
})();
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
core-js(/library)/fn/is-iterable
core-js(/library)/fn/get-iterator
core-js(/library)/fn/get-iterator-method
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
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.String#normalize
is not a very useful feature, but this polyfill will be very large. If you need it, you can use unorm.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.@@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.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 makes no sense. For this reason, I don't think it should be in core-js
. Looking at a large number of requests it may be added in the future. Now you can use, for example, this polyfill.Intl
is missed because of size. You can use this polyfill.