diff --git a/src/core/budgetManager.ts b/src/core/budgetManager.ts index af4b96f..9f2b703 100644 --- a/src/core/budgetManager.ts +++ b/src/core/budgetManager.ts @@ -11,7 +11,7 @@ export class BudgetManager { constructor(options: BudgetGuardOptions) { // Validate monthly limit - if (typeof options.monthlyLimit !== 'number' || isNaN(options.monthlyLimit) || !isFinite(options.monthlyLimit)) { + if (typeof options.monthlyLimit !== 'number' || Number.isNaN(options.monthlyLimit) || !isFinite(options.monthlyLimit)) { throw new Error('TokenFirewall: monthlyLimit must be a valid number'); } @@ -36,7 +36,7 @@ export class BudgetManager { */ public async track(cost: number): Promise { // Validate cost parameter - if (typeof cost !== 'number' || isNaN(cost) || !isFinite(cost)) { + if (typeof cost !== 'number' || Number.isNaN(cost) || !isFinite(cost)) { throw new Error('TokenFirewall: Cost must be a valid number'); } @@ -116,7 +116,7 @@ export class BudgetManager { */ public importState(state: { totalSpent: number }): void { // Validate totalSpent - if (typeof state.totalSpent !== 'number' || isNaN(state.totalSpent) || !isFinite(state.totalSpent)) { + if (typeof state.totalSpent !== 'number' || Number.isNaN(state.totalSpent) || !isFinite(state.totalSpent)) { throw new Error('TokenFirewall: Invalid budget state - totalSpent must be a valid number'); } diff --git a/src/index.ts b/src/index.ts index c769e99..0217095 100644 --- a/src/index.ts +++ b/src/index.ts @@ -66,10 +66,10 @@ export function registerPricing(provider: string, model: string, pricing: ModelP if (!pricing || typeof pricing !== 'object') { throw new Error('TokenFirewall: Pricing must be an object'); } - if (typeof pricing.input !== 'number' || pricing.input < 0 || !isFinite(pricing.input) || isNaN(pricing.input)) { + if (typeof pricing.input !== 'number' || pricing.input < 0 || !isFinite(pricing.input) || Number.isNaN(pricing.input)) { throw new Error('TokenFirewall: Pricing input must be a non-negative finite number'); } - if (typeof pricing.output !== 'number' || pricing.output < 0 || !isFinite(pricing.output) || isNaN(pricing.output)) { + if (typeof pricing.output !== 'number' || pricing.output < 0 || !isFinite(pricing.output) || Number.isNaN(pricing.output)) { throw new Error('TokenFirewall: Pricing output must be a non-negative finite number'); } @@ -90,7 +90,7 @@ export function registerContextLimit(provider: string, model: string, contextLim if (!model || typeof model !== 'string' || model.trim() === '') { throw new Error('TokenFirewall: Model must be a non-empty string'); } - if (typeof contextLimit !== 'number' || contextLimit <= 0 || !isFinite(contextLimit) || isNaN(contextLimit)) { + if (typeof contextLimit !== 'number' || contextLimit <= 0 || !isFinite(contextLimit) || Number.isNaN(contextLimit)) { throw new Error('TokenFirewall: Context limit must be a positive finite number'); }