function shouldExpand(token, opts, platform) {
  const expand = platform?.expand ?? opts.expand ?? false;

  /** @type {ExpandFilter | boolean} */
  let condition = false;
  let reverse = false;

  if (typeof expand === 'function' || typeof expand === 'boolean') {
    condition = expand;
  } else {
    const type = /** @type {string} */ (opts.usesDtcg ? token.$type : token.type);
    if (expand.include === undefined && expand.exclude === undefined) {
      condition = true;
    }

    if (expand.include) {
      condition =
        typeof expand.include === 'function' ? expand.include : expand.include.includes(type);
    }

    if (/** @type {Expand} */ (expand).exclude) {
      if (expand.include) {
        throw Error(
          'expand.include should not be combined with expand.exclude, use one or the other.',
        );
      }
      condition =
        typeof expand.exclude === 'function' ? expand.exclude : expand.exclude.includes(type);
      reverse = true;
    }
  }

  let result = condition;
  if (typeof condition === 'function') {
    result = condition(token, opts, platform);
  }

  return reverse ? !result : result;
}
@param {DesignToken} token
@param {Config} opts
@param {PlatformConfig} [platform]