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

RobotWebTools / rclnodejs / 16044464595

03 Jul 2025 07:38AM UTC coverage: 84.526% (-0.1%) from 84.625%
16044464595

Pull #1158

github

web-flow
Merge 90720ad95 into 82bbc82ff
Pull Request #1158: Enable npm test on Windows workflow

775 of 1009 branches covered (76.81%)

Branch coverage included in aggregate %.

1907 of 2164 relevant lines covered (88.12%)

3222.81 hits per line

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

82.61
/lib/validator.js
1
// Copyright (c) 2017 Intel Corporation. All rights reserved.
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
'use strict';
16

17
const rclnodejs = require('bindings')('rclnodejs');
208✔
18

19
/**
20
 * An object - Representing a validator in ROS.
21
 * @exports validator
22
 */
23
let validator = {
208✔
24
  _createErrorFromValidation: function (result) {
25
    let err = new Error(result[0]);
72✔
26
    err.invalidIndex = result[1];
72✔
27
    return err;
72✔
28
  },
29

30
  /**
31
   * Validate a given topic or service name, and throw an error if invalid.
32
   * @param {string} topic - The name of topic/service. and it must be fully-qualified and already expanded.
33
   * @return {boolean} - True if it is valid.
34
   */
35
  validateFullTopicName(topic) {
36
    if (typeof topic !== 'string') {
78!
37
      throw new TypeError('Invalid argument');
×
38
    }
39

40
    let result = rclnodejs.validateFullTopicName(topic);
78✔
41
    if (result === null) {
78✔
42
      return true;
62✔
43
    }
44
    throw this._createErrorFromValidation(result);
16✔
45
  },
46

47
  /**
48
   * Validate a given node name, and throw an error if invalid.
49
   * @param {string} name - The name of node.
50
   * @return {boolean} - True if it is valid.
51
   */
52
  validateNodeName(name) {
53
    if (typeof name !== 'string') {
32!
54
      throw new TypeError('Invalid argument');
×
55
    }
56

57
    let result = rclnodejs.validateNodeName(name);
32✔
58
    if (result === null) {
32✔
59
      return true;
8✔
60
    }
61
    throw this._createErrorFromValidation(result);
24✔
62
  },
63

64
  /**
65
   * Validate a given topic or service name, and throw an error if invalid.
66
   * @param {string} topic - The name of topic/service and does not have to be fully-qualified and is not expanded.
67
   * @return {boolean} - True if it is valid.
68
   */
69
  validateTopicName(topic) {
70
    if (typeof topic !== 'string') {
40!
71
      throw new TypeError('Invalid argument');
×
72
    }
73

74
    let result = rclnodejs.validateTopicName(topic);
40✔
75
    if (result === null) {
40✔
76
      return true;
24✔
77
    }
78
    throw this._createErrorFromValidation(result);
16✔
79
  },
80

81
  /**
82
   * Validate a given namespace, and throw an error if invalid.
83
   * @param {string} namespace - The namespace to be validated
84
   * @return {boolean} - True if it is valid.
85
   */
86
  validateNamespace(namespace) {
87
    if (typeof namespace !== 'string') {
32!
88
      throw new TypeError('Invalid argument');
×
89
    }
90

91
    let result = rclnodejs.validateNamespace(namespace);
32✔
92
    if (result === null) {
32✔
93
      return true;
16✔
94
    }
95
    throw this._createErrorFromValidation(result);
16✔
96
  },
97
};
98

99
module.exports = validator;
208✔
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