bv-ui-core 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/.eslintrc +40 -0
  2. package/.travis.yml +5 -0
  3. package/CONTRIBUTING.md +98 -0
  4. package/LICENSE.md +13 -0
  5. package/OWNERS +2 -0
  6. package/README.md +63 -0
  7. package/catalog-info.yaml +30 -0
  8. package/karma.conf.js +130 -0
  9. package/lib/README.md +61 -0
  10. package/lib/api/.babelrc +3 -0
  11. package/lib/api/.eslintrc +9 -0
  12. package/lib/api/README.md +134 -0
  13. package/lib/api/index.js +15 -0
  14. package/lib/api/statistics.js +148 -0
  15. package/lib/application/README.md +96 -0
  16. package/lib/application/index.js +171 -0
  17. package/lib/body/README.md +13 -0
  18. package/lib/body/index.js +19 -0
  19. package/lib/bvFetch/README.md +101 -0
  20. package/lib/bvFetch/index.js +383 -0
  21. package/lib/checkHighContrast/README.md +26 -0
  22. package/lib/checkHighContrast/index.js +36 -0
  23. package/lib/cookie/README.md +29 -0
  24. package/lib/cookie/index.js +111 -0
  25. package/lib/cookieConsent/README.md +41 -0
  26. package/lib/cookieConsent/index.js +227 -0
  27. package/lib/cssLoadChecker/README.md +19 -0
  28. package/lib/cssLoadChecker/index.js +72 -0
  29. package/lib/date.now/README.md +11 -0
  30. package/lib/date.now/index.js +40 -0
  31. package/lib/domainPolice/README.md +66 -0
  32. package/lib/domainPolice/index.js +95 -0
  33. package/lib/evented/README.md +42 -0
  34. package/lib/evented/index.js +135 -0
  35. package/lib/getOriginalConstructor/README.md +16 -0
  36. package/lib/getOriginalConstructor/index.js +52 -0
  37. package/lib/global/README.md +10 -0
  38. package/lib/global/index.js +48 -0
  39. package/lib/ie/README.md +13 -0
  40. package/lib/ie/index.js +25 -0
  41. package/lib/loader/README.md +73 -0
  42. package/lib/loader/index.js +358 -0
  43. package/lib/logger/README.md +82 -0
  44. package/lib/logger/index.js +180 -0
  45. package/lib/messageFormat/README.md +10 -0
  46. package/lib/messageFormat/index.js +42 -0
  47. package/lib/namespacer/README.md +57 -0
  48. package/lib/namespacer/index.js +98 -0
  49. package/lib/performance/README.md +35 -0
  50. package/lib/performance/entries.js +5 -0
  51. package/lib/performance/getEntries.js +42 -0
  52. package/lib/performance/getEntriesByName.js +61 -0
  53. package/lib/performance/getEntriesByType.js +55 -0
  54. package/lib/performance/index.js +11 -0
  55. package/lib/performance/mark.js +97 -0
  56. package/lib/performance/measure.js +106 -0
  57. package/lib/performance/now.js +63 -0
  58. package/lib/pixelsDisplayed/README.md +19 -0
  59. package/lib/pixelsDisplayed/index.js +113 -0
  60. package/lib/polyfills/README.md +39 -0
  61. package/lib/polyfills/fetch/Headers.js +3 -0
  62. package/lib/polyfills/fetch/Request.js +3 -0
  63. package/lib/polyfills/fetch/Response.js +3 -0
  64. package/lib/polyfills/fetch/fetch.js +3 -0
  65. package/lib/polyfills/fetch/index.js +57 -0
  66. package/lib/polyfills/promise.js +265 -0
  67. package/lib/queryShadowDom/README.md +50 -0
  68. package/lib/queryShadowDom/index.js +93 -0
  69. package/lib/region/README.md +64 -0
  70. package/lib/region/europe/index.js +94 -0
  71. package/lib/region/europe/territories.js +40 -0
  72. package/lib/region/index.js +123 -0
  73. package/lib/staticAssetLoader/README.md +116 -0
  74. package/lib/staticAssetLoader/index.js +248 -0
  75. package/lib/waitForBody/README.md +21 -0
  76. package/lib/waitForBody/index.js +36 -0
  77. package/mkdocs.yaml +5 -0
  78. package/package.json +55 -0
  79. package/test/.eslintrc +5 -0
  80. package/test/fixtures/lib.loader.document-is-wrong-in-ie8.js +5 -0
  81. package/test/fixtures/lib.loader.loadscript-attribute.js +3 -0
  82. package/test/fixtures/lib.loader.loadscript.js +3 -0
  83. package/test/fixtures/lib.loader.loadstylesheet.css +3 -0
  84. package/test/unit/api/.eslintrc +6 -0
  85. package/test/unit/api/index.spec.js +37 -0
  86. package/test/unit/api/response.json +67 -0
  87. package/test/unit/api/statistics.spec.js +218 -0
  88. package/test/unit/application/index.spec.js +313 -0
  89. package/test/unit/body/index.spec.js +15 -0
  90. package/test/unit/bvFetch/index.spec.js +246 -0
  91. package/test/unit/checkHighContrast/index.spec.js +16 -0
  92. package/test/unit/cookie/index.spec.js +191 -0
  93. package/test/unit/cookieConsent/index.spec.js +119 -0
  94. package/test/unit/cssLoadChecker/index.spec.js +75 -0
  95. package/test/unit/date.now/index.spec.js +21 -0
  96. package/test/unit/domainPolice/index.spec.js +141 -0
  97. package/test/unit/evented/index.spec.js +59 -0
  98. package/test/unit/getOriginalConstructor/index.spec.js +60 -0
  99. package/test/unit/global/index.spec.js +84 -0
  100. package/test/unit/ie/index.spec.js +14 -0
  101. package/test/unit/loader/index.spec.js +644 -0
  102. package/test/unit/logger/index.spec.js +141 -0
  103. package/test/unit/messageFormat/index.spec.js +31 -0
  104. package/test/unit/mochaInit.js +8 -0
  105. package/test/unit/namespacer/index.spec.js +100 -0
  106. package/test/unit/performance/getEntries.spec.js +30 -0
  107. package/test/unit/performance/getEntriesByName.spec.js +88 -0
  108. package/test/unit/performance/getEntriesByType.spec.js +48 -0
  109. package/test/unit/performance/index.spec.js +35 -0
  110. package/test/unit/performance/mark.spec.js +40 -0
  111. package/test/unit/performance/measure.spec.js +50 -0
  112. package/test/unit/performance/now.spec.js +21 -0
  113. package/test/unit/pixelsDisplayed/index.spec.js +271 -0
  114. package/test/unit/polyfills/fetch/Headers.js +12 -0
  115. package/test/unit/polyfills/fetch/Request.js +12 -0
  116. package/test/unit/polyfills/fetch/Response.js +12 -0
  117. package/test/unit/polyfills/fetch/fetch.js +12 -0
  118. package/test/unit/polyfills/fetch/index.js +61 -0
  119. package/test/unit/polyfills/promise.spec.js +48 -0
  120. package/test/unit/region/europe/index.spec.js +70 -0
  121. package/test/unit/region/index.spec.js +113 -0
  122. package/test/unit/staticAssetLoader/index.spec.js +215 -0
@@ -0,0 +1,135 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * @fileOverview
4
+ * asEvented v0.4.3 - an event emitter mixin which provides
5
+ * the observer pattern to JavaScript object.
6
+ *
7
+ * Copyright 2012, Michal Kuklis
8
+ * Dual licensed under the MIT or GPL Version 2 licenses.
9
+ *
10
+ **/
11
+ /*
12
+ * Originally from https://github.com/mkuklis/asEvented
13
+ *
14
+ * Changelog:
15
+ * - removed UMD wrapper
16
+ * - do not export `bind` or `unbind`
17
+ */
18
+ var ArrayProto = Array.prototype;
19
+ var nativeIndexOf = ArrayProto.indexOf;
20
+ var slice = ArrayProto.slice;
21
+
22
+ /**
23
+ * By default, we should simply log the error to the console.
24
+ */
25
+ function defaultErrorHandler(e) {
26
+ global.console.error(e);
27
+ }
28
+
29
+ /**
30
+ * Initialize a custom error handler for this instance, which may decide to log or even re-throw the error.
31
+ *
32
+ * @param {Function} fn - the custom callback to be invoked whenever an error is
33
+ * detected as the result of a trigger event
34
+ */
35
+ function setErrorHandler(fn) {
36
+ this.eventErrorHandler = fn;
37
+ }
38
+
39
+ function bind(event, fn) {
40
+ var i, part;
41
+ var events = this.events = this.events || {};
42
+ var parts = event.split(/\s+/);
43
+ var num = parts.length;
44
+
45
+ for (i = 0; i < num; i++) {
46
+ events[(part = parts[i])] = events[part] || [];
47
+ events[part].push(fn);
48
+ }
49
+ return this;
50
+ }
51
+
52
+ function one(event, fn) {
53
+ // [notice] The value of fn and fn1 is not equivalent in the case
54
+ // of the following in MSIE.
55
+ //
56
+ // var fn = function fn1 () { alert(fn === fn1) } ie.<9 false
57
+ var fnc = function () {
58
+ this.off(event, fnc);
59
+ fn.apply(this, slice.call(arguments));
60
+ };
61
+ this.on(event, fnc);
62
+ return this;
63
+ }
64
+
65
+ function unbind(event, fn) {
66
+ var eventName, i, index, num, parts;
67
+ var events = this.events;
68
+
69
+ if (!events) {
70
+ return;
71
+ }
72
+
73
+ parts = event.split(/\s+/);
74
+ for (i = 0, num = parts.length; i < num; i++) {
75
+ if ((eventName = parts[i]) in events !== false) {
76
+ index = (fn) ? _indexOf(events[eventName], fn) : 0;
77
+ if (index !== -1) {
78
+ events[eventName].splice(index, 1);
79
+ }
80
+ }
81
+ }
82
+ return this;
83
+ }
84
+
85
+ function trigger(event) {
86
+ var args, i;
87
+ var events = this.events;
88
+
89
+ if (!events || event in events === false) {
90
+ return;
91
+ }
92
+
93
+ args = slice.call(arguments, 1);
94
+ for (i = events[event].length - 1; i >= 0; i--) {
95
+ try {
96
+ events[event][i].apply(this, args);
97
+ }
98
+ catch (e) {
99
+ (this.eventErrorHandler || defaultErrorHandler).call(this, e, {
100
+ event: event,
101
+ data: args
102
+ });
103
+ }
104
+ }
105
+ return this;
106
+ }
107
+
108
+ // TODO: This is the same as the inArray method provided
109
+ // by the utils module. This should be replaced in favor
110
+ // of using that.
111
+ function _indexOf(array, needle) {
112
+ var i, l;
113
+
114
+ if (nativeIndexOf && array.indexOf === nativeIndexOf) {
115
+ return array.indexOf(needle);
116
+ }
117
+
118
+ for (i = 0, l = array.length; i < l; i++) {
119
+ if (array[i] === needle) {
120
+ return i;
121
+ }
122
+ }
123
+ return -1;
124
+ }
125
+
126
+ module.exports = function () {
127
+ this.on = bind;
128
+ this.off = unbind;
129
+ this.trigger = this.emit = trigger;
130
+ this.one = this.once = one;
131
+ this.setErrorHandler = setErrorHandler;
132
+
133
+ return this;
134
+ };
135
+ /* eslint-enable */
@@ -0,0 +1,16 @@
1
+ # getOriginalConstructor
2
+
3
+ This file exposes a utility function to get a reset version of a primitive
4
+ constructor, in the event that a site has overridden or polyfilled prototype
5
+ methods in their own primitives, or used a utility like Prototype.js, which
6
+ does that on its own. It returns a Promise that will be resolved with the
7
+ original primitive constructor.
8
+
9
+ ## Usage
10
+ ```javascript
11
+ var getOriginalConstructor = require('bv-ui-core/lib/getOriginalConstructor');
12
+
13
+ getOriginalConstructor(Array).then(function (originalArray) {
14
+ originalArray.prototype.forEach(someNodeList, callback);
15
+ });
16
+ ```
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @fileOverview
3
+ * This file exposes a utility function to get a reset version of a primitive
4
+ * constructor, in the event that a site has overridden or polyfilled
5
+ * prototype methods in their own primitives, or used a utility like
6
+ * Prototype.js, which does that on its own.
7
+ */
8
+
9
+ var waitForBody = require('../waitForBody');
10
+
11
+ var constructors = {};
12
+ // eslint-disable-next-line no-useless-escape
13
+ var constructorNameRegExp = /function\s+([^\(\s]+)/;
14
+
15
+ var getOriginalConstructor = function getOriginalConstructor (constructor) {
16
+ return new Promise(function (resolve) {
17
+ waitForBody(function () {
18
+ var constructorName = constructor.name;
19
+ // IE11 doesn't have a constructor.name property, so just in case any other
20
+ // browsers also don't, use a simple regex to pull the constructor's name
21
+ // out of the .toString()'d function declaration, e.g. "function Array()"
22
+ if (!constructorName) {
23
+ constructorName = constructorNameRegExp.exec(constructor.toString())[1];
24
+ }
25
+
26
+ if (constructors[constructorName]) {
27
+ resolve(constructors[constructorName]);
28
+ return;
29
+ }
30
+ const tempIframe = document.createElement('iframe');
31
+ tempIframe.src = 'about:blank';
32
+ tempIframe.style.display = 'none';
33
+ tempIframe.style.position = 'absolute';
34
+ tempIframe.style.left = '-9999px';
35
+ tempIframe.height = '0';
36
+ tempIframe.width = '0';
37
+ tempIframe.tabIndex = '-1';
38
+ tempIframe.title = '';
39
+ tempIframe.setAttribute('aria-hidden', 'true');
40
+ tempIframe.setAttribute('role', 'presentation');
41
+
42
+ document.body.appendChild(tempIframe);
43
+
44
+ constructors[constructorName] = tempIframe.contentWindow[constructorName];
45
+ document.body.removeChild(tempIframe);
46
+
47
+ resolve(constructors[constructorName]);
48
+ });
49
+ });
50
+ };
51
+
52
+ module.exports = getOriginalConstructor;
@@ -0,0 +1,10 @@
1
+ # Global
2
+
3
+ Exposes the browser's `window` object for safe use elsewhere.
4
+
5
+ ## Usage
6
+ ```javascript
7
+ var global = require('bv-ui-core/lib/global');
8
+
9
+ var window = global;
10
+ ```
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @fileOverview Provides a reference to the global object
3
+ * the below solution works in ES3+ environment and doesn't violates CSP in Chrome apps
4
+ * see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
5
+ */
6
+ 'use strict'; /* eslint strict:0 */
7
+
8
+ var getGlobal = function () {
9
+ var globalObj = (function () {
10
+ if (typeof globalThis !== 'undefined') { return globalThis; }
11
+ if (typeof window !== 'undefined') { return window; }
12
+ if (typeof self !== 'undefined') { return self; }
13
+ if (typeof global !== 'undefined') { return global; }
14
+ throw new Error('unable to locate global object');
15
+ })()
16
+ /*
17
+ The below code was added in case there is pollution in global namespace
18
+ windows object during transpilation with __esModule being set. Below code would support
19
+ global import in all bundle use cases
20
+ */
21
+ if (globalObj && globalObj.__esModule) {
22
+ const proxyGlobal = new Proxy(globalObj, {
23
+ get: function (target, prop) {
24
+ if (prop === 'default') {
25
+ return target
26
+ }
27
+
28
+ var value = target[prop]
29
+ // Native/branded methods (e.g. getComputedStyle) throw "Illegal invocation"
30
+ // if called with the Proxy as `this` instead of the real target.
31
+ if (typeof value === 'function') {
32
+ return value.bind(target)
33
+ }
34
+
35
+ return value
36
+ },
37
+
38
+ set: function (target, prop, value) {
39
+ target[prop] = value
40
+ return true
41
+ },
42
+ })
43
+ return proxyGlobal
44
+ }
45
+ return globalObj
46
+ };
47
+
48
+ module.exports = getGlobal();
@@ -0,0 +1,13 @@
1
+ # ie
2
+
3
+ The ie module provides the version of IE in which the scout is running, if the
4
+ browser is IE and the version is less than or equal to 9. In other cases, the
5
+ value provided by the module is false.
6
+
7
+ ```js
8
+ var ie = require('bv-ui-core/lib/ie');
9
+
10
+ if (!ie) {
11
+ // Thank goodness.
12
+ }
13
+ ```
@@ -0,0 +1,25 @@
1
+ /* eslint no-sequences: 0 */
2
+ /**
3
+ * @fileOverview
4
+ * A short snippet for detecting versions of IE in JavaScript
5
+ * without resorting to user-agent sniffing. Will only work for IE >=5 and <=9
6
+ * since IE10 dropped support for conditional comments. When ie is undefined
7
+ * it means it's either IE10+ or not an IE browser.
8
+ */
9
+
10
+ var doc = require('../global').document;
11
+
12
+ module.exports = (function () {
13
+ var ie = (function (v, div, undef) {
14
+ var all = div.getElementsByTagName('i');
15
+
16
+ while (
17
+ div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->', all[0]
18
+ ) {
19
+ // Empty.
20
+ }
21
+ return v > 4 ? v : undef;
22
+ })(3, doc.createElement('div'));
23
+
24
+ return ie;
25
+ })();
@@ -0,0 +1,73 @@
1
+ # loader
2
+
3
+ The loader module provides the following methods:
4
+
5
+ - `loadScript(url, [options], [callback])`: Loads the script at the provided
6
+ URL in a non-blocking manner, and executes a Node-style callback (if
7
+ provided) when the script is loaded or fails to load. A
8
+ `timeout` value in milliseconds can be provided via the `options` argument.
9
+ - `loadStyleSheet(url, [options], [callback])`: Loads the CSS at the provided
10
+ URL in a non-blocking manner, and executes a Node-style callback (if
11
+ provided) when the CSS is loaded or fails to load. Also returns a promise
12
+ that will be resolved if the CSS loads, and rejected if it does not. A
13
+ `timeout` value in milliseconds can be provided via the `options` argument.
14
+
15
+ ```js
16
+ var loader = require('bv-ui-core/lib/loader');
17
+
18
+ loader.loadScript('/scripts/main.js', function (err) {
19
+ if (!err) {
20
+ console.log('it worked');
21
+ }
22
+ });
23
+ ```
24
+
25
+ Note: Failure to load is *not* reliably detected in older versions of IE. For
26
+ both `loadScript` and `loadStyleSheet`, the callback will not be executed on
27
+ failure in old IE.
28
+
29
+ ### loadScript options
30
+
31
+ - **attributes**: an object containing key/value pairs to be used as
32
+ attributes on the created `<script>` element.
33
+ - **timeout**: the time in milliseconds before the loading should be
34
+ considered failed. Defaults to 10000ms.
35
+ - **forceLoad**: a boolean value as to whether the script should
36
+ attempt to be loaded if an earlier attempt was made. Defaults to false.
37
+ - **namespaceName**: a string containing the name of the namespace to check
38
+ if the script has been previously loaded and store the loadedUrls hash
39
+
40
+ ### loadStyleSheet options
41
+
42
+ - **attributes**: an object containing key/value pairs to be used as
43
+ attributes on the created `<link>` element.
44
+ - **injectionNode**: a DOM node into which the `<link>` element should be
45
+ placed. The default insertion point is after the first `<script>` element on the page.
46
+ - **timeout**: the time in milliseconds before the loading should be
47
+ considered failed. Defaults to 10000ms.
48
+ - **forceLoad**: a boolean value as to whether the stylesheet should
49
+ attempt to be loaded if an earlier attempt was made. Defaults to false.
50
+ - **namespaceName**: a string containing the name of the namespace to check
51
+ if the stylesheet has been previously loaded and store the loadedUrls hash
52
+
53
+ ### loader timeout
54
+
55
+ The loader module provides an extensible timeout that will invoke the provided
56
+ callback with an error. In certain remote testing environments, the default
57
+ timeout may not be sufficient for an initial page load. If you experience
58
+ timeout errors when using the loader module you should experiment with raising
59
+ this timeout using the provided `option.timeout`.
60
+
61
+ ```js
62
+ var loader = require('bv-ui-core/lib/loader');
63
+
64
+ var options = {
65
+ timeout : 30000
66
+ }
67
+
68
+ loader.loadScript('/scripts/main.js', options, function (err, cb) {
69
+ if (err) {
70
+ console.log('We may have timed out :(');
71
+ }
72
+ });
73
+ ```