From db1252898537dc9c0f2ac9bac9c8b49cffd70fc2 Mon Sep 17 00:00:00 2001 From: chee Date: Sat, 22 Feb 2020 14:11:03 +0000 Subject: [PATCH] Add polyfils --- polyfill.js | 19 +++++++++++++++++++ util.js | 0 2 files changed, 19 insertions(+) create mode 100644 polyfill.js create mode 100644 util.js diff --git a/polyfill.js b/polyfill.js new file mode 100644 index 0000000..bce9725 --- /dev/null +++ b/polyfill.js @@ -0,0 +1,19 @@ +if (!String.prototype.padStart) { + String.prototype.padStart = function padStart(targetLength, padString) { + targetLength = targetLength >> 0; //floor if number or convert non-number to 0; + padString = String(typeof padString !== 'undefined' ? padString : ' '); + if (this.length > targetLength) { + return String(this); + } else { + targetLength = targetLength - this.length; + if (targetLength > padString.length) { + padString += padString.repeat(targetLength / padString.length); //append to original to ensure we are longer than needed + } + return padString.slice(0, targetLength) + String(this); + } + } +} + +Number.prototype.toHex = function () { + return this.toString(16).padStart(2, "0") +} diff --git a/util.js b/util.js new file mode 100644 index 0000000..e69de29