lighthouse 11.7.0-dev.20240401 → 11.7.0-dev.20240402
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -83,28 +83,44 @@ function processForProto(lhr) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
86
|
+
* Execute `cb(obj, key)` on every object property where obj[key] is a string, recursively.
|
|
87
87
|
* @param {any} obj
|
|
88
|
+
* @param {(obj: Record<string, string>, key: string) => void} cb
|
|
88
89
|
*/
|
|
89
|
-
function
|
|
90
|
+
function iterateStrings(obj, cb) {
|
|
90
91
|
if (obj && typeof obj === 'object' && !Array.isArray(obj)) {
|
|
91
92
|
Object.keys(obj).forEach(key => {
|
|
92
|
-
if (typeof obj[key] === 'string'
|
|
93
|
-
|
|
94
|
-
} else
|
|
95
|
-
|
|
93
|
+
if (typeof obj[key] === 'string') {
|
|
94
|
+
cb(obj, key);
|
|
95
|
+
} else {
|
|
96
|
+
iterateStrings(obj[key], cb);
|
|
96
97
|
}
|
|
97
98
|
});
|
|
98
99
|
} else if (Array.isArray(obj)) {
|
|
99
100
|
obj.forEach(item => {
|
|
100
101
|
if (typeof item === 'object' || Array.isArray(item)) {
|
|
101
|
-
|
|
102
|
+
iterateStrings(item, cb);
|
|
102
103
|
}
|
|
103
104
|
});
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
iterateStrings(reportJson, (obj, key) => {
|
|
109
|
+
const value = obj[key];
|
|
110
|
+
|
|
111
|
+
// Remove empty strings, as they are dropped after round-tripping anyway.
|
|
112
|
+
if (value === '') {
|
|
113
|
+
delete obj[key];
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Sanitize lone surrogates.
|
|
118
|
+
// @ts-expect-error node 20
|
|
119
|
+
if (String.prototype.isWellFormed && !value.isWellFormed()) {
|
|
120
|
+
// @ts-expect-error node 20
|
|
121
|
+
obj[key] = value.toWellFormed();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
108
124
|
|
|
109
125
|
return reportJson;
|
|
110
126
|
}
|
package/package.json
CHANGED