@adguard/agtree
Version:
Tool set for working with adblock filter lists
54 lines (51 loc) • 1.41 kB
JavaScript
/*
* AGTree v3.4.3 (build date: Thu, 11 Dec 2025 13:43:19 GMT)
* (c) 2025 Adguard Software Ltd.
* Released under the MIT license
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
*/
import { isUndefined } from '../utils/type-guards.js';
import { clone } from '../utils/clone.js';
/**
* @file Utility functions for working with modifier nodes
*/
/**
* Creates a modifier node
*
* @param name Name of the modifier
* @param value Value of the modifier
* @param exception Whether the modifier is an exception
* @returns Modifier node
*/
function createModifierNode(name, value = undefined, exception = false) {
const result = {
type: 'Modifier',
exception,
name: {
type: 'Value',
value: name,
},
};
if (!isUndefined(value)) {
result.value = {
type: 'Value',
value,
};
}
return result;
}
/**
* Creates a modifier list node
*
* @param modifiers Modifiers to put in the list (optional, defaults to an empty list)
* @returns Modifier list node
*/
function createModifierListNode(modifiers = []) {
const result = {
type: 'ModifierList',
// We need to clone the modifiers to avoid side effects
children: modifiers.length ? clone(modifiers) : [],
};
return result;
}
export { createModifierListNode, createModifierNode };