bv-ui-core
Advanced tools
Comparing version 0.14.5 to 0.14.6
@@ -26,5 +26,2 @@ /** | ||
files: [ | ||
// We need the polyfill for testing es6 modules. | ||
'node_modules/babel-polyfill/dist/polyfill.js', | ||
// Loaded into the browser test page. | ||
@@ -43,2 +40,5 @@ 'test/unit/mochaInit.js', | ||
}, | ||
// We need the polyfill for testing es6 modules. | ||
'node_modules/babel-polyfill/dist/polyfill.js', | ||
], | ||
@@ -45,0 +45,0 @@ |
@@ -9,35 +9,28 @@ /** | ||
var waitForBody = require('../waitForBody'); | ||
var constructors = {}; | ||
// eslint-disable-next-line no-useless-escape | ||
var constructorNameRegExp = /function\s+([^\(\s]+)/; | ||
var constructorNameRegExp = /function\s+([^\(\s]+)/ | ||
var iframe; | ||
var getOriginalConstructor = function getOriginalConstructor (constructor) { | ||
return new Promise(function (resolve) { | ||
waitForBody(function () { | ||
var constructorName = constructor.name; | ||
// IE11 doesn't have a constructor.name property, so just in case any other | ||
// browsers also don't, use a simple regex to pull the constructor's name | ||
// out of the .toString()'d function declaration, e.g. "function Array()" | ||
if (!constructorName) { | ||
constructorName = constructorNameRegExp.exec(constructor.toString())[1]; | ||
} | ||
var constructorName = constructor.name; | ||
// IE11 doesn't have a constructor.name property, so just in case any other | ||
// browsers also don't, use a simple regex to pull the constructor's name | ||
// out of the .toString()'d function declaration, e.g. "function Array()" | ||
if (!constructorName) { | ||
constructorName = constructorNameRegExp.exec(constructor.toString())[1]; | ||
} | ||
if (!iframe) { | ||
iframe = document.createElement('iframe'); | ||
iframe.src = 'about:blank'; | ||
document.body.appendChild(iframe); | ||
} | ||
if (!iframe) { | ||
iframe = document.createElement('iframe'); | ||
iframe.src = 'about:blank'; | ||
document.head.appendChild(iframe); | ||
} | ||
if (!constructors[constructorName]) { | ||
constructors[constructorName] = iframe.contentWindow[constructorName]; | ||
} | ||
if (!constructors[constructorName]) { | ||
constructors[constructorName] = iframe.contentWindow[constructorName]; | ||
} | ||
resolve(constructors[constructorName]); | ||
}); | ||
}); | ||
return constructors[constructorName]; | ||
}; | ||
module.exports = getOriginalConstructor; |
@@ -6,12 +6,9 @@ # getOriginalConstructor | ||
methods in their own primitives, or used a utility like Prototype.js, which | ||
does that on its own. It returns a Promise that will be resolved with the | ||
original primitive constructor. | ||
does that on its own. | ||
## Usage | ||
```javascript | ||
var getOriginalConstructor = require('bv-ui-core/lib/getOriginalConstructor'); | ||
var getOriginalConstructor = require('getOriginalConstructor'); | ||
getOriginalConstructor(Array).then(function (originalArray) { | ||
originalArray.prototype.forEach(someNodeList, callback); | ||
}); | ||
getOriginalConstructor(Array).prototype.forEach(someNodeList, callback); | ||
``` |
{ | ||
"name": "bv-ui-core", | ||
"version": "0.14.5", | ||
"version": "0.14.6", | ||
"license": "Apache 2.0", | ||
@@ -5,0 +5,0 @@ "description": "Bazaarvoice UI-related JavaScript", |
@@ -47,3 +47,2 @@ ![](https://travis-ci.org/bazaarvoice/bv-ui-core.svg) | ||
- [evented](./lib/evented) | ||
- [getOriginalConstructor](./lib/getOriginalConstructor) | ||
- [global](./lib/global) | ||
@@ -59,5 +58,4 @@ - [ie](./lib/ie) | ||
- [staticAssetLoader](./lib/staticAssetLoader) | ||
- [waitForBody](./lib/waitForBody) | ||
[1]: ./CONTRIBUTING.md | ||
[2]: https://nodejs.org/download/ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122114
59
2385
60