Skip to content

Commit

Permalink
Ensure IE11 compatiblity for unicode regex patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
alubbe committed Apr 1, 2020
1 parent c4d7852 commit f345add
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,29 @@ require('core-js/modules/es.object.assign');
require('core-js/modules/es.object.keys');
require('regenerator-runtime/runtime');

// ...

const ExcelJS = require('exceljs/dist/es5');
```

For IE 11, you'll also need a polyfill to support unicode regex patterns. For example,

```js
const rewritePattern = require('regexpu-core');
const {generateRegexpuOptions} = require('@babel/helper-create-regexp-features-plugin/lib/util');

const {RegExp} = global;
try {
new RegExp('a', 'u');
} catch (err) {
global.RegExp = function(pattern, flags) {
if (flags && flags.includes('u')) {
return new RegExp(rewritePattern(pattern, flags, generateRegexpuOptions({flags, pattern})));
}
return new RegExp(pattern, flags);
};
global.RegExp.prototype = RegExp;
}
```

## Browserify

ExcelJS publishes two browserified bundles inside the dist/ folder:
Expand Down
17 changes: 17 additions & 0 deletions lib/exceljs.browser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
/* eslint-disable import/no-extraneous-dependencies,node/no-unpublished-require */
require('core-js/modules/es.promise');
require('core-js/modules/es.string.includes');
require('core-js/modules/es.object.assign');
require('core-js/modules/es.object.keys');
require('regenerator-runtime/runtime');

const rewritePattern = require('regexpu-core');
const {generateRegexpuOptions} = require('@babel/helper-create-regexp-features-plugin/lib/util');

const {RegExp} = global;
try {
RegExp('a', 'u');
} catch (err) {
global.RegExp = function(pattern, flags) {
if (flags && flags.includes('u')) {
return new RegExp(rewritePattern(pattern, flags, generateRegexpuOptions({flags, pattern})));
}
return new RegExp(pattern, flags);
};
global.RegExp.prototype = RegExp;
}

const ExcelJS = {
Workbook: require('./doc/workbook'),
};
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.9.0",
"@babel/helper-create-regexp-features-plugin": "^7.8.8",
"@babel/preset-env": "^7.9.0",
"@types/chai": "^4.2.11",
"@types/mocha": "^5.2.7",
Expand Down Expand Up @@ -138,6 +139,7 @@
"prettier-eslint": "^9.0.0",
"prettier-eslint-cli": "^5.0.0",
"regenerator-runtime": "^0.13.5",
"regexpu-core": "^4.7.0",
"semver": "^5.6.0",
"ts-node": "^8.8.1",
"typescript": "^3.8.3"
Expand Down

0 comments on commit f345add

Please sign in to comment.