UNPKG

1.69 kBJavaScriptView Raw
1// Polyfills
2
3if ( Number.EPSILON === undefined ) {
4
5 Number.EPSILON = Math.pow( 2, - 52 );
6
7}
8
9if ( Number.isInteger === undefined ) {
10
11 // Missing in IE
12 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
13
14 Number.isInteger = function ( value ) {
15
16 return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
17
18 };
19
20}
21
22//
23
24if ( Math.sign === undefined ) {
25
26 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
27
28 Math.sign = function ( x ) {
29
30 return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
31
32 };
33
34}
35
36if ( 'name' in Function.prototype === false ) {
37
38 // Missing in IE
39 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
40
41 Object.defineProperty( Function.prototype, 'name', {
42
43 get: function () {
44
45 return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
46
47 }
48
49 } );
50
51}
52
53if ( Object.assign === undefined ) {
54
55 // Missing in IE
56 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
57
58 Object.assign = function ( target ) {
59
60 'use strict';
61
62 if ( target === undefined || target === null ) {
63
64 throw new TypeError( 'Cannot convert undefined or null to object' );
65
66 }
67
68 const output = Object( target );
69
70 for ( let index = 1; index < arguments.length; index ++ ) {
71
72 const source = arguments[ index ];
73
74 if ( source !== undefined && source !== null ) {
75
76 for ( const nextKey in source ) {
77
78 if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
79
80 output[ nextKey ] = source[ nextKey ];
81
82 }
83
84 }
85
86 }
87
88 }
89
90 return output;
91
92 };
93
94}