Helpers

toPercents.mjs

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

Target Style

Target Style

1 exports

const

percentOf

Target Style
export const percentOf = (partial, { in: all }) => Math.round((partial / all) * 1000) / 10

Converts a partial value into percents using named options.

Target style API. Preferred for new code.

Parameters

  • partialnumber
  • options{ in: number }

Returns

number

Legacy Style

Legacy Style

1 exports

const

toPercents

Legacy Style
export const toPercents = (all, partial) => percentOf(partial, { in: all })

Converts a partial value into percents with one decimal place precision.

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

Parameters

  • allnumber
  • partialnumber

Returns

number

Example

const ratio = percentOf(20, {
  in: 80,
})