mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-12-29 09:05:28 +01:00
New: Project Aphrodite
This commit is contained in:
5
frontend/src/Utilities/String/combinePath.js
Normal file
5
frontend/src/Utilities/String/combinePath.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export default function combinePath(isWindows, basePath, paths = []) {
|
||||
const slash = isWindows ? '\\' : '/';
|
||||
|
||||
return `${basePath}${slash}${paths.join(slash)}`;
|
||||
}
|
||||
6
frontend/src/Utilities/String/generateUUIDv4.js
Normal file
6
frontend/src/Utilities/String/generateUUIDv4.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export default function generateUUIDv4() {
|
||||
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, (c) =>
|
||||
// eslint-disable-next-line no-bitwise
|
||||
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
||||
);
|
||||
}
|
||||
3
frontend/src/Utilities/String/isString.js
Normal file
3
frontend/src/Utilities/String/isString.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function isString(possibleString) {
|
||||
return typeof possibleString === 'string' || possibleString instanceof String;
|
||||
}
|
||||
36
frontend/src/Utilities/String/parseUrl.js
Normal file
36
frontend/src/Utilities/String/parseUrl.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import _ from 'lodash';
|
||||
import qs from 'qs';
|
||||
|
||||
// See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils
|
||||
const anchor = document.createElement('a');
|
||||
|
||||
export default function parseUrl(url) {
|
||||
anchor.href = url;
|
||||
|
||||
// The `origin`, `password`, and `username` properties are unavailable in
|
||||
// Opera Presto. We synthesize `origin` if it's not present. While `password`
|
||||
// and `username` are ignored intentionally.
|
||||
const properties = _.pick(
|
||||
anchor,
|
||||
'hash',
|
||||
'host',
|
||||
'hostname',
|
||||
'href',
|
||||
'origin',
|
||||
'pathname',
|
||||
'port',
|
||||
'protocol',
|
||||
'search'
|
||||
);
|
||||
|
||||
properties.isAbsolute = (/^[\w:]*\/\//).test(url);
|
||||
|
||||
if (properties.search) {
|
||||
// Remove leading ? from querystring before parsing.
|
||||
properties.params = qs.parse(properties.search.substring(1));
|
||||
} else {
|
||||
properties.params = {};
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
17
frontend/src/Utilities/String/split.js
Normal file
17
frontend/src/Utilities/String/split.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
function split(input, separator = ',') {
|
||||
if (!input) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return _.reduce(input.split(separator), (result, s) => {
|
||||
if (s) {
|
||||
result.push(s);
|
||||
}
|
||||
|
||||
return result;
|
||||
}, []);
|
||||
}
|
||||
|
||||
export default split;
|
||||
11
frontend/src/Utilities/String/titleCase.js
Normal file
11
frontend/src/Utilities/String/titleCase.js
Normal file
@@ -0,0 +1,11 @@
|
||||
function titleCase(input) {
|
||||
if (!input) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return input.replace(/\b\w+/g, (match) => {
|
||||
return match.charAt(0).toUpperCase() + match.substr(1).toLowerCase();
|
||||
});
|
||||
}
|
||||
|
||||
export default titleCase;
|
||||
Reference in New Issue
Block a user