# core-js
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/zloirock/core-js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![version](https://img.shields.io/npm/v/core-js.svg)](https://www.npmjs.com/package/core-js) [![npm downloads](https://img.shields.io/npm/dm/core-js.svg)](http://npm-stat.com/charts.html?package=core-js&author=&from=2014-11-18&to=2114-11-18) [![Build Status](https://travis-ci.org/zloirock/core-js.png)](https://travis-ci.org/zloirock/core-js) [![devDependency Status](https://david-dm.org/zloirock/core-js/dev-status.svg)](https://david-dm.org/zloirock/core-js#info=devDependencies)
Modular compact standard library for JavaScript. Includes polyfills for [ECMAScript 5](#ecmascript-5), [ECMAScript 6](#ecmascript-6): [symbols](#ecmascript-6-symbol), [collections](#ecmascript-6-collections), [iterators](#ecmascript-6-iterators), [promises](#ecmascript-6-promise), [ECMAScript 7 proposals](#ecmascript-7); [setImmediate](#setimmediate), [array generics](#mozilla-javascript-array-generics). Some additional features such as [dictionaries](#dict) or [extended partial application](#partial-application). You can require only standardized features polyfills, use features without global namespace pollution or create a custom build.
[Example](http://goo.gl/mfHYm2):
```javascript
Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3]
'*'.repeat(10); // => '**********'
Promise.resolve(32).then(log); // => 32
setImmediate(log, 42); // => 42
```
[Without global namespace pollution](http://goo.gl/WBhs43):
```javascript
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(core.log); // => 32
core.setImmediate(core.log, 42); // => 42
```
- [Usage](#usage)
- [Basic](#basic)
- [CommonJS](#commonjs)
- [Custom build](#custom-build)
- [Features](#features)
- [ECMAScript 5](#ecmascript-5)
- [ECMAScript 6](#ecmascript-6)
- [ECMAScript 6: Object](#ecmascript-6-object)
- [ECMAScript 6: Function](#ecmascript-6-function)
- [ECMAScript 6: Array](#ecmascript-6-array)
- [ECMAScript 6: String](#ecmascript-6-string)
- [ECMAScript 6: RegExp](#ecmascript-6-regexp)
- [ECMAScript 6: Number](#ecmascript-6-number)
- [ECMAScript 6: Math](#ecmascript-6-math)
- [ECMAScript 6: Symbol](#ecmascript-6-symbol)
- [ECMAScript 6: Collections](#ecmascript-6-collections)
- [ECMAScript 6: Iterators](#ecmascript-6-iterators)
- [ECMAScript 6: Promise](#ecmascript-6-promise)
- [ECMAScript 6: Reflect](#ecmascript-6-reflect)
- [ECMAScript 7](#ecmascript-7)
- [Mozilla JavaScript: Array generics](#mozilla-javascript-array-generics)
- [Web standards](#web-standards)
- [setTimeout / setInterval](#settimeout--setinterval)
- [setImmediate](#setimmediate)
- [Non-standard](#non-standard)
- [Object](#object)
- [Dict](#dict)
- [Partial application](#partial-application)
- [Number Iterator](#number-iterator)
- [Escaping HTML](#escaping-html)
- [delay](#delay)
- [console](#console)
- [Missing polyfills](#missing-polyfills)
- [Changelog](./CHANGELOG.md)
## Usage
### Basic
```
npm i core-js
bower install core.js
```
```javascript
// 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: [default](https://raw.githack.com/zloirock/core-js/master/client/core.min.js), [without global namespace pollution](https://raw.githack.com/zloirock/core-js/master/client/library.min.js), [shim only](https://raw.githack.com/zloirock/core-js/master/client/shim.min.js).
Warning: if you uses `core-js` with the extension of native objects, require all needed `core-js` modules at the beginning of entry point of your application, otherwise maybe conflicts.
### CommonJS
You can require only needed modules.
```js
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`](#ecmascript-5) 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](#ecmascript-6-array), `core-js/es6` (`core-js/library/es6`) contains all ES6 features.
### Custom build
```
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](#ecmascript-6-array), `es6` contains all modules whose names start with `es6`.
Available custom build from js code (required `webpack`):
```js
require('core-js/build')({
modules: ['es6', 'core.dict'], // modules / namespaces
blacklist: ['es6.reflect'], // blacklist of modules / namespaces
library: false, // flag for build without global namespace pollution
}, function(err, code){ // callback
// ...
});
```
## Features:
### ECMAScript 5
Module [`es5`](https://github.com/zloirock/core-js/blob/v1.2.6/modules/es5.js), nothing new - without examples.
```javascript
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](#ecmascript-6), but available as part of `es5` namespace too:
```js
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
```
### ECMAScript 6
#### ECMAScript 6: Object
Modules [`es6.object.assign`](https://github.com/zloirock/core-js/blob/v1.2.6/modules/es6.object.assign.js), [`es6.object.is`](https://github.com/zloirock/core-js/blob/v1.2.6/modu
- 1
- 2
前往页