The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/server/lib/ldap/operations/replace.ts

23 lines
743 B

export type LDAPVariableReplace = {
operation: 'replace';
pattern: string;
regex?: boolean;
flags?: string;
all?: boolean;
replacement: string;
};
export function executeReplace(input: string, operation: LDAPVariableReplace): string {
if (!operation.pattern || typeof operation.replacement !== 'string') {
throw new Error('Invalid REPLACE operation.');
}
const flags = operation.regex && operation.all ? `${operation.flags || ''}${operation.flags?.includes('g') ? '' : 'g'}` : operation.flags;
const pattern = operation.regex ? new RegExp(operation.pattern, flags) : operation.pattern;
if (operation.all) {
return input.replaceAll(pattern, operation.replacement);
}
return input.replace(pattern, operation.replacement);
}