@alugha/ima

中文文档
2.2.1发布于 2023/05/17MITTypeScriptESM + CJS零依赖近 30 天下载 2.3万

A library for asynchronously loading the Google IMA SDK with static typing for the SDK

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. TypeScript with async loading
  4. TypeScript without async loading
  5. Disclaimer

Typed Google IMA SDK

A library without runtime dependencies for asynchronously loading the Google IMA SDK, including TypeScript type definitions for the SDK itself.

For information on the Google IMA SDK itself, please visit Google's official documentation.

Installation

yarn add @alugha/ima or npm install --save @alugha/ima

Usage

TypeScript with async loading

With promises and CommonJS modules:

const { loadImaSdk, google } = require("@alugha/ima");

loadImaSdk()
  .then(ima => {
    // Use the IMA SDK like any other typed module
    const adDisplayContainer: google.ima.AdDisplayContainer = new ima.AdDisplayContainer(
      document.getElementById("ad-container")
    );
    adDisplayContainer.initialize();
  })
  .catch(() => {
    console.log("SDK could not be loaded. Check your ad blocker!");
  });

With async / await and ES2015 modules:

import { loadImaSdk, google } from "@alugha/ima";

const example = async () => {
  try {
    const ima = await loadImaSdk();
    // Use the IMA SDK like any other typed module
    const adDisplayContainer: google.ima.AdDisplayContainer = new ima.AdDisplayContainer(
      document.getElementById("ad-container")
    );
    adDisplayContainer.initialize();
  } catch (e) {
    console.log("SDK could not be loaded. Check your ad blocker!");
  }
};

TypeScript without async loading

If you prefer to directly load the SDK using a script tag, you can still make use of the included type definitions in types/ima.d.ts.

Disclaimer

We are not involved in the development of the Google IMA SDK itself. This library is not connected to Google in any way either.

版本与发布记录

@alugha/ima 共发布 19 个版本,首次发布于 2018/01/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.2.1latest2023/05/173 年前
2.2.02023/05/173 年前
2.1.02021/09/285 年前
2.0.32021/05/025 年前
2.0.22020/11/205 年前
2.0.2-preview.12020/11/205 年前

关于 @alugha/ima 的常见问题

@alugha/ima 是什么?

A library for asynchronously loading the Google IMA SDK with static typing for the SDK

如何安装 @alugha/ima?

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

@alugha/ima 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@alugha/ima 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@alugha/ima 可以商用吗?

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

@alugha/ima 的下载量有多少?

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

@alugha/ima 还在维护吗?

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