1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00
onion/js/utils/url.js

25 lines
965 B
JavaScript
Raw Permalink Normal View History

2016-06-13 15:30:20 +02:00
// Re-export related utilities from js-utility-belt for easier access
export { getCurrentQueryParams, stringifyAsQueryParam, parseQueryParamStr } from 'js-utility-belt/es6/url';
/**
2016-06-13 17:33:47 +02:00
* Takes a string and a boolean and generates an string ordering query parameter for API calls.
*
* @param {string} orderBy Property to order by
* @param {bool} orderAsc Whether the order should be ascending (false makes order descending)
* @return {string} Ordering query parameter
*/
export function generateOrderingQueryParams(orderBy, orderAsc) {
2016-06-13 15:30:29 +02:00
return orderAsc ? orderBy : `-${orderBy}`;
}
2016-06-13 17:33:47 +02:00
/**
* Extracts the current location's subdomain.
* If no subdomain is found (for example on a naked domain), the default "www" is just assumed.
*
* @return {string} Subdomain (if none found, defaults to "www")
*/
export function getCurrentSubdomain() {
const tokens = window.location.host.split('.');
return tokens.length > 2 ? tokens[0] : 'www';
}