(options)
| 315 | * } |
| 316 | */ |
| 317 | export function normalizeFormatOptions (options) { |
| 318 | // default values for options |
| 319 | let notation = 'auto' |
| 320 | let precision |
| 321 | let wordSize |
| 322 | |
| 323 | if (options !== undefined) { |
| 324 | if (isNumber(options)) { |
| 325 | precision = options |
| 326 | } else if (isBigNumber(options)) { |
| 327 | precision = options.toNumber() |
| 328 | } else if (isObject(options)) { |
| 329 | if (options.precision !== undefined) { |
| 330 | precision = _toNumberOrThrow(options.precision, () => { |
| 331 | throw new Error('Option "precision" must be a number or BigNumber') |
| 332 | }) |
| 333 | } |
| 334 | |
| 335 | if (options.wordSize !== undefined) { |
| 336 | wordSize = _toNumberOrThrow(options.wordSize, () => { |
| 337 | throw new Error('Option "wordSize" must be a number or BigNumber') |
| 338 | }) |
| 339 | } |
| 340 | |
| 341 | if (options.notation) { |
| 342 | notation = options.notation |
| 343 | } |
| 344 | } else { |
| 345 | throw new Error('Unsupported type of options, number, BigNumber, or object expected') |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | return { notation, precision, wordSize } |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Split a number into sign, coefficients, and exponent |
no test coverage detected
searching dependent graphs…