Recursively requests and parses VAST chains into a single JavaScript object.
VAST Chains are VAST Wrappers wrapped in more VAST Wrappers eventually resulting in a VAST Inline.
import { VastAdManager } from '@unruly/vast-parser'
const vastAdManager = new VastAdManager()
vastAdManager.requestVastChain({ url: 'http://example.com/vast-file.xml' })
.then(
vastResponse => {
// success
},
vastError => {
// failure
}
)
You'll need to use a package manager like npm to install this package.
# npm
npm install @unruly/vast-parser
# yarn
yarn add @unruly/vast-parser
- jQuery for requesting nested VAST URIs. We hope to replace this in the future.
You may need to include some polyfills depending on your target environment.
Use this package like a typical ES6 module. For detailed usage information on each export, see the subsections below.
// import what you need
import {
VastAdManager,
VastErrorCodes,
VastParser
} from '@unruly/vast-parser'
// do what you want
Creates a VastAdManager
.
Recursively requests a given VAST URL until a VAST Inline is reached.
Resolves to a VastResponse
.
Rejects to a VastError
with a code
matching to one of the VastErrorCodes.code
(see VastErrorCodes
section).
Calls the given handler
when an event
of the eventName
is fired. The handler
is passed the event
as its first parameter.
Event Names
requestStart
- start of request for VAST filerequestEnd
- end of request for VAST file
Event Properties
requestNumber
- the current depth of the VAST chain.uri
- the URI for the request.vastResponse
- theVastResponse
by being built reference.
- VastAdManager currently does not support NodeJS as it relies on jQuery.
An Enum of possible error codes on a VastError
(see vastAdManager.requestVastChain
section).
For possible values, see the module.
Parses a given VAST document into a JSXMLNode. JSXMLNode a simple JS representation of an XML document.
- To work in NodeJS, you'll need to pass a
Document
. Use a library likexmldom
to parse your document string before sending it toVastParser.parse
.
License information can be found in the LICENSE file.