Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
49 changes: 31 additions & 18 deletions packages/url-manager/src/URLManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { objectLoop } from '@dzeio/object-util'
*/
export default class URLManager {

private _protocols: Array<string> = []
private _protocols?: Array<string>
private _username: string | undefined
private _password: string | undefined
private _domain: string | undefined
Expand Down Expand Up @@ -95,20 +95,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
}

Expand All @@ -121,18 +125,22 @@ export default class URLManager {
* set the list of protocols
* @param val the list
*/
public protocols(val: Array<string>): this
public protocols(val: Array<string> | null): this

/**
* Manipulate the list of protocols
* @param { Array<string> | undefined } val the list of protocols to set
* @return { Array<string> }
*/
public protocols(val?: Array<string>) {
if (!val) {
return this._protocols
public protocols(val?: Array<string> | null) {
if (typeof val === 'undefined') {
return this._protocols ?? []
}
if (val === null) {
delete this._protocols
} else {
this._protocols = val
}
this._protocols = val
return this
}

Expand All @@ -145,18 +153,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
}

Expand All @@ -180,7 +193,7 @@ export default class URLManager {
if (typeof val === 'undefined') {
return this._domain
}
if (!val) {
if (val === null) {
delete this._domain
return this
}
Expand Down