Skip to content

Commit

Permalink
feat: improves performance by fixing JS-D007
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmeese7 committed Sep 26, 2023
1 parent dd18dbe commit ca34729
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 48 deletions.
4 changes: 2 additions & 2 deletions apps/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ const openFile = async (core, proc, win, a, file, restore) => {
const url = await core.make("meeseOS/vfs").url(file);
const ref = { ...file, url };

if (file.mime.match(/^image/)) {
if (/^image/.test(file.mime)) {
a.setImage({ image: ref, restore });
} else if (file.mime.match(/^video/)) {
} else if (/^video/.test(file.mime)) {
a.setVideo({ video: ref, restore });
}

Expand Down
2 changes: 1 addition & 1 deletion apps/preview/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meese-os/preview",
"version": "1.0.3",
"version": "1.0.4",
"description": "MeeseOS Preview Application",
"scripts": {
"eslint": "eslint *.js",
Expand Down
2 changes: 1 addition & 1 deletion backend/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meese-os/server",
"version": "1.0.5",
"version": "1.0.6",
"description": "meeseOS Server",
"scripts": {
"build": "echo \"There is no build command for server\" && exit 0",
Expand Down
2 changes: 1 addition & 1 deletion backend/server/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const maxAge = 60 * 60 * 12;
const mb = (m) => m * 1024 * 1024;

const defaultConfiguration = {
development: !(process.env.NODE_ENV || "").match(/^prod/i),
development: !/^prod/i.test(process.env.NODE_ENV || ""),
logging: true,
index: "index.html",
bind: "127.0.0.1",
Expand Down
4 changes: 1 addition & 3 deletions backend/server/src/providers/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,7 @@ class CoreServiceProvider extends ServiceProvider {
// NOTE: 'ignored' does not work as expected with callback
// ignored: str => str.match(/\.(js|css)$/) === null
// for unknown reasons
if (!filename.match(/\.(js|css)$/)) {
return;
}
if (!/\.(js|css)$/i.test(filename)) return;

const relative = filename.replace(watchdir, "");
this.core.broadcast("meeseOS/dist:changed", [relative]);
Expand Down
2 changes: 1 addition & 1 deletion development/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meese-os/cli",
"version": "1.0.6",
"version": "1.0.7",
"description": "meeseOS CLI",
"scripts": {
"build": "echo \"There is no build command for cli\" && exit 0",
Expand Down
4 changes: 2 additions & 2 deletions development/cli/src/tasks/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const removeSoftDeleted = (logger, disabled) => (iter) => {
return false;
}

if (iter.filename.toLowerCase().match(/\.disabled$/)) {
if (/\.disabled$/i.test(iter.filename)) {
logger.warn(iter.meta.name, "was disabled by directory suffix");
return false;
}
Expand Down Expand Up @@ -173,7 +173,7 @@ const action = async ({ logger, options, args }) => {
});

packages.forEach((pkg) => {
const type = pkg.filename.match(/node_modules/) ? "npm" : "local";
const type = /node_modules/.test(pkg.filename) ? "npm" : "local";
const method = copyFiles ? "copy" : "symlink";
logger.log(`- ${pkg.json.name} as ${pkg.meta.name} [${method}, ${type}]`);
});
Expand Down
2 changes: 1 addition & 1 deletion development/cli/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const loadTasks = async (defaults, includes, options) => {
};

const createOptions = (options) => ({
production: Boolean((process.env.NODE_ENV || "development").match(/^prod/)),
production: /^prod/i.test(process.env.NODE_ENV || "development"),
cli: createPath(options.root, "src/cli"),
npm: createPath(options.root, "package.json"),
packages: createPath(options.root, "packages.json"),
Expand Down
2 changes: 1 addition & 1 deletion frontend/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meese-os/client",
"version": "1.0.7",
"version": "1.0.8",
"description": "meeseOS client",
"scripts": {
"test": "npm run eslint && npm run stylelint && npm run jest",
Expand Down
2 changes: 1 addition & 1 deletion frontend/client/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const createUri = (str) =>

const pathname = createUri(window.location.pathname);
const href = createUri(window.location.href);
const development = !(process.env.NODE_ENV || "").match(/^prod/i);
const development = !/^prod/i.test(process.env.NODE_ENV || "");

export const defaultConfiguration = {
development: development,
Expand Down
4 changes: 2 additions & 2 deletions frontend/client/src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default class Core extends CoreBase {
this.options.classNames.forEach((n) => this.$root.classList.add(n));

const { uri } = this.configuration.ws;
if (!uri.match(/^wss?:/)) {
if (!/^wss?:/.test(uri)) {
const { protocol, host } = window.location;

this.configuration.ws.uri =
Expand Down Expand Up @@ -485,7 +485,7 @@ export default class Core extends CoreBase {
);
}

if (!url.match(/^((http|ws|ftp)s?:)/i)) {
if (!/^((http|ws|ftp)s?:)/i.test(url)) {
url = this.url(url);

options = merge(
Expand Down
2 changes: 1 addition & 1 deletion frontend/client/src/providers/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ export default class CoreServiceProvider extends ServiceProvider {
resource: soundResource,
play: (src, options = {}) => {
if (soundsEnabled()) {
const absoluteSrc = src.match(/^(\/|https?:)/)
const absoluteSrc = /^(\/|https?:)/.test(src)
? src
: soundResource(src);

Expand Down
4 changes: 2 additions & 2 deletions frontend/client/src/utils/desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const createStaticBackground = (core, background) => {
styles.backgroundImage = `url(${getRandomWallpaper()})`;
} else if (background.src === undefined) {
styles.backgroundImage = undefined;
} else if (background.src.match(/^meeseOS:/)) {
} else if (/^meeseOS:/.test(background.src)) {
core
.make("meeseOS/vfs")
.url(background.src)
Expand Down Expand Up @@ -242,7 +242,7 @@ export const resourceResolver = (core) => {
const getSoundThemeName = () => getThemeName("sounds");

const soundResource = (path) => {
if (!path.match(/\.([a-z]+)$/)) {
if (!/\.([a-z]+)$/i.test(path)) {
const defaultExtension = "mp3";
const checkExtensions = ["oga", "mp3"];
const found = checkExtensions.find((str) => media.audio[str] === true);
Expand Down
10 changes: 5 additions & 5 deletions frontend/client/src/utils/preloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ import logger from "../logger";
*/

/**
* The Preloader loads styles and scripts
* The Preloader loads styles and scripts.
*/
export default class Preloader {
constructor(root) {
/**
* A list of cached preloads
* A list of cached preloads.
* @type {String[]}
*/
this.loaded = [];
Expand All @@ -71,7 +71,7 @@ export default class Preloader {
}

/**
* Loads all resources required for a package
* Loads all resources required for a package.
* @param {String[]} list A list of resources
* @param {Boolean} [force=false] Force loading even though previously cached
* @returns {Promise<PreloaderResult>} A list of failed resources
Expand All @@ -85,7 +85,7 @@ export default class Preloader {
.map((entry) => {
logger.debug("Packages::preload()", entry);

const p = entry.match(/\.js$/)
const p = /\.js$/.test(entry)
? script(this.$root, entry)
: style(this.$root, entry);

Expand All @@ -98,7 +98,7 @@ export default class Preloader {
}

/**
* Checks the loaded list
* Checks the loaded list.
* @private
* @param {Object[]} results Preload results
* @param {String[]} cached Already cached preloads
Expand Down
2 changes: 1 addition & 1 deletion frontend/client/src/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const urlResolver = (configuration) => {
return (endpoint = "/", options = {}, metadata = {}) => {
if (typeof endpoint !== "string") {
return http.public;
} else if (endpoint.match(/^(http|ws|ftp)s?:/i)) {
} else if (/^(http|ws|ftp)s?:/i.test(endpoint)) {
return endpoint;
}

Expand Down
42 changes: 21 additions & 21 deletions frontend/client/src/utils/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const ONTOP_ZINDEX = 8388635;
const BOTTOM_ZINDEX = 10;

/**
* Creates window attributes from an object
* Creates window attributes from an object.
* @param {Object} attrs
*/
export const createAttributes = (attrs) => ({
Expand Down Expand Up @@ -77,7 +77,7 @@ export const createAttributes = (attrs) => ({
});

/**
* Creates window state from an object
* Creates window state from an object.
* @param {WindowState} state
* @param {Object} options
* @param {WindowAttributes} attrs
Expand Down Expand Up @@ -108,7 +108,7 @@ export const createState = (state, options, attrs) => ({
});

/**
* Creates data attributes for window DOM
* Creates data attributes for window DOM.
* @param {String} id
* @param {WindowState} state
* @param {WindowAttributes} attributes
Expand All @@ -132,7 +132,7 @@ export const createDOMAttributes = (id, state, attributes) => ({
});

/**
* Creates styles for window DOM
* Creates styles for window DOM.
* @param {WindowState} state
* @param {WindowAttributes} attributes
* @returns {Object}
Expand All @@ -150,7 +150,7 @@ export const createDOMStyles = (
});

/**
* Clamps position to viewport
* Clamps position to viewport.
* @param {Object} rect
*/
export const clampPosition = (rect, { dimension, position }) => {
Expand All @@ -168,7 +168,7 @@ export const clampPosition = (rect, { dimension, position }) => {
};

/**
* Window rendering callback function
* Window rendering callback function.
* @param {Window} win Window reference
* @param {Function} callback
*/
Expand All @@ -195,7 +195,7 @@ export const renderCallback = (win, callback) => {
};

/**
* Gets new position based on "gravity"
* Gets new position based on "gravity".
* @param {Window} win Window reference
* @param {Object} rect
* @param {String} gravity
Expand All @@ -210,21 +210,21 @@ export const positionFromGravity = (win, rect, gravity) => {
const hasVertical = gravity.match(/top|bottom/);
const hasHorizontal = gravity.match(/left|rigth/);

if (gravity.match(/top/)) {
if (/top/.test(gravity)) {
top = rect.top;
} else if (gravity.match(/bottom/)) {
} else if (/bottom/.test(gravity)) {
top = rect.height - win.state.dimension.height + rect.top;
}

if (gravity.match(/left/)) {
if (/left/.test(gravity)) {
left = rect.left;
} else if (gravity.match(/right/)) {
} else if (/right/.test(gravity)) {
left = rect.width - win.state.dimension.width;
}

if (!hasVertical && gravity.match(/center/)) {
if (!hasVertical && /center/.test(gravity)) {
top = rect.height / 2 - win.state.dimension.height / 2;
} else if (!hasHorizontal && gravity.match(/center/)) {
} else if (!hasHorizontal && /center/.test(gravity)) {
left = rect.width / 2 - win.state.dimension.width / 2;
}
}
Expand All @@ -233,7 +233,7 @@ export const positionFromGravity = (win, rect, gravity) => {
};

/**
* Gets new dimension based on container
* Gets new dimension based on container.
* @param {Window} win Window reference
* @param {Object} rect
* @param {HTMLElement} container
Expand Down Expand Up @@ -277,7 +277,7 @@ export const dimensionFromElement = (win, rect, container) => {
};

/**
* Transforms vector values (ex. float to integer)
* Transforms vector values (ex. float to integer).
* @param {Object} rect
*/
export const transformVectors = (rect, { width, height }, { top, left }) => {
Expand All @@ -304,7 +304,7 @@ export const transformVectors = (rect, { width, height }, { top, left }) => {
};

/**
* Creates a clamper for resize/move
* Creates a clamper for resize/move.
* @param {Window} win Window reference
*/
const clamper = (win) => {
Expand All @@ -330,7 +330,7 @@ const clamper = (win) => {
};

/**
* Creates a resize handler
* Creates a resize handler.
* @param {Window} win Window reference
*/
export const resizer = (win, handle) => {
Expand All @@ -352,7 +352,7 @@ export const resizer = (win, handle) => {
};

/**
* Creates a movement handler
* Creates a movement handler.
* @param {Window} win Window reference
*/
export const mover = (win, rect) => {
Expand All @@ -367,7 +367,7 @@ export const mover = (win, rect) => {
};

/**
* Calculates a new initial position for window
* Calculates a new initial position for window.
* @param {Window} win Window reference
* @param {Object} rect
*/
Expand Down Expand Up @@ -395,7 +395,7 @@ const getScreenOrientation = (screen) =>
: "landscape";

/**
* Gets a media query name from a map
* Gets a media query name from a map.
* @param {Window} win Window reference
* @returns {String}
*/
Expand All @@ -412,7 +412,7 @@ export const getMediaQueryName = (win) =>
.pop();

/**
* Loads [certain] window options from configuration
* Loads [certain] window options from configuration.
*/
export const loadOptionsFromConfig = (config, appName, windowId) => {
const matchStringOrRegex = (str, matcher) =>
Expand Down
2 changes: 1 addition & 1 deletion frontend/panels/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meese-os/panels",
"version": "1.0.4",
"version": "1.0.5",
"description": "meeseOS Panels",
"scripts": {
"test": "npm run eslint && npm run stylelint",
Expand Down
2 changes: 1 addition & 1 deletion frontend/panels/src/items/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const makeTree = (core, icon) => {

const getIcon = (m, fallbackIcon) =>
m.icon
? m.icon.match(/^(https?:)\//)
? /^(https?:)\//.test(m.icon)
? m.icon
: core.url(m.icon, {}, m)
: fallbackIcon;
Expand Down

0 comments on commit ca34729

Please sign in to comment.