Helpers

switchKeyValue.mjs

@mr_ozio/scraper-utils · v2.5.0 · Generated April 21, 2026

Target Style

Target Style

1 exports

const

invertMap

Target Style
export const invertMap = (map) => new Map(Array.from(map.entries()).map(([key, value]) => [value, key]))

Swaps keys and values with a more descriptive name.

Target style API. Preferred for new code.

Parameters

  • mapMap<K, V>

Returns

Map<V, K>

Legacy Style

Legacy Style

1 exports

const

switchKeyValue

Legacy Style
export const switchKeyValue = (map) => invertMap(map)

Swaps keys and values in a map.

Legacy API. Kept for older code and not the preferred choice for new code.

Parameters

  • mapMap<K, V>

Returns

Map<V, K>

Example

const colorByHex = invertMap(new Map([['red', '#f00']]))