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

RobotWebTools / rclnodejs / 18584865265

17 Oct 2025 06:48AM UTC coverage: 83.249% (+0.01%) from 83.239%
18584865265

Pull #1295

github

web-flow
Merge 2481dbac8 into 898c8dcde
Pull Request #1295: Remove is-close dependency

810 of 1068 branches covered (75.84%)

Branch coverage included in aggregate %.

11 of 13 new or added lines in 2 files covered. (84.62%)

1 existing line in 1 file now uncovered.

1988 of 2293 relevant lines covered (86.7%)

416.96 hits per line

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

72.73
/lib/utils.js
1
// Copyright (c) 2025, The Robot Web Tools Contributors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
const fs = require('fs');
26✔
16

17
/**
18
 * Detect Ubuntu codename from /etc/os-release
19
 * @returns {string|null} Ubuntu codename (e.g., 'noble', 'jammy') or null if not detectable
20
 */
21
function detectUbuntuCodename() {
22
  if (process.platform !== 'linux') {
52!
23
    return null;
×
24
  }
25

26
  try {
52✔
27
    const osRelease = fs.readFileSync('/etc/os-release', 'utf8');
52✔
28
    const match = osRelease.match(/^VERSION_CODENAME=(.*)$/m);
52✔
29
    return match ? match[1].trim() : null;
52!
30
  } catch {
31
    return null;
×
32
  }
33
}
34

35
/**
36
 * Check if two numbers are equal within a given tolerance.
37
 *
38
 * This function compares two numbers using both relative and absolute tolerance,
39
 * matching the behavior of the 'is-close' npm package.
40
 *
41
 * The comparison uses the formula:
42
 *   abs(a - b) <= max(rtol * max(abs(a), abs(b)), atol)
43
 *
44
 * @param {number} a - The first number to compare
45
 * @param {number} b - The second number to compare
46
 * @param {number} [rtol=1e-9] - The relative tolerance parameter (default: 1e-9)
47
 * @param {number} [atol=0.0] - The absolute tolerance parameter (default: 0.0)
48
 * @returns {boolean} True if the numbers are close within the tolerance
49
 *
50
 * @example
51
 * isClose(1.0, 1.0) // true
52
 * isClose(1.0, 1.1, 0.01) // false - difference 0.1 > 0.01 * max(1.0, 1.1) = 0.011
53
 * isClose(10, 10.00001, 1e-6) // true - difference 0.00001 <= 1e-6 * 10 = 0.00001
54
 */
55
function isClose(a, b, rtol = 1e-9, atol = 0.0) {
25!
56
  // Handle exact equality
57
  if (a === b) {
25✔
58
    return true;
6✔
59
  }
60

61
  // Handle non-finite numbers
62
  if (!Number.isFinite(a) || !Number.isFinite(b)) {
19!
NEW
63
    return false;
×
64
  }
65

66
  const absDiff = Math.abs(a - b);
19✔
67

68
  // Check absolute tolerance first (optimization)
69
  if (atol >= absDiff) {
19!
NEW
70
    return true;
×
71
  }
72

73
  // Check relative tolerance
74
  const relativeScaler = Math.max(Math.abs(a), Math.abs(b));
19✔
75
  const relativeDiff = absDiff / relativeScaler;
19✔
76

77
  return rtol >= relativeDiff;
19✔
78
}
79
module.exports = {
26✔
80
  detectUbuntuCodename,
81
  isClose,
82
};
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