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

RobotWebTools / rclnodejs / 14751919636

30 Apr 2025 10:00AM UTC coverage: 85.071%. Remained the same
14751919636

Pull #1112

github

web-flow
Merge 0d09af349 into 131ebf8e1
Pull Request #1112: Add typescript interface for the added new functions

711 of 928 branches covered (76.62%)

Branch coverage included in aggregate %.

1745 of 1959 relevant lines covered (89.08%)

1103.7 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');
78✔
18

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

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

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

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

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

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