[![Build status][build-image]][build-url]
[![Tests coverage][cov-image]][cov-url]
[![npm version][npm-image]][npm-url]
# es5-ext
## ECMAScript 5 extensions
### (with respect to ECMAScript 6 standard)
Shims for upcoming ES6 standard and other goodies implemented strictly with ECMAScript conventions in mind.
It's designed to be used in compliant ECMAScript 5 or ECMAScript 6 environments. Older environments are not supported, although most of the features should work with correct ECMAScript 5 shim on board.
When used in ECMAScript 6 environment, native implementation (if valid) takes precedence over shims.
### Installation
```bash
npm install es5-ext
```
To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/)
### Usage
#### ECMAScript 6 features
You can force ES6 features to be implemented in your environment, e.g. following will assign `from` function to `Array` (only if it's not implemented already).
```javascript
require("es5-ext/array/from/implement");
Array.from("foo"); // ['f', 'o', 'o']
```
You can also access shims directly, without fixing native objects. Following will return native `Array.from` if it's available and fallback to shim if it's not.
```javascript
var aFrom = require("es5-ext/array/from");
aFrom("foo"); // ['f', 'o', 'o']
```
If you want to use shim unconditionally (even if native implementation exists) do:
```javascript
var aFrom = require("es5-ext/array/from/shim");
aFrom("foo"); // ['f', 'o', 'o']
```
##### List of ES6 shims
It's about properties introduced with ES6 and those that have been updated in new spec.
- `Array.from` -> `require('es5-ext/array/from')`
- `Array.of` -> `require('es5-ext/array/of')`
- `Array.prototype.concat` -> `require('es5-ext/array/#/concat')`
- `Array.prototype.copyWithin` -> `require('es5-ext/array/#/copy-within')`
- `Array.prototype.entries` -> `require('es5-ext/array/#/entries')`
- `Array.prototype.fill` -> `require('es5-ext/array/#/fill')`
- `Array.prototype.filter` -> `require('es5-ext/array/#/filter')`
- `Array.prototype.find` -> `require('es5-ext/array/#/find')`
- `Array.prototype.findIndex` -> `require('es5-ext/array/#/find-index')`
- `Array.prototype.keys` -> `require('es5-ext/array/#/keys')`
- `Array.prototype.map` -> `require('es5-ext/array/#/map')`
- `Array.prototype.slice` -> `require('es5-ext/array/#/slice')`
- `Array.prototype.splice` -> `require('es5-ext/array/#/splice')`
- `Array.prototype.values` -> `require('es5-ext/array/#/values')`
- `Array.prototype[@@iterator]` -> `require('es5-ext/array/#/@@iterator')`
- `Math.acosh` -> `require('es5-ext/math/acosh')`
- `Math.asinh` -> `require('es5-ext/math/asinh')`
- `Math.atanh` -> `require('es5-ext/math/atanh')`
- `Math.cbrt` -> `require('es5-ext/math/cbrt')`
- `Math.clz32` -> `require('es5-ext/math/clz32')`
- `Math.cosh` -> `require('es5-ext/math/cosh')`
- `Math.exmp1` -> `require('es5-ext/math/expm1')`
- `Math.fround` -> `require('es5-ext/math/fround')`
- `Math.hypot` -> `require('es5-ext/math/hypot')`
- `Math.imul` -> `require('es5-ext/math/imul')`
- `Math.log1p` -> `require('es5-ext/math/log1p')`
- `Math.log2` -> `require('es5-ext/math/log2')`
- `Math.log10` -> `require('es5-ext/math/log10')`
- `Math.sign` -> `require('es5-ext/math/sign')`
- `Math.signh` -> `require('es5-ext/math/signh')`
- `Math.tanh` -> `require('es5-ext/math/tanh')`
- `Math.trunc` -> `require('es5-ext/math/trunc')`
- `Number.EPSILON` -> `require('es5-ext/number/epsilon')`
- `Number.MAX_SAFE_INTEGER` -> `require('es5-ext/number/max-safe-integer')`
- `Number.MIN_SAFE_INTEGER` -> `require('es5-ext/number/min-safe-integer')`
- `Number.isFinite` -> `require('es5-ext/number/is-finite')`
- `Number.isInteger` -> `require('es5-ext/number/is-integer')`
- `Number.isNaN` -> `require('es5-ext/number/is-nan')`
- `Number.isSafeInteger` -> `require('es5-ext/number/is-safe-integer')`
- `Object.assign` -> `require('es5-ext/object/assign')`
- `Object.keys` -> `require('es5-ext/object/keys')`
- `Object.setPrototypeOf` -> `require('es5-ext/object/set-prototype-of')`
- `Promise.prototype.finally` -> `require('es5-ext/promise/#/finally')`
- `RegExp.prototype.match` -> `require('es5-ext/reg-exp/#/match')`
- `RegExp.prototype.replace` -> `require('es5-ext/reg-exp/#/replace')`
- `RegExp.prototype.search` -> `require('es5-ext/reg-exp/#/search')`
- `RegExp.prototype.split` -> `require('es5-ext/reg-exp/#/split')`
- `RegExp.prototype.sticky` -> Implement with `require('es5-ext/reg-exp/#/sticky/implement')`, use as function with `require('es5-ext/reg-exp/#/is-sticky')`
- `RegExp.prototype.unicode` -> Implement with `require('es5-ext/reg-exp/#/unicode/implement')`, use as function with `require('es5-ext/reg-exp/#/is-unicode')`
- `String.fromCodePoint` -> `require('es5-ext/string/from-code-point')`
- `String.raw` -> `require('es5-ext/string/raw')`
- `String.prototype.codePointAt` -> `require('es5-ext/string/#/code-point-at')`
- `String.prototype.contains` -> `require('es5-ext/string/#/contains')`
- `String.prototype.endsWith` -> `require('es5-ext/string/#/ends-with')`
- `String.prototype.normalize` -> `require('es5-ext/string/#/normalize')`
- `String.prototype.repeat` -> `require('es5-ext/string/#/repeat')`
- `String.prototype.startsWith` -> `require('es5-ext/string/#/starts-with')`
- `String.prototype[@@iterator]` -> `require('es5-ext/string/#/@@iterator')`
#### Non ECMAScript standard features
**es5-ext** provides also other utils, and implements them as if they were proposed for a standard. It mostly offers methods (not functions) which can directly be assigned to native prototypes:
```javascript
Object.defineProperty(Function.prototype, "partial", {
value: require("es5-ext/function/#/partial"),
configurable: true,
enumerable: false,
writable: true
});
Object.defineProperty(Array.prototype, "flatten", {
value: require("es5-ext/array/#/flatten"),
configurable: true,
enumerable: false,
writable: true
});
Object.defineProperty(String.prototype, "capitalize", {
value: require("es5-ext/string/#/capitalize"),
configurable: true,
enumerable: false,
writable: true
});
```
See [es5-extend](https://github.com/wookieb/es5-extend#es5-extend), a great utility that automatically will extend natives for you.
**Important:** Remember to **not** extend natives in scope of generic reusable packages (e.g. ones you intend to publish to npm). Extending natives is fine **only** if you're the _owner_ of the global scope, so e.g. in final project you lead development of.
When you're in situation when native extensions are not good idea, then you should use methods indirectly:
```javascript
var flatten = require("es5-ext/array/#/flatten");
flatten.call([1, [2, [3, 4]]]); // [1, 2, 3, 4]
```
for better convenience you can turn methods into functions:
```javascript
var call = Function.prototype.call;
var flatten = call.bind(require("es5-ext/array/#/flatten"));
flatten([1, [2, [3, 4]]]); // [1, 2, 3, 4]
```
You can configure custom toolkit (like [underscorejs](http://underscorejs.org/)), and use it throughout your application
```javascript
var util = {};
util.partial = call.bind(require("es5-ext/function/#/partial"));
util.flatten = call.bind(require("es5-ext/array/#/flatten"));
util.startsWith = call.bind(require("es5-ext/string/#/starts-with"));
util.flatten([1, [2, [3, 4]]]); // [1, 2, 3, 4]
```
As with native ones most methods are generic and can be run on any type of object.
## API
### Global extensions
#### global _(es5-ext/global)_
Object that represents global scope
### Array Constructor extensions
#### from(arrayLike[, mapFn[, thisArg]]) _(es5-ext/array/from)_
[_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from).
Returns array representation of _iterable_ or _arrayLike_. If _arrayLike_ is an instance of array, its copy
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
NFT铸币和AI生图两大热点话题,创造自己的NFT图片 (2000个子文件)
tests.c 214KB
KeccakP-1600-inplace32BI.c 42KB
tests_exhaustive.c 20KB
secp256k1.c 20KB
KeccakP-1600-opt64.c 18KB
bench_internal.c 13KB
org_bitcoin_NativeSecp256k1.c 12KB
bench_ecmult.c 7KB
lax_der_privatekey_parsing.c 5KB
bench_verify.c 4KB
bufferutil.c 4KB
lax_der_parsing.c 4KB
gen_context.c 2KB
bench_recover.c 2KB
bench_ecdh.c 2KB
bench_sign.c 2KB
KeccakSpongeWidth1600.c 2KB
KeccakSpongeWidth1600.c 2KB
org_bitcoin_Secp256k1Context.c 404B
map-file-comment-inline.css 1KB
map-file-comment.css 252B
map-file-comment-double-slash.css 249B
nan.h 86KB
field_10x26_impl.h 46KB
ecmult_impl.h 43KB
scalar_4x64_impl.h 30KB
secp256k1.h 29KB
group_impl.h 27KB
scalar_8x32_impl.h 26KB
tests_impl.h 20KB
nan_callbacks_12_inl.h 17KB
nan_callbacks_pre_12_inl.h 17KB
field_5x52_impl.h 16KB
nan_weak.h 15KB
nan_implementation_12_inl.h 15KB
field_5x52_asm_impl.h 13KB
hash_impl.h 12KB
nan_maybe_43_inl.h 12KB
scalar_impl.h 12KB
ecdsa_impl.h 10KB
ecmult_const_impl.h 9KB
field_5x52_int128_impl.h 9KB
field_impl.h 9KB
nan_new.h 9KB
num_gmp_impl.h 8KB
ecmult_gen_impl.h 8KB
nan_string_bytes.h 8KB
nan_implementation_pre_12_inl.h 8KB
group.h 7KB
main_impl.h 7KB
nan_maybe_pre_43_inl.h 7KB
field.h 6KB
SnP-Relaned.h 6KB
SnP-Relaned.h 6KB
nan_persistent_pre_12_inl.h 6KB
util.h 6KB
nan_json.h 6KB
brg_endian.h 6KB
brg_endian.h 6KB
tests_impl.h 5KB
scalar.h 5KB
secp256k1_recovery.h 5KB
nan_object_wrap.h 4KB
testrand_impl.h 4KB
lax_der_parsing.h 4KB
nan_persistent_12_inl.h 4KB
lax_der_privatekey_parsing.h 4KB
scalar_low_impl.h 4KB
org_bitcoin_NativeSecp256k1.h 4KB
eckey_impl.h 3KB
util.h 3KB
nan_callbacks.h 3KB
nan_typedarray_contents.h 3KB
nan_scriptorigin.h 3KB
scratch_impl.h 3KB
num.h 3KB
nan_converters_43_inl.h 3KB
messages.h 2KB
ecmult.h 2KB
nan_private.h 2KB
ecmult_gen.h 2KB
main_impl.h 2KB
KeccakP-1600-SnP.h 2KB
secp256k1_ecdh.h 2KB
nan_converters.h 2KB
bench.h 2KB
field_10x26.h 2KB
field_5x52.h 2KB
scratch.h 2KB
hash.h 2KB
KeccakP-1600-SnP.h 2KB
KeccakSponge-common.h 2KB
KeccakSponge-common.h 2KB
testrand.h 1KB
nan_converters_pre_43_inl.h 1KB
eckey.h 1KB
ecdsa.h 1KB
KeccakSpongeWidth1600.h 1KB
KeccakSpongeWidth1600.h 1KB
nan_define_own_property_helper.h 1KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
奔强的程序
- 粉丝: 1028
- 资源: 2750
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 地面无线电台(站)设置使用申请表.xlsx
- 档案材料归档移交目录表.docx
- 辅导员工作考核汇总表.docx
- 辅导员工作考核上报表.docx
- 辅导员工作考核登记表、辅导员工作量化考核表.docx
- 高中阶段(水平五)体育寒假作业建议表.docx
- 各年龄段骨密度参考值表.docx
- 工贸小微企业公示牌内容填写示范.docx
- 公寓管理服务中心研究生入住申请表.doc
- 管理工程系学生周五和周六晚不住校申请表.doc
- 国内公务接待清单.doc
- 技能学分项目和分值表.docx
- 教师学生听课记录.doc
- 快速随机Hough变换应用于多圆检测的研究与实现
- 普通高等学校毕业就业证明函.doc
- 省直住房货币化补贴提取申请表.xls
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功