|
1 | 1 | import '../es2018/mod.ts' |
2 | 2 |
|
3 | 3 | // Object.values/Object.entries are stage 4, in ES2017 |
4 | | -import valuesShim from 'https://esm.sh/object.values/shim' |
5 | | -import entriesShim from 'https://esm.sh/object.entries/shim' |
| 4 | +// Copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries |
| 5 | +if (!Object.values) { |
| 6 | + Object.values = function values(obj) { |
| 7 | + var ownProps = Object.keys(obj), |
| 8 | + i = ownProps.length, |
| 9 | + resArray = new Array(i) // preallocate the Array |
| 10 | + while (i--) |
| 11 | + resArray[i] = obj[ownProps[i]] |
| 12 | + |
| 13 | + return resArray |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +if (!Object.entries) { |
| 18 | + Object.entries = function (obj) { |
| 19 | + var ownProps = Object.keys(obj), |
| 20 | + i = ownProps.length, |
| 21 | + resArray = new Array(i) // preallocate the Array |
| 22 | + while (i--) |
| 23 | + resArray[i] = [ownProps[i], obj[ownProps[i]]] |
| 24 | + |
| 25 | + return resArray |
| 26 | + } |
| 27 | +} |
6 | 28 |
|
7 | 29 | // String#padStart/String#padEnd are stage 4, in ES2017 |
8 | | -import padStartShim from 'https://esm.sh/string.prototype.padstart/shim' |
9 | | -import padEndShim from 'https://esm.sh/string.prototype.padend/shim' |
| 30 | +// Copied from https://github.com/behnammodi/polyfill/blob/master/string.polyfill.js |
| 31 | +if (!String.prototype.padStart) { |
| 32 | + Object.defineProperty(String.prototype, 'padStart', { |
| 33 | + configurable: true, |
| 34 | + writable: true, |
| 35 | + value: function (targetLength, padString) { |
| 36 | + targetLength = targetLength >> 0 //floor if number or convert non-number to 0; |
| 37 | + padString = String(typeof padString !== 'undefined' ? padString : ' ') |
| 38 | + if (this.length > targetLength) { |
| 39 | + return String(this) |
| 40 | + } else { |
| 41 | + targetLength = targetLength - this.length |
| 42 | + if (targetLength > padString.length) { |
| 43 | + padString += padString.repeat(targetLength / padString.length) //append to original to ensure we are longer than needed |
| 44 | + } |
| 45 | + return padString.slice(0, targetLength) + String(this) |
| 46 | + } |
| 47 | + }, |
| 48 | + }) |
| 49 | +} |
| 50 | +if (!String.prototype.padEnd) { |
| 51 | + Object.defineProperty(String.prototype, 'padEnd', { |
| 52 | + configurable: true, |
| 53 | + writable: true, |
| 54 | + value: function (targetLength, padString) { |
| 55 | + targetLength = targetLength >> 0 //floor if number or convert non-number to 0; |
| 56 | + padString = String(typeof padString !== 'undefined' ? padString : ' ') |
| 57 | + if (this.length > targetLength) { |
| 58 | + return String(this) |
| 59 | + } else { |
| 60 | + targetLength = targetLength - this.length |
| 61 | + if (targetLength > padString.length) { |
| 62 | + padString += padString.repeat(targetLength / padString.length) //append to original to ensure we are longer than needed |
| 63 | + } |
| 64 | + return String(this) + padString.slice(0, targetLength) |
| 65 | + } |
| 66 | + }, |
| 67 | + }) |
| 68 | +} |
10 | 69 |
|
11 | 70 | // Object.getOwnPropertyDescriptors is stage 4, in ES2017 |
12 | | -import getOwnPropertyDescriptorsShim from 'https://esm.sh/object.getownpropertydescriptors/shim' |
| 71 | +// Copied from https://github.com/watson/get-own-property-descriptors-polyfill/blob/master/index.js |
| 72 | +// Licensed MIT |
| 73 | +if (!Object.getOwnPropertyDescriptors) { |
| 74 | + Object.getOwnPropertyDescriptors = function (obj) { |
| 75 | + if (obj === null || obj === undefined) { |
| 76 | + throw new TypeError('Cannot convert undefined or null to object') |
| 77 | + } |
| 78 | + |
| 79 | + const protoPropDescriptor = Object.getOwnPropertyDescriptor(obj, '__proto__') |
| 80 | + const descriptors = protoPropDescriptor ? { ['__proto__']: protoPropDescriptor } : {} |
| 81 | + |
| 82 | + for (const name of Object.getOwnPropertyNames(obj)) { |
| 83 | + descriptors[name] = Object.getOwnPropertyDescriptor(obj, name) |
| 84 | + } |
13 | 85 |
|
14 | | -valuesShim() |
15 | | -entriesShim() |
16 | | -padStartShim() |
17 | | -padEndShim() |
18 | | -getOwnPropertyDescriptorsShim() |
| 86 | + return descriptors |
| 87 | + } |
| 88 | +} |
0 commit comments