Skip to content

Commit

Permalink
Add docstrings for route builder service (#9118)
Browse files Browse the repository at this point in the history
* add docstrings for route builder service
  • Loading branch information
pr7prashant committed May 1, 2023
1 parent ac3effd commit 96a06d4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions services/route-builder.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* Common functions and utilities for tasks related to route building
*
* @module
*/

import toArray from '../core/base-service/to-array.js'

/*
Expand All @@ -9,24 +15,47 @@ import toArray from '../core/base-service/to-array.js'
* haven't done so yet.
*/
export default class RouteBuilder {
/**
* Creates a RouteBuilder object.
*
* @param {object} attrs - Refer to individual attributes
* @param {string} attrs.base - Base URL, defaults to ''
*/
constructor({ base = '' } = {}) {
this.base = base

this._formatComponents = []
this.capture = []
}

/**
* Get the format components separated by '/'
*
* @returns {string} Format components, for example: "format1/format2/format3"
*/
get format() {
return this._formatComponents.join('/')
}

/**
* Saves the format and capture values in the RouteBuilder instance.
*
* @param {string} format - Pattern based on path-to-regex, for example: (?:(.+)\\.)?${serviceBaseUrl}
* @param {string} capture - Value to capture
* @returns {object} RouteBuilder instance for chaining
*/
push(format, capture) {
this._formatComponents = this._formatComponents.concat(toArray(format))
this.capture = this.capture.concat(toArray(capture))
// Return `this` for chaining.
return this
}

/**
* Returns a new object based on RouteBuilder instance containing its base, format and capture properties.
*
* @returns {object} Object containing base, format and capture properties of the RouteBuilder instance
*/
toObject() {
const { base, format, capture } = this
return { base, format, capture }
Expand Down

0 comments on commit 96a06d4

Please sign in to comment.