New: Project Aphrodite

This commit is contained in:
Qstick
2018-11-23 02:04:42 -05:00
parent 65efa15551
commit 8430cb40ab
1080 changed files with 73015 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
export default function combinePath(isWindows, basePath, paths = []) {
const slash = isWindows ? '\\' : '/';
return `${basePath}${slash}${paths.join(slash)}`;
}

View 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)
);
}

View File

@@ -0,0 +1,3 @@
export default function isString(possibleString) {
return typeof possibleString === 'string' || possibleString instanceof String;
}

View 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;
}

View 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;

View 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;