Skip to content

Commit cb18519

Browse files
authoredJan 30, 2024
Merge pull request #908 from ssi02014/fix/utils
fix(utils): Fixed getOwnPropertyDescriptor to hasOwnProperty function
2 parents 9a1ba81 + 3081134 commit cb18519

9 files changed

+31
-19
lines changed
 

‎dist/purify.cjs.js

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.cjs.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.es.mjs

+6-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const stringMatch = unapply(String.prototype.match);
4545
const stringReplace = unapply(String.prototype.replace);
4646
const stringIndexOf = unapply(String.prototype.indexOf);
4747
const stringTrim = unapply(String.prototype.trim);
48+
const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
4849
const regExpTest = unapply(RegExp.prototype.test);
4950
const typeErrorCreate = unconstruct(TypeError);
5051

@@ -120,7 +121,8 @@ function addToSet(set, array) {
120121
*/
121122
function cleanArray(array) {
122123
for (let index = 0; index < array.length; index++) {
123-
if (getOwnPropertyDescriptor(array, index) === undefined) {
124+
const isPropertyExist = objectHasOwnProperty(array, index);
125+
if (!isPropertyExist) {
124126
array[index] = null;
125127
}
126128
}
@@ -136,7 +138,8 @@ function cleanArray(array) {
136138
function clone(object) {
137139
const newObject = create(null);
138140
for (const [property, value] of entries(object)) {
139-
if (getOwnPropertyDescriptor(object, property) !== undefined) {
141+
const isPropertyExist = objectHasOwnProperty(object, property);
142+
if (isPropertyExist) {
140143
if (Array.isArray(value)) {
141144
newObject[property] = cleanArray(value);
142145
} else if (value && typeof value === 'object' && value.constructor === Object) {
@@ -169,8 +172,7 @@ function lookupGetter(object, prop) {
169172
}
170173
object = getPrototypeOf(object);
171174
}
172-
function fallbackValue(element) {
173-
console.warn('fallback value for', element);
175+
function fallbackValue() {
174176
return null;
175177
}
176178
return fallbackValue;

‎dist/purify.es.mjs.map

+1-1
Large diffs are not rendered by default.

‎dist/purify.js

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/utils.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const stringReplace = unapply(String.prototype.replace);
4646
const stringIndexOf = unapply(String.prototype.indexOf);
4747
const stringTrim = unapply(String.prototype.trim);
4848

49+
const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
50+
4951
const regExpTest = unapply(RegExp.prototype.test);
5052

5153
const typeErrorCreate = unconstruct(TypeError);
@@ -115,7 +117,9 @@ function addToSet(set, array, transformCaseFunc = stringToLowerCase) {
115117
*/
116118
function cleanArray(array) {
117119
for (let index = 0; index < array.length; index++) {
118-
if (getOwnPropertyDescriptor(array, index) === undefined) {
120+
const isPropertyExist = objectHasOwnProperty(array, index);
121+
122+
if (!isPropertyExist) {
119123
array[index] = null;
120124
}
121125
}
@@ -133,7 +137,9 @@ function clone(object) {
133137
const newObject = create(null);
134138

135139
for (const [property, value] of entries(object)) {
136-
if (getOwnPropertyDescriptor(object, property) !== undefined) {
140+
const isPropertyExist = objectHasOwnProperty(object, property);
141+
142+
if (isPropertyExist) {
137143
if (Array.isArray(value)) {
138144
newObject[property] = cleanArray(value);
139145
} else if (

0 commit comments

Comments
 (0)
Please sign in to comment.