Search Google

This commit is contained in:
Mike Phares 2021-10-20 09:10:06 -07:00
parent 9efe4e506b
commit b7453ff4f1
5 changed files with 88 additions and 73 deletions

Binary file not shown.

View File

@ -4,7 +4,7 @@
"description": "Helper for VS Code in TypeScript", "description": "Helper for VS Code in TypeScript",
"publisher": "IFX", "publisher": "IFX",
"repository": "https://github.com/mikepharesjr/YO-VSCode/tree/master/type-script-helper", "repository": "https://github.com/mikepharesjr/YO-VSCode/tree/master/type-script-helper",
"version": "1.2.3", "version": "1.2.4",
"engines": { "engines": {
"vscode": "^1.40.0" "vscode": "^1.40.0"
}, },
@ -22,6 +22,7 @@
"onCommand:helper.listToListWrappedComma", "onCommand:helper.listToListWrappedComma",
"onCommand:helper.prettySql", "onCommand:helper.prettySql",
"onCommand:helper.removeComment", "onCommand:helper.removeComment",
"onCommand:helper.searchGoogle",
"onCommand:helper.sortLength", "onCommand:helper.sortLength",
"onCommand:helper.sortNormal", "onCommand:helper.sortNormal",
"onCommand:helper.unwrapSql", "onCommand:helper.unwrapSql",
@ -39,6 +40,7 @@
{ "command": "helper.listToListWrappedComma", "title": "List to list wrapped comma" }, { "command": "helper.listToListWrappedComma", "title": "List to list wrapped comma" },
{ "command": "helper.prettySql", "title": "Pretty Sql" }, { "command": "helper.prettySql", "title": "Pretty Sql" },
{ "command": "helper.removeComment", "title": "Remove comment" }, { "command": "helper.removeComment", "title": "Remove comment" },
{ "command": "helper.searchGoogle", "title": "Search Google" },
{ "command": "helper.sortLength", "title": "Sort by Length" }, { "command": "helper.sortLength", "title": "Sort by Length" },
{ "command": "helper.sortNormal", "title": "My Sort lines (ascending, case sensitive)" }, { "command": "helper.sortNormal", "title": "My Sort lines (ascending, case sensitive)" },
{ "command": "helper.unwrapSql", "title": "Un-wrap Sql" }, { "command": "helper.unwrapSql", "title": "Un-wrap Sql" },

View File

@ -34,6 +34,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('helper.listToListWrappedComma', helper.listToListWrappedComma), vscode.commands.registerCommand('helper.listToListWrappedComma', helper.listToListWrappedComma),
vscode.commands.registerCommand('helper.prettySql', helper.prettySql), vscode.commands.registerCommand('helper.prettySql', helper.prettySql),
vscode.commands.registerCommand('helper.removeComment', helper.removeComment), vscode.commands.registerCommand('helper.removeComment', helper.removeComment),
vscode.commands.registerCommand('helper.searchGoogle', helper.searchGoogle),
vscode.commands.registerCommand('helper.sortLength', helper.sortLength), vscode.commands.registerCommand('helper.sortLength', helper.sortLength),
vscode.commands.registerCommand('helper.sortNormal', helper.sortNormal), vscode.commands.registerCommand('helper.sortNormal', helper.sortNormal),
vscode.commands.registerCommand('helper.unwrapSql', helper.unwrapSql), vscode.commands.registerCommand('helper.unwrapSql', helper.unwrapSql),

View File

@ -15,6 +15,7 @@ enum LinesAction {
prettySql, prettySql,
pdsfToFixedWidth, pdsfToFixedWidth,
removeComment, removeComment,
searchGoogle,
sortLength, sortLength,
sortNormal, sortNormal,
unwrapSql, unwrapSql,
@ -148,15 +149,23 @@ function prettySqlLogic(lines: string[]): void {
function removeCommentLogic(lines: string[]): void { function removeCommentLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) { for (let i = 0; i < lines.length; ++i) {
lines[i] = lines[i].trim(); lines[i] = lines[i].trim();
if(lines[i].length > 1 && lines[i][0] === '/' && lines[i][1] === '/') { if (lines[i].length > 1 && lines[i][0] === '/' && lines[i][1] === '/') {
lines[i] = lines[i].substr(2); lines[i] = lines[i].substr(2);
} }
if(lines[i].length > 0 && lines[i][0] === "'") { if (lines[i].length > 0 && lines[i][0] === "'") {
lines[i] = lines[i].substr(1); lines[i] = lines[i].substr(1);
} }
} }
} }
function searchGoogleLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) {
vscode.env.openExternal(
vscode.Uri.parse(`https://www.google.com/search?q=${lines[i]}`)
)
}
}
function makeSorter(algorithm?: SortingAlgorithm): ArrayTransformer { function makeSorter(algorithm?: SortingAlgorithm): ArrayTransformer {
return function (lines: string[]): string[] { return function (lines: string[]): string[] {
return lines.sort(algorithm); return lines.sort(algorithm);
@ -193,12 +202,12 @@ function unwrapSqlLogic(lines: string[]): void {
function wrapSqlCSharpLogic(lines: string[]): void { function wrapSqlCSharpLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) { for (let i = 0; i < lines.length; ++i) {
lines[i] = lines[i].trim(); lines[i] = lines[i].trim();
if(lines[i].length > 1 && lines[i][0] === '/' && lines[i][1] === '/') { if (lines[i].length > 1 && lines[i][0] === '/' && lines[i][1] === '/') {
lines[i] = lines[i].substr(2); lines[i] = lines[i].substr(2);
} }
lines[i] = 'Append(" ' + lines[i] + ' ").'; lines[i] = 'Append(" ' + lines[i] + ' ").';
} }
if(lines.length > 0) { if (lines.length > 0) {
lines[0] = 'sql.' + lines[0]; lines[0] = 'sql.' + lines[0];
lines[lines.length - 1] = lines[lines.length - 1].split(' ").').join(' ");'); lines[lines.length - 1] = lines[lines.length - 1].split(' ").').join(' ");');
} }
@ -207,18 +216,18 @@ function wrapSqlCSharpLogic(lines: string[]): void {
function wrapSqlVBLogic(lines: string[]): void { function wrapSqlVBLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) { for (let i = 0; i < lines.length; ++i) {
lines[i] = lines[i].trim(); lines[i] = lines[i].trim();
if(lines[i].length > 0 && lines[i][0] === "'") { if (lines[i].length > 0 && lines[i][0] === "'") {
lines[i] = lines[i].substr(1); lines[i] = lines[i].substr(1);
} }
lines[i] = 'Append(" ' + lines[i] + ' ").'; lines[i] = 'Append(" ' + lines[i] + ' ").';
} }
if(lines.length > 0) { if (lines.length > 0) {
lines[0] = 'sql.' + lines[0]; lines[0] = 'sql.' + lines[0];
} }
} }
function sortLengthLogic(lines: string[]): void { function sortLengthLogic(lines: string[]): void {
lines.sort(function(a, b) { lines.sort(function (a, b) {
// ASC -> a.length - b.length // ASC -> a.length - b.length
// DESC -> b.length - a.length // DESC -> b.length - a.length
return a.length - b.length || // sort by length, if equal then return a.length - b.length || // sort by length, if equal then
@ -229,7 +238,7 @@ function sortLengthLogic(lines: string[]): void {
function cutEachLineLogic(lines: string[]): void { function cutEachLineLogic(lines: string[]): void {
for (let i = 0; i < lines.length; ++i) { for (let i = 0; i < lines.length; ++i) {
if(lines[i].length > 0 && lines[i].indexOf("|||") > 0) { if (lines[i].length > 0 && lines[i].indexOf("|||") > 0) {
lines[i] = lines[i].substr(0, lines[i].indexOf("|||")); lines[i] = lines[i].substr(0, lines[i].indexOf("|||"));
} }
lines[i] = lines[i].trim(); lines[i] = lines[i].trim();
@ -267,6 +276,7 @@ function linesFunction(linesAction: LinesAction): Thenable<boolean> | undefined
case LinesAction.listToListWrappedComma: { listToListWrappedCommaLogic(lines); break; } case LinesAction.listToListWrappedComma: { listToListWrappedCommaLogic(lines); break; }
case LinesAction.prettySql: { prettySqlLogic(lines); break; } case LinesAction.prettySql: { prettySqlLogic(lines); break; }
case LinesAction.removeComment: { removeCommentLogic(lines); break; } case LinesAction.removeComment: { removeCommentLogic(lines); break; }
case LinesAction.searchGoogle: { searchGoogleLogic(lines); break; }
case LinesAction.sortLength: { sortLengthLogic(lines); break; } case LinesAction.sortLength: { sortLengthLogic(lines); break; }
case LinesAction.sortNormal: { sortNormalLogic(lines); break; } case LinesAction.sortNormal: { sortNormalLogic(lines); break; }
case LinesAction.unwrapSql: { unwrapSqlLogic(lines); break; } case LinesAction.unwrapSql: { unwrapSqlLogic(lines); break; }
@ -287,6 +297,7 @@ export const listToListWrappedComma = () => linesFunction(LinesAction.listToList
export const prettySql = () => linesFunction(LinesAction.prettySql); export const prettySql = () => linesFunction(LinesAction.prettySql);
export const pdsfToFixedWidth = () => linesFunction(LinesAction.pdsfToFixedWidth); export const pdsfToFixedWidth = () => linesFunction(LinesAction.pdsfToFixedWidth);
export const removeComment = () => linesFunction(LinesAction.removeComment); export const removeComment = () => linesFunction(LinesAction.removeComment);
export const searchGoogle = () => linesFunction(LinesAction.searchGoogle);
export const sortLength = () => linesFunction(LinesAction.sortLength); export const sortLength = () => linesFunction(LinesAction.sortLength);
export const sortNormal = () => linesFunction(LinesAction.sortNormal); export const sortNormal = () => linesFunction(LinesAction.sortNormal);
export const unwrapSql = () => linesFunction(LinesAction.unwrapSql); export const unwrapSql = () => linesFunction(LinesAction.unwrapSql);

View File

@ -8,6 +8,7 @@
], ],
"sourceMap": true, "sourceMap": true,
"rootDir": "src", "rootDir": "src",
"resolveJsonModule": true,
"strict": true /* enable all strict type-checking options */ "strict": true /* enable all strict type-checking options */
/* Additional Checks */ /* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */