| Server IP : 13.235.167.51 / Your IP : 216.73.217.116 Web Server : Apache System : Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64 User : root ( 0) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/control.machinox.in/node_modules/parchment/src/attributor/ |
Upload File : |
import Scope from '../scope.js';
export interface AttributorOptions {
scope?: Scope;
whitelist?: string[];
}
export default class Attributor {
public static keys(node: HTMLElement): string[] {
return Array.from(node.attributes).map((item: Attr) => item.name);
}
public scope: Scope;
public whitelist: string[] | undefined;
constructor(
public readonly attrName: string,
public readonly keyName: string,
options: AttributorOptions = {},
) {
const attributeBit = Scope.TYPE & Scope.ATTRIBUTE;
this.scope =
options.scope != null
? // Ignore type bits, force attribute bit
(options.scope & Scope.LEVEL) | attributeBit
: Scope.ATTRIBUTE;
if (options.whitelist != null) {
this.whitelist = options.whitelist;
}
}
public add(node: HTMLElement, value: any): boolean {
if (!this.canAdd(node, value)) {
return false;
}
node.setAttribute(this.keyName, value);
return true;
}
public canAdd(_node: HTMLElement, value: any): boolean {
if (this.whitelist == null) {
return true;
}
if (typeof value === 'string') {
return this.whitelist.indexOf(value.replace(/["']/g, '')) > -1;
} else {
return this.whitelist.indexOf(value) > -1;
}
}
public remove(node: HTMLElement): void {
node.removeAttribute(this.keyName);
}
public value(node: HTMLElement): any {
const value = node.getAttribute(this.keyName);
if (this.canAdd(node, value) && value) {
return value;
}
return '';
}
}