mirror of https://github.com/vizality/vizality
More restructuring and changes...
- Added 'time' util module - Reworked 'string' util modules - Added deprecate log function - Renamed many modules function to include an action i.e. 'getX' - Added Discord 'routes' submodule - Changed module and submodule log badge colors - Other stuffpull/2/head
parent
149e895b08
commit
9e5c8e58fd
@ -1,8 +1,8 @@
|
||||
const { React } = require('vizality/webpack');
|
||||
const { classNames } = require('vizality/util');
|
||||
const { joinClassNames } = require('vizality/util');
|
||||
|
||||
module.exports = React.memo(({ type, wrapperClassName, className, ...props }) =>
|
||||
<div className={classNames('vizality-icon-wrapper', wrapperClassName)}>
|
||||
<icon className={classNames('vizality-icon', type, className)} {...props}></icon>
|
||||
<div className={joinClassNames('vizality-icon-wrapper', wrapperClassName)}>
|
||||
<icon className={joinClassNames('vizality-icon', type, className)} {...props}></icon>
|
||||
</div>
|
||||
);
|
||||
|
@ -0,0 +1,18 @@
|
||||
const { getModule } = require('vizality/webpack');
|
||||
|
||||
const _getRoutes = () => {
|
||||
const DISCORD_ROUTES = getModule([ 'Routes' ], false).Routes;
|
||||
const ROUTES = {
|
||||
discover: DISCORD_ROUTES.GUILD_DISCOVERY,
|
||||
// channel: '//channels/[0-9]+/.*/',
|
||||
dm: '/channels/@me/',
|
||||
friends: DISCORD_ROUTES.FRIENDS,
|
||||
guild: '/channels/',
|
||||
library: DISCORD_ROUTES.APPLICATION_LIBRARY,
|
||||
nitro: DISCORD_ROUTES.APPLICATION_STORE
|
||||
};
|
||||
|
||||
return ROUTES;
|
||||
};
|
||||
|
||||
module.exports = _getRoutes;
|
@ -0,0 +1,28 @@
|
||||
const { logger: { log, warn } } = require('vizality/util');
|
||||
/* const currentWebContents = require('electron').remote.getCurrentWebContents(); */
|
||||
|
||||
const _getRoutes = require('./_getRoutes');
|
||||
|
||||
const getCurrentRoute = () => {
|
||||
const MODULE = 'Module';
|
||||
const SUBMODULE = 'Discord:routes:getCurrentRoute';
|
||||
|
||||
const routes = _getRoutes();
|
||||
/* const historyRoute = currentWebContents.history[currentWebContents.history.length - 2]; */
|
||||
|
||||
for (const location in routes) {
|
||||
if (window.location.href.includes(routes[location])) {
|
||||
let locationStr = window.location.href.split('/');
|
||||
locationStr = `/${locationStr[3]}/${locationStr[4]}/`;
|
||||
/*
|
||||
* if (location === 'guild' && historyRoute.includes(locationStr)) {
|
||||
* location = 'channel';
|
||||
* }
|
||||
*/
|
||||
return log(MODULE, SUBMODULE, null, `The current route is '${location}'.`);
|
||||
}
|
||||
}
|
||||
return warn(MODULE, SUBMODULE, null, `The current route is unknown.`);
|
||||
};
|
||||
|
||||
module.exports = getCurrentRoute;
|
@ -0,0 +1,15 @@
|
||||
const { logger: { log } } = require('vizality/util');
|
||||
|
||||
const _getRoutes = require('./_getRoutes');
|
||||
|
||||
const getRoutes = () => {
|
||||
const MODULE = 'Module';
|
||||
const SUBMODULE = 'Discord:routes:getRoutes';
|
||||
|
||||
const routeList = Object.keys(_getRoutes().filter(r => r !== 'guild'));
|
||||
|
||||
log(MODULE, SUBMODULE, null, `List of available routes to be used with 'Discord.routes.goTo':`);
|
||||
return console.log(routeList);
|
||||
};
|
||||
|
||||
module.exports = getRoutes;
|
@ -0,0 +1,48 @@
|
||||
const { getModule } = require('vizality/webpack');
|
||||
const { logger: { warn } } = require('vizality/util');
|
||||
|
||||
const _getRoutes = require('./_getRoutes');
|
||||
|
||||
const goTo = (location) => {
|
||||
const MODULE = 'Module';
|
||||
const SUBMODULE = 'Discord:routes:goTo';
|
||||
|
||||
const routeList = Object.keys(_getRoutes().filter(r => r !== 'guild'));
|
||||
|
||||
if (!location) {
|
||||
warn(MODULE, SUBMODULE, null, `You must enter a valid route string. List of available routes:`);
|
||||
return console.warn(routeList);
|
||||
}
|
||||
|
||||
const DISCORD_ROUTES = getModule([ 'Routes' ], false).Routes;
|
||||
|
||||
if (Object.keys(DISCORD_ROUTES).includes(location)) {
|
||||
return getModule([ 'transitionTo' ], false).transitionTo(DISCORD_ROUTES[location]);
|
||||
}
|
||||
|
||||
if (Object.values(DISCORD_ROUTES).includes(location)) {
|
||||
return getModule([ 'transitionTo' ], false).transitionTo(location);
|
||||
}
|
||||
|
||||
location = location.toLowerCase();
|
||||
|
||||
switch (location) {
|
||||
case 'discover':
|
||||
return getModule([ 'transitionTo' ], false).transitionTo(DISCORD_ROUTES.GUILD_DISCOVERY);
|
||||
case 'dm':
|
||||
return getModule([ 'transitionTo' ], false).transitionTo(
|
||||
DISCORD_ROUTES.CHANNEL('@me', getModule([ 'getPrivateChannelIds' ], false).getPrivateChannelIds()[0])
|
||||
);
|
||||
case 'friends':
|
||||
return getModule([ 'transitionTo' ], false).transitionTo(DISCORD_ROUTES.FRIENDS);
|
||||
case 'library':
|
||||
return getModule([ 'transitionTo' ], false).transitionTo(DISCORD_ROUTES.APPLICATION_LIBRARY);
|
||||
case 'nitro':
|
||||
return getModule([ 'transitionTo' ], false).transitionTo(DISCORD_ROUTES.APPLICATION_STORE);
|
||||
default:
|
||||
warn(MODULE, SUBMODULE, null, `The route '${location}' was not found. List of available routes:`);
|
||||
return console.warn(routeList);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = goTo;
|
@ -0,0 +1,7 @@
|
||||
require('fs')
|
||||
.readdirSync(__dirname)
|
||||
.filter(file => file !== 'index.js')
|
||||
.forEach(filename => {
|
||||
const moduleName = filename.split('.')[0];
|
||||
exports[moduleName] = require(`${__dirname}/${filename}`);
|
||||
});
|
@ -0,0 +1,11 @@
|
||||
const { getModule } = require('vizality/webpack');
|
||||
|
||||
const _getSections = () => {
|
||||
const DISCORD_SECTIONS = Object.values(getModule([ 'UserSettingsSections' ], false).UserSettingsSections);
|
||||
const VIZALITY_SECTIONS = Object.keys(vizality.api.settings.tabs);
|
||||
const ALL_SECTIONS = DISCORD_SECTIONS.concat(VIZALITY_SECTIONS);
|
||||
|
||||
return ALL_SECTIONS;
|
||||
};
|
||||
|
||||
module.exports = _getSections;
|
@ -0,0 +1,13 @@
|
||||
const { logger: { log } } = require('vizality/util');
|
||||
|
||||
const _getSections = require('./_getSections');
|
||||
|
||||
const getSections = () => {
|
||||
const MODULE = 'Module';
|
||||
const SUBMODULE = 'Discord:settings:getSections';
|
||||
|
||||
log(MODULE, SUBMODULE, null, 'List of available user settings sections:');
|
||||
return _getSections();
|
||||
};
|
||||
|
||||
module.exports = getSections;
|
@ -1,18 +0,0 @@
|
||||
const { getModule } = require('vizality/webpack');
|
||||
|
||||
const discordSections = {
|
||||
...Object.values(getModule([ 'UserSettingsSections' ], false).UserSettingsSections)
|
||||
};
|
||||
|
||||
const vizalitySections = {
|
||||
...Object.keys(vizality.api.settings.tabs)
|
||||
};
|
||||
|
||||
const sectionsObject = {
|
||||
...vizalitySections,
|
||||
...discordSections
|
||||
};
|
||||
|
||||
const sections = Object.values(sectionsObject);
|
||||
|
||||
module.exports = sections;
|
@ -1,11 +0,0 @@
|
||||
/**
|
||||
* @hack: Figure out why const { getModule } = require('vizality/webpack') doesn't work.
|
||||
*/
|
||||
let classNames;
|
||||
|
||||
module.exports = (...args) => {
|
||||
if (!classNames) {
|
||||
classNames = require('vizality/webpack').getModule(e => e.default && e.default.default, false);
|
||||
}
|
||||
return classNames(...args);
|
||||
};
|
@ -1,7 +1,9 @@
|
||||
module.exports = (color) => {
|
||||
const _hex2int = (color) => {
|
||||
if (color.length === 4) {
|
||||
color = `#${color[1]}${color[1]}${color[2]}${color[2]}${color[3]}${color[3]}`;
|
||||
}
|
||||
|
||||
return parseInt(color.slice(1), 16);
|
||||
};
|
||||
|
||||
module.exports = _hex2int;
|
@ -0,0 +1,5 @@
|
||||
const _int2hex = (color) => {
|
||||
return `#${((color) >>> 0).toString(16)}`;
|
||||
};
|
||||
|
||||
module.exports = _int2hex;
|
@ -1,3 +1,5 @@
|
||||
module.exports = (color) => {
|
||||
const _int2rgb = (color) => {
|
||||
return `rgb(${(color >> 16 & 255)} ${(color >> 8 & 255)} ${(255 & color)})`;
|
||||
};
|
||||
|
||||
module.exports = _int2rgb;
|
@ -1,45 +0,0 @@
|
||||
const rgb2hex = require('./rgb2hex');
|
||||
const hsl2hex = require('./hsl2hex');
|
||||
const int2hex = require('./int2hex');
|
||||
|
||||
module.exports = (color) => {
|
||||
const ex = {
|
||||
hex: /^#([\da-f]{3}){1,2}$/i,
|
||||
|
||||
rgb: /^rgb\((((((((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5]),\s?)){2}|((((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5])\s)){2})((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5]))|((((([1-9]?\d(\.\d+)?)|100|(\.\d+))%,\s?){2}|((([1-9]?\d(\.\d+)?)|100|(\.\d+))%\s){2})(([1-9]?\d(\.\d+)?)|100|(\.\d+))%))\)$/i,
|
||||
|
||||
hsl: /^hsl\(((((([12]?[1-9]?\d)|[12]0\d|(3[0-5]\d))(\.\d+)?)|(\.\d+))(deg)?|(0|0?\.\d+)turn|(([0-6](\.\d+)?)|(\.\d+))rad)((,\s?(([1-9]?\d(\.\d+)?)|100|(\.\d+))%){2}|(\s(([1-9]?\d(\.\d+)?)|100|(\.\d+))%){2})\)$/i
|
||||
};
|
||||
|
||||
let r, g, b;
|
||||
|
||||
function _hex (arg) {
|
||||
if (arg.length === 4) {
|
||||
r = `0x${arg[1]}${arg[1]}`;
|
||||
g = `0x${arg[2]}${arg[2]}`;
|
||||
b = `0x${arg[3]}${arg[3]}`;
|
||||
|
||||
// 6 digits
|
||||
} else if (arg.length === 7) {
|
||||
r = `0x${arg[1]}${arg[2]}`;
|
||||
g = `0x${arg[3]}${arg[4]}`;
|
||||
b = `0x${arg[5]}${arg[6]}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (ex.rgb.test(color)) {
|
||||
_hex(rgb2hex(color));
|
||||
} else if (ex.hex.test(color)) {
|
||||
_hex(color);
|
||||
} else if (ex.hsl.test(color)) {
|
||||
_hex(hsl2hex(color));
|
||||
} else if (Number.isInteger(color)) {
|
||||
_hex(int2hex(color));
|
||||
} else {
|
||||
throw new Error('Invalid color type entered.');
|
||||
}
|
||||
|
||||
if ((r * 0.299) + (g * 0.587) + (b * 0.114) > 186) return '#000';
|
||||
|
||||
return '#fff';
|
||||
};
|
@ -0,0 +1,26 @@
|
||||
const toHex = require('./toHex');
|
||||
|
||||
const getContrast = (color) => {
|
||||
let r, g, b;
|
||||
|
||||
function _hex (arg) {
|
||||
if (arg.length === 4) {
|
||||
r = `0x${arg[1]}${arg[1]}`;
|
||||
g = `0x${arg[2]}${arg[2]}`;
|
||||
b = `0x${arg[3]}${arg[3]}`;
|
||||
// 6 digits
|
||||
} else if (arg.length === 7) {
|
||||
r = `0x${arg[1]}${arg[2]}`;
|
||||
g = `0x${arg[3]}${arg[4]}`;
|
||||
b = `0x${arg[5]}${arg[6]}`;
|
||||
}
|
||||
}
|
||||
|
||||
_hex(toHex(color));
|
||||
|
||||
if ((r * 0.299) + (g * 0.587) + (b * 0.114) > 186) return '#000';
|
||||
|
||||
return '#fff';
|
||||
};
|
||||
|
||||
module.exports = getContrast;
|
@ -0,0 +1,33 @@
|
||||
const logger = require('../logger');
|
||||
|
||||
const _int2hex = require('./_int2hex');
|
||||
const _rgb2hex = require('./_rgb2hex');
|
||||
const _hsl2hex = require('./_hsl2hex');
|
||||
|
||||
const getRandom = (type) => {
|
||||
const MODULE = 'Module';
|
||||
const SUBMODULE = 'Util:color:getRandom';
|
||||
|
||||
if (!type) type = 'hex';
|
||||
|
||||
String(type);
|
||||
|
||||
const base = '000000';
|
||||
const number = Math.floor(Math.random() * 16777215).toString(16);
|
||||
const color = `#${(base + number).substr(-6)}`;
|
||||
|
||||
switch (type) {
|
||||
case 'hex':
|
||||
return color;
|
||||
case 'rgb':
|
||||
return _rgb2hex(color);
|
||||
case 'hsl':
|
||||
return _hsl2hex(color);
|
||||
case 'int':
|
||||
return _int2hex(color);
|
||||
default:
|
||||
return logger.warn(MODULE, SUBMODULE, null, `Input type '${type}' is not a valid color type. Please choose 'hex', 'rgb', 'hsl', or 'int'.`);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = getRandom;
|
@ -1,26 +0,0 @@
|
||||
const logger = require('../logger');
|
||||
|
||||
const int2hex = require('./int2hex');
|
||||
const rgb2hex = require('./rgb2hex');
|
||||
const hsl2hex = require('./hsl2hex');
|
||||
const type = require('./type');
|
||||
|
||||
/**
|
||||
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
|
||||
*/
|
||||
module.exports = (color) => {
|
||||
const colorType = type(color);
|
||||
|
||||
switch (colorType) {
|
||||
case 'hex':
|
||||
return color;
|
||||
case 'rgb':
|
||||
return rgb2hex(color);
|
||||
case 'hsl':
|
||||
return hsl2hex(color);
|
||||
case 'int':
|
||||
return int2hex(color);
|
||||
default:
|
||||
logger.warn('Module', 'Util:color:hex', null, `Input color '${color}' is not a recognized color type.`);
|
||||
}
|
||||
};
|
@ -1,26 +0,0 @@
|
||||
const logger = require('../logger');
|
||||
|
||||
const int2hsl = require('./int2hsl');
|
||||
const hex2hsl = require('./hex2hsl');
|
||||
const rgb2hsl = require('./rgb2hsl');
|
||||
const type = require('./type');
|
||||
|
||||
/**
|
||||
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
|
||||
*/
|
||||
module.exports = (color) => {
|
||||
const colorType = type(color);
|
||||
|
||||
switch (colorType) {
|
||||
case 'hsl':
|
||||
return color;
|
||||
case 'hex':
|
||||
return hex2hsl(color);
|
||||
case 'rgb':
|
||||
return rgb2hsl(color);
|
||||
case 'int':
|
||||
return int2hsl(color);
|
||||
default:
|
||||
logger.warn('Module', 'Util:color:hsl', null, `Input color '${color}' is not a recognized color type.`);
|
||||
}
|
||||
};
|
@ -1,26 +0,0 @@
|
||||
const logger = require('../logger');
|
||||
|
||||
const hex2int = require('./hex2int');
|
||||
const rgb2int = require('./rgb2int');
|
||||
const hsl2int = require('./hsl2int');
|
||||
const type = require('./type');
|
||||
|
||||
/**
|
||||
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
|
||||
*/
|
||||
module.exports = (color) => {
|
||||
const colorType = type(color);
|
||||
|
||||
switch (colorType) {
|
||||
case 'int':
|
||||
return color;
|
||||
case 'hex':
|
||||
return hex2int(color);
|
||||
case 'rgb':
|
||||
return rgb2int(color);
|
||||
case 'hsl':
|
||||
return hsl2int(color);
|
||||
default:
|
||||
logger.warn('Module', 'Util:color:hsl', null, `Input color '${color}' is not a recognized color type.`);
|
||||
}
|
||||
};
|
@ -1,3 +0,0 @@
|
||||
module.exports = (color) => {
|
||||
return `#${((color) >>> 0).toString(16)}`;
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
module.exports = () => {
|
||||
const base = '000000';
|
||||
const number = Math.floor(Math.random() * 16777215).toString(16);
|
||||
return `#${(base + number).substr(-6)}`;
|
||||
};
|
@ -1,26 +0,0 @@
|
||||
const logger = require('../logger');
|
||||
|
||||
const int2rgb = require('./int2rgb');
|
||||
const hex2rgb = require('./hex2rgb');
|
||||
const hsl2rgb = require('./hsl2rgb');
|
||||
const type = require('./type');
|
||||
|
||||
/**
|
||||
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
|
||||
*/
|
||||
module.exports = (color) => {
|
||||
const colorType = type(color);
|
||||
|
||||
switch (colorType) {
|
||||
case 'rgb':
|
||||
return color;
|
||||
case 'hex':
|
||||
return hex2rgb(color);
|
||||
case 'hsl':
|
||||
return hsl2rgb(color);
|
||||
case 'int':
|
||||
return int2rgb(color);
|
||||
default:
|
||||
logger.warn('Module', 'Util:color:hsl', null, `Input color '${color}' is not a recognized color type.`);
|
||||
}
|
||||
};
|
@ -0,0 +1,31 @@
|
||||
const logger = require('../logger');
|
||||
|
||||
const _int2hex = require('./_int2hex');
|
||||
const _rgb2hex = require('./_rgb2hex');
|
||||
const _hsl2hex = require('./_hsl2hex');
|
||||
const getType = require('./getType');
|
||||
|
||||
/**
|
||||
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
|
||||
*/
|
||||
const toHex = (color) => {
|
||||
const MODULE = 'Module';
|
||||
const SUBMODULE = 'Util:color:toHex';
|
||||
|
||||
const colorType = getType(color);
|
||||
|
||||
switch (colorType) {
|
||||
case 'hex':
|
||||
return color;
|
||||
case 'rgb':
|
||||
return _rgb2hex(color);
|
||||
case 'hsl':
|
||||
return _hsl2hex(color);
|
||||
case 'int':
|
||||
return _int2hex(color);
|
||||
default:
|
||||
return logger.warn(MODULE, SUBMODULE, null, `Input color '${color}' is not a recognized color type.`);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = toHex;
|
@ -0,0 +1,31 @@
|
||||
const logger = require('../logger');
|
||||
|
||||
const _int2hsl = require('./_int2hsl');
|
||||
const _hex2hsl = require('./_hex2hsl');
|
||||
const _rgb2hsl = require('./_rgb2hsl');
|
||||
const getType = require('./getType');
|
||||
|
||||
/**
|
||||
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
|
||||
*/
|
||||
const toHsl = (color) => {
|
||||
const MODULE = 'Module';
|
||||
const SUBMODULE = 'Util:color:toHsl';
|
||||
|
||||
const colorType = getType(color);
|
||||
|
||||
switch (colorType) {
|
||||
case 'hsl':
|
||||
return color;
|
||||
case 'hex':
|
||||
return _hex2hsl(color);
|
||||
case 'rgb':
|
||||
return _rgb2hsl(color);
|
||||
case 'int':
|
||||
return _int2hsl(color);
|
||||
default:
|
||||
return logger.warn(MODULE, SUBMODULE, null, `Input color '${color}' is not a recognized color type.`);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = toHsl;
|
@ -0,0 +1,31 @@
|
||||
const logger = require('../logger');
|
||||
|
||||
const _hex2int = require('./_hex2int');
|
||||
const _rgb2int = require('./_rgb2int');
|
||||
const _hsl2int = require('./_hsl2int');
|
||||
const getType = require('./getType');
|
||||
|
||||
/**
|
||||
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
|
||||
*/
|
||||
const toInt = (color) => {
|
||||
const MODULE = 'Module';
|
||||
const SUBMODULE = 'Util:color:toInt';
|
||||
|
||||
const colorType = getType(color);
|
||||
|
||||
switch (colorType) {
|
||||
case 'int':
|
||||
return color;
|
||||
case 'hex':
|
||||
return _hex2int(color);
|
||||
case 'rgb':
|
||||
return _rgb2int(color);
|
||||
case 'hsl':
|
||||
return _hsl2int(color);
|
||||
default:
|
||||
return logger.warn(MODULE, SUBMODULE, null, `Input color '${color}' is not a recognized color type.`);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = toInt;
|
@ -0,0 +1,31 @@
|
||||
const logger = require('../logger');
|
||||
|
||||
const _int2rgb = require('./_int2rgb');
|
||||
const _hex2rgb = require('./_hex2rgb');
|
||||
const _hsl2rgb = require('./_hsl2rgb');
|
||||
const getType = require('./getType');
|
||||
|
||||
/**
|
||||
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
|
||||
*/
|
||||
const toRgb = (color) => {
|
||||
const MODULE = 'Module';
|
||||
const SUBMODULE = 'Util:color:toRgb';
|
||||
|
||||
const colorType = getType(color);
|
||||
|
||||
switch (colorType) {
|
||||
case 'rgb':
|
||||
return color;
|
||||
case 'hex':
|
||||
return _hex2rgb(color);
|
||||
case 'hsl':
|
||||
return _hsl2rgb(color);
|
||||
case 'int':
|
||||
return _int2rgb(color);
|
||||
default:
|
||||
return logger.warn(MODULE, SUBMODULE, null, `Input color '${color}' is not a recognized color type.`);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = toRgb;
|
@ -1,10 +1,35 @@
|
||||
module.exports = (time) => {
|
||||
/**
|
||||
* @deprecated:
|
||||
* @powercord: This function/module is only here to provide
|
||||
* backwards-compatability with Powercord plugins that may utilize it.
|
||||
*
|
||||
* There is no replacement for this as it has been removed entirely from Vizality,
|
||||
* due the seemingly niche nature of it. If you want it left in, let us know!
|
||||
*/
|
||||
|
||||
/**
|
||||
* Converts milliseconds to hours:minutes:seconds
|
||||
* @param {*} time
|
||||
*/
|
||||
|
||||
const logger = require('./logger');
|
||||
|
||||
const formatTime = (time) => {
|
||||
const MODULE = 'Module';
|
||||
const SUBMODULE = 'Util:formatTime';
|
||||
|
||||
logger.deprecate(MODULE, SUBMODULE, null);
|
||||
|
||||
time = Math.floor(time / 1000);
|
||||
|
||||
const hours = Math.floor(time / 3600) % 24;
|
||||
const minutes = Math.floor(time / 60) % 60;
|
||||
const seconds = time % 60;
|
||||
|
||||
return [ hours, minutes, seconds ]
|
||||
.map(v => v < 10 ? `0${v}` : v)
|
||||
.filter((v, i) => v !== '00' || i > 0)
|
||||
.join(':');
|
||||
};
|
||||
|
||||
module.exports = formatTime;
|
||||
|
@ -1,6 +1,24 @@
|
||||
module.exports = (node) => {
|
||||
/**
|
||||
* @deprecated:
|
||||
* @powercord: This function/module is only here to provide
|
||||
* backwards-compatability with Powercord plugins that may utilize it.
|
||||
*
|
||||
* Plugins should be using `Util.react.getReactInstance` instead.
|
||||
*/
|
||||
|
||||
const logger = require('./logger');
|
||||
|
||||
const getReactInstance = (node) => {
|
||||
const MODULE = 'Module';
|
||||
const SUBMODULE = 'Util:getReactInstance';
|
||||
const REPLACEMENT_SUBMODULE = 'Util:react:getReactInstance';
|
||||
|
||||
logger.deprecate(MODULE, SUBMODULE, REPLACEMENT_SUBMODULE);
|
||||
|
||||
if (!node) return null;
|
||||
if (!Object.keys(node) || !Object.keys(node).length) return null;
|
||||
const reactInternalInstanceKey = Object.keys(node).find(key => key.startsWith('__reactInternalInstance'));
|
||||
return reactInternalInstanceKey ? node[reactInternalInstanceKey] : null;
|
||||
};
|
||||
|
||||
module.exports = getReactInstance;
|
||||
|
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @hack: Figure out why const { getModule } = require('vizality/webpack') doesn't work.
|
||||
*/
|
||||
|
||||
let joinClassNamesModule;
|
||||
|
||||
const joinClassNames = (...args) => {
|
||||
if (!joinClassNamesModule) joinClassNamesModule = require('vizality/webpack').getModule(e => e.default && e.default.default, false);
|
||||
|
||||
return joinClassNamesModule(...args);
|
||||
};
|
||||
|
||||
module.exports = joinClassNames;
|
@ -0,0 +1,16 @@
|
||||
const logger = require('../logger');
|
||||
|
||||
/**
|
||||
* Logs a warning message to let the user know the method is deprecated.
|
||||
*
|
||||
* @param {string} module - Name of the calling module.
|
||||
* @param {string} message - Message to have logged.
|
||||
*/
|
||||
const deprecate = (module, submodule, replacement) => {
|
||||
return void 0;
|
||||
// const message = `${submodule} is deprecated in Vizality.${replacement ? ` We recommend you use ${replacement} instead.` : ''}`;
|
||||
|
||||
// return logger._log(module, submodule, null, message, 'warn');
|
||||
};
|
||||
|
||||
module.exports = deprecate;
|
@ -1,5 +1,9 @@
|
||||
// @todo: Rework to note use lodash
|
||||
|
||||
const { get } = require('lodash');
|
||||
|
||||
module.exports = (object, path, defaultValue) => {
|
||||
const getNestedProp = (object, path, defaultValue) => {
|
||||
return get(object, path, defaultValue);
|
||||
};
|
||||
|
||||
module.exports = getNestedProp;
|
||||
|
@ -1,4 +1,7 @@
|
||||
module.exports = (time) =>
|
||||
new Promise(resolve =>
|
||||
const sleep = (time) => {
|
||||
return new Promise(resolve =>
|
||||
setTimeout(resolve, time)
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = sleep;
|
||||
|
@ -1,5 +0,0 @@
|
||||
const convert = require('js-convert-case');
|
||||
|
||||
module.exports = (str) => {
|
||||
return convert.toCamelCase(str);
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
const convert = require('js-convert-case');
|
||||
|
||||
module.exports = (str) => {
|
||||
return convert.toDotCase(str);
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
const convert = require('js-convert-case');
|
||||
|
||||
module.exports = (str) => {
|
||||
return convert.toHeaderCase(str);
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
const convert = require('js-convert-case');
|
||||
|
||||
module.exports = (str) => {
|
||||
return convert.toPascalCase(str);
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
const convert = require('js-convert-case');
|
||||
|
||||
module.exports = (str) => {
|
||||
return convert.toPathCase(str);
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
const convert = require('js-convert-case');
|
||||
|
||||
module.exports = (str) => {
|
||||
return convert.toSentenceCase(str);
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
const convert = require('js-convert-case');
|
||||
|
||||
module.exports = (str) => {
|
||||
return convert.toSnakeCase(str);
|
||||
};
|
@ -0,0 +1,16 @@
|
||||
const toCamelCase = (string) => {
|
||||
if (!string) return '';
|
||||
|
||||
return String(string)
|
||||
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
|
||||
.replace(/[^A-Za-z0-9]+/g, '$')
|
||||
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
|
||||
return `${a}$${b}`;
|
||||
})
|
||||
.toLowerCase().trim()
|
||||
.replace(/(\$)(\w)/g, (m, a, b) => {
|
||||
return b.toUpperCase();
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = toCamelCase;
|
@ -0,0 +1,13 @@
|
||||
const toDotCase = (string) => {
|
||||
if (!string) return '';
|
||||
|
||||
return String(string)
|
||||
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
|
||||
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
|
||||
return `${a}_${b.toLowerCase()}`;
|
||||
})
|
||||
.replace(/[^A-Za-z0-9]+|_+/g, '.')
|
||||
.toLowerCase().trim();
|
||||
};
|
||||
|
||||
module.exports = toDotCase;
|
@ -0,0 +1,16 @@
|
||||
const toHeaderCase = (string) => {
|
||||
if (!string) return '';
|
||||
|
||||
return String(string)
|
||||
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
|
||||
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
|
||||
return `${a}_${b.toLowerCase()}`;
|
||||
})
|
||||
.replace(/[^A-Za-z0-9]+|_+/g, ' ')
|
||||
.toLowerCase().trim()
|
||||
.replace(/( ?)(\w+)( ?)/g, (m, a, b, c) => {
|
||||
return a + b.charAt(0).toUpperCase() + b.slice(1) + c;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = toHeaderCase;
|
@ -0,0 +1,27 @@
|
||||
const toKebabCase = (string) => {
|
||||
if (!string) return '';
|
||||
|
||||
let from = 'ąàáäâãåæăćčĉęèéëêĝĥìíïîĵłľńňòóöőôõðøśșşšŝťțţŭùúüűûñÿýçżźž';
|
||||
let to = 'aaaaaaaaaccceeeeeghiiiijllnnoooooooossssstttuuuuuunyyczzz';
|
||||
|
||||
from += from.toUpperCase();
|
||||
to += to.toUpperCase();
|
||||
|
||||
to = to.split('');
|
||||
|
||||
// for tokens requiring multitoken output
|
||||
from += 'ß';
|
||||
to.push('ss');
|
||||
|
||||
return String(string)
|
||||
.trim()
|
||||
.replace(/.{1}/g, c => {
|
||||
const index = from.indexOf(c);
|
||||
return index === -1 ? c : to[index];
|
||||
})
|
||||
.replace(/[^\w\s-]/g, '-').toLowerCase()
|
||||
.replace(/([A-Z])/g, '-$1')
|
||||
.replace(/[-_\s]+/g, '-').toLowerCase();
|
||||
};
|
||||
|
||||
module.exports = toKebabCase;
|
@ -0,0 +1,16 @@
|
||||
const toPascalCase = (string) => {
|
||||
if (!string) return '';
|
||||
|
||||
return String(string)
|
||||
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '$')
|
||||
.replace(/[^A-Za-z0-9]+/g, '$')
|
||||
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
|
||||
return `${a}$${b}`;
|
||||
})
|
||||
.toLowerCase().trim()
|
||||
.replace(/(\$)(\w?)/g, (m, a, b) => {
|
||||
return b.toUpperCase();
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = toPascalCase;
|
@ -0,0 +1,13 @@
|
||||
const toPathCase = (string) => {
|
||||
if (!string) return '';
|
||||
|
||||
return String(string)
|
||||
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
|
||||
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
|
||||
return `${a}_${b.toLowerCase()}`;
|
||||
})
|
||||
.replace(/[^A-Za-z0-9]+|_+/g, '/')
|
||||
.toLowerCase().trim();
|
||||
};
|
||||
|
||||
module.exports = toPathCase;
|
@ -0,0 +1,15 @@
|
||||
const toSentenceCase = (string) => {
|
||||
if (!string) return '';
|
||||
|
||||
const textcase = String(string)
|
||||
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
|
||||
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
|
||||
return `${a}_${b.toLowerCase()}`;
|
||||
})
|
||||
.replace(/[^A-Za-z0-9]+|_+/g, ' ')
|
||||
.toLowerCase().trim();
|
||||
|
||||
return textcase.charAt(0).toUpperCase() + textcase.slice(1);
|
||||
};
|
||||
|
||||
module.exports = toSentenceCase;
|
@ -0,0 +1,13 @@
|
||||
const toSnakeCase = (string) => {
|
||||
if (!string) return '';
|
||||
|
||||
return String(string)
|
||||
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
|
||||
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
|
||||
return `${a}_${b.toLowerCase()}`;
|
||||
})
|
||||
.replace(/[^A-Za-z0-9]+|_+/g, '_')
|
||||
.toLowerCase().trim();
|
||||
};
|
||||
|
||||
module.exports = toSnakeCase;
|
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* moment().add(Number, String);
|
||||
* moment().add(Duration);
|
||||
* moment().add(Object);
|
||||
*/
|
||||
|
||||
const moment = require('./moment');
|
||||
|
||||
module.exports = (...args) => {
|
||||
return moment().add(...args);
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue