Skip to content

Commit

Permalink
Add Capital Case and path/case
Browse files Browse the repository at this point in the history
  • Loading branch information
wsbak committed Mar 9, 2024
1 parent 025bc1e commit 7a260ef
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
## 0.0.5

- feat: can select multiple cases.
- feat: add Capital Case.
- feat: add path/case.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The extension based on native search component. It is used to search for multipl
* PascalCase
* snake_case
* UPPER_SNAKE_CASE
* Capital Case
* path/case

If no case is specified, it defaults to **all cases**.

Expand Down
26 changes: 19 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { commands, QuickPickItem, window } from "vscode";
import type { ExtensionContext } from "vscode";
import { paramCase, pascalCase, constantCase, snakeCase, camelCase } from "change-case";
import { paramCase, camelCase, pascalCase, snakeCase, constantCase, capitalCase, pathCase } from "change-case";


const kebabCaseQPI: QuickPickItem = { label: "kebab-case", alwaysShow: true, };
const camelCaseQPI: QuickPickItem = { label: "camelCase", alwaysShow: true, };
const pascalCaseQPI: QuickPickItem = { label: "PascalCase", alwaysShow: true, };
const snakeCaseQPI: QuickPickItem = { label: "snake_case", alwaysShow: true, };
const snakeUpperCaseQPI: QuickPickItem = { label: "UPPER_SNAKE_CASE", alwaysShow: true, };
const quickPickItems: QuickPickItem[] = [ kebabCaseQPI, camelCaseQPI, pascalCaseQPI, snakeCaseQPI, snakeUpperCaseQPI ];
const kebabCaseQPI: QuickPickItem = { label: "kebab-case", alwaysShow: true, };
const camelCaseQPI: QuickPickItem = { label: "camelCase", alwaysShow: true, };
const pascalCaseQPI: QuickPickItem = { label: "PascalCase", alwaysShow: true, };
const snakeCaseQPI: QuickPickItem = { label: "snake_case", alwaysShow: true, };
const snakeUpperCaseQPI: QuickPickItem = { label: "UPPER_SNAKE_CASE", alwaysShow: true, };
const capitalCaseQPI: QuickPickItem = { label: "Capital Case", alwaysShow: true, };
const pathCaseQPI: QuickPickItem = { label: "path/case", alwaysShow: true, };
const quickPickItems: QuickPickItem[] = [ kebabCaseQPI,
camelCaseQPI, pascalCaseQPI,
snakeCaseQPI, snakeUpperCaseQPI,
capitalCaseQPI,
pathCaseQPI ];

function transformQuery2RegExp(query: string, scope: string) {
switch(scope) {
Expand All @@ -22,6 +28,10 @@ function transformQuery2RegExp(query: string, scope: string) {
return snakeCase(query);
case "UPPER_SNAKE_CASE":
return constantCase(query);
case "Capital Case":
return capitalCase(query);
case "path/case":
return pathCase(query);
}
}

Expand Down Expand Up @@ -103,6 +113,8 @@ export const exportedForTesting = {
pascalCaseQPI,
snakeCaseQPI,
snakeUpperCaseQPI,
capitalCaseQPI,
pathCaseQPI,
transformQuery2RegExp,
buildRegexQuery,
};
12 changes: 11 additions & 1 deletion src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as vscode from 'vscode';

import { exportedForTesting } from '../../extension';
const { kebabCaseQPI, camelCaseQPI, pascalCaseQPI, snakeCaseQPI, snakeUpperCaseQPI } = exportedForTesting;
const { transformQuery2RegExp, buildRegexQuery } = exportedForTesting;
const { capitalCaseQPI, pathCaseQPI } = exportedForTesting;
const { transformQuery2RegExp, buildRegexQuery } = exportedForTesting;


suite('Extension Test Suite', () => {
Expand All @@ -20,6 +21,10 @@ suite('Extension Test Suite', () => {
assert.strictEqual("one_two_three_four", transformQuery2RegExp("one two_three-Four", "snake_case"));
assert.strictEqual("ONE_TWO_THREE_FOUR", transformQuery2RegExp("oneTwoThreeFour", "UPPER_SNAKE_CASE"));
assert.strictEqual("ONE_TWO_THREE_FOUR", transformQuery2RegExp("one two_three-Four", "UPPER_SNAKE_CASE"));
assert.strictEqual("One Two Three Four", transformQuery2RegExp("oneTwoThreeFour", "Capital Case"));
assert.strictEqual("One Two Three Four", transformQuery2RegExp("one two_three-Four", "Capital Case"));
assert.strictEqual("one/two/three/four", transformQuery2RegExp("oneTwoThreeFour", "path/case"));
assert.strictEqual("one/two/three/four", transformQuery2RegExp("one two_three-Four", "path/case"));
});

test('buildRegexQuery', () => {
Expand All @@ -32,10 +37,15 @@ suite('Extension Test Suite', () => {
assert.strictEqual("OneTwoThreeFour", buildRegexQuery(query, [pascalCaseQPI]));
assert.strictEqual("one_two_three_four", buildRegexQuery(query, [snakeCaseQPI]));
assert.strictEqual("ONE_TWO_THREE_FOUR", buildRegexQuery(query, [snakeUpperCaseQPI]));
assert.strictEqual("One Two Three Four", buildRegexQuery(query, [capitalCaseQPI]));
assert.strictEqual("one/two/three/four", buildRegexQuery(query, [pathCaseQPI]));

assert.strictEqual("one-two-three-four|oneTwoThreeFour",
buildRegexQuery(query, [kebabCaseQPI, camelCaseQPI]));

assert.strictEqual("oneTwoThreeFour|One Two Three Four",
buildRegexQuery(query, [camelCaseQPI, capitalCaseQPI]));

assert.strictEqual("OneTwoThreeFour|one_two_three_four|ONE_TWO_THREE_FOUR",
buildRegexQuery(query, [pascalCaseQPI, snakeCaseQPI, snakeUpperCaseQPI]));

Expand Down

0 comments on commit 7a260ef

Please sign in to comment.