Files
my_site/node_modules/@mswjs/interceptors/src/utils/getValueBySymbol.ts
2026-03-24 14:30:59 +08:00

20 lines
391 B
TypeScript

/**
* Returns the value behind the symbol with the given name.
*/
export function getValueBySymbol<T>(
symbolName: string,
source: object
): T | undefined {
const ownSymbols = Object.getOwnPropertySymbols(source)
const symbol = ownSymbols.find((symbol) => {
return symbol.description === symbolName
})
if (symbol) {
return Reflect.get(source, symbol)
}
return
}