npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

iab-vast-loader

v2.5.1

Published

Loads and parses IAB VAST tags, resolving wrapped tags along the way.

Downloads

219

Readme

iab-vast-loader

npm Dependencies Build Status Coverage Status JavaScript Standard Style

Loads and parses IAB VAST tags, resolving wrapped tags along the way.

Usage

import { VASTLoader } from 'iab-vast-loader'

const tagUrl = 'https://example.com/vast.xml'

// Create the loader
const loader = new VASTLoader(tagUrl)

// Load the tag chain and await the resulting Promise
loader.load()
  .then(chain => {
    console.info('Loaded VAST tags:', chain)
  })
  .catch(err => {
    console.error('Error loading tag:', err)
  })

This should work in both Node.js version 8 and above as well as in the browser. However, in the browser, you'll probably want to use a bundler first.

API

new VASTLoader(tagUrl[, options])

Creates a VAST loader.

loader.load()

Returns a Promise for an array of VAST instances. The VAST class is provided by iab-vast-model.

Error Handling

In addition to VASTLoader, the main module also exports the VASTLoaderError class, which maps errors to the VAST specification:

import { VASTLoader, VASTLoaderError } from 'iab-vast-loader'

const loader = new VASTLoader(tagUrl)

loader.load()
  .catch(err => {
    if (err instanceof VASTLoaderError) {
      console.error('VAST error: ' + err.code + ' ' + err.message)
    } else {
      console.error('Unknown error: ' + err)
    }
  })

As with iab-vast-model, if instanceof doesn't work for you, you may want to inspect error.$type instead. This issue can occur if you load multiple versions of iab-vast-loader, each with their own VASTLoaderError class.

Options

maxDepth

The maximum number of VAST documents to load within one chain. The default is 10.

timeout

The maximum number of milliseconds to spend per HTTP request. The default is 10,000.

credentials

Controls CORS behavior. You can pass a string, an array of strings, or a function producing either of those.

If you pass a string, it will be used as the value for the credentials option to every request. Valid values are 'omit' (the default), 'same-origin' and 'include'.

If you pass an array, each of the values in the array will be tried consecutively. For example, to first try each request with credentials and then without, you can pass ['include', 'omit'].

To control the behavior on a per-request basis, pass a function receiving the request URL and returning one of the accepted values. For example:

const loader = new VASTLoader(wrapperUrl, {
  credentials: uri => {
    if (uri.indexOf('.doubleclick.net/') >= 0) {
      return 'include'
    } else {
      return 'omit'
    }
  }
})

fetch

Sets the implementation of fetch, used to make HTTP requests. In Node.js, this defaults to node-fetch. In the browser, unfetch is used.

Events

A VASTLoader is an EventEmitter. To be notified about progress, you can subscribe to the events willFetch, didFetch, willParse, and didParse as follows:

loader
  .on('willFetch', ({ uri }) => {
    console.info('Fetching', uri)
  })
  .on('didFetch', ({ uri, body }) => {
    console.info('Fetched', body.length, 'bytes from', uri)
  })
  .on('willParse', ({ uri, body }) => {
    console.info('Parsing', uri)
  })
  .on('didParse', ({ uri, body, vast }) => {
    console.info('Parsed', uri)
  })
  .load()
  .then(chain => {
    console.info('Loaded VAST tags:', chain)
  })
  .catch(err => {
    console.error('Error loading tag:', err)
  })

Maintainer

Tim De Pauw

License

MIT