UNPKG

@adguard/aglint

Version:

Universal adblock filter list linter.

44 lines (41 loc) 1.43 kB
/* * AGLint v3.0.0 (build date: Wed, 21 May 2025 13:24:14 GMT) * (c) 2025 AdGuard Software Ltd. * Released under the MIT license * https://github.com/AdguardTeam/AGLint#readme */ import { isNumber } from '../../utils/type-guards.js'; /** * Check if the error is an instance of ErrorWithOffset. * * @param possibleError Possible error to check. * * @returns `true` if the error is an instance of ErrorWithOffset. */ const isErrorContainingOffset = (possibleError) => { if (!(possibleError instanceof Error)) { return false; } return 'offset' in possibleError && isNumber(possibleError.offset); }; /** * Check if the error is an instance of SyntaxError, SyntaxMatchError or SyntaxReferenceError. * * Based on https://github.com/csstree/validator/blob/38e7319d7b049c190f04665df77c836646f3b35e/lib/validate.js#L5-L17 * * @param possibleError Error to check. * * @returns `true` if the error is an instance of SyntaxError, SyntaxMatchError or SyntaxReferenceError. */ const isCssTreeSyntaxError = (possibleError) => { if (!possibleError || !(possibleError instanceof Error)) { return false; } if (!('name' in possibleError)) { return false; } return possibleError.name === 'SyntaxError' || possibleError.name === 'SyntaxMatchError' || possibleError.name === 'SyntaxReferenceError'; }; export { isCssTreeSyntaxError, isErrorContainingOffset };