• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thednp / svg-path-commander / 13741544977

08 Mar 2025 09:17PM UTC coverage: 97.839%. Remained the same
13741544977

Pull #60

github

web-flow
Merge 54cf004cf into 44d6d893a
Pull Request #60: Update getPointAtArcLength's distance description

729 of 729 branches covered (100.0%)

Branch coverage included in aggregate %.

1354 of 1400 relevant lines covered (96.71%)

3288.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/convert/pathToString.ts
1
import type { PathArray, PathSegment } from "../types";
2
import defaultOptions from "../options/options";
3
import roundTo from "../math/roundTo";
4

5
/**
6
 * Returns a valid `d` attribute string value created
7
 * by rounding values and concatenating the `pathArray` segments.
8
 *
9
 * @param path the `pathArray` object
10
 * @param roundOption amount of decimals to round values to
11
 * @returns the concatenated path string
12
 */
13
const pathToString = (
2✔
14
  path: PathArray,
15
  roundOption?: number | "off",
16
): string => {
17
  const pathLen = path.length;
171✔
18
  let { round } = defaultOptions;
171✔
19
  let segment = path[0] as PathSegment;
171✔
20
  let result = "";
171✔
21

22
  // allow for ZERO decimals
23
  round = roundOption === "off"
171✔
24
    ? roundOption
25
    : typeof roundOption === "number" && roundOption >= 0
493✔
26
    ? roundOption
27
    : typeof round === "number" && round >= 0
24✔
28
    ? round
29
    : /* istanbul ignore next @preserve */ "off";
30

31
  for (let i = 0; i < pathLen; i += 1) {
171✔
32
    segment = path[i];
3,741✔
33
    const [pathCommand] = segment;
3,741✔
34
    const values = segment.slice(1) as number[];
3,741✔
35
    result += pathCommand;
3,741✔
36
    if (round === "off") {
3,741✔
37
      result += values.join(" ");
35✔
38
    } else {
39
      let j = 0;
3,706✔
40
      const valLen = values.length;
3,706✔
41
      while (j < valLen) {
3,706✔
42
        result += roundTo(values[j], round);
13,692✔
43
        if (j !== valLen - 1) result += " ";
13,692✔
44
        j += 1;
13,692✔
45
      }
46
    }
47
  }
48

49
  return result;
171✔
50
};
51

52
export default pathToString;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc