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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@abetterchoice/abc_web_sdk

v1.0.1

Published

ABetterChoice实验平台配套Web SDK

Readme

TAB 实验平台 web js sdk

Installation

  1. install using tnpm
$ tnpm install @tencent/abc_web_sdk
// (可选)上报实验数据,还需要加入灯塔sdk。如果业务已经集成灯塔sdk或者不需要在上报实验数据,忽略这一步
$ tnpm install @tencent/beacon-web-sdk
  1. import script
<script src="https://res.ab.qq.com/tab/tab_jssdk.min.js"></script>

//
可选)上报实验数据,还需要加入灯塔sdk。如果业务已经集成灯塔sdk或者不需要在上报实验数据,忽略这一步
<script src="https://beaconcdn.qq.com/sdk/3.1.42/beacon_web.min.js"></script>

Usage

1. 集成 SDK:

wabt.init(
  // 可选 await 或者promise.then替代onInit
  // 只能初始化一次
  {
    appid: "303", // TAB平台的业务id
    guid: "123456789012345678901234567890ab", // 可选,传人一个用户身份,用来做分流标识。 不设置的话默认生成一个
    // isTest: true, // 使用测试环境
    profiles: { age: "10" }, // 用户属性,可以用来做标签使用
    onInit: function (data) {
      // 初始化完成,加载完本地缓存策略
      console.log("init fniish");
    },
    onNetData: function (data) {
      // 加载完成网络策略
      console.log("net fnish");
    },
  }
);

profilesvalue 的类型必须为字符串,其它类型会被强制转换成字符串。

//获取不同的实例,(比如不同的业务或者不同的实验用户体系)
const abtest2 = abtest.getInstance("otherKey"); // use otherKey get target instance
abtest2.init({
  /** appid */
}); //
// 设置用户属性 (只会追加和覆盖)
wabt.setProfiles(pfs);

// 强制更新策略
await wabt.forceReload();

// 切换用户
// newProfiles为空则使用旧的profiles,否则使用新的profiles
await wabt.switchUser(newGuid, newProfiles);

2. 使用方法:

// 2.1 获取实验,并上报一次实验曝光
// 通过expName获取实验, 缓存中没有数据则发起网络请求获取
const exp = await wabt.getExpByNameAndReport("expName1");
// TAB平台定义的实验版本名称,一般用control代替对照组。你也可以定义其他的名字
if (exp.assignment === "contorol") {
  // 对照组逻辑
} else if (exp.assignment === "treatment1") {
  // TAB平台定义的实验版本名称
  // 实验组1逻辑
} else {
  // exp.assignment === 'default' 未命中实验
  // 默认
}
// 2.2 获取实验, 不上报曝光
// 通过expName获取实验, 缓存中没有数据则发起网络请求获取
const exp2 = await wabt.getExpByName('expName2');
......
// 在合适的时机手动上报曝光
wabt.reportExpExpose(exp2);
// 2.3 获取缓存中得实验, 不上报曝光
// 通过expName获取实验, 缓存中没有数据则发起网络请求获取
const exp2 = wabt.getCachedExpByName("expName2");
// 上报一条实验自定义事件
wabt.reportExpEvent("myEvent", exp);
// 2.4 通过expName和guid获取实验(只限本次的网络请求,不会缓存到内存和磁盘)
const exp3 = await wabt.getTargetExpByName("expName", "userid");

远程配置

TAB 平台提供了远程配置功能,使用远程配置需要对应业务的appkey,可找 TAB 接口人查询(@kelvinxiao、@xieli)。

使用

import RemoteConfig from "@tencent/abc_web_sdk/dist/config.min";

const remoteConfig = new RemoteConfig({
  appid: "6666",
  appKey: "*****",
  guid: "xxxx",
  defaultConfig: {
    color: "red",
    amount: 0,
  },
});

remoteConfig.init(() => {
  remoteConfig.getString("color");
  remoteConfig.getNumber("amount");
});

加载策略

SDK 会读取缓存中的数据,判断是否过期。没有过期,直接使用缓存数据。

如果过期,将会收集 defaultConfig 所有的属性 key,向服务端发送请求。服务端只会返回 defaultConfig 中有的值。在拉取数据之后,会更新本地缓存。SDK 首先会使用 indexDB 缓存,不支持的浏览器则会用 localStorage

使用 API 取值时,首先尝试读取远端配置,如果没有则会返回实例化时传入的默认值,如果都没有,则会返回一个空值。

API

getAll()

返回全部配置表。

getValue(string)

返回对应 Value 实例,可以调用asStringasBooleanasNumber将数据转换成特定的类型。getSource返回数据的来源。

getString(string)

将值转换成 String 返回。

getNumber(string)

将值转换成 Number 返回。

getBoolean(string)

将值转换成 Boolean 返回。

clearLocalstorage()

清除 localstoarge 缓存。

Options

| 属性 | 说明 | 类型 | | ------------- | ----------------------------- | ------- | | appid | 业务 ID,必填 | String | | appkey | 请求时用作鉴权,必填 | String | | defaultConfig | 默认配置 | Object | | guid | 用户 id,可选,不填会默认生成 | String | | profiles | 用户属性,可选 | Object | | isTest | 设置成测试环境 | Boolean | | fetchInterval | 缓存过期时长,默认 1 小时 | Number | | disableCache | 是否禁用缓存 | Boolean |

License

ISC