Registry / testing / har-guard

har-guard

JSON →
library0.1.0jsnpmunverified

Zero-dependency TypeScript library for validating HAR 1.2 (HTTP Archive) files, designed as a modern replacement for the deprecated har-validator package. Current version 0.1.0, released as an independent migration helper supporting Node >=18. Key differentiators: fully typed with TypeScript, no external dependencies, offers both synchronous (validateHar, assertHar, isHar) and Promise-based (har, request, response, entry) APIs, and provides structured validation results with detailed issues instead of simple boolean flags. Suitable for projects migrating away from har-validator or building new HAR validation pipelines.

npm install har-guard
INSTALL
IMPORT
SIG · HAR-GUARD
H
har-guard
testingjavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

validateHar
import { validateHar } from 'har-guard'
const validateHar = require('har-guard').validateHar
ESM-only package; CommonJS require will not work. Use ESM imports.
assertHar
import { assertHar } from 'har-guard'
import assertHar from 'har-guard' (default import does not exist)
assertHar is a named export, not the default export.
isHar
import { isHar } from 'har-guard'
Type guard returning boolean; no wrong pattern common yet.

Demonstrates synchronous validation, assertion, and type guard with a sample HAR 1.2 object.

import { assertHar, validateHar } from 'har-guard'; const sampleHar = { log: { version: '1.2', creator: { name: 'test', version: '0.1' }, entries: [] } }; const result = validateHar(sampleHar); console.log(result.valid); // true or false console.log(result.issues); // array of issues if invalid // Throws HarValidationError on invalid try { assertHar(sampleHar); console.log('HAR is valid'); } catch (e) { console.error(e.message); } // Type guard example if (isHar(sampleHar)) { console.log('Sample is a valid HAR object'); }
Debug
Known issues
breakinghar-guard is ESM-only and cannot be used with CommonJS require().
fix
Ensure your project uses ESM (type: module in package.json) and use import syntax.
affects: >=0.1.0
breakingThe validateHar function returns an object with valid and issues properties, not a boolean like har-validator's validate().
fix
Access result.valid to check validity, not the result directly.
affects: >=0.1.0
deprecatedhar-validator is deprecated; har-guard is an independent replacement.
fix
Migrate from har-validator to har-guard as recommended by the original project.
affects: any
gotchaThe Promise-based functions (har(), request(), etc.) reject with HarValidationError, not a boolean or result object.
fix
Use .catch() or try/catch with async/await to handle errors.
affects: >=0.1.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Trying to load har-guard with CommonJS require() while it is ESM-only.
fix
Switch your project to ESM (add type: module to package.json) and use import statements.
TypeError: harGuard_1.validateHar is not a function
Incorrectly destructuring from a default import instead of named imports.
fix
Use import { validateHar } from 'har-guard' correctly.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
Resources
har-guard — npm install har-guard · libregistry