Skip to content

add title to dot case #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ function activate(context) {
utils.applyToAllSelections(operations.titleToKebab);
})

let titleToDotDisposable = vscode.commands.registerCommand('extension.titleToDot', function() {
utils.applyToAllSelections(operations.titleToDot);
})

let snakeToCamelDisposable = vscode.commands.registerCommand('extension.snakeToCamel', function() {
utils.applyToAllSelections(operations.snakeToCamel);
})
Expand Down Expand Up @@ -73,6 +77,7 @@ function activate(context) {
titleToCamelDisposable,
titleToSnakeDisposable,
titleToKebabDisposable,
titleToDotDisposable,
snakeToCamelDisposable,
snakeToTitleDisposable,
snakeToKebabDisposable,
Expand Down
5 changes: 5 additions & 0 deletions lib/stringOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ function titleToKebab(string) {
return string.trim().split(' ').map(substring => substring.toLowerCase()).join('-');
}

function titleToDot(string) {
return string.trim().split(' ').map(substring => substring.toLowerCase()).join('.');
}

function snakeToCamel(string) {
return string.trim().split('_').map((substring, index) => {
if (index === 0) {
Expand Down Expand Up @@ -114,6 +118,7 @@ module.exports = {
titleToCamel,
titleToSnake,
titleToKebab,
titleToDot,
snakeToCamel,
snakeToKebab,
snakeToTitle,
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"onCommand:extension.titleToCamel",
"onCommand:extension.titleToSnake",
"onCommand:extension.titleToKebab",
"onCommand:extension.titleToDot",
"onCommand:extension.toLower",
"onCommand:extension.toUpper"
],
Expand Down Expand Up @@ -72,6 +73,10 @@
"command": "extension.titleToKebab",
"title": "Title to Kebab"
},
{
"command": "extension.titleToDot",
"title": "Title to Dot"
},
{
"command": "extension.snakeToCamel",
"title": "Snake to Camel"
Expand Down
7 changes: 7 additions & 0 deletions test/suite/stringOperations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
titleToCamel,
titleToSnake,
titleToKebab,
titleToDot,
snakeToCamel,
snakeToKebab,
snakeToTitle,
Expand Down Expand Up @@ -72,6 +73,12 @@ suite('String Operations Suite', () => {
assert.strictEqual(titleToKebab(' Hello World '), 'hello-world');
})

test('Title to Dot test', () => {
assert.strictEqual(titleToKebab('My New String'), 'my.new.string');
assert.strictEqual(titleToKebab('Hello world'), 'hello.world');
assert.strictEqual(titleToKebab(' Hello World '), 'hello.world');
})

test('Snake to Camel test', () => {
assert.strictEqual(snakeToCamel('my_new_string'), 'myNewString');
assert.strictEqual(snakeToCamel('hello_world'), 'helloWorld');
Expand Down