diff --git a/package.json b/package.json index bd74f0cd..9eef7b93 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "indent-string": "^4.0.0", "lodash.merge": "^4.6.0", "loglevel-colored-level-prefix": "^1.0.0", - "prettier": "^1.7.0", + "prettier": "^2.0.0", "pretty-format": "^23.0.1", "require-relative": "^0.8.7", "typescript": "^3.2.1", diff --git a/polyfills/trim-end.js b/polyfills/trim-end.js new file mode 100644 index 00000000..76da6e8c --- /dev/null +++ b/polyfills/trim-end.js @@ -0,0 +1,9 @@ +/** + * String.prototype.trimEnd() polyfill + * Adapted from polyfill.io + */ +if (!String.prototype.trimEnd) { + String.prototype.trimEnd = function () { + return this.replace(new RegExp(/[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+/.source + '$', 'g'), ''); + }; +} diff --git a/polyfills/trim-start.js b/polyfills/trim-start.js new file mode 100644 index 00000000..3e7870d2 --- /dev/null +++ b/polyfills/trim-start.js @@ -0,0 +1,9 @@ +/** + * String.prototype.trimStart() polyfill + * Adapted from polyfill.io + */ +if (!String.prototype.trimStart) { + String.prototype.trimStart = function () { + return this.replace(new RegExp('^' + /[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+/.source, 'g'), ''); + }; +} diff --git a/polyfills/trim.js b/polyfills/trim.js new file mode 100644 index 00000000..060a6456 --- /dev/null +++ b/polyfills/trim.js @@ -0,0 +1,9 @@ +/** + * String.prototype.trim() polyfill + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill + */ +if (!String.prototype.trim) { + String.prototype.trim = function () { + return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); + }; +} diff --git a/src/index.js b/src/index.js index 0014d55e..4b258e48 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,11 @@ /* eslint no-console:0, global-require:0, import/no-dynamic-require:0 */ /* eslint complexity: [1, 13] */ + +// Add node 8 polyfills +import '../polyfills/trim'; +import '../polyfills/trim-start'; +import '../polyfills/trim-end'; + import fs from 'fs'; import path from 'path'; import requireRelative from 'require-relative';