All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ducks.api.utils.createQueryUrl.ts Maven / Gradle / Ivy

The newest version!
import isEmpty from 'lodash/isEmpty'

import { SortDirection } from '../../../core/datasource/const'

const ESCAPED_SYMBOL = '%26'

export function createQueryUrl(url: string, sorting: Partial> = {}) {
    const escapedUrl = url.replace(/'&'/g, ESCAPED_SYMBOL)

    if (isEmpty(sorting)) {
        return escapedUrl
    }

    let urlWithSorting = escapedUrl
    const sortingKeys = Object.keys(sorting)

    sortingKeys.forEach((sortKey, index) => {
        const params = `${sortKey}=${sorting[sortKey]}`

        if (index === 0) {
            urlWithSorting += `${ESCAPED_SYMBOL}sorting.${params}`
        } else {
            urlWithSorting += `${ESCAPED_SYMBOL}${params}`
        }
    })

    return urlWithSorting
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy