Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 22x 22x 22x 22x 22x 22x | import auto from './auto.js'
import line from './line.js'
import number from './number.js'
import raw from './raw.js'
import type S from './sanitised.js'
/**
* @returns top expression.
* @example top(1, raw('with ties'))
* @example top(1, star)
* @example top(0.1, star) // value in <0,1> range returns percent, ie. `top 10 percent`.
* @example top(1, ids('foo', 'bar', 'baz'))
*/
export const top =
(x = 1, ...rest: S[]): S => {
Iif (x <= 0) {
throw new TypeError(`Expected positive value in top, got ${x}.`)
}
const [ x_, percent ] = x < 1 ?
[ Math.round(x * 100), true ] :
[ Math.round(x), false ]
return line(
raw('top'),
number(x_),
percent ? raw('percent') : undefined,
...rest.map(auto)
)
}
export default top
|