UNPKG

@palmcode/zkteco-iclock-parser

Version:

A TypeScript/JavaScript parser for ZKTeco iClock protocol attendance data with type safety and comprehensive error handling

128 lines 4.78 kB
import type { AttendanceLog, DeviceInfo, ParseResult, ParserOptions } from "./types"; import { InOutMode, VerifyType } from "./types"; export declare class ZKTecoiClockParser { /** * Human readable names for `VerifyType` values. */ private static readonly VERIFY_TYPE_NAMES; /** * Human readable names for `InOutMode` values. */ private static readonly IN_OUT_MODE_NAMES; /** * Parse a timestamp string into a Date, treating it as device local time. * * @param timestampStr String timestamp from the device (e.g., "2025-09-04 16:14:09") * @param timezoneOffset Timezone offset from UTC in hours (e.g., +4 for Dubai, -5 for EST) * @returns Date instance or null when invalid */ private static parseTimestamp; /** * Parse a raw verify type into `VerifyType` enum. * * @param value Raw string value (e.g. "25") * @returns VerifyType enum or null when unknown/invalid */ private static parseVerifyType; /** * Parse a raw in/out mode into `InOutMode` enum. * * @param value Raw string value (e.g. "0") * @returns InOutMode enum or null when unknown/invalid */ private static parseInOutMode; /** * Parse a work code or default to NORMAL when invalid. * * @param value Raw string value (e.g. "0") * @returns WorkCode enum */ private static parseWorkCode; /** * Safe integer parsing helper. * * @param value Raw numeric string * @returns Parsed number or undefined when invalid */ private static parseNumber; /** * Parse a single ATTLOG row from ZKTeco iClock. * * Input is expected to be tab-separated fields. * * @param line The raw, single line of ATTLOG data * @param lineNumber Optional line number (for error/warning context) * @param options Parser options * @returns ParseResult with a single AttendanceLog * * @example * const row = "11\t2025-08-27 10:57:49\t0\t25\t0"; * const r = parseSingleAttendanceRecord(row); * if (r.success) console.log(r.data!.userID); */ static parseSingleAttendanceRecord(line: string, lineNumber?: number, options?: ParserOptions): ParseResult<AttendanceLog>; /** * Parse multi-line ATTLOG data into structured attendance logs. * * @param data Raw text body sent by device (tab-separated rows) * @param options Parser options * @returns ParseResult with list of AttendanceLog entries * * @example * const body = `11\t2025-08-27 10:57:49\t0\t25\n11\t2025-08-27 10:58:58\t1\t1`; * const result = ZKTecoiClockParser.parseAttendanceLog(body); * if (result.success) result.data.forEach(log => console.log(log.userID)); */ static parseAttendanceLog(data: string, options?: ParserOptions): ParseResult<AttendanceLog[]>; /** * Parse device info from iClock getrequest query parameters. * * @param queryParams Key-value map from request query (must include SN) * @returns ParseResult with DeviceInfo details * * @example * const q = { SN: 'ABC123', INFO: 'ZMM,1,0,10,192.168.1.10,0,0,0,0' }; * const r = ZKTecoiClockParser.parseDeviceInfo(q); */ static parseDeviceInfo(queryParams: Record<string, string>): ParseResult<DeviceInfo>; /** * Get human-friendly name for a VerifyType. * @param type VerifyType enum value * @returns Name like "Palm Recognition" */ static getVerifyTypeName(type: VerifyType): string; /** * Get human-friendly name for an InOutMode. * @param mode InOutMode enum value * @returns Name like "Check In" */ static getInOutModeName(mode: InOutMode): string; /** * Pretty format an AttendanceLog for logs/console. * @param log AttendanceLog entry * @returns Formatted single-line string * * @example * console.log(formatAttendanceLog(log)); */ static formatAttendanceLog(log: AttendanceLog): string; /** * Whether an attendance log indicates a check-in event. * @param log AttendanceLog entry * @returns true if CHECK_IN/BREAK_IN/OT_IN */ static isCheckIn(log: AttendanceLog): boolean; /** * Whether an attendance log indicates a check-out event. * @param log AttendanceLog entry * @returns true if CHECK_OUT/BREAK_OUT/OT_OUT */ static isCheckOut(log: AttendanceLog): boolean; /** * Validate structure and enum values of an AttendanceLog. * @param log The attendance log to validate * @returns ParseResult with the same log or an error */ static validateAttendanceLog(log: AttendanceLog): ParseResult<AttendanceLog>; } //# sourceMappingURL=parser.d.ts.map