Functional Weave
Code in Rust

manufacturing.takt-time@1.0.0

impl/typescript.ts

999 bytes · the TypeScript implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

import { type RoundingMode } from "./math_round_div.ts";  ← from math.round-div ^1.0.0 · built alongside by fune
import { rational, rationalToInteger } from "./math_rational.ts";  ← from math.rational ^1.0.0 · built alongside by fune
import { type TaktTime } from "./manufacturing_takt_time_types.ts";

/**
 * Takt time, available time / demand, as an exact fraction and in whole
 * seconds. The whole seconds are rounded once from the exact fraction, so a
 * caller balancing a line on `exact` never inherits a rounding step.
 */
export function taktTime(availableSeconds: number, demand: number, mode: RoundingMode): TaktTime {
  if (!Number.isSafeInteger(availableSeconds) || availableSeconds < 0) {
    throw new RangeError(`availableSeconds must be a whole number of seconds, not negative, received ${availableSeconds}`);
  }
  if (!Number.isSafeInteger(demand) || demand <= 0) {
    throw new RangeError(`demand must be a whole number of units greater than zero, received ${demand}`);
  }
  const exact = rational(availableSeconds, demand);
  return { exact, seconds: rationalToInteger(exact, mode) };
}