2 ## ECMAScript 5 extensions
3 ### (with respect to ECMAScript 6 standard)
5 Shims for upcoming ES6 standard and other goodies implemented strictly with ECMAScript conventions in mind.
7 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.
9 When used in ECMAScript 6 environment, native implementation (if valid) takes precedence over shims.
15 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/)
19 #### ECMAScript 6 features
21 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).
24 require('es5-ext/array/from/implement');
25 Array.from('foo'); // ['f', 'o', 'o']
28 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.
31 var aFrom = require('es5-ext/array/from');
32 aFrom('foo'); // ['f', 'o', 'o']
35 If you want to use shim unconditionally (even if native implementation exists) do:
38 var aFrom = require('es5-ext/array/from/shim');
39 aFrom('foo'); // ['f', 'o', 'o']
42 ##### List of ES6 shims
44 It's about properties introduced with ES6 and those that have been updated in new spec.
46 - `Array.from` -> `require('es5-ext/array/from')`
47 - `Array.of` -> `require('es5-ext/array/of')`
48 - `Array.prototype.concat` -> `require('es5-ext/array/#/concat')`
49 - `Array.prototype.copyWithin` -> `require('es5-ext/array/#/copy-within')`
50 - `Array.prototype.entries` -> `require('es5-ext/array/#/entries')`
51 - `Array.prototype.fill` -> `require('es5-ext/array/#/fill')`
52 - `Array.prototype.filter` -> `require('es5-ext/array/#/filter')`
53 - `Array.prototype.find` -> `require('es5-ext/array/#/find')`
54 - `Array.prototype.findIndex` -> `require('es5-ext/array/#/find-index')`
55 - `Array.prototype.keys` -> `require('es5-ext/array/#/keys')`
56 - `Array.prototype.map` -> `require('es5-ext/array/#/map')`
57 - `Array.prototype.slice` -> `require('es5-ext/array/#/slice')`
58 - `Array.prototype.splice` -> `require('es5-ext/array/#/splice')`
59 - `Array.prototype.values` -> `require('es5-ext/array/#/values')`
60 - `Array.prototype[@@iterator]` -> `require('es5-ext/array/#/@@iterator')`
61 - `Math.acosh` -> `require('es5-ext/math/acosh')`
62 - `Math.asinh` -> `require('es5-ext/math/asinh')`
63 - `Math.atanh` -> `require('es5-ext/math/atanh')`
64 - `Math.cbrt` -> `require('es5-ext/math/cbrt')`
65 - `Math.clz32` -> `require('es5-ext/math/clz32')`
66 - `Math.cosh` -> `require('es5-ext/math/cosh')`
67 - `Math.exmp1` -> `require('es5-ext/math/expm1')`
68 - `Math.fround` -> `require('es5-ext/math/fround')`
69 - `Math.hypot` -> `require('es5-ext/math/hypot')`
70 - `Math.imul` -> `require('es5-ext/math/imul')`
71 - `Math.log1p` -> `require('es5-ext/math/log1p')`
72 - `Math.log2` -> `require('es5-ext/math/log2')`
73 - `Math.log10` -> `require('es5-ext/math/log10')`
74 - `Math.sign` -> `require('es5-ext/math/sign')`
75 - `Math.signh` -> `require('es5-ext/math/signh')`
76 - `Math.tanh` -> `require('es5-ext/math/tanh')`
77 - `Math.trunc` -> `require('es5-ext/math/trunc')`
78 - `Number.EPSILON` -> `require('es5-ext/number/epsilon')`
79 - `Number.MAX_SAFE_INTEGER` -> `require('es5-ext/number/max-safe-integer')`
80 - `Number.MIN_SAFE_INTEGER` -> `require('es5-ext/number/min-safe-integer')`
81 - `Number.isFinite` -> `require('es5-ext/number/is-finite')`
82 - `Number.isInteger` -> `require('es5-ext/number/is-integer')`
83 - `Number.isNaN` -> `require('es5-ext/number/is-nan')`
84 - `Number.isSafeInteger` -> `require('es5-ext/number/is-safe-integer')`
85 - `Object.assign` -> `require('es5-ext/object/assign')`
86 - `Object.keys` -> `require('es5-ext/object/keys')`
87 - `Object.setPrototypeOf` -> `require('es5-ext/object/set-prototype-of')`
88 - `RegExp.prototype.match` -> `require('es5-ext/reg-exp/#/match')`
89 - `RegExp.prototype.replace` -> `require('es5-ext/reg-exp/#/replace')`
90 - `RegExp.prototype.search` -> `require('es5-ext/reg-exp/#/search')`
91 - `RegExp.prototype.split` -> `require('es5-ext/reg-exp/#/split')`
92 - `RegExp.prototype.sticky` -> Implement with `require('es5-ext/reg-exp/#/sticky/implement')`, use as function with `require('es5-ext/reg-exp/#/is-sticky')`
93 - `RegExp.prototype.unicode` -> Implement with `require('es5-ext/reg-exp/#/unicode/implement')`, use as function with `require('es5-ext/reg-exp/#/is-unicode')`
94 - `String.fromCodePoint` -> `require('es5-ext/string/from-code-point')`
95 - `String.raw` -> `require('es5-ext/string/raw')`
96 - `String.prototype.codePointAt` -> `require('es5-ext/string/#/code-point-at')`
97 - `String.prototype.contains` -> `require('es5-ext/string/#/contains')`
98 - `String.prototype.endsWith` -> `require('es5-ext/string/#/ends-with')`
99 - `String.prototype.normalize` -> `require('es5-ext/string/#/normalize')`
100 - `String.prototype.repeat` -> `require('es5-ext/string/#/repeat')`
101 - `String.prototype.startsWith` -> `require('es5-ext/string/#/starts-with')`
102 - `String.prototype[@@iterator]` -> `require('es5-ext/string/#/@@iterator')`
104 #### Non ECMAScript standard features
106 __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:
109 Object.defineProperty(Function.prototype, 'partial', { value: require('es5-ext/function/#/partial'),
110 configurable: true, enumerable: false, writable: true });
111 Object.defineProperty(Array.prototype, 'flatten', { value: require('es5-ext/array/#/flatten'),
112 configurable: true, enumerable: false, writable: true });
113 Object.defineProperty(String.prototype, 'capitalize', { value: require('es5-ext/string/#/capitalize'),
114 configurable: true, enumerable: false, writable: true });
117 See [es5-extend](https://github.com/wookieb/es5-extend#es5-extend), a great utility that automatically will extend natives for you.
119 __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.
121 When you're in situation when native extensions are not good idea, then you should use methods indirectly:
125 var flatten = require('es5-ext/array/#/flatten');
127 flatten.call([1, [2, [3, 4]]]); // [1, 2, 3, 4]
130 for better convenience you can turn methods into functions:
134 var call = Function.prototype.call
135 var flatten = call.bind(require('es5-ext/array/#/flatten'));
137 flatten([1, [2, [3, 4]]]); // [1, 2, 3, 4]
140 You can configure custom toolkit (like [underscorejs](http://underscorejs.org/)), and use it throughout your application
144 util.partial = call.bind(require('es5-ext/function/#/partial'));
145 util.flatten = call.bind(require('es5-ext/array/#/flatten'));
146 util.startsWith = call.bind(require('es5-ext/string/#/starts-with'));
148 util.flatten([1, [2, [3, 4]]]); // [1, 2, 3, 4]
151 As with native ones most methods are generic and can be run on any type of object.
155 ### Global extensions
157 #### global _(es5-ext/global)_
159 Object that represents global scope
161 ### Array Constructor extensions
163 #### from(arrayLike[, mapFn[, thisArg]]) _(es5-ext/array/from)_
165 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from).
166 Returns array representation of _iterable_ or _arrayLike_. If _arrayLike_ is an instance of array, its copy is returned.
168 #### generate([length[, …fill]]) _(es5-ext/array/generate)_
170 Generate an array of pre-given _length_ built of repeated arguments.
172 #### isPlainArray(x) _(es5-ext/array/is-plain-array)_
174 Returns true if object is plain array (not instance of one of the Array's extensions).
176 #### of([…items]) _(es5-ext/array/of)_
178 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.of).
179 Create an array from given arguments.
181 #### toArray(obj) _(es5-ext/array/to-array)_
183 Returns array representation of `obj`. If `obj` is already an array, `obj` is returned back.
185 #### validArray(obj) _(es5-ext/array/valid-array)_
187 Returns `obj` if it's an array, otherwise throws `TypeError`
189 ### Array Prototype extensions
191 #### arr.binarySearch(compareFn) _(es5-ext/array/#/binary-search)_
193 In __sorted__ list search for index of item for which _compareFn_ returns value closest to _0_.
194 It's variant of binary search algorithm
196 #### arr.clear() _(es5-ext/array/#/clear)_
200 #### arr.compact() _(es5-ext/array/#/compact)_
202 Returns a copy of the context with all non-values (`null` or `undefined`) removed.
204 #### arr.concat() _(es5-ext/array/#/concat)_
206 [_Updated with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.prototype.concat).
207 ES6's version of `concat`. Supports `isConcatSpreadable` symbol, and returns array of same type as the context.
209 #### arr.contains(searchElement[, position]) _(es5-ext/array/#/contains)_
211 Whether list contains the given value.
213 #### arr.copyWithin(target, start[, end]) _(es5-ext/array/#/copy-within)_
215 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.copywithin).
217 #### arr.diff(other) _(es5-ext/array/#/diff)_
219 Returns the array of elements that are present in context list but not present in other list.
221 #### arr.eIndexOf(searchElement[, fromIndex]) _(es5-ext/array/#/e-index-of)_
223 _egal_ version of `indexOf` method. [_SameValueZero_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) logic is used for comparision
225 #### arr.eLastIndexOf(searchElement[, fromIndex]) _(es5-ext/array/#/e-last-index-of)_
227 _egal_ version of `lastIndexOf` method. [_SameValueZero_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) logic is used for comparision
229 #### arr.entries() _(es5-ext/array/#/entries)_
231 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.prototype.entries).
232 Returns iterator object, which traverses the array. Each value is represented with an array, where first value is an index and second is corresponding to index value.
234 #### arr.exclusion([…lists]]) _(es5-ext/array/#/exclusion)_
236 Returns the array of elements that are found only in one of the lists (either context list or list provided in arguments).
238 #### arr.fill(value[, start, end]) _(es5-ext/array/#/fill)_
240 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.fill).
242 #### arr.filter(callback[, thisArg]) _(es5-ext/array/#/filter)_
244 [_Updated with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.filter).
245 ES6's version of `filter`, returns array of same type as the context.
247 #### arr.find(predicate[, thisArg]) _(es5-ext/array/#/find)_
249 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.find).
250 Return first element for which given function returns true
252 #### arr.findIndex(predicate[, thisArg]) _(es5-ext/array/#/find-index)_
254 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.findindex).
255 Return first index for which given function returns true
257 #### arr.first() _(es5-ext/array/#/first)_
259 Returns value for first defined index
261 #### arr.firstIndex() _(es5-ext/array/#/first-index)_
263 Returns first declared index of the array
265 #### arr.flatten() _(es5-ext/array/#/flatten)_
267 Returns flattened version of the array
269 #### arr.forEachRight(cb[, thisArg]) _(es5-ext/array/#/for-each-right)_
271 `forEach` starting from last element
273 #### arr.group(cb[, thisArg]) _(es5-ext/array/#/group)_
275 Group list elements by value returned by _cb_ function
277 #### arr.indexesOf(searchElement[, fromIndex]) _(es5-ext/array/#/indexes-of)_
279 Returns array of all indexes of given value
281 #### arr.intersection([…lists]) _(es5-ext/array/#/intersection)_
283 Computes the array of values that are the intersection of all lists (context list and lists given in arguments)
285 #### arr.isCopy(other) _(es5-ext/array/#/is-copy)_
287 Returns true if both context and _other_ lists have same content
289 #### arr.isUniq() _(es5-ext/array/#/is-uniq)_
291 Returns true if all values in array are unique
293 #### arr.keys() _(es5-ext/array/#/keys)_
295 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.prototype.keys).
296 Returns iterator object, which traverses all array indexes.
298 #### arr.last() _(es5-ext/array/#/last)_
300 Returns value of last defined index
302 #### arr.lastIndex() _(es5-ext/array/#/last)_
304 Returns last defined index of the array
306 #### arr.map(callback[, thisArg]) _(es5-ext/array/#/map)_
308 [_Updated with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.map).
309 ES6's version of `map`, returns array of same type as the context.
311 #### arr.remove(value[, …valuen]) _(es5-ext/array/#/remove)_
313 Remove values from the array
315 #### arr.separate(sep) _(es5-ext/array/#/separate)_
317 Returns array with items separated with `sep` value
319 #### arr.slice(callback[, thisArg]) _(es5-ext/array/#/slice)_
321 [_Updated with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.slice).
322 ES6's version of `slice`, returns array of same type as the context.
324 #### arr.someRight(cb[, thisArg]) _(es5-ext/array/#/someRight)_
326 `some` starting from last element
328 #### arr.splice(callback[, thisArg]) _(es5-ext/array/#/splice)_
330 [_Updated with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.splice).
331 ES6's version of `splice`, returns array of same type as the context.
333 #### arr.uniq() _(es5-ext/array/#/uniq)_
335 Returns duplicate-free version of the array
337 #### arr.values() _(es5-ext/array/#/values)_
339 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.prototype.values).
340 Returns iterator object which traverses all array values.
342 #### arr[@@iterator] _(es5-ext/array/#/@@iterator)_
344 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.prototype-@@iterator).
345 Returns iterator object which traverses all array values.
347 ### Boolean Constructor extensions
349 #### isBoolean(x) _(es5-ext/boolean/is-boolean)_
351 Whether value is boolean
353 ### Date Constructor extensions
355 #### isDate(x) _(es5-ext/date/is-date)_
357 Whether value is date instance
359 #### validDate(x) _(es5-ext/date/valid-date)_
361 If given object is not date throw TypeError in other case return it.
363 ### Date Prototype extensions
365 #### date.copy(date) _(es5-ext/date/#/copy)_
367 Returns a copy of the date object
369 #### date.daysInMonth() _(es5-ext/date/#/days-in-month)_
371 Returns number of days of date's month
373 #### date.floorDay() _(es5-ext/date/#/floor-day)_
375 Sets the date time to 00:00:00.000
377 #### date.floorMonth() _(es5-ext/date/#/floor-month)_
379 Sets date day to 1 and date time to 00:00:00.000
381 #### date.floorYear() _(es5-ext/date/#/floor-year)_
383 Sets date month to 0, day to 1 and date time to 00:00:00.000
385 #### date.format(pattern) _(es5-ext/date/#/format)_
387 Formats date up to given string. Supported patterns:
389 * `%Y` - Year with century, 1999, 2003
390 * `%y` - Year without century, 99, 03
391 * `%m` - Month, 01..12
392 * `%d` - Day of the month 01..31
393 * `%H` - Hour (24-hour clock), 00..23
394 * `%M` - Minute, 00..59
395 * `%S` - Second, 00..59
396 * `%L` - Milliseconds, 000..999
398 ### Error Constructor extensions
400 #### custom(message/*, code, ext*/) _(es5-ext/error/custom)_
402 Creates custom error object, optinally extended with `code` and other extension properties (provided with `ext` object)
404 #### isError(x) _(es5-ext/error/is-error)_
406 Whether value is an error (instance of `Error`).
408 #### validError(x) _(es5-ext/error/valid-error)_
410 If given object is not error throw TypeError in other case return it.
412 ### Error Prototype extensions
414 #### err.throw() _(es5-ext/error/#/throw)_
418 ### Function Constructor extensions
420 Some of the functions were inspired by [Functional JavaScript](http://osteele.com/sources/javascript/functional/) project by Olivier Steele
422 #### constant(x) _(es5-ext/function/constant)_
424 Returns a constant function that returns pregiven argument
428 #### identity(x) _(es5-ext/function/identity)_
430 Identity function. Returns first argument
434 #### invoke(name[, …args]) _(es5-ext/function/invoke)_
436 Returns a function that takes an object as an argument, and applies object's
437 _name_ method to arguments.
438 _name_ can be name of the method or method itself.
440 _invoke(name, …args)(object, …args2) =def object\[name\]\(…args, …args2\)_
442 #### isArguments(x) _(es5-ext/function/is-arguments)_
444 Whether value is arguments object
446 #### isFunction(arg) _(es5-ext/function/is-function)_
448 Wether value is instance of function
450 #### noop() _(es5-ext/function/noop)_
452 No operation function
454 #### pluck(name) _(es5-ext/function/pluck)_
456 Returns a function that takes an object, and returns the value of its _name_
459 _pluck(name)(obj) =def obj[name]_
461 #### validFunction(arg) _(es5-ext/function/valid-function)_
463 If given object is not function throw TypeError in other case return it.
465 ### Function Prototype extensions
467 Some of the methods were inspired by [Functional JavaScript](http://osteele.com/sources/javascript/functional/) project by Olivier Steele
469 #### fn.compose([…fns]) _(es5-ext/function/#/compose)_
471 Applies the functions in reverse argument-list order.
473 _f1.compose(f2, f3, f4)(…args) =def f1(f2(f3(f4(…arg))))_
475 #### fn.copy() _(es5-ext/function/#/copy)_
477 Produces copy of given function
479 #### fn.curry([n]) _(es5-ext/function/#/curry)_
481 Invoking the function returned by this function only _n_ arguments are passed to the underlying function. If the underlying function is not saturated, the result is a function that passes all its arguments to the underlying function.
482 If _n_ is not provided then it defaults to context function length
484 _f.curry(4)(arg1, arg2)(arg3)(arg4) =def f(arg1, args2, arg3, arg4)_
486 #### fn.lock([…args]) _(es5-ext/function/#/lock)_
488 Returns a function that applies the underlying function to _args_, and ignores its own arguments.
490 _f.lock(…args)(…args2) =def f(…args)_
492 _Named after it's counterpart in Google Closure_
494 #### fn.not() _(es5-ext/function/#/not)_
496 Returns a function that returns boolean negation of value returned by underlying function.
498 _f.not()(…args) =def !f(…args)_
500 #### fn.partial([…args]) _(es5-ext/function/#/partial)_
502 Returns a function that when called will behave like context function called with initially passed arguments. If more arguments are suplilied, they are appended to initial args.
504 _f.partial(…args1)(…args2) =def f(…args1, …args2)_
506 #### fn.spread() _(es5-ext/function/#/spread)_
508 Returns a function that applies underlying function with first list argument
510 _f.match()(args) =def f.apply(null, args)_
512 #### fn.toStringTokens() _(es5-ext/function/#/to-string-tokens)_
514 Serializes function into two (arguments and body) string tokens. Result is plain object with `args` and `body` properties.
518 #### acosh(x) _(es5-ext/math/acosh)_
520 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.acosh).
522 #### asinh(x) _(es5-ext/math/asinh)_
524 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.asinh).
526 #### atanh(x) _(es5-ext/math/atanh)_
528 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.atanh).
530 #### cbrt(x) _(es5-ext/math/cbrt)_
532 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.cbrt).
534 #### clz32(x) _(es5-ext/math/clz32)_
536 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.clz32).
538 #### cosh(x) _(es5-ext/math/cosh)_
540 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.cosh).
542 #### expm1(x) _(es5-ext/math/expm1)_
544 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.expm1).
546 #### fround(x) _(es5-ext/math/fround)_
548 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.fround).
550 #### hypot([…values]) _(es5-ext/math/hypot)_
552 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.hypot).
554 #### imul(x, y) _(es5-ext/math/imul)_
556 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.imul).
558 #### log1p(x) _(es5-ext/math/log1p)_
560 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.log1p).
562 #### log2(x) _(es5-ext/math/log2)_
564 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.log2).
566 #### log10(x) _(es5-ext/math/log10)_
568 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.log10).
570 #### sign(x) _(es5-ext/math/sign)_
572 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.sign).
574 #### sinh(x) _(es5-ext/math/sinh)_
576 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.sinh).
578 #### tanh(x) _(es5-ext/math/tanh)_
580 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.tanh).
582 #### trunc(x) _(es5-ext/math/trunc)_
584 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.trunc).
586 ### Number Constructor extensions
588 #### EPSILON _(es5-ext/number/epsilon)_
590 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.epsilon).
592 The difference between 1 and the smallest value greater than 1 that is representable as a Number value, which is approximately 2.2204460492503130808472633361816 x 10-16.
594 #### isFinite(x) _(es5-ext/number/is-finite)_
596 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfinite).
597 Whether value is finite. Differs from global isNaN that it doesn't do type coercion.
599 #### isInteger(x) _(es5-ext/number/is-integer)_
601 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isinteger).
602 Whether value is integer.
604 #### isNaN(x) _(es5-ext/number/is-nan)_
606 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isnan).
607 Whether value is NaN. Differs from global isNaN that it doesn't do type coercion.
609 #### isNumber(x) _(es5-ext/number/is-number)_
611 Whether given value is number
613 #### isSafeInteger(x) _(es5-ext/number/is-safe-integer)_
615 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.issafeinteger).
617 #### MAX_SAFE_INTEGER _(es5-ext/number/max-safe-integer)_
619 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.maxsafeinteger).
620 The value of Number.MAX_SAFE_INTEGER is 9007199254740991.
622 #### MIN_SAFE_INTEGER _(es5-ext/number/min-safe-integer)_
624 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.minsafeinteger).
625 The value of Number.MIN_SAFE_INTEGER is -9007199254740991 (253-1).
627 #### toInteger(x) _(es5-ext/number/to-integer)_
629 Converts value to integer
631 #### toPosInteger(x) _(es5-ext/number/to-pos-integer)_
633 Converts value to positive integer. If provided value is less than 0, then 0 is returned
635 #### toUint32(x) _(es5-ext/number/to-uint32)_
637 Converts value to unsigned 32 bit integer. This type is used for array lengths.
638 See: http://www.2ality.com/2012/02/js-integers.html
640 ### Number Prototype extensions
642 #### num.pad(length[, precision]) _(es5-ext/number/#/pad)_
644 Pad given number with zeros. Returns string
646 ### Object Constructor extensions
648 #### assign(target, source[, …sourcen]) _(es5-ext/object/assign)_
650 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign).
651 Extend _target_ by enumerable own properties of other objects. If properties are already set on target object, they will be overwritten.
653 #### clear(obj) _(es5-ext/object/clear)_
655 Remove all enumerable own properties of the object
657 #### compact(obj) _(es5-ext/object/compact)_
659 Returns copy of the object with all enumerable properties that have no falsy values
661 #### compare(obj1, obj2) _(es5-ext/object/compare)_
663 Universal cross-type compare function. To be used for e.g. array sort.
665 #### copy(obj) _(es5-ext/object/copy)_
667 Returns copy of the object with all enumerable properties.
669 #### copyDeep(obj) _(es5-ext/object/copy-deep)_
671 Returns deep copy of the object with all enumerable properties.
673 #### count(obj) _(es5-ext/object/count)_
675 Counts number of enumerable own properties on object
677 #### create(obj[, properties]) _(es5-ext/object/create)_
679 `Object.create` alternative that provides workaround for [V8 issue](http://code.google.com/p/v8/issues/detail?id=2804).
681 When `null` is provided as a prototype, it's substituted with specially prepared object that derives from Object.prototype but has all Object.prototype properties shadowed with undefined.
683 It's quirky solution that allows us to have plain objects with no truthy properties but with turnable prototype.
685 Use only for objects that you plan to switch prototypes of and be aware of limitations of this workaround.
687 #### eq(x, y) _(es5-ext/object/eq)_
689 Whether two values are equal, using [_SameValueZero_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) algorithm.
691 #### every(obj, cb[, thisArg[, compareFn]]) _(es5-ext/object/every)_
693 Analogous to Array.prototype.every. Returns true if every key-value pair in this object satisfies the provided testing function.
694 Optionally _compareFn_ can be provided which assures that keys are tested in given order. If provided _compareFn_ is equal to `true`, then order is alphabetical (by key).
696 #### filter(obj, cb[, thisArg]) _(es5-ext/object/filter)_
698 Analogous to Array.prototype.filter. Returns new object with properites for which _cb_ function returned truthy value.
700 #### firstKey(obj) _(es5-ext/object/first-key)_
702 Returns first enumerable key of the object, as keys are unordered by specification, it can be any key of an object.
704 #### flatten(obj) _(es5-ext/object/flatten)_
706 Returns new object, with flatten properties of input object
708 _flatten({ a: { b: 1 }, c: { d: 1 } }) =def { b: 1, d: 1 }_
710 #### forEach(obj, cb[, thisArg[, compareFn]]) _(es5-ext/object/for-each)_
712 Analogous to Array.prototype.forEach. Calls a function for each key-value pair found in object
713 Optionally _compareFn_ can be provided which assures that properties are iterated in given order. If provided _compareFn_ is equal to `true`, then order is alphabetical (by key).
715 #### getPropertyNames() _(es5-ext/object/get-property-names)_
717 Get all (not just own) property names of the object
719 #### is(x, y) _(es5-ext/object/is)_
721 Whether two values are equal, using [_SameValue_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) algorithm.
723 #### isArrayLike(x) _(es5-ext/object/is-array-like)_
725 Whether object is array-like object
727 #### isCopy(x, y) _(es5-ext/object/is-copy)_
729 Two values are considered a copy of same value when all of their own enumerable properties have same values.
731 #### isCopyDeep(x, y) _(es5-ext/object/is-copy-deep)_
733 Deep comparision of objects
735 #### isEmpty(obj) _(es5-ext/object/is-empty)_
737 True if object doesn't have any own enumerable property
739 #### isObject(arg) _(es5-ext/object/is-object)_
741 Whether value is not primitive
743 #### isPlainObject(arg) _(es5-ext/object/is-plain-object)_
745 Whether object is plain object, its protototype should be Object.prototype and it cannot be host object.
747 #### keyOf(obj, searchValue) _(es5-ext/object/key-of)_
749 Search object for value
751 #### keys(obj) _(es5-ext/object/keys)_
753 [_Updated with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.keys).
754 ES6's version of `keys`, doesn't throw on primitive input
756 #### map(obj, cb[, thisArg]) _(es5-ext/object/map)_
758 Analogous to Array.prototype.map. Creates a new object with properties which values are results of calling a provided function on every key-value pair in this object.
760 #### mapKeys(obj, cb[, thisArg]) _(es5-ext/object/map-keys)_
762 Create new object with same values, but remapped keys
764 #### mixin(target, source) _(es5-ext/object/mixin)_
766 Extend _target_ by all own properties of other objects. Properties found in both objects will be overwritten (unless they're not configurable and cannot be overwritten).
767 _It was for a moment part of ECMAScript 6 draft._
769 #### mixinPrototypes(target, …source]) _(es5-ext/object/mixin-prototypes)_
771 Extends _target_, with all source and source's prototype properties.
772 Useful as an alternative for `setPrototypeOf` in environments in which it cannot be shimmed (no `__proto__` support).
774 #### normalizeOptions(options) _(es5-ext/object/normalize-options)_
776 Normalizes options object into flat plain object.
778 Useful for functions in which we either need to keep options object for future reference or need to modify it for internal use.
780 - It never returns input `options` object back (always a copy is created)
781 - `options` can be undefined in such case empty plain object is returned.
782 - Copies all enumerable properties found down prototype chain.
784 #### primitiveSet([…names]) _(es5-ext/object/primitive-set)_
786 Creates `null` prototype based plain object, and sets on it all property names provided in arguments to true.
788 #### safeTraverse(obj[, …names]) _(es5-ext/object/safe-traverse)_
790 Safe navigation of object properties. See http://wiki.ecmascript.org/doku.php?id=strawman:existential_operator
792 #### serialize(value) _(es5-ext/object/serialize)_
794 Serialize value into string. Differs from [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) that it serializes also dates, functions and regular expresssions.
796 #### setPrototypeOf(object, proto) _(es5-ext/object/set-prototype-of)_
798 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.setprototypeof).
799 If native version is not provided, it depends on existence of `__proto__` functionality, if it's missing, `null` instead of function is exposed.
801 #### some(obj, cb[, thisArg[, compareFn]]) _(es5-ext/object/some)_
803 Analogous to Array.prototype.some Returns true if any key-value pair satisfies the provided
805 Optionally _compareFn_ can be provided which assures that keys are tested in given order. If provided _compareFn_ is equal to `true`, then order is alphabetical (by key).
807 #### toArray(obj[, cb[, thisArg[, compareFn]]]) _(es5-ext/object/to-array)_
809 Creates an array of results of calling a provided function on every key-value pair in this object.
810 Optionally _compareFn_ can be provided which assures that results are added in given order. If provided _compareFn_ is equal to `true`, then order is alphabetical (by key).
812 #### unserialize(str) _(es5-ext/object/unserialize)_
814 Userializes value previously serialized with [serialize](#serializevalue-es5-extobjectserialize)
816 #### validCallable(x) _(es5-ext/object/valid-callable)_
818 If given object is not callable throw TypeError in other case return it.
820 #### validObject(x) _(es5-ext/object/valid-object)_
822 Throws error if given value is not an object, otherwise it is returned.
824 #### validValue(x) _(es5-ext/object/valid-value)_
826 Throws error if given value is `null` or `undefined`, otherwise returns value.
828 ### RegExp Constructor extensions
830 #### escape(str) _(es5-ext/reg-exp/escape)_
832 Escapes string to be used in regular expression
834 #### isRegExp(x) _(es5-ext/reg-exp/is-reg-exp)_
836 Whether object is regular expression
838 #### validRegExp(x) _(es5-ext/reg-exp/valid-reg-exp)_
840 If object is regular expression it is returned, otherwise TypeError is thrown.
842 ### RegExp Prototype extensions
844 #### re.isSticky(x) _(es5-ext/reg-exp/#/is-sticky)_
846 Whether regular expression has `sticky` flag.
848 It's to be used as counterpart to [regExp.sticky](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-regexp.prototype.sticky) if it's not implemented.
850 #### re.isUnicode(x) _(es5-ext/reg-exp/#/is-unicode)_
852 Whether regular expression has `unicode` flag.
854 It's to be used as counterpart to [regExp.unicode](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-regexp.prototype.unicode) if it's not implemented.
856 #### re.match(string) _(es5-ext/reg-exp/#/match)_
858 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-regexp.prototype.match).
860 #### re.replace(string, replaceValue) _(es5-ext/reg-exp/#/replace)_
862 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-regexp.prototype.replace).
864 #### re.search(string) _(es5-ext/reg-exp/#/search)_
866 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-regexp.prototype.search).
868 #### re.split(string) _(es5-ext/reg-exp/#/search)_
870 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-regexp.prototype.split).
872 #### re.sticky _(es5-ext/reg-exp/#/sticky/implement)_
874 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-regexp.prototype.sticky).
875 It's a getter, so only `implement` and `is-implemented` modules are provided.
877 #### re.unicode _(es5-ext/reg-exp/#/unicode/implement)_
879 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-regexp.prototype.unicode).
880 It's a getter, so only `implement` and `is-implemented` modules are provided.
882 ### String Constructor extensions
884 #### formatMethod(fMap) _(es5-ext/string/format-method)_
886 Creates format method. It's used e.g. to create `Date.prototype.format` method
888 #### fromCodePoint([…codePoints]) _(es5-ext/string/from-code-point)_
890 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.fromcodepoint)
892 #### isString(x) _(es5-ext/string/is-string)_
894 Whether object is string
896 #### randomUniq() _(es5-ext/string/random-uniq)_
898 Returns randomly generated id, with guarantee of local uniqueness (no same id will be returned twice)
900 #### raw(callSite[, …substitutions]) _(es5-ext/string/raw)_
902 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.raw)
904 ### String Prototype extensions
906 #### str.at(pos) _(es5-ext/string/#/at)_
908 _Proposed for ECMAScript 6/7 standard, but not (yet) in a draft_
910 Returns a string at given position in Unicode-safe manner.
911 Based on [implementation by Mathias Bynens](https://github.com/mathiasbynens/String.prototype.at).
913 #### str.camelToHyphen() _(es5-ext/string/#/camel-to-hyphen)_
915 Convert camelCase string to hyphen separated, e.g. one-two-three -> oneTwoThree.
916 Useful when converting names from js property convention into filename convention.
918 #### str.capitalize() _(es5-ext/string/#/capitalize)_
920 Capitalize first character of a string
922 #### str.caseInsensitiveCompare(str) _(es5-ext/string/#/case-insensitive-compare)_
924 Case insensitive compare
926 #### str.codePointAt(pos) _(es5-ext/string/#/code-point-at)_
928 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.prototype.codepointat)
930 Based on [implementation by Mathias Bynens](https://github.com/mathiasbynens/String.prototype.codePointAt).
932 #### str.contains(searchString[, position]) _(es5-ext/string/#/contains)_
934 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.prototype.contains)
936 Whether string contains given string.
938 #### str.endsWith(searchString[, endPosition]) _(es5-ext/string/#/ends-with)_
940 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.prototype.endswith).
941 Whether strings ends with given string
943 #### str.hyphenToCamel() _(es5-ext/string/#/hyphen-to-camel)_
945 Convert hyphen separated string to camelCase, e.g. one-two-three -> oneTwoThree.
946 Useful when converting names from filename convention to js property name convention.
948 #### str.indent(str[, count]) _(es5-ext/string/#/indent)_
950 Indents each line with provided _str_ (if _count_ given then _str_ is repeated _count_ times).
952 #### str.last() _(es5-ext/string/#/last)_
954 Return last character
956 #### str.normalize([form]) _(es5-ext/string/#/normalize)_
958 [_Introduced with ECMAScript 6_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize).
959 Returns the Unicode Normalization Form of a given string.
960 Based on Matsuza's version. Code used for integrated shim can be found at [github.com/walling/unorm](https://github.com/walling/unorm/blob/master/lib/unorm.js)
962 #### str.pad(fill[, length]) _(es5-ext/string/#/pad)_
964 Pad string with _fill_.
965 If _length_ si given than _fill_ is reapated _length_ times.
966 If _length_ is negative then pad is applied from right.
968 #### str.repeat(n) _(es5-ext/string/#/repeat)_
970 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.prototype.repeat).
971 Repeat given string _n_ times
973 #### str.plainReplace(search, replace) _(es5-ext/string/#/plain-replace)_
975 Simple `replace` version. Doesn't support regular expressions. Replaces just first occurrence of search string. Doesn't support insert patterns, therefore it is safe to replace text with text obtained programmatically (there's no need for additional _$_ characters escape in such case).
977 #### str.plainReplaceAll(search, replace) _(es5-ext/string/#/plain-replace-all)_
979 Simple `replace` version. Doesn't support regular expressions. Replaces all occurrences of search string. Doesn't support insert patterns, therefore it is safe to replace text with text obtained programmatically (there's no need for additional _$_ characters escape in such case).
981 #### str.startsWith(searchString[, position]) _(es5-ext/string/#/starts-with)_
983 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.prototype.startswith).
984 Whether strings starts with given string
986 #### str[@@iterator] _(es5-ext/string/#/@@iterator)_
988 [_Introduced with ECMAScript 6_](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.prototype-@@iterator).
989 Returns iterator object which traverses all string characters (with respect to unicode symbols)
991 ### Tests [![Build Status](https://travis-ci.org/medikoo/es5-ext.png)](https://travis-ci.org/medikoo/es5-ext)