@@ -28,8 +28,10 @@ let validator = {
2828
2929 /**
3030 * Validate a given topic or service name, and throw an error if invalid.
31- * @param {string } topic - The name of topic/service. and it must be fully-qualified and already expanded.
32- * @return {boolean } - True if it is valid.
31+ * @param {string } topic - The name of topic/service. Must be fully-qualified and already expanded.
32+ * @returns {true } Always returns true if valid.
33+ * @throws {TypeValidationError } If topic is not a string.
34+ * @throws {NameValidationError } If the topic name is invalid.
3335 */
3436 validateFullTopicName ( topic ) {
3537 if ( typeof topic !== 'string' ) {
@@ -43,10 +45,24 @@ let validator = {
4345 throw this . _createErrorFromValidation ( result , topic , 'topic' ) ;
4446 } ,
4547
48+ /**
49+ * Check if a fully-qualified topic name is valid without throwing.
50+ * @param {string } topic - The name of topic/service. Must be fully-qualified and already expanded.
51+ * @returns {boolean } True if valid, false otherwise.
52+ */
53+ isValidFullTopicName ( topic ) {
54+ if ( typeof topic !== 'string' ) {
55+ return false ;
56+ }
57+ return rclnodejs . validateFullTopicName ( topic ) === null ;
58+ } ,
59+
4660 /**
4761 * Validate a given node name, and throw an error if invalid.
4862 * @param {string } name - The name of node.
49- * @return {boolean } - True if it is valid.
63+ * @returns {true } Always returns true if valid.
64+ * @throws {TypeValidationError } If name is not a string.
65+ * @throws {NameValidationError } If the node name is invalid.
5066 */
5167 validateNodeName ( name ) {
5268 if ( typeof name !== 'string' ) {
@@ -60,10 +76,24 @@ let validator = {
6076 throw this . _createErrorFromValidation ( result , name , 'node' ) ;
6177 } ,
6278
79+ /**
80+ * Check if a node name is valid without throwing.
81+ * @param {string } name - The name of node.
82+ * @returns {boolean } True if valid, false otherwise.
83+ */
84+ isValidNodeName ( name ) {
85+ if ( typeof name !== 'string' ) {
86+ return false ;
87+ }
88+ return rclnodejs . validateNodeName ( name ) === null ;
89+ } ,
90+
6391 /**
6492 * Validate a given topic or service name, and throw an error if invalid.
65- * @param {string } topic - The name of topic/service and does not have to be fully-qualified and is not expanded.
66- * @return {boolean } - True if it is valid.
93+ * @param {string } topic - The name of topic/service. Does not have to be fully-qualified.
94+ * @returns {true } Always returns true if valid.
95+ * @throws {TypeValidationError } If topic is not a string.
96+ * @throws {NameValidationError } If the topic name is invalid.
6797 */
6898 validateTopicName ( topic ) {
6999 if ( typeof topic !== 'string' ) {
@@ -77,10 +107,24 @@ let validator = {
77107 throw this . _createErrorFromValidation ( result , topic , 'topic' ) ;
78108 } ,
79109
110+ /**
111+ * Check if a topic name is valid without throwing.
112+ * @param {string } topic - The name of topic/service. Does not have to be fully-qualified.
113+ * @returns {boolean } True if valid, false otherwise.
114+ */
115+ isValidTopicName ( topic ) {
116+ if ( typeof topic !== 'string' ) {
117+ return false ;
118+ }
119+ return rclnodejs . validateTopicName ( topic ) === null ;
120+ } ,
121+
80122 /**
81123 * Validate a given namespace, and throw an error if invalid.
82- * @param {string } namespace - The namespace to be validated
83- * @return {boolean } - True if it is valid.
124+ * @param {string } namespace - The namespace to be validated.
125+ * @returns {true } Always returns true if valid.
126+ * @throws {TypeValidationError } If namespace is not a string.
127+ * @throws {NameValidationError } If the namespace is invalid.
84128 */
85129 validateNamespace ( namespace ) {
86130 if ( typeof namespace !== 'string' ) {
@@ -93,6 +137,18 @@ let validator = {
93137 }
94138 throw this . _createErrorFromValidation ( result , namespace , 'namespace' ) ;
95139 } ,
140+
141+ /**
142+ * Check if a namespace is valid without throwing.
143+ * @param {string } namespace - The namespace to be validated.
144+ * @returns {boolean } True if valid, false otherwise.
145+ */
146+ isValidNamespace ( namespace ) {
147+ if ( typeof namespace !== 'string' ) {
148+ return false ;
149+ }
150+ return rclnodejs . validateNamespace ( namespace ) === null ;
151+ } ,
96152} ;
97153
98154module . exports = validator ;
0 commit comments