|  | 
| 1 |  | -import { processOperators } from "./operators"; | 
|  | 1 | +import { processOperators, processOperatorsAsync } from "./operators"; | 
| 2 | 2 | 
 | 
| 3 | 3 | // Store a reference to the original getAttribute function | 
| 4 | 4 | const originalGetAttribute = Element.prototype.getAttribute; | 
| @@ -41,10 +41,29 @@ function getAttribute(element, name) { | 
| 41 | 41 | 	return processOperators(element, value); | 
| 42 | 42 | } | 
| 43 | 43 | 
 | 
|  | 44 | +/** | 
|  | 45 | + * Asynchronously gets an attribute and processes its value for operators. | 
|  | 46 | + * @param {Element} element - The element from which to get the attribute. | 
|  | 47 | + * @param {string} name - The attribute name. | 
|  | 48 | + * @returns {Promise<string|object>} - A promise that resolves to the processed attribute value. | 
|  | 49 | + */ | 
|  | 50 | +async function getAttributeAsync(element, name) { | 
|  | 51 | +	if (!(element instanceof Element)) { | 
|  | 52 | +		throw new Error("First argument must be an Element"); | 
|  | 53 | +	} | 
|  | 54 | +	let value = originalGetAttribute.call(element, name); | 
|  | 55 | +	return await processOperatorsAsync(element, value); | 
|  | 56 | +} | 
|  | 57 | + | 
| 44 | 58 | // Override the getAttribute method on Element prototype | 
| 45 | 59 | Element.prototype.getAttribute = function (name) { | 
| 46 | 60 | 	return getAttribute(this, name); // Use the custom getAttribute function | 
| 47 | 61 | }; | 
| 48 | 62 | 
 | 
|  | 63 | +// Add getAttributeAsync to the Element prototype | 
|  | 64 | +Element.prototype.getAttributeAsync = function (name) { | 
|  | 65 | +	return getAttributeAsync(this, name); | 
|  | 66 | +}; | 
|  | 67 | + | 
| 49 | 68 | // Export the custom getAttribute function | 
| 50 |  | -export { getAttribute }; | 
|  | 69 | +export { getAttribute, getAttributeAsync }; | 
0 commit comments