Abdulmuiz A.
Snippets

Every code block, in one place.

16 snippets pulled from 3 posts. Filter by language or post, or search the code itself. These are the same blocks that appear in the articles — nothing rewritten or re-extracted.

16 snippets

read post →
static compareVersions(a: string, b: string): number {
  const parse = (v: string) =>
    v.split('.').map(part => parseInt(part, 10))
      .map(n => (Number.isNaN(n) ? 0 : n));

  const pa = parse(a);
  const pb = parse(b);
  const len = Math.max(pa.length, pb.length);

  for (let i = 0; i < len; i++) {
    const na = pa[i] ?? 0;
    const nb = pb[i] ?? 0;
    if (na < nb) return -1;
    if (na > nb) return 1;
  }
  return 0;
}
read post →
if (compareVersions(currentVersion, config.minSupportedVersion) < 0) {
  return { status: 'blocked', updateMessage: config.forceUpdateMessage };
}
if (compareVersions(currentVersion, config.latestVersion) < 0) {
  return { status: 'update_available', updateMessage: config.updateAvailableMessage };
}
return { status: 'ok', updateMessage: '' };
read post →
export const DEFAULTS = {
  vendor_min_supported_version: '0.0.0',
  vendor_latest_version: '0.0.0',
  vendor_force_update_message: `A mandatory update is required to continue using the ${appName} app…`,
  vendor_update_available_message: `A new version of the ${appName} app is available with bug fixes and improvements.`,
  vendor_ios_store_url: 'https://apps.apple.com/…',
  vendor_android_store_url: 'https://play.google.com/…',
  vendor_android_native_update_enabled: false,
};
read post →
try {
  const config = await configProvider.fetchConfig();
  return VersionGateEngine.evaluate(currentVersion, config);
} catch (err) {
  console.warn('[versionGate] Remote Config check failed, failing open:', err);
  return {
    status: 'error',
    currentVersion,
    minSupportedVersion: DEFAULTS.vendor_min_supported_version,
    latestVersion: DEFAULTS.vendor_latest_version,
    updateMessage: '',
    storeUrl: { ios: '', android: '' },
    androidNativeUpdateEnabled: false,
  };
}
read post →
console.log('⚠️  MAJOR VERSION RELEASE: MANUAL ACTION REQUIRED ⚠️');
console.log('Decide whether to bump `min_supported_version` in Firebase Remote Config.');
console.log('Do NOT flip it automatically: confirm the store build is LIVE first');
read post →
export function formatMoney(value: number): string {
  // formats the value AS-IS: assumes naira
  return new Intl.NumberFormat("en-NG", { style: "currency", currency: "NGN" }).format(value);
}

export function formatCurrency(koboValue: number): string {
  // assumes kobo: divides by 100 first
  return formatMoney(koboValue / 100);   // the bug, in three words
}
read post →
export type CurrencyUnit = 'kobo' | 'naira';

export function koboToNaira(amount: number | string | bigint): number {
  const kobo = parseMoneyNumber(amount);
  return Number.isFinite(kobo) ? kobo / 100 : 0;
}

export function formatCurrency(
  amount: number | string | bigint,
  decimals: number = 2,
  unit: CurrencyUnit = 'kobo',         // the unit is right there
  showDecimals: ShowDecimalsMode = 'auto',
): string {
  const numAmount = toNairaAmount(amount, unit);   // convert, explicitly
  // ...then format, and only format
}