Skip to content

Commit

Permalink
feat : transform text to numbered text
Browse files Browse the repository at this point in the history
  • Loading branch information
otnansirk committed Jul 4, 2024
1 parent 55981d4 commit 84584b8
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ Read on [this page](https://code.visualstudio.com/docs/getstarted/keybindings) t

- **screamKebabCase**: Convert text to `SCREAM-KEBAB-CASE`. The text is converted to uppercase letters, and the hyphen ("-") is used as a separator between words.

- **json2ArrayPHP**: Convert json to array PHP
- **json2ArrayPHP**: Convert json to array PHP.

- **arrayPHP2Json**: Convert array PHP to json
- **arrayPHP2Json**: Convert array PHP to json.

- **enterNumberByLines**: Transform the text to numbered text line by line.

These casing conventions provide flexible options to transform your text according to specific requirements.

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Casing Convention",
"description": "Transform your text with the power of casing convention.",
"publisher": "otnansirk",
"version": "1.1.2",
"version": "1.2.2",
"icon": "./assets/logo.png",
"license": "MIT",
"engines": {
Expand Down Expand Up @@ -175,6 +175,10 @@
{
"command": "casing-convention.arrayPHP2Json",
"title": "casing: array PHP to json"
},
{
"command": "casing-convention.enterNumberByLines",
"title": "casing: Numbered text"
}
],
"menus": {
Expand Down
9 changes: 9 additions & 0 deletions src/commands/commandRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { screamKebabCase } from "../handler/screamKebabCase";
import { json2PhpArray } from "../handler/json2PhpArray";
import { phpArray2Json } from "../handler/phpArray2Json";
import { capitalCase } from "../handler/capitalCase";
import { numberedByLines } from "../handler/numberedByLines";


type CommandType = {
Expand Down Expand Up @@ -223,6 +224,14 @@ const commandRegister: CommandType[] = [
description: '{"name": "kris"}',
detail: 'Transform the array PHP to json.',
callback: commandProvider(phpArray2Json)
},
{
type: COMMAND_TYPE_HANDLER,
name: 'casing-convention.enterNumberByLines',
label: 'enterNumberByLines',
description: '1. Hello casing convention',
detail: 'Transform the text to numbered text line by line.',
callback: commandProvider(numberedByLines)
}
];

Expand Down
32 changes: 32 additions & 0 deletions src/handler/numberedByLines.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { strictEqual } from "assert";
import { capitalCase } from "./capitalCase";
import { numberedByLines } from "./numberedByLines";

describe('numberedByLines', function() {

const TEST_CASES = [
{
input: "javascript",
expected: "1. javascript"
},
{
input: "Hi, kris how are you ?",
expected: "1. Hi, kris how are you ?"
},
{
input: "Hi, KRIS HowAreYou",
expected: "1. Hi, KRIS HowAreYou"
},
{
input: "KRIS_HowAreYOU\nhalo semua",
expected: "1. KRIS_HowAreYOU\n2. halo semua"
},
];

TEST_CASES.forEach(({input, expected}: any) => {
it(`Sould convert ${input} to ${expected}`, function() {
let result = numberedByLines(input);
strictEqual(result, expected);
});
});
});
14 changes: 14 additions & 0 deletions src/handler/numberedByLines.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const numberedByLines = (text: string): string => {
let numbered = 0;
return text
.split('\n')
.map((line: string) => {
if(line === "") {
return line;
}

++numbered;
return `${numbered}. ${line}`;
})
.join('\n');
};

0 comments on commit 84584b8

Please sign in to comment.