diff --git a/src/compat/object/invertBy.ts b/src/compat/object/invertBy.ts index dd8a1c4a9..2d3e2ba36 100644 --- a/src/compat/object/invertBy.ts +++ b/src/compat/object/invertBy.ts @@ -1,3 +1,4 @@ +import { isUnsafeProperty } from '../../_internal/isUnsafeProperty.ts'; import { identity } from '../../function/identity.ts'; import { isNil } from '../../predicate/isNil.ts'; import { ValueIteratee } from '../_internal/ValueIteratee.ts'; @@ -88,6 +89,10 @@ export function invertBy( const value = (object as any)[key]; const valueStr = getString(value); + if (isUnsafeProperty(valueStr)) { + continue; + } + if (Array.isArray(result[valueStr])) { result[valueStr].push(key); } else { diff --git a/src/object/invert.ts b/src/object/invert.ts index 263010dc3..3279c69f5 100644 --- a/src/object/invert.ts +++ b/src/object/invert.ts @@ -1,3 +1,5 @@ +import { isUnsafeProperty } from '../_internal/isUnsafeProperty'; + /** * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa. * @@ -24,6 +26,9 @@ export function invert(obj: Record for (let i = 0; i < keys.length; i++) { const key = keys[i]; const value = obj[key]; + if (isUnsafeProperty(value)) { + continue; + } result[value] = key; }