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

vastacular

v0.2.0

Published

Fetches/parses IAB VAST 2.0/3.0 XML.

Downloads

900

Readme

vastacular

Fetches/parses IAB VAST 2.0/3.0 XML.

API Documentation

VAST(json)

Accepts a JSON-formatted VAST document (described below.) All properties of the JSON-formatted VAST document will be copied to the VAST object. Any unspecified properties will be given default values. For example, if no mediaFiles are specified, the default will be an empty Array.

Here is complete JSON-formatted VAST document:

{
    version: '2.0',
    ads: [
        {
            id: '12345',
            type: 'inline',
            system: {
                name: 'LiveRail',
                version: 'LR_DELIVERY_VERSION'
            },
            title: 'LiveRail creative 2',
            description: 'Lorem ipsum dolor sit amet, consectetur adipiscing.',
            survey: 'http://cinema6.com/survey',
            errors: ['http://cinema6.com/pixels/error'],
            impressions: [
                {
                    uri: 'http://cinema6.com/pixels/impression',
                    id: 'LR'
                }
            ],
            creatives: [
                {
                    id: '7969',
                    sequence: 1,
                    adID: 'foo',
                    type: 'linear',
                    duration: 30, // seconds
                    trackingEvents: [
                        {
                            event: 'start',
                            uri: 'http://cinema6.com/pixels/start'
                        },
                        {
                            event: 'midpoint',
                            uri: 'http://cinema6.com/pixels/midpoint'
                        }
                    ],
                    parameters: 'foo=bar',
                    videoClicks: {
                        clickThrough: 'http://cinema6.com/',
                        clickTrackings: ['http://cinema6.com/pixels/click'],
                        customClicks: [
                            {
                                id: 'some-id',
                                uri: 'http://cinema6.com/pixels/custom-click'
                            }
                        ]
                    },
                    mediaFiles: [
                        {
                            id: 'media-id',
                            delivery: 'streaming',
                            type: 'video/mp4',
                            uri: 'http://cinema6.com/videos/my-ad.mp4',
                            bitrate: 1024,
                            width: 1920,
                            height: 1080,
                            scalable: true,
                            maintainAspectRatio: true,
                            apiFramework: 'none'
                        }
                    ]
                },
                {
                    id: 'companion-id',
                    type: 'companions',
                    companions: [
                        {
                            width: 300,
                            height: 250,
                            expandedWidth: 800,
                            expandedHeight: 600,
                            apiFramework: '...',
                            resources: [
                                {
                                    type: 'static',
                                    creativeType: 'image/png',
                                    data: 'http://cinema6.com/images/ad.png' // or a blob of html
                                },
                                {
                                    type: 'iframe',
                                    data: 'http://cinema6.com/pages/ad.html'
                                },
                                {
                                    type: 'html',
                                    data: '<p>Hello!</p>'
                                }
                            ],
                            trackingEvents: [
                                {
                                    event: 'creativeView',
                                    uri: 'http://cinema6.com/pixels/companion-view'
                                }
                            ],
                            clickThrough: 'http://cinema6.com/store',
                            altText: 'Visit the Store!',
                            parameters: 'foo=bar'
                        }
                    ]
                },
                {
                    id: 'some-id',
                    type: 'nonLinear',
                    ads: [
                        {
                            id: 'linear-id',
                            width: 970,
                            height: 200,
                            expandedWidth: 800,
                            expandedHeight: 600,
                            scalable: true,
                            maintainAspectRatio: true,
                            minSuggestedDuration: 10, // seconds
                            apiFramework: '...',
                            resources: [
                                {
                                    type: 'static',
                                    creativeType: 'image/png',
                                    data: 'http://cinema6.com/images/ad.png' // or a blob of html
                                },
                                {
                                    type: 'iframe',
                                    data: 'http://cinema6.com/pages/ad.html'
                                },
                                {
                                    type: 'html',
                                    data: '<p>Hello!</p>'
                                }
                            ]
                            clickThrough: 'http://cinema6.com/store',
                            parameters: 'foo=bar'
                        }
                    ],
                    trackingEvents: [
                        {
                            event: 'start',
                            uri: 'http://cinema6.com/pixels/start'
                        },
                        {
                            event: 'midpoint',
                            uri: 'http://cinema6.com/pixels/midpoint'
                        }
                    ]
                }
            ]
        },
        {
            type: 'wrapper',
            vastAdTagURI: 'http://cinema6.com/vast/some-vast.xml'

            // Wrapper ad can also have any of the properties of the "inline" type
        }
    ]
}

VAST.prototype.wrappers

Returns all of the ads with type "wrapper."

VAST.prototype.inlines

Returns all of the ads with type "inline."

VAST.prototype.get(prop)

Gets the specified property from the VAST instance. If one of the parent properties is a non-object, it will return undefined instead of throwing a TypeError.

VAST.prototype.set(prop, value)

Sets the specified prop to the provided value. If one of the parent properties is a non-object, it will be converted into a POJO ({}.)

VAST.prototype.map(array, mapper)

Uses Vast.prototype.get() to retrieve the array and calls the mapper for each item in the array with the item, index and array. In the mapper, this will refer to the VAST instance. A new Array will be returned containing items with the result of each call of mapper.

If array does not resolve to an Array, an empty Array will be returned.

VAST.prototype.filter(array, predicate)

Uses Vast.prototype.get() to retrieve the array and calls the predicate for each item in the array with the item, index and array. In the predicate, this will refer to the VAST instance. A new Array will be returned containing items for which predicate returned something truthy.

If array does not resolve to an Array, an empty Array will be returned.

VAST.prototype.find(array, predicate)

Uses Vast.prototype.get() to retrieve the array and calls the predicate for each item in the array with the item, index and array. As soon as predicate returns a truthy value, the corresponding item will be returned. If predicate never returns something truthy, undefined will be returned.

If array does not resolve to an Array, undefined will be returned.

VAST.prototype.resolveWrappers([maxRedirects], [cb])

Returns a Promise. This method will make a request for all the wrappers' vastAdTagURIs. A new VAST will be created, with each wrapper being replaced by the ad(s) that were fetched. This process will repeat recursively until there are no more wrappers or maxRedirects is exceeded.

When there are no more wrappers, the returned Promise will be fulfilled with the new wrapper-free VAST instance. If maxRedirects is exceeded, the Promise will be rejected with an Error.

If the optional callback cb is provided, it will be called in the Node.js conventional way: (err, result).

VAST.prototype.copy()

Returns a new VAST instance that is a copy of this one.

VAST.prototype.toPOJO()

Returns the instance converted to JSON-formatted VAST.

VAST.prototype.toXML()

Returns the instance converted to VAST XML.

VAST.pojoFromXML(xml)

Converts a String of xml into JSON-formatted VAST.

VAST.fetch(uri, [options], [cb])

Returns a Promise. This method will make a network request for the provided uri and fulfill the returned Promise with a VAST instance representing the fetched VAST XML.

options:

{
    resolveWrappers: Boolean, // Should 'wrapper' ads be automatically resolved?
    maxRedirects: Number // Maximum number of wrapper redirects that should be followed,
    headers: Object // Request headers to include
}

If the optional callback cb is provided, it will be called in the Node.js conventional way: (err, result).