Skip to content

Commit cf4d56e

Browse files
Gidi & PetrutMarmaladeDevelopers
Gidi & Petrut
authored and
MarmaladeDevelopers
committed
Converted all modules to ES6 and added Rollup distribution in AMD
1 parent 948274b commit cf4d56e

34 files changed

+1094
-201
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"scripts": {
77
"start": "python -m SimpleHTTPServer",
88
"lint": "./node_modules/.bin/eslint src/* && ./node_modules/.bin/eslint -c test/.eslintrc test/*",
9-
"test": "mocha --recursive --reporter list test/mocha.conf.js ./test",
10-
"testWatch": "npm run lint && npm run testMocha -- --watch"
9+
"test": "mocha --compilers js:babel-core/register --recursive --reporter list test/mocha.conf.js ./test",
10+
"testWatch": "npm run lint && npm run testMocha -- --watch",
11+
"build": "rollup --config"
1112
},
1213
"repository": {
1314
"type": "git",
@@ -22,6 +23,8 @@
2223
"url": "https://github.com/devunrulymedia/vast-parser/issues"
2324
},
2425
"devDependencies": {
26+
"babel-core": "^6.26.0",
27+
"babel-preset-es2015": "^6.24.1",
2528
"chai": "^3.5.0",
2629
"chai-as-promised": "^5.3.0",
2730
"eslint": "^3.1.1",
@@ -30,6 +33,8 @@
3033
"node-fetch": "^1.7.3",
3134
"requirejs": "^2.2.0",
3235
"requirejs-text": "^2.0.12",
36+
"rollup": "^0.50.0",
37+
"rollup-plugin-amd": "^1.3.0",
3338
"sinon": "^1.17.4",
3439
"sinon-as-promised": "^4.0.2",
3540
"sinon-chai": "^2.8.0",

rollup.config.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// rollup.config.js
2+
import amd from 'rollup-plugin-amd';
3+
4+
export default {
5+
input: './src/js/index.js',
6+
output: {
7+
file: 'vast-parser.amd.js',
8+
format: 'amd'
9+
},
10+
plugins: [
11+
amd({
12+
include: 'src/js/**' // Optional, Default: undefined (everything)
13+
})
14+
]
15+
};

src/js/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const VastParser = require('./vastParser');
2-
const VastErrorCodes = require('./vastErrorCodes');
3-
const VastError = require('./vastError');
4-
const VastResponse = require('./model/vastResponse');
5-
const VastIcon = require('./model/vastIcon');
6-
const VastAdManager= require('./vastAdManager');
7-
const helpers = require('./util/helpers');
1+
import VastParser from './vastParser';
2+
import VastErrorCodes from './vastErrorCodes';
3+
import VastError from './vastError';
4+
import VastResponse from './model/vastResponse';
5+
import VastIcon from './model/vastIcon';
6+
import VastAdManager from './vastAdManager';
7+
import helpers from './util/helpers';
88

9-
module.exports = {
9+
export default {
1010
VastParser,
1111
VastErrorCodes,
1212
VastResponse,

src/js/model/vastExtension.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const objectUtil = require('../util/objectUtil');
1+
import { getArrayFromObjectPath } from '../util/objectUtil';
22

3-
function VastExtension(extensionNodes) {
3+
export default function VastExtension(extensionNodes) {
44
this.extension = extensionNodes;
55
}
66

@@ -9,7 +9,5 @@ VastExtension.prototype.getExtensionNodes = function() {
99
};
1010

1111
VastExtension.prototype.getDetailsByPath = function (path) {
12-
return objectUtil.getArrayFromObjectPath(this.extension, path);
13-
};
14-
15-
module.exports = VastExtension;
12+
return getArrayFromObjectPath(this.extension, path);
13+
};

src/js/model/vastIcon.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
const objectUtil = require('../util/objectUtil');
2-
const helpers = require('../util/helpers');
1+
import { getArrayFromObjectPath, getFromObjectPath, getIntegerFromObjectPath } from '../util/objectUtil';
2+
import helpers from '../util/helpers';
33

4-
function VastIcon(iconXMLJson) {
5-
this.program = objectUtil.getFromObjectPath(iconXMLJson, '@program', 'unknown');
6-
this.width = objectUtil.getIntegerFromObjectPath(iconXMLJson, '@width', 0);
7-
this.height = objectUtil.getIntegerFromObjectPath(iconXMLJson, '@height', 0);
8-
this.xPosition = objectUtil.getFromObjectPath(iconXMLJson, '@xPosition', 'top');
9-
this.yPosition = objectUtil.getFromObjectPath(iconXMLJson, '@yPosition', 'right');
10-
this.clickThrough = helpers.convertProtocol(objectUtil.getFromObjectPath(iconXMLJson, 'IconClicks.IconClickThrough.nodeValue', ''));
4+
export default function VastIcon(iconXMLJson) {
5+
this.program = getFromObjectPath(iconXMLJson, '@program', 'unknown');
6+
this.width = getIntegerFromObjectPath(iconXMLJson, '@width', 0);
7+
this.height = getIntegerFromObjectPath(iconXMLJson, '@height', 0);
8+
this.xPosition = getFromObjectPath(iconXMLJson, '@xPosition', 'top');
9+
this.yPosition = getFromObjectPath(iconXMLJson, '@yPosition', 'right');
10+
this.clickThrough = helpers.convertProtocol(getFromObjectPath(iconXMLJson, 'IconClicks.IconClickThrough.nodeValue', ''));
1111
this.resource = {
12-
type: objectUtil.getFromObjectPath(iconXMLJson, 'StaticResource.@creativeType', ''),
13-
url: helpers.convertProtocol(objectUtil.getFromObjectPath(iconXMLJson, 'StaticResource.nodeValue', ''))
12+
type: getFromObjectPath(iconXMLJson, 'StaticResource.@creativeType', ''),
13+
url: helpers.convertProtocol(getFromObjectPath(iconXMLJson, 'StaticResource.nodeValue', ''))
1414
};
15-
this.clickTracking = objectUtil.getArrayFromObjectPath(iconXMLJson, 'IconClicks.IconClickTracking')
15+
this.clickTracking = getArrayFromObjectPath(iconXMLJson, 'IconClicks.IconClickTracking')
1616
.map(function(trackingObject) {
1717
return helpers.convertProtocol(trackingObject.nodeValue);
1818
});
19-
}
20-
21-
module.exports = VastIcon;
19+
}

src/js/model/vastLinearCreative.js

+21-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
const objectUtil = require('../util/objectUtil');
2-
const helpers = require('../util/helpers');
3-
const VastMediaFile = require('../model/vastMediaFile');
4-
const VastIcon = require('../model/vastIcon');
1+
import { getArrayFromObjectPath, getFromObjectPath } from '../util/objectUtil';
2+
import helpers from '../util/helpers';
3+
import VastMediaFile from '../model/vastMediaFile';
4+
import VastIcon from '../model/vastIcon';
55

66
function nonEmptyString(trackingObject) {
77
return helpers.isNonEmptyString(trackingObject.nodeValue);
88
}
99

10-
function VastLinearCreative(vastResponse) {
10+
export default function VastLinearCreative(vastResponse) {
1111
this.vastResponse = vastResponse;
12-
this.linearInline = objectUtil.getFromObjectPath(this.vastResponse, 'inline.VAST.Ad.InLine.Creatives.Creative.Linear');
13-
this.linearWrappers = objectUtil.getArrayFromObjectPath(this.vastResponse, 'wrappers.VAST.Ad.Wrapper.Creatives.Creative.Linear');
12+
this.linearInline = getFromObjectPath(this.vastResponse, 'inline.VAST.Ad.InLine.Creatives.Creative.Linear');
13+
this.linearWrappers = getArrayFromObjectPath(this.vastResponse, 'wrappers.VAST.Ad.Wrapper.Creatives.Creative.Linear');
1414
}
1515

1616
VastLinearCreative.prototype.getDuration = function getDuration(getSecondsFromTimeString = helpers.getSecondsFromTimeString) {
17-
var stringTime = objectUtil.getFromObjectPath(this.linearInline, 'Duration.nodeValue');
17+
var stringTime = getFromObjectPath(this.linearInline, 'Duration.nodeValue');
1818
return getSecondsFromTimeString(stringTime);
1919
};
2020

2121
VastLinearCreative.prototype.getClickTrackers = function getClickTrackers(clickTrackerId) {
22-
var wrapperClickTracking = objectUtil.getArrayFromObjectPath(this.linearWrappers, 'VideoClicks.ClickTracking'),
23-
inlineClickTracking = objectUtil.getArrayFromObjectPath(this.linearInline, 'VideoClicks.ClickTracking'),
22+
var wrapperClickTracking = getArrayFromObjectPath(this.linearWrappers, 'VideoClicks.ClickTracking'),
23+
inlineClickTracking = getArrayFromObjectPath(this.linearInline, 'VideoClicks.ClickTracking'),
2424
allClickTracking = inlineClickTracking.concat(wrapperClickTracking);
2525

2626
return allClickTracking
@@ -38,8 +38,8 @@ VastLinearCreative.prototype.getClickTrackers = function getClickTrackers(clickT
3838
};
3939

4040
VastLinearCreative.prototype.getAllClickTrackersAsMap = function getAllClickTrackersAsMap() {
41-
var wrapperClickTracking = objectUtil.getArrayFromObjectPath(this.linearWrappers, 'VideoClicks.ClickTracking'),
42-
inlineClickTracking = objectUtil.getArrayFromObjectPath(this.linearInline, 'VideoClicks.ClickTracking'),
41+
var wrapperClickTracking = getArrayFromObjectPath(this.linearWrappers, 'VideoClicks.ClickTracking'),
42+
inlineClickTracking = getArrayFromObjectPath(this.linearInline, 'VideoClicks.ClickTracking'),
4343
allClickTracking = inlineClickTracking.concat(wrapperClickTracking);
4444

4545
var defaultID = 'unknown';
@@ -60,14 +60,14 @@ VastLinearCreative.prototype.getAllClickTrackersAsMap = function getAllClickTrac
6060
};
6161

6262
VastLinearCreative.prototype.getClickThrough = function getClickThrough() {
63-
return objectUtil.getFromObjectPath(this.linearInline, 'VideoClicks.ClickThrough.nodeValue');
63+
return getFromObjectPath(this.linearInline, 'VideoClicks.ClickThrough.nodeValue');
6464
};
6565

6666
VastLinearCreative.prototype.getTrackingEvents = function getTrackingEvents(eventName) {
6767

6868
function getAllTrackingEvents() {
69-
return objectUtil.getArrayFromObjectPath(this.linearInline, 'TrackingEvents.Tracking')
70-
.concat(objectUtil.getArrayFromObjectPath(this.linearWrappers, 'TrackingEvents.Tracking'));
69+
return getArrayFromObjectPath(this.linearInline, 'TrackingEvents.Tracking')
70+
.concat(getArrayFromObjectPath(this.linearWrappers, 'TrackingEvents.Tracking'));
7171
}
7272

7373
this.trackingEvents = this.trackingEvents || getAllTrackingEvents.call(this);
@@ -82,8 +82,8 @@ VastLinearCreative.prototype.getTrackingEvents = function getTrackingEvents(even
8282
};
8383

8484
VastLinearCreative.prototype.getAdParameters = function getAdParameters() {
85-
var adParameters = objectUtil.getFromObjectPath(this.linearInline, 'AdParameters.nodeValue'),
86-
xmlEncoded = objectUtil.getFromObjectPath(this.linearInline, 'AdParameters.@xmlEncoded');
85+
var adParameters = getFromObjectPath(this.linearInline, 'AdParameters.nodeValue'),
86+
xmlEncoded = getFromObjectPath(this.linearInline, 'AdParameters.@xmlEncoded');
8787

8888
if(xmlEncoded === 'true' && typeof adParameters === 'string') {
8989
adParameters = helpers.decodeXML(adParameters);
@@ -105,15 +105,15 @@ VastLinearCreative.prototype.getIcons = function getIcons() {
105105
return programDict;
106106
};
107107

108-
return objectUtil.getArrayFromObjectPath(this.linearWrappers, 'Icons.Icon')
109-
.concat(objectUtil.getArrayFromObjectPath(this.linearInline, 'Icons.Icon'))
108+
return getArrayFromObjectPath(this.linearWrappers, 'Icons.Icon')
109+
.concat(getArrayFromObjectPath(this.linearInline, 'Icons.Icon'))
110110
.map(createIcon)
111111
.filter(hasValidProgram)
112112
.reduce(chooseClosestProgram, {});
113113
};
114114

115115
VastLinearCreative.prototype.getMediaFiles = function getMediaFiles(filter) {
116-
var mediaFiles = objectUtil.getArrayFromObjectPath(this.linearInline, 'MediaFiles.MediaFile');
116+
var mediaFiles = getArrayFromObjectPath(this.linearInline, 'MediaFiles.MediaFile');
117117

118118
filter = filter || {};
119119

@@ -168,6 +168,4 @@ VastLinearCreative.prototype.hasJavascriptVPAID = function hasJavascriptVPAID()
168168

169169
VastLinearCreative.prototype.hasMp4 = function hasMp4() {
170170
return this.getMp4MediaFiles().length > 0;
171-
};
172-
173-
module.exports = VastLinearCreative;
171+
};

src/js/model/vastMediaFile.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
const objectUtil = require('../util/objectUtil');
2-
const helpers = require('../util/helpers');
1+
import { getArrayFromObjectPath, getFromObjectPath, getIntegerFromObjectPath } from '../util/objectUtil';
2+
import helpers from '../util/helpers';
33

44
function VastMediaFile(mediaFileXml) {
5-
this.url = helpers.convertProtocol(objectUtil.getFromObjectPath(mediaFileXml, 'nodeValue'));
6-
this.apiFramework = objectUtil.getFromObjectPath(mediaFileXml, '@apiFramework');
7-
this.type = objectUtil.getFromObjectPath(mediaFileXml, '@type');
8-
this.width = objectUtil.getIntegerFromObjectPath(mediaFileXml, '@width');
9-
this.height = objectUtil.getIntegerFromObjectPath(mediaFileXml, '@height');
10-
this.delivery = objectUtil.getFromObjectPath(mediaFileXml, '@delivery');
11-
this.bitrate = objectUtil.getIntegerFromObjectPath(mediaFileXml, '@bitrate');
5+
this.url = helpers.convertProtocol(getFromObjectPath(mediaFileXml, 'nodeValue'));
6+
this.apiFramework = getFromObjectPath(mediaFileXml, '@apiFramework');
7+
this.type = getFromObjectPath(mediaFileXml, '@type');
8+
this.width = getIntegerFromObjectPath(mediaFileXml, '@width');
9+
this.height = getIntegerFromObjectPath(mediaFileXml, '@height');
10+
this.delivery = getFromObjectPath(mediaFileXml, '@delivery');
11+
this.bitrate = getIntegerFromObjectPath(mediaFileXml, '@bitrate');
1212
}
1313

1414
VastMediaFile.prototype.isMP4 = function() {
@@ -23,5 +23,5 @@ VastMediaFile.prototype.isJavascriptVPAID = function() {
2323
return this.apiFramework === 'VPAID' && this.type === 'application/javascript';
2424
};
2525

26-
module.exports = VastMediaFile;
26+
export default VastMediaFile;
2727

src/js/model/vastModelFactory.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const VastExtension = require('./vastExtension');
1+
import VastExtension from './vastExtension';
22

3-
module.exports = {
3+
export default {
44
createVastExtension: function(extensionNodes) {
55
return new VastExtension(extensionNodes);
66
}

src/js/model/vastNonLinearCreative.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
const objectUtil = require('../util/objectUtil');
2-
const helpers = require('../util/helpers');
1+
import { getFromObjectPath } from '../util/objectUtil';
2+
import helpers from '../util/helpers';
33

4-
function VastNonLinearCreative(vastResponse) {
5-
this.nonLinearInline = objectUtil.getFromObjectPath(vastResponse, 'inline.VAST.Ad.InLine.Creatives.Creative.NonLinearAds');
4+
export default function VastNonLinearCreative(vastResponse) {
5+
this.nonLinearInline = getFromObjectPath(vastResponse, 'inline.VAST.Ad.InLine.Creatives.Creative.NonLinearAds');
66
}
77

88
VastNonLinearCreative.prototype.getStaticResource = function getStaticResource(convertProtocol = helpers.convertProtocol) {
9-
var url = objectUtil.getFromObjectPath(this.nonLinearInline, 'NonLinear.StaticResource.nodeValue');
9+
var url = getFromObjectPath(this.nonLinearInline, 'NonLinear.StaticResource.nodeValue');
1010

1111
if(url) {
1212
return convertProtocol(url);
1313
}
14-
};
15-
16-
module.exports = VastNonLinearCreative;
14+
};

src/js/model/vastResponse.js

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const helpers = require('../util/helpers');
2-
const objectUtil = require('../util/objectUtil');
3-
const VastLinearCreative = require('./vastLinearCreative');
4-
const VastNonLinearCreative = require('./vastNonLinearCreative');
5-
const VastExtension = require('./vastExtension');
6-
const vastModelFactory = require('./vastModelFactory');
7-
8-
function VastResponse(vastChain) {
1+
import helpers from '../util/helpers';
2+
import { getArrayFromObjectPath, getFromObjectPath } from '../util/objectUtil';
3+
import VastLinearCreative from './vastLinearCreative';
4+
import VastNonLinearCreative from './vastNonLinearCreative';
5+
import VastExtension from './vastExtension';
6+
import vastModelFactory from './vastModelFactory';
7+
8+
export default function VastResponse(vastChain) {
99
this.wrappers = [];
1010
this.inline = undefined;
1111
this._raw = [];
@@ -19,8 +19,8 @@ function VastResponse(vastChain) {
1919
}
2020

2121
VastResponse.prototype.getImpressions = function() {
22-
var inlineImps = objectUtil.getArrayFromObjectPath(this.inline, 'VAST.Ad.InLine.Impression.nodeValue'),
23-
wrapperImps = objectUtil.getArrayFromObjectPath(this.wrappers, 'VAST.Ad.Wrapper.Impression.nodeValue');
22+
var inlineImps = getArrayFromObjectPath(this.inline, 'VAST.Ad.InLine.Impression.nodeValue'),
23+
wrapperImps = getArrayFromObjectPath(this.wrappers, 'VAST.Ad.Wrapper.Impression.nodeValue');
2424

2525
return inlineImps.concat(wrapperImps).filter(helpers.isNonEmptyString);
2626
};
@@ -31,7 +31,7 @@ VastResponse.prototype.getAdTitle = function() {
3131

3232
VastResponse.prototype.getLinearCreative = function(LinearCreative = VastLinearCreative) {
3333
if (!this.linearCreative) {
34-
var hasLinearCreative = objectUtil.getFromObjectPath(this.inline, 'VAST.Ad.InLine.Creatives.Creative.Linear');
34+
var hasLinearCreative = getFromObjectPath(this.inline, 'VAST.Ad.InLine.Creatives.Creative.Linear');
3535

3636
if (hasLinearCreative) {
3737
this.linearCreative = new LinearCreative(this);
@@ -42,7 +42,7 @@ VastResponse.prototype.getLinearCreative = function(LinearCreative = VastLinearC
4242

4343
VastResponse.prototype.getNonLinearCreative = function(NonLinearCreative = VastNonLinearCreative) {
4444
if (!this.nonLinearCreative) {
45-
var hasNonLinearCreative = objectUtil.getFromObjectPath(this.inline, 'VAST.Ad.InLine.Creatives.Creative.NonLinearAds');
45+
var hasNonLinearCreative = getFromObjectPath(this.inline, 'VAST.Ad.InLine.Creatives.Creative.NonLinearAds');
4646

4747
if (hasNonLinearCreative) {
4848
this.nonLinearCreative = new NonLinearCreative(this);
@@ -60,8 +60,8 @@ VastResponse.prototype.addRawResponse = function(data) {
6060
};
6161

6262
VastResponse.prototype.getExtensions = function(createVastExtension = vastModelFactory.createVastExtension) {
63-
var inlineExtensions = objectUtil.getArrayFromObjectPath(this.inline, 'VAST.Ad.InLine.Extensions.Extension'),
64-
wrapperExtensions = objectUtil.getArrayFromObjectPath(this.wrappers, 'VAST.Ad.Wrapper.Extensions.Extension'),
63+
var inlineExtensions = getArrayFromObjectPath(this.inline, 'VAST.Ad.InLine.Extensions.Extension'),
64+
wrapperExtensions = getArrayFromObjectPath(this.wrappers, 'VAST.Ad.Wrapper.Extensions.Extension'),
6565
allExtensions = inlineExtensions.concat(wrapperExtensions);
6666

6767
return allExtensions.map(function(ext) {
@@ -76,6 +76,4 @@ VastResponse.prototype.getLastVASTURL = function() {
7676

7777
var lastVAST = this._raw[this._raw.length - 1];
7878
return lastVAST.uri;
79-
};
80-
81-
module.exports = VastResponse;
79+
};

0 commit comments

Comments
 (0)