From 48ea2b5cd4a75ffecedc076b5461cd6109fe16df Mon Sep 17 00:00:00 2001 From: Avior Date: Sun, 11 Apr 2021 01:36:23 +0200 Subject: [PATCH 1/4] Work in progress Signed-off-by: Avior --- packages/url-manager/src/URLManager.ts | 59 +++++++++++++++++--------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/packages/url-manager/src/URLManager.ts b/packages/url-manager/src/URLManager.ts index 9888e44..920a10f 100644 --- a/packages/url-manager/src/URLManager.ts +++ b/packages/url-manager/src/URLManager.ts @@ -3,7 +3,7 @@ */ export default class URLManager { - private _protocols: Array = [] + private _protocols?: Array private _username: string | undefined private _password: string | undefined private _domain: string | undefined @@ -93,20 +93,24 @@ export default class URLManager { /** * Set the url path - * @param val the path to set + * @param val the path to set, if `null` it will remove the path */ - public path(val: string): this + public path(val: string | null): this /** * Manipulate the url path - * @param { string | undefined } val the path to set + * @param { string | undefined | null } val the path to set * @return { URLManager | string } erer */ - public path(val?: string) { - if (!val) { + public path(val?: string | null) { + if (typeof val === 'undefined') { return this._path } - this._path = val + if (val === null) { + delete this._path + } else { + this._path = val + } return this } @@ -119,18 +123,22 @@ export default class URLManager { * set the list of protocols * @param val the list */ - public protocols(val: Array): this + public protocols(val: Array | null): this /** * Manipulate the list of protocols * @param { Array | undefined } val the list of protocols to set * @return { Array } */ - public protocols(val?: Array) { - if (!val) { - return this._protocols + public protocols(val?: Array | null) { + if (typeof val === 'undefined') { + return this._protocols ?? [] + } + if (val === null) { + delete this._protocols + } else { + this._protocols = val } - this._protocols = val return this } @@ -143,18 +151,23 @@ export default class URLManager { * Set the url protocol * @param val the protocol to set */ - public protocol(val: string): this + public protocol(val: string | null): this /** * Manipulate the url protocol * @param { string | undefined } val the protocol to set (Optionnal) * @return { string } */ - public protocol(val?: string) { - if (!val) { - return this._protocols.length > 0 ? this._protocols[0] : undefined + public protocol(val?: string | null) { + if (typeof val === 'undefined') { + const protocols = this.protocols() + return protocols.length > 0 ? protocols[0] : undefined + } + if (val === null) { + this.protocols(null) + } else { + this.protocols([val]) } - this._protocols = [val] return this } @@ -167,18 +180,22 @@ export default class URLManager { * set the url domain name * @param val the domain name */ - public domain(val: string): this + public domain(val: string | null): this /** * Manipulate the url domain * @param { string | undefined } val the url domain (Optionnal) * @return { string | this } */ - public domain(val?: string) { - if (!val) { + public domain(val?: string | null) { + if (typeof val === 'undefined') { return this._domain } - this._domain = val + if (val === null) { + delete this._domain + } else { + this._domain = val + } return this } From 5aa6636cf0bbfa1621a7d96f2e0183521ac77646 Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 21 Mar 2023 15:26:50 +0100 Subject: [PATCH 2/4] Update URLManager.ts --- packages/url-manager/src/URLManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/url-manager/src/URLManager.ts b/packages/url-manager/src/URLManager.ts index bb2c245..77cae16 100644 --- a/packages/url-manager/src/URLManager.ts +++ b/packages/url-manager/src/URLManager.ts @@ -195,7 +195,7 @@ export default class URLManager { } if (val === null) { delete this._domain - return this + return this } this._domain = val return this From eedea143362865678957c1602361ccd31d1dc1f5 Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 21 Mar 2023 15:28:48 +0100 Subject: [PATCH 3/4] Update node.js.yml --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index ac80acd..b9dbe18 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [14.x, 16.x, 18.x] steps: - uses: actions/checkout@v2 From e92a4f2f110b8f3728c9df657cc99cc62ee25cd4 Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 21 Mar 2023 15:29:12 +0100 Subject: [PATCH 4/4] Update node.js.yml --- .github/workflows/node.js.yml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index b9dbe18..7cb9447 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -37,20 +37,3 @@ jobs: - name: Test packages run: npm run test --workspaces --if-present - - - uses: sonarsource/sonarcloud-github-action@master - if: matrix.node-version == '16.x' - with: - args: > - -Dsonar.organization=dzeio - -Dsonar.projectKey=dzeiocom_libs - -Dsonar.javascript.lcov.reportPaths=packages/**/coverage/lcov.info - -Dsonar.testExecutionReportPaths=packages/easy-sitemap/test-report.xml,packages/object-util/test-report.xml,packages/url-manager/test-report.xml - -Dsonar.sources=packages - -Dsonar.exclusions=packages/**/__tests__,packages/**/dist,node_modules,packages/**/coverage - -Dsonar.tests=packages/easy-sitemap/__tests__,packages/object-util/__tests__,packages/url-manager/__tests__ - -Dsonar.test.inclusions=packages/**/*.test.ts - -Dsonar.sourceEncoding=UTF-8 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}