Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 106 lines (84 sloc) 4.027 kB
50213b5 @paulmillr Initial commit.
authored
1 # ES6 Shim
2 Provides compatibility shims so that legacy JavaScript engines behave as
3 closely as possible to ECMAScript 6 (Harmony).
4
15693cc @paulmillr Add browser tests. Closes #1.
authored
5 Project targets engines that support ES5 (Firefox, Chrome, Safari, Opera). With
4fde010 @paulmillr Would -> could because it's untested in ie.
authored
6 [ES5-shim](https://github.com/kriskowal/es5-shim) it could also work in older
d4c699b @paulmillr Add es5-shim note.
authored
7 browsers.
8
50213b5 @paulmillr Initial commit.
authored
9 ## Installation
10
11 npm install es6-shim
12
c1d6cca @paulmillr Add getting started to readme.
authored
13 Or just include es6-shim before your scripts if you want to use it in browser.
14
50213b5 @paulmillr Initial commit.
authored
15 ## Safe shims
1d8e4fb @paulmillr Remove "iteration" note in maps / sets.
authored
16 * Maps & Sets
50213b5 @paulmillr Initial commit.
authored
17 * String.prototype.repeat, String.prototype.startsWith,
eef8324 @paulmillr Remove String#toArray and Object#isObject as per update.
authored
18 String.prototype.endsWith, String.prototype.contains
50213b5 @paulmillr Initial commit.
authored
19 * Array.from, Array.of
0c40513 @paulmillr Add more Number and Object functions.
authored
20 * Number.MAX_INTEGER, Number.EPSILON, Number.parseInt, Number.parseFloat,
21 Number.isNaN, Number.toInteger, Number.isInteger, Number.isFinite
5a19679 @paulmillr Add Math.sign().
authored
22 * Object.getOwnPropertyDescriptors, Object.getPropertyDescriptor,
eef8324 @paulmillr Remove String#toArray and Object#isObject as per update.
authored
23 Object.getPropertyNames, Object.is, Object.isnt
38d38b6 @paulmillr Fix readme & re-publish 0.4.0.
authored
24 * Math.sign, Math.log10, Math.log2, Math.log1p, Math.expm1, Math.cosh,
25 Math.sinh, Math.tanh, Math.acosh, Math.asinh, Math.atanh, Math.hypot,
bc0f83c @paulmillr Add math funcs accuracy note to readme.
authored
26 Math.trunc (accuracy is 1e-11).
50213b5 @paulmillr Initial commit.
authored
27
8e8e415 @paulmillr Add a note on weak map shim.
authored
28 ## WeakMap shim
29 It is not possible to implement WeakMap in pure javascript.
30 [es6-collections](https://github.com/WebReflection/es6-collections)
31 implementation doesn't held values strongly which is critical
32 for the collection. es6-shim decided to not include incorrect shim.
33
34 WeakMap has very unusual use-case so you probably won't need it at all (
35 use simple `Map` instead).
36
8506851 @paulmillr Release 0.3.1 with IE8 support.
authored
37 ## IE8 support
38 There are some shims that do not work in IE8, because it is simply not
39 possible to implement them properly:
40
41 * Object.getOwnPropertyDescriptors, Object.getPropertyDescriptor, Object.getPropertyNames
42
c1d6cca @paulmillr Add getting started to readme.
authored
43 ## Getting started
44
45 ```javascript
46 'abc'.startsWith('a') // true
47 'abc'.endsWith('a') // false
48 Object.is(NaN, NaN) // Fixes ===. 0 isnt -0, NaN is NaN
49 '123'.repeat(2) // '123123'
50 'john alice'.contains('john') // true
51 Number.isNaN('123') // false. isNaN('123') will give true.
52 Number.toInteger(2.4) // 2. converts values to IEEE754 double precision integers
53 // Tests if value is a number, finite,
edc883d @paulmillr Release 0.4.1.
authored
54 // >= -9007199254740992 && <= 9007199254740992 and floor(value) === value
c91cd12 @mathiasbynens Fix typo: `Number.isInteger(2.4)` equals `false`, not `true`
mathiasbynens authored
55 Number.isInteger(2.4) // false.
c1d6cca @paulmillr Add getting started to readme.
authored
56 Number.isFinite('asd') // false. Global isFinite() will give true.
57 Math.sign(400) // 1, 0 or -1 depending on sign. In this case 1.
58
59 // Replacement for `{}` key-value storage.
60 // Keys can be anything.
61 var map = new Map()
62 map.set('John', 25)
63 map.set('Alice', 400)
64 map.set(['meh'], 555)
65 map.get(['meh']) // undefined because you need to use exactly the same object.
66 map.delete('Alice')
67
68 // Useful for storing unique items.
69 var set = new Set()
70 set.add(1)
71 set.add(5)
72 set.has(1)
73 set.has(4) // => false
74 set.delete(5)
75 ```
76
73b77fa @paulmillr Add links to es6 spec drafts and harmony proposals.
authored
77 Other stuff:
78
79 * [ECMAScript 6 drafts](http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts)
80 * [Harmony proposals](http://wiki.ecmascript.org/doku.php?id=harmony:harmony)
81
50213b5 @paulmillr Initial commit.
authored
82 ## License
7327e9c @paulmillr Add "initially based" note.
authored
83 The project was initially based on [es6-shim by Axel Rauschmayer](https://github.com/rauschma/es6-shim).
84
50213b5 @paulmillr Initial commit.
authored
85 The MIT License (MIT)
86
73b77fa @paulmillr Add links to es6 spec drafts and harmony proposals.
authored
87 Copyright (c) 2012 Paul Miller (http://paulmillr.com)
50213b5 @paulmillr Initial commit.
authored
88
89 Permission is hereby granted, free of charge, to any person obtaining a copy of
90 this software and associated documentation files (the "Software"), to deal in
91 the Software without restriction, including without limitation the rights to
92 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
93 of the Software, and to permit persons to whom the Software is furnished to do
94 so, subject to the following conditions:
95
96 The above copyright notice and this permission notice shall be included in all
97 copies or substantial portions of the Software.
98
99 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
100 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
101 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
102 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
103 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
104 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
105 SOFTWARE.
Something went wrong with that request. Please try again.