bv-ui-core 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ apiVersion: backstage.io/v1alpha1
2
+ kind: Component
3
+ metadata:
4
+ name: bv-ui-core
5
+ github.com/project-slug: bazaarvoice/bv-ui-core
6
+ description: This project provides a central location for common Bazaarvoice UI code. It is intended to be installed into a project via NPM. Individual modules are authored as CommonJS modules, to be consumed by Webpack or another build tool that can ingest CommonJS.
7
+ annotations:
8
+ backstage.io/techdocs-ref: dir:.
9
+ github.com/project-slug: bazaarvoice/bv-ui-core
10
+ links:
11
+ - url: https://bazaarvoice.slack.com/app_redirect?channel=sme-swat
12
+ title: Slack channel
13
+ icon: send
14
+ - url: https://sonarqube.qa.bazaarvoice.com/dashboard?id=bazaarvoice_bv-ui-core
15
+ title: SonarQube
16
+ icon: dashboard
17
+ labels:
18
+ tech: javascript
19
+ tags:
20
+ - javascript
21
+ - nodejs
22
+ spec:
23
+ type: library
24
+ system: swat
25
+ lifecycle: production
26
+ owner: swat
27
+
28
+
29
+
30
+
package/karma.conf.js CHANGED
@@ -20,12 +20,10 @@ module.exports = function (config) {
20
20
  ui: 'bdd'
21
21
  }
22
22
  },
23
-
24
23
  // list of files / patterns to load in the browser.
25
24
  files: [
26
25
  // We need the polyfill for testing es6 modules.
27
26
  'node_modules/babel-polyfill/dist/polyfill.js',
28
-
29
27
  // Loaded into the browser test page.
30
28
  'test/unit/mochaInit.js',
31
29
  'test/unit/**/*.spec.js',
@@ -109,10 +107,21 @@ module.exports = function (config) {
109
107
  // Enable / disable watching file and executing tests whenever any file
110
108
  // changes.
111
109
  autoWatch: true,
110
+ customLaunchers: {
111
+ ChromeHeadless: {
112
+ base: 'Chrome',
113
+ flags: [
114
+ '--no-sandbox',
115
+ '--headless',
116
+ '--disable-gpu',
117
+ '--remote-debugging-port=9222'
118
+ ]
119
+ }
120
+ },
112
121
 
113
122
  // Start these browsers.
114
123
  // See: https://npmjs.org/browse/keyword/karma-launcher
115
- browsers: ['Chrome'],
124
+ browsers: ['ChromeHeadless'],
116
125
 
117
126
  // Continuous Integration mode. If true, Karma captures browsers, runs the
118
127
  // tests and exits.
package/lib/README.md ADDED
@@ -0,0 +1,61 @@
1
+ ![](https://travis-ci.org/bazaarvoice/bv-ui-core.svg)
2
+
3
+ # bv-ui-core
4
+
5
+ This project provides a central location for common Bazaarvoice UI code. It is
6
+ intended to be installed into a project via NPM. Individual modules are authored
7
+ as CommonJS modules, to be consumed by Webpack or another build tool that can
8
+ ingest CommonJS.
9
+
10
+ **This is a public repository.** Please see the [contribution guidelines][1] for
11
+ details on contributing to this repo.
12
+
13
+ ## Installation
14
+
15
+ You will need NPM to add this to your project; it is installed when you install
16
+ Node, so it is likely that you already have it. If not, you can install Node
17
+ using an [installer][2], or by using your favorite package manager (such as
18
+ Homebrew).
19
+
20
+ Once you have NPM, you can install bv-ui-core as follows:
21
+
22
+ ```bash
23
+ npm install --save bv-ui-core
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ Require bv-ui-core modules into your code:
29
+
30
+ ```javascript
31
+ var someModule = require('bv-ui-core/lib/someModule');
32
+ someModule.doThings();
33
+ ```
34
+
35
+ For details on how to use a specific module, see the README document in the
36
+ module's directory.
37
+
38
+ ## Modules
39
+
40
+ - [body](./lib/body)
41
+ - [checkHighContrast](./lib/checkHighContrast)
42
+ - [cookie](./lib/cookie)
43
+ - [cookieConsent](./lib/cookieConsent)
44
+ - [cssLoadChecker](./lib/cssLoadChecker)
45
+ - [date.now](./lib/date.now)
46
+ - [domainPolice](./lib/domainPolice)
47
+ - [evented](./lib/evented)
48
+ - [getOriginalConstructor](./lib/getOriginalConstructor)
49
+ - [global](./lib/global)
50
+ - [ie](./lib/ie)
51
+ - [loader](./lib/loader)
52
+ - [logger](./lib/logger)
53
+ - [namespacer](./lib/namespacer)
54
+ - [performance](./lib/performance)
55
+ - [polyfills](./lib/polyfills)
56
+ - [pixelsDisplayed](./lib/pixelsDisplayed)
57
+ - [staticAssetLoader](./lib/staticAssetLoader)
58
+ - [waitForBody](./lib/waitForBody)
59
+
60
+ [1]: ./CONTRIBUTING.md
61
+ [2]: https://nodejs.org/download/
@@ -0,0 +1,10 @@
1
+ # messageFormat
2
+
3
+ Uses `INTL.DisplayNames` and uses a polyfill from `https://cdn.polyfill.io/v3/polyfill.min.js?features=Intl.DisplayNames`
4
+
5
+ # Usage
6
+
7
+ ```javascript
8
+ var messageFormat = require('bv-ui-core/lib/messageFormat');
9
+ messageFormat.generateCountryFromLocale('en_US') // United States
10
+ ```
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @fileOverview
3
+ * messageFormat provides utility functions to which use the INTL API which provides
4
+ * language sensitive string comparison, number formatting, and date and time formatting.
5
+ *
6
+ * messageFormat can have functions which are used in multiple places
7
+ *
8
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl
9
+ */
10
+
11
+
12
+ var global = require('../global');
13
+ /**
14
+ * Generates the country name associated with the given locale
15
+ * @param {string} locale The locale code (e.g., 'en_US')
16
+ * @returns {string} The name of the country associated with the locale, or an empty string if the locale is not supported by Intl.DisplayNames
17
+ */
18
+ function generateCountryFromLocale (locale) {
19
+ if (!locale || locale.length === 0) {
20
+ return '';
21
+ }
22
+
23
+ // Split the locale code into language and region components
24
+ try {
25
+ var localeArr = locale.split('_');
26
+ if (localeArr.length < 2) {
27
+ return '';
28
+ }
29
+ // Get the display name for the region (i.e., the country name)
30
+ var regionNames = new global.Intl.DisplayNames(localeArr[0], { type: 'region' });
31
+ var countryName = regionNames.of(localeArr[1]);
32
+ }
33
+ catch (error) {
34
+ return '';
35
+ }
36
+ // Return the country name, or an empty string if the region is not valid
37
+ return countryName
38
+ }
39
+
40
+ module.exports = {
41
+ generateCountryFromLocale: generateCountryFromLocale
42
+ }
@@ -53,6 +53,7 @@ module.exports = {
53
53
  getEntriesByName: function (name, entryType) {
54
54
  // Note: because the implementation functions explicitly check their number of arguments,
55
55
  // we want to preserve the calls exactly as they came in
56
+
56
57
  var hasArguments = (arguments.length > 0);
57
58
  var func = (isNativeSupported ? nativeImplementation : polyfillImplementation);
58
59
  return (hasArguments ? func(name, entryType) : func());
package/mkdocs.yaml ADDED
@@ -0,0 +1,5 @@
1
+ site_name: bv-ui-core
2
+ docs_dir: lib
3
+ plugins:
4
+ - techdocs-core
5
+ repo_url: https://github.com/bazaarvoice/bv-ui-core/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bv-ui-core",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "license": "Apache 2.0",
5
5
  "description": "Bazaarvoice UI-related JavaScript",
6
6
  "repository": {
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "scripts": {
14
14
  "lint": "eslint karma.conf.js lib test",
15
- "test": "./node_modules/karma/bin/karma start --single-run --browsers PhantomJS",
15
+ "test": "./node_modules/karma/bin/karma start --single-run --browsers ChromeHeadless",
16
16
  "dev": "./node_modules/karma/bin/karma start --browsers Chrome"
17
17
  },
18
18
  "devDependencies": {
@@ -28,7 +28,7 @@
28
28
  "json-loader": "^0.5.7",
29
29
  "karma": "^3.0.0",
30
30
  "karma-chai": "^0.1.0",
31
- "karma-chrome-launcher": "2.0.0",
31
+ "karma-chrome-launcher": "^2.0.0",
32
32
  "karma-coverage": "^1.1.2",
33
33
  "karma-firefox-launcher": "^1.1.0",
34
34
  "karma-htmlfile-reporter": "^0.3.6",
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @fileOverview
3
+ * Unit tests for the messageFormat module
4
+ */
5
+ var messageFormat = require('../../../lib/messageFormat');
6
+
7
+ describe('lib/messageFormat', function () {
8
+ it('messageFormat.generateCountryFromLocale', function () {
9
+ function test1 () {
10
+ return messageFormat.generateCountryFromLocale('en_US');
11
+ }
12
+
13
+ expect(test1()).to.be.equal('United States');
14
+
15
+ function test2 () {
16
+ return messageFormat.generateCountryFromLocale('en_DE');
17
+ }
18
+
19
+ expect(test2()).to.be.equal('Germany')
20
+
21
+ function test3 () {
22
+ return messageFormat.generateCountryFromLocale('de_DE');
23
+ }
24
+ expect(test3()).to.be.equal('Deutschland')
25
+
26
+ function test4 () {
27
+ return messageFormat.generateCountryFromLocale()
28
+ }
29
+ expect(test4()).to.be.empty
30
+ });
31
+ });
@@ -76,8 +76,13 @@ describe('lib/performance/getEntriesByName', function () {
76
76
  expect(result.length).to.equal(0);
77
77
  });
78
78
 
79
+
79
80
  it('throws an error if no arguments are passed', function () {
80
- expect(function () { perfGetEntriesByName.getEntriesByName(); }).to.throw(TypeError);
81
+ //name is passed to the nativeImplementation which is undefined and returns an empty array
82
+ function test () {
83
+ return perfGetEntriesByName.getEntriesByName()
84
+ }
85
+ expect(test()).to.be.empty;
81
86
  });
82
87
 
83
88
  });
@@ -9,13 +9,14 @@ var perfMark = require('../../../lib/performance/mark.js');
9
9
 
10
10
  describe('lib/performance/getEntriesByType', function () {
11
11
  before(function () {
12
+ //Clearing all the marks as marks from other tests were being added
13
+ performance.clearMarks()
12
14
  perfMark.mark('test-by-name1');
13
15
  perfMark.mark('test-by-name2');
14
16
  });
15
17
 
16
18
  it('returns an array of all matching performance marks by type', function () {
17
19
  var result = perfGetEntriesByType.getEntriesByType('mark');
18
-
19
20
  // Test 1: it returns an array.
20
21
  expect(result).to.be.an('array');
21
22
 
@@ -41,7 +42,7 @@ describe('lib/performance/getEntriesByType', function () {
41
42
  });
42
43
 
43
44
  it('throws an error if no arguments are passed', function () {
44
- expect(function () { perfGetEntriesByType.getEntriesByType(); }).to.throw(TypeError);
45
+ expect(perfGetEntriesByType.getEntriesByType()).to.be.empty;
45
46
  });
46
47
 
47
48
  });
@@ -32,7 +32,7 @@ describe('lib/performance/measure', function () {
32
32
  });
33
33
 
34
34
  it('throws an error if the measure name is omitted', function () {
35
- expect(function () { perfMeasure.measure(); }).to.throw(Error);
35
+ expect(perfMeasure.measure()).to.be.empty;
36
36
  });
37
37
 
38
38
  it('throws an error if the startMark or endMark name is supplied, but is invalid', function () {