feat(#197): prettier formatting on all files in packages/bruno-app

This commit is contained in:
Anoop M D
2023-09-18 13:37:00 +05:30
parent a103f41d85
commit 19a7f397bb
117 changed files with 1249 additions and 854 deletions

View File

@@ -1,4 +1,3 @@
let CodeMirror;
const SERVER_RENDERED = typeof navigator === 'undefined' || global['PREVENT_CODEMIRROR_RENDER'] === true;
@@ -7,29 +6,29 @@ if (!SERVER_RENDERED) {
}
export const defineCodeMirrorBrunoVariablesMode = (variables, mode) => {
CodeMirror.defineMode("brunovariables", function(config, parserConfig) {
CodeMirror.defineMode('brunovariables', function (config, parserConfig) {
let variablesOverlay = {
token: function(stream, state) {
if (stream.match("{{", true)) {
token: function (stream, state) {
if (stream.match('{{', true)) {
let ch;
let word = "";
let word = '';
while ((ch = stream.next()) != null) {
if (ch == "}" && stream.next() == "}") {
stream.eat("}");
if (ch == '}' && stream.next() == '}') {
stream.eat('}');
if (word in variables) {
return "variable-valid";
return 'variable-valid';
} else {
return "variable-invalid";
return 'variable-invalid';
}
}
word += ch;
}
}
while (stream.next() != null && !stream.match("{{", false)) {}
while (stream.next() != null && !stream.match('{{', false)) {}
return null;
}
};
return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || mode), variablesOverlay);
});
};
};

View File

@@ -26,7 +26,7 @@ export const waitForNextTick = () => {
};
export const safeParseJSON = (str) => {
if(!str || !str.length || typeof str !== 'string') {
if (!str || !str.length || typeof str !== 'string') {
return str;
}
try {
@@ -36,19 +36,19 @@ export const safeParseJSON = (str) => {
}
};
export const safeStringifyJSON = (obj, indent=false) => {
if(!obj) {
export const safeStringifyJSON = (obj, indent = false) => {
if (!obj) {
return obj;
}
try {
if(indent) {
if (indent) {
return JSON.stringify(obj, null, 2);
}
return JSON.stringify(obj);
} catch (e) {
return obj;
}
}
};
// Remove any characters that are not alphanumeric, spaces, hyphens, or underscores
export const normalizeFileName = (name) => {
@@ -60,4 +60,4 @@ export const normalizeFileName = (name) => {
const formattedName = name.replace(validChars, '-');
return formattedName;
}
};

View File

@@ -1,19 +1,19 @@
const { describe, it, expect } = require("@jest/globals");
const { describe, it, expect } = require('@jest/globals');
import { normalizeFileName } from './index';
describe("common utils", () => {
describe("normalizeFileName", () => {
it("should remove special characters", () => {
expect(normalizeFileName("hello world")).toBe("hello world");
expect(normalizeFileName("hello-world")).toBe("hello-world");
expect(normalizeFileName("hello_world")).toBe("hello_world");
expect(normalizeFileName("hello_world-")).toBe("hello_world-");
expect(normalizeFileName("hello_world-123")).toBe("hello_world-123");
expect(normalizeFileName("hello_world-123!@#$%^&*()")).toBe("hello_world-123----------");
expect(normalizeFileName("hello_world?")).toBe("hello_world-");
expect(normalizeFileName("foo/bar/")).toBe("foo-bar-");
expect(normalizeFileName("foo\\bar\\")).toBe("foo-bar-");
describe('common utils', () => {
describe('normalizeFileName', () => {
it('should remove special characters', () => {
expect(normalizeFileName('hello world')).toBe('hello world');
expect(normalizeFileName('hello-world')).toBe('hello-world');
expect(normalizeFileName('hello_world')).toBe('hello_world');
expect(normalizeFileName('hello_world-')).toBe('hello_world-');
expect(normalizeFileName('hello_world-123')).toBe('hello_world-123');
expect(normalizeFileName('hello_world-123!@#$%^&*()')).toBe('hello_world-123----------');
expect(normalizeFileName('hello_world?')).toBe('hello_world-');
expect(normalizeFileName('foo/bar/')).toBe('foo-bar-');
expect(normalizeFileName('foo\\bar\\')).toBe('foo-bar-');
});
});
});
});

View File

@@ -1,6 +1,6 @@
import trim from 'lodash/trim';
import path from 'path';
import slash from './slash';
import slash from './slash';
export const isElectron = () => {
if (!window) {
@@ -32,4 +32,4 @@ export const getDirectoryName = (pathname) => {
pathname = slash(pathname);
return path.dirname(pathname);
}
};

View File

@@ -1,6 +1,6 @@
/**
* MIT License
*
*
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@@ -8,13 +8,13 @@
*/
const slash = (path) => {
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
if (isExtendedLengthPath) {
return path;
}
if (isExtendedLengthPath) {
return path;
}
return path.replace(/\\/g, '/');
}
return path.replace(/\\/g, '/');
};
export default slash;