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

RobotWebTools / rclnodejs / 18585428157

17 Oct 2025 07:14AM UTC coverage: 83.18% (-0.06%) from 83.239%
18585428157

push

github

web-flow
Remove is-close dependency (#1295)

This PR removes the external `is-close` dependency and replaces it with a custom implementation in the project's utility module. The change eliminates a third-party dependency while maintaining the same floating-point comparison functionality.

Key changes:
- Implemented a custom `isClose` function in `lib/utils.js` that matches the behavior of the `is-close` npm package
- Updated all imports across test files and production code to use the new internal implementation
- Removed the `is-close` dependency from `package.json`

Fix: #1294

810 of 1070 branches covered (75.7%)

Branch coverage included in aggregate %.

11 of 14 new or added lines in 2 files covered. (78.57%)

1 existing line in 1 file now uncovered.

1989 of 2295 relevant lines covered (86.67%)

417.64 hits per line

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

70.27
/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
 * Implementation checks:
45
 *   1. Absolute tolerance: abs(a - b) <= atol
46
 *   2. Relative tolerance: abs(a - b) / max(abs(a), abs(b)) <= rtol
47
 *
48
 * @param {number} a - The first number to compare
49
 * @param {number} b - The second number to compare
50
 * @param {number} [rtol=1e-9] - The relative tolerance parameter (default: 1e-9)
51
 * @param {number} [atol=0.0] - The absolute tolerance parameter (default: 0.0)
52
 * @returns {boolean} True if the numbers are close within the tolerance
53
 *
54
 * @example
55
 * isClose(1.0, 1.0) // true - exact equality
56
 * isClose(1.0, 1.1, 0.01) // false - relative diff: 0.1/1.1 ≈ 0.091 > 0.01
57
 * isClose(10, 10.00001, 1e-6) // true - relative diff: 0.00001/10 = 1e-6 <= 1e-6
58
 * isClose(0, 0.05, 0, 0.1) // true - absolute diff: 0.05 <= 0.1 (atol)
59
 */
60
function isClose(a, b, rtol = 1e-9, atol = 0.0) {
25!
61
  // Handle exact equality
62
  if (a === b) {
25✔
63
    return true;
6✔
64
  }
65

66
  // Handle non-finite numbers
67
  if (!Number.isFinite(a) || !Number.isFinite(b)) {
19!
NEW
68
    return false;
×
69
  }
70

71
  const absDiff = Math.abs(a - b);
19✔
72

73
  // Check absolute tolerance first (optimization)
74
  if (atol >= absDiff) {
19!
NEW
75
    return true;
×
76
  }
77

78
  // Check relative tolerance
79
  const relativeScaler = Math.max(Math.abs(a), Math.abs(b));
19✔
80

81
  // Handle division by zero when both values are zero or very close to zero
82
  if (relativeScaler === 0) {
19!
NEW
83
    return true; // Both are zero, already handled by absolute tolerance
×
84
  }
85

86
  const relativeDiff = absDiff / relativeScaler;
19✔
87

88
  return rtol >= relativeDiff;
19✔
89
}
90
module.exports = {
26✔
91
  detectUbuntuCodename,
92
  isClose,
93
};
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