Skip to content

Commit 6eaa531

Browse files
committed
prettier format
1 parent 7acfba5 commit 6eaa531

File tree

6 files changed

+42
-23
lines changed

6 files changed

+42
-23
lines changed

packages/rrweb-snapshot/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import snapshot, {
88
classMatchesRegex,
99
IGNORED_NODE,
1010
genId,
11-
getMatchedCustomMaskTextFn
11+
getMatchedCustomMaskTextFn,
1212
} from './snapshot';
1313
import rebuild, {
1414
buildNodeWithSN,
@@ -33,5 +33,5 @@ export {
3333
classMatchesRegex,
3434
IGNORED_NODE,
3535
genId,
36-
getMatchedCustomMaskTextFn
36+
getMatchedCustomMaskTextFn,
3737
};

packages/rrweb-snapshot/src/snapshot.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ import {
2323
getInputType,
2424
} from './utils';
2525

26-
import {
27-
maskTextRule
28-
} from '@rrweb/types';
26+
import { maskTextRule } from '@rrweb/types';
2927

3028
let _id = 1;
3129
const tagNameRegex = new RegExp('[^a-z0-9-_:]');
@@ -321,7 +319,7 @@ export function needMaskingText(
321319
node: Node,
322320
maskTextClass: string | RegExp,
323321
maskTextSelector: string | null,
324-
customMaskTextRule: maskTextRule[]
322+
customMaskTextRule: maskTextRule[],
325323
): boolean {
326324
try {
327325
const el: HTMLElement | null =
@@ -341,8 +339,8 @@ export function needMaskingText(
341339
if (el.matches(maskTextSelector)) return true;
342340
if (el.closest(maskTextSelector)) return true;
343341
}
344-
if(customMaskTextRule) {
345-
for(let rule of customMaskTextRule){
342+
if (customMaskTextRule) {
343+
for (let rule of customMaskTextRule) {
346344
if (el.matches(rule.cssSelector)) return true;
347345
if (el.closest(rule.cssSelector)) return true;
348346
}
@@ -353,20 +351,23 @@ export function needMaskingText(
353351
return false;
354352
}
355353

356-
export function getMatchedCustomMaskTextFn(node: Node, customMaskTextRule: maskTextRule[]): ((originText: string) => string) | null{
354+
export function getMatchedCustomMaskTextFn(
355+
node: Node,
356+
customMaskTextRule: maskTextRule[],
357+
): ((originText: string) => string) | null {
357358
try {
358359
const el: HTMLElement | null =
359360
node.nodeType === node.ELEMENT_NODE
360361
? (node as HTMLElement)
361362
: node.parentElement;
362363
if (el === null) return null;
363364

364-
for(let rule of customMaskTextRule){
365+
for (let rule of customMaskTextRule) {
365366
if (el.matches(rule.cssSelector)) return rule.maskFn;
366367
if (el.closest(rule.cssSelector)) return rule.maskFn;
367368
}
368369
} catch (error) {
369-
return null
370+
return null;
370371
}
371372

372373
return null;
@@ -578,7 +579,13 @@ function serializeTextNode(
578579
rootId: number | undefined;
579580
},
580581
): serializedNode {
581-
const { maskTextClass, maskTextSelector, customMaskTextRule, maskTextFn, rootId } = options;
582+
const {
583+
maskTextClass,
584+
maskTextSelector,
585+
customMaskTextRule,
586+
maskTextFn,
587+
rootId,
588+
} = options;
582589
// The parent node may not be a html element which has a tagName attribute.
583590
// So just let it be undefined which is ok in this use case.
584591
const parentTagName = n.parentNode && (n.parentNode as HTMLElement).tagName;

packages/rrweb/src/record/mutation.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,18 @@ export default class MutationBuffer {
474474
value !== m.oldValue
475475
) {
476476
let textValue = value;
477-
if(needMaskingText(m.target, this.maskTextClass, this.maskTextSelector, this.customMaskTextRule)){
478-
const customMaskFn = getMatchedCustomMaskTextFn(m.target, this.customMaskTextRule);
477+
if (
478+
needMaskingText(
479+
m.target,
480+
this.maskTextClass,
481+
this.maskTextSelector,
482+
this.customMaskTextRule,
483+
)
484+
) {
485+
const customMaskFn = getMatchedCustomMaskTextFn(
486+
m.target,
487+
this.customMaskTextRule,
488+
);
479489
const maskFn = customMaskFn ?? this.maskTextFn;
480490
textValue = maskFn ? maskFn(value) : value.replace(/[\S]/g, '*');
481491
}

packages/rrweb/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export type recordOptions<T> = {
5454
* customMaskTextRule has higher priority than maskTextSelector & maskTextFn
5555
* once one of customMaskTextRule match, maskTextSelector & maskTextFn won't be applied
5656
*/
57-
customMaskTextRule?: maskTextRule[],
57+
customMaskTextRule?: maskTextRule[];
5858
maskAllInputs?: boolean;
5959
maskInputOptions?: MaskInputOptions;
6060
maskInputFn?: MaskInputFn;
@@ -93,7 +93,7 @@ export type observerParam = {
9393
ignoreClass: string;
9494
maskTextClass: maskTextClass;
9595
maskTextSelector: string | null;
96-
customMaskTextRule: maskTextRule[],
96+
customMaskTextRule: maskTextRule[];
9797
maskInputOptions: MaskInputOptions;
9898
maskInputFn?: MaskInputFn;
9999
maskTextFn?: MaskTextFn;

packages/rrweb/test/integration.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,10 +1123,12 @@ describe('record integration tests', function (this: ISuite) {
11231123
await page.goto('about:blank');
11241124
await page.setContent(
11251125
getHtml.call(this, 'mask-text.html', {
1126-
customMaskTextRule:[{
1127-
cssSelector: '[data-masking="true"]',
1128-
maskFn: (t: string) => t.replace(/[a-z]/g, '*')
1129-
}]
1126+
customMaskTextRule: [
1127+
{
1128+
cssSelector: '[data-masking="true"]',
1129+
maskFn: (t: string) => t.replace(/[a-z]/g, '*'),
1130+
},
1131+
],
11301132
}),
11311133
);
11321134

packages/types/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ export type blockClass = string | RegExp;
181181
export type maskTextClass = string | RegExp;
182182

183183
export type maskTextRule = {
184-
cssSelector: string,
185-
maskFn: (originText: string) => string
186-
}
184+
cssSelector: string;
185+
maskFn: (originText: string) => string;
186+
};
187187

188188
export type SamplingStrategy = Partial<{
189189
/**

0 commit comments

Comments
 (0)