Skip to content

Commit bb5dea4

Browse files
author
Marc Lipovsky
authored
Merge pull request #62 from marclipovsky/feature/reorg
Refactor: Reorganize commands into separate files and update README
2 parents bc0cc8b + 3f13004 commit bb5dea4

13 files changed

+410
-278
lines changed

README.md

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,43 @@ as multiple selections.
77

88
Current string functions available:
99

10-
1. camelize
11-
1. capitalize
12-
1. classify
13-
1. chop - split into groups provided n # of characters
14-
1. clean
15-
1. clean diacritics
16-
1. dasherize
17-
1. decapitalize
18-
1. humanize
19-
1. reverse
20-
1. screaming snake
21-
1. sentence
22-
1. slugify
23-
1. snake
24-
1. underscore
25-
1. swap case
26-
1. titleize
27-
1. titleize (AP Style)
28-
1. titleize (Chicago Style)
10+
1. camelize - converts hyphenated strings to camelCase
11+
1. capitalize - capitalizes the first character of each selection
12+
1. classify - converts underscored text to PascalCase
13+
1. chop - splits into groups provided n # of characters
14+
1. clean - collapses multiple spaces into one
15+
1. clean diacritics - removes diacritic marks from characters
16+
1. dasherize - converts camelCase to kebab-case
17+
1. decapitalize - lowercases the first character of each selection
18+
1. humanize - converts text to human-readable form
19+
1. reverse - reverses the characters in the selection
20+
1. screaming snake - converts text to SCREAMING_SNAKE_CASE
21+
1. sentence - transforms text to sentence case
22+
1. slugify - converts text to a URL-friendly slug
23+
1. snake - converts text to snake_case
24+
1. swap case - inverts the case of each character
25+
1. titleize - capitalizes the first letter of each word
26+
1. titleize (AP Style) - capitalizes titles according to AP style
27+
1. titleize (Chicago Style) - capitalizes titles according to Chicago style
2928
1. truncate - trims string to n # of characters and appends ellipsis
3029
1. prune - truncate but keeps ellipsis within character count provided
31-
1. repeat - repeat selection n #of times
32-
1. convert between unicode and readable characters.
30+
1. repeat - repeat selection n # of times
31+
1. random case - randomly changes the case of characters
32+
1. swap quotes - swaps between single and double quotes
33+
1. utf8ToChar - converts Unicode escapes to characters
34+
1. charToUtf8 - converts characters to Unicode escapes
3335

3436
Number related functions:
3537

36-
1. increment all numbers in selection
37-
1. decrement all numbers in selection
38-
1. duplicate selection and increment all number
39-
1. duplicate selection and decrement all number
40-
1. sequence all numbers in selection from first number
38+
1. increment - increases all numbers in the selection by 1
39+
1. decrement - decreases all numbers in the selection by 1
40+
1. duplicate and increment - duplicates selection and increments all numbers
41+
1. duplicate and decrement - duplicates selection and decrements all numbers
42+
1. sequence - replaces numbers with a sequence starting from the first number
43+
44+
Additional utility commands:
45+
46+
1. repeat last action - repeats the last string manipulation command that was executed
4147

4248
## Use
4349

@@ -49,7 +55,7 @@ To use these commands, press ⌘+p and enter any of the commands above while tex
4955

5056
Introducing String Manipulation Labs
5157

52-
Were excited to announce the launch of String Manipulation Labs—a collection of (really just one at this moment) experimental features designed to enhance and expand the capabilities of the String Manipulation extension. Labs features are disabled by default to ensure a stable experience with the core functionalities.
58+
We're excited to announce the launch of String Manipulation Labs—a collection of (really just one at this moment) experimental features designed to enhance and expand the capabilities of the String Manipulation extension. Labs features are disabled by default to ensure a stable experience with the core functionalities.
5359

5460
### 🚀 How to Enable Labs Features
5561

src/commands.ts

Lines changed: 0 additions & 249 deletions
This file was deleted.

src/commands/default-functions.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as underscore from "underscore.string";
2+
import { CommandFunction } from "./types";
3+
4+
export const defaultFunction =
5+
(commandName: string, option?: any) => (str: string) =>
6+
(underscore as any)[commandName](str, option);
7+
8+
export const snake = (str: string) =>
9+
underscore
10+
.underscored(str)
11+
.replace(/([A-Z])[^A-Z]/g, " $1")
12+
.replace(/[^a-z0-9]+/gi, " ")
13+
.trim()
14+
.replace(/\s/gi, "_");
15+
16+
export const screamingSnake: CommandFunction = (str: string) =>
17+
snake(str).toUpperCase();
18+
19+
export const camelize: CommandFunction = (str: string) =>
20+
underscore.camelize(/[a-z]/.test(str) ? str : str.toLowerCase());
21+
22+
// Default functions
23+
export const titleize: CommandFunction = defaultFunction("titleize");
24+
export const classify: CommandFunction = defaultFunction("classify");
25+
export const clean: CommandFunction = defaultFunction("clean");
26+
export const cleanDiacritics: CommandFunction =
27+
defaultFunction("cleanDiacritics");
28+
export const dasherize: CommandFunction = defaultFunction("dasherize");
29+
export const humanize: CommandFunction = defaultFunction("humanize");
30+
export const reverse: CommandFunction = defaultFunction("reverse");
31+
export const decapitalize: CommandFunction = defaultFunction("decapitalize");
32+
export const capitalize: CommandFunction = defaultFunction("capitalize");
33+
export const sentence: CommandFunction = defaultFunction("capitalize", true);
34+
export const swapCase: CommandFunction = defaultFunction("swapCase");
35+
36+
// Functions with arguments
37+
export const chop: CommandFunction = (n: number) => defaultFunction("chop", n);
38+
export const truncate: CommandFunction = (n: number) =>
39+
defaultFunction("truncate", n);
40+
export const prune: CommandFunction = (n: number) => (str: string) =>
41+
str.slice(0, n - 3).trim() + "...";
42+
export const repeat: CommandFunction = (n: number) =>
43+
defaultFunction("repeat", n);

0 commit comments

Comments
 (0)