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

RobotWebTools / rclnodejs / 15105063955

19 May 2025 05:29AM UTC coverage: 84.742%. Remained the same
15105063955

Pull #1133

github

web-flow
Merge fd1eadeec into 7a4b2e1fa
Pull Request #1133: Reorg the actions badge

716 of 938 branches covered (76.33%)

Branch coverage included in aggregate %.

1761 of 1985 relevant lines covered (88.72%)

1462.68 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');
104✔
18

19
/**
20
 * An object - Representing a validator in ROS.
21
 * @exports validator
22
 */
23
let validator = {
104✔
24
  _createErrorFromValidation: function (result) {
25
    let err = new Error(result[0]);
36✔
26
    err.invalidIndex = result[1];
36✔
27
    return err;
36✔
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') {
20!
37
      throw new TypeError('Invalid argument');
×
38
    }
39

40
    let result = rclnodejs.validateFullTopicName(topic);
20✔
41
    if (result === null) {
20✔
42
      return true;
12✔
43
    }
44
    throw this._createErrorFromValidation(result);
8✔
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') {
16!
54
      throw new TypeError('Invalid argument');
×
55
    }
56

57
    let result = rclnodejs.validateNodeName(name);
16✔
58
    if (result === null) {
16✔
59
      return true;
4✔
60
    }
61
    throw this._createErrorFromValidation(result);
12✔
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') {
20!
71
      throw new TypeError('Invalid argument');
×
72
    }
73

74
    let result = rclnodejs.validateTopicName(topic);
20✔
75
    if (result === null) {
20✔
76
      return true;
12✔
77
    }
78
    throw this._createErrorFromValidation(result);
8✔
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') {
16!
88
      throw new TypeError('Invalid argument');
×
89
    }
90

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

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