@dailymotion/vmap

中文文档
3.3.3发布于 2025/06/30MITCommonJS零依赖近 30 天下载 3.5万

Javascript VMAP Parser

原始使用文档
文档目录9 节
  1. Installation
  2. Usage
  3. API
  4. VMAP
  5. VMAPAdBreak
  6. VMAPAdSource
  7. Support and compatibility
  8. Pre-bundled versions
  9. Build and tests

VMAP Javascript Library

Build Status code style: prettier License: MIT npm version

Parse a VMAP XML document to Javascript object. Complies with VMAP 1.0.1 spec.

Installation

Install with npm

npm install @dailymotion/vmap

Usage

Provide the VMAP constructor an XML in order to have a parsed version of it.

Access VMAP properties using the APIs documented below.

import VMAP from '@dailymotion/vmap';

// Fetch VMAP as XML
fetch(vmapURL)
    .then(response => response.text())
    .then(xmlText => {
        // Get a parsed VMAP object
        const parser = new DOMParser();
        const xmlDoc = parser.parseFromString(xmlText, 'text/xml');
        const vmap = new VMAP(xmlDoc);
    })
    .catch(error => {
        console.error('Error fetching VMAP:', error);
    });

API

VMAP

Properties

  • version: The VMAP version (should be 1.0).
  • adBreaks: An array of VMAPAdBreak objects.
  • extensions: An array of Object with
    • children: Object containing all this extension children and their name as the key
    • attribute: Object containing all this extension attributes and their name as the key
    • value: Object parsed from CDATA or as a fallback all of the text nodes of this extension concatenated

VMAPAdBreak

Provides information about an ad break.

Properties

  • timeOffset: Represents the timing of the ad break.
  • breakType: Identifies whether the ad break allows "linear", "nonlinear" or "display" ads.
  • breakId: An optional string identifier for the ad break.
  • repeatAfter: An option used to distribute ad breaks equally spaced apart from one another along a linear timeline.
  • adSource: A VMAPAdSource object.
  • trackingEvents: An array of Object with tracking URLs
    • event: The name of the event to track for the element. Can be one of breakStart, breakEnd or error.
    • uri: The URI of the tracker.
  • extensions: An array of Object with
    • children: Object containing all this extension children and their name as the key
    • attribute: Object containing all this extension attributes and their name as the key
    • value: Object parsed from CDATA or as a fallback all of the text nodes of this extension concatenated

Methods

  • track(event, errorCode): Call the trackers for the given event with an option error code parameter for error events.

VMAPAdSource

Provides the player with either an inline ad response or a reference to an ad response.

Properties

  • id: Ad identifier for the ad source.
  • allowMultipleAds: Indicates whether a VAST ad pod or multple buffet of ads can be served into an ad break.
  • followRedirects: Indicates whether the video player should honor the redirects within an ad response.
  • vastAdData: Contains an embedded VAST response.
  • adTagURI: Contains a URI to the VAST.
  • customData: Contains custom ad data.

Support and compatibility

The library is 100% written in JavaScript and the source code uses modern features like modules, classes, ecc... . Make sure your environment supports these features, or transpile the library when bundling your project.

Pre-bundled versions

We provide several pre-bundled versions of the library (see dist directory)

Browser

A pre-bundled version of VMAP-jsis available: vmap-js.js.

You can add the script directly to your page and access the library through the VMAP constructor.

<script src="dist/vmap-js.js"></script>
var vmap = new VMAP(vmapXML);

Node

A pre-bundled version for node is available too: vmap-js-node.js.

const VMAP = require('@dailymotion/vmap')

const vmap = new VMAP(vmapXML);

Build and tests

Install dependencies with:

npm install

The project is bundled using Rollup. Build with:

npm run-script build

Run tests with:

npm test

版本与发布记录

@dailymotion/vmap 共发布 4 个版本,首次发布于 2021/09/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.3.3latest2025/06/301.4 年前
3.3.22025/01/231.8 年前
3.3.12022/10/144 年前
3.3.02021/09/215 年前

关于 @dailymotion/vmap 的常见问题

@dailymotion/vmap 是什么?

Javascript VMAP Parser

如何安装 @dailymotion/vmap?

在项目目录运行 npm install @dailymotion/vmap,或使用 pnpm add / yarn add / bun add。

@dailymotion/vmap 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dailymotion__vmap 是否存在。

@dailymotion/vmap 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dailymotion/vmap 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=12.22.1。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dailymotion/vmap 可以商用吗?

@dailymotion/vmap 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dailymotion/vmap 的下载量有多少?

根据 npm 官方下载统计,@dailymotion/vmap 在 2026/10/11 – 2026/11/09 这 30 天内被下载 35,427 次,日均约 1,181 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dailymotion/vmap 还在维护吗?

最新版本 3.3.3 发布于 2025/06/30(1.4 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/09/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。