@adguard/aglint
Version:
Universal adblock filter list linter.
44 lines (41 loc) • 1.03 kB
JavaScript
/*
* 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 { object, number, mask } from 'superstruct';
/**
* Minimal schema for location object.
*/
const locSchema = object({
start: object({
offset: number(),
}),
end: object({
offset: number(),
}),
});
/**
* Schema for object with `loc` property.
*/
const objWithLocSchema = object({
loc: locSchema,
});
/**
* Get start and end offsets from the object with `loc` property.
*
* @param input Object with `loc` property.
*
* @returns Tuple with start and end offsets or `null` if the object does not have `loc` property.
*/
const getCssTreeStartAndEndOffsetsFromObject = (input) => {
try {
const { loc } = mask(input, objWithLocSchema);
return [loc.start.offset, loc.end.offset];
}
catch {
return null;
}
};
export { getCssTreeStartAndEndOffsetsFromObject };