vast-parser-ts
v1.0.1
Published
common scripts for ad templates ui
Readme
VAST Unwrapper
A TypeScript library for parsing and unwrapping VAST (Video Ad Serving Template) XML documents. This library supports VAST versions 2.0 through 4.2 and provides a robust solution for handling both inline and wrapper VAST ads.
Features
- Supports VAST versions 2.0 to 4.2
- Handles both inline and wrapper VAST ads
- Automatic unwrapping of VAST wrapper chains
- Configurable wrapper depth limit
- Error tracking and reporting
- XML validation
- Macro resolution support
- TypeScript support with comprehensive type definitions
Installation
npm install vast-unwrapperUsage
import { VASTParser } from 'vast-unwrapper';
// Initialize the parser
const parser = new VASTParser({
maxWrapperDepth: 5, // Optional, defaults to 6
proxyUrl: 'https://your-proxy-url.com' // Required for CORS handling
});
// Parse VAST from URL
async function parseVastFromUrl(vastUrl: string) {
try {
const ads = await parser.getAndParseVastXml(vastUrl);
console.log('Parsed ads:', ads);
} catch (error) {
console.error('Error parsing VAST:', error);
}
}
// Parse VAST from XML string
async function parseVastFromString(vastXmlString: string) {
try {
const ads = await parser.parseVastXMLFromString(vastXmlString);
console.log('Parsed ads:', ads);
} catch (error) {
console.error('Error parsing VAST:', error);
}
}API Reference
VASTParser
Main class for parsing VAST documents.
Constructor
new VASTParser(config: ParserConfig)config.maxWrapperDepth(optional): Maximum depth for wrapper resolution (default: 6)config.proxyUrl(required): URL for proxy server to handle CORS requests
Methods
getAndParseVastXml(url: string): Promise<AdObject[]>Fetches and parses a VAST document from the given URLparseVastXMLFromString(vastString: string): Promise<AdObject[]>Parses a VAST XML stringparseVastXML(vastXml: XMLDocument): Promise<AdObject[]>Parses a VAST XML document
Development
Setup
npm installBuild
npm run buildTest
npm testLint
npm run lintContributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
