Skip to content

Commit 4c171e4

Browse files
Add swap case and tests cases
1 parent d59d24b commit 4c171e4

File tree

4 files changed

+243
-64
lines changed

4 files changed

+243
-64
lines changed

content.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,11 @@ abc中文💖
4343
Hello, World!
4444
12345!@#$%
4545
Test123!
46+
'She said, "Hello"'
47+
"My name's Minalike"
48+
"He said, 'It's a trap!'"
49+
'She exclaimed, \"Wow!\"'
50+
"'Double' and 'single' quotes"
51+
No quotes at all
52+
'It's'
53+
"My name's %20 Minalike!"

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@
194194
"title": "Random Case",
195195
"category": "String Manipulation",
196196
"command": "string-manipulation.randomCase"
197+
},
198+
{
199+
"title": "Swap Quotes",
200+
"category": "String Manipulation",
201+
"command": "string-manipulation.swapQuotes"
197202
}
198203
],
199204
"submenus": [
@@ -329,6 +334,10 @@
329334
{
330335
"command": "string-manipulation.randomCase",
331336
"group": "7_modification"
337+
},
338+
{
339+
"command": "string-manipulation.swapQuotes",
340+
"group": "7_modification"
332341
}
333342
]
334343
}

src/commands.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import * as underscore from "underscore.string";
3+
import { swapQuotes } from "./commands/swap_quotes";
34
const apStyleTitleCase = require("ap-style-title-case");
45
const chicagoStyleTitleCase = require("chicago-capitalize");
56
const slugify = require("@sindresorhus/slugify");
@@ -39,6 +40,14 @@ const randomCase = (input: string): string => {
3940
return result;
4041
};
4142

43+
const snake = (str: string) =>
44+
underscore
45+
.underscored(str)
46+
.replace(/([A-Z])[^A-Z]/g, " $1")
47+
.replace(/[^a-z0-9]+/gi, " ")
48+
.trim()
49+
.replace(/\s/gi, "_");
50+
4251
export type StringFunction = (
4352
str: string,
4453
multiselectData?: MultiSelectData
@@ -53,7 +62,7 @@ const commandNameFunctionMap: { [key: string]: CommandFunction } = {
5362
classify: defaultFunction("classify"),
5463
clean: defaultFunction("clean"),
5564
cleanDiacritics: defaultFunction("cleanDiacritics"),
56-
underscored: defaultFunction("underscored"),
65+
underscored: snake,
5766
dasherize: defaultFunction("dasherize"),
5867
humanize: defaultFunction("humanize"),
5968
reverse: defaultFunction("reverse"),
@@ -64,21 +73,8 @@ const commandNameFunctionMap: { [key: string]: CommandFunction } = {
6473
underscore.camelize(/[a-z]/.test(str) ? str : str.toLowerCase()),
6574
slugify: slugify,
6675
swapCase: defaultFunction("swapCase"),
67-
snake: (str: string) =>
68-
underscore
69-
.underscored(str)
70-
.replace(/([A-Z])[^A-Z]/g, " $1")
71-
.replace(/[^a-z]+/gi, " ")
72-
.trim()
73-
.replace(/\s/gi, "_"),
74-
screamingSnake: (str: string) =>
75-
underscore
76-
.underscored(str)
77-
.replace(/([A-Z])[^A-Z]/g, " $1")
78-
.replace(/[^a-z]+/gi, " ")
79-
.trim()
80-
.replace(/\s/gi, "_")
81-
.toUpperCase(),
76+
snake,
77+
screamingSnake: (str: string) => snake(str).toUpperCase(),
8278
titleizeApStyle: apStyleTitleCase,
8379
titleizeChicagoStyle: chicagoStyleTitleCase,
8480
truncate: (n: number) => defaultFunction("truncate", n),
@@ -101,6 +97,7 @@ const commandNameFunctionMap: { [key: string]: CommandFunction } = {
10197
.map((x) => `\\u${x.charCodeAt(0).toString(16).padStart(4, "0")}`)
10298
.join(""),
10399
randomCase,
100+
swapQuotes,
104101
};
105102

106103
const numberFunctionNames = [

0 commit comments

Comments
 (0)