Merged in feat/syncDefaultMessage (pull request #3022)
Sync defaultMessage from lokalise * Enhance translation sync functionality and tests - Added logging for found component files during sync. - Introduced tests for handling complex components with replacements. - Updated regex in syncIntlFormatMessage to support optional second arguments. - Removed unused test files. * feat(syncDefaultMessage): add script for syncing default message with lokalise * feat(syncDefaultMessage): add script for syncing default message with lokalise Approved-by: Matilda Landström
This commit is contained in:
@@ -8,35 +8,39 @@
|
||||
*/
|
||||
const maskChar = "*";
|
||||
export function mask(
|
||||
value: string,
|
||||
options?: { visibleStart?: number; visibleEnd?: number; maxLength?: number },
|
||||
value: string,
|
||||
options?: {
|
||||
visibleStart?: number;
|
||||
visibleEnd?: number;
|
||||
maxLength?: number;
|
||||
},
|
||||
): string {
|
||||
if (!value) return "";
|
||||
if (!value) return "";
|
||||
|
||||
const { visibleStart = 2, visibleEnd = 2, maxLength = 10 } = options ?? {};
|
||||
const { visibleStart = 2, visibleEnd = 2, maxLength = 10 } = options ?? {};
|
||||
|
||||
if (isEmail(value)) {
|
||||
return maskEmail(value);
|
||||
}
|
||||
if (isEmail(value)) {
|
||||
return maskEmail(value);
|
||||
}
|
||||
|
||||
const totalVisible = visibleStart + visibleEnd;
|
||||
if (value.length <= totalVisible) {
|
||||
return maskChar.repeat(value.length);
|
||||
}
|
||||
const totalVisible = visibleStart + visibleEnd;
|
||||
if (value.length <= totalVisible) {
|
||||
return maskChar.repeat(value.length);
|
||||
}
|
||||
|
||||
const start = value.slice(0, visibleStart);
|
||||
const middle = value.slice(visibleStart, -visibleEnd || undefined);
|
||||
const end = visibleEnd ? value.slice(-visibleEnd) : "";
|
||||
const start = value.slice(0, visibleStart);
|
||||
const middle = value.slice(visibleStart, -visibleEnd || undefined);
|
||||
const end = visibleEnd ? value.slice(-visibleEnd) : "";
|
||||
|
||||
const maskedLength = Math.min(middle.length, maxLength);
|
||||
return start + maskChar.repeat(maskedLength) + end;
|
||||
const maskedLength = Math.min(middle.length, maxLength);
|
||||
return start + maskChar.repeat(maskedLength) + end;
|
||||
}
|
||||
|
||||
function maskEmail(email: string): string {
|
||||
const [local, domain] = email.split("@");
|
||||
if (!domain || !local) return mask(email);
|
||||
const [subDomain, tld] = domain.split(/\.(?=[^.]+$)/);
|
||||
return `${mask(local)}@${mask(subDomain ?? "")}.${tld}`;
|
||||
const [local, domain] = email.split("@");
|
||||
if (!domain || !local) return mask(email);
|
||||
const [subDomain, tld] = domain.split(/\.(?=[^.]+$)/);
|
||||
return `${mask(local)}@${mask(subDomain ?? "")}.${tld}`;
|
||||
}
|
||||
|
||||
const isEmail = (value: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
||||
|
||||
Reference in New Issue
Block a user