1
0
mirror of https://github.com/badges/shields.git synced 2025-04-18 19:44:04 +03:00

Add docstrings for route builder service (#9118)

* add docstrings for route builder service
This commit is contained in:
Prashant Rawat 2023-05-01 23:24:50 +05:30 committed by GitHub
parent ac3effd87f
commit 96a06d48b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,9 @@
/**
* Common functions and utilities for tasks related to route building
*
* @module
*/
import toArray from '../core/base-service/to-array.js'
/*
@ -9,6 +15,12 @@ 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
@ -16,10 +28,22 @@ export default class RouteBuilder {
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))
@ -27,6 +51,11 @@ export default class RouteBuilder {
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 }