Skip to content

otplib API Documentation / @otplib/core / normalizeCounterTolerance

Function: normalizeCounterTolerance()

normalizeCounterTolerance(counterTolerance): number[]

Defined in: packages/core/src/utils.ts:692

Normalize counter tolerance to an array of offsets

Converts a number or array counter tolerance specification into an array of offsets

  • Number: creates symmetric range [-tolerance, +tolerance]
  • Array: uses the array as-is (already contains specific offsets)

Parameters

counterTolerance

Counter tolerance specification (number or array of offsets)

number | number[]

Returns

number[]

Array of offsets to check

Example

ts
normalizeCounterTolerance(0)  // [0]
normalizeCounterTolerance(1)  // [-1, 0, 1]
normalizeCounterTolerance(2)  // [-2, -1, 0, 1, 2]
normalizeCounterTolerance([0, 1])  // [0, 1]
normalizeCounterTolerance([-1, 0, 1])  // [-1, 0, 1]

Released under the MIT License.