diff --git a/extension.js b/extension.js index a362abc..6b84bd4 100644 --- a/extension.js +++ b/extension.js @@ -58,6 +58,8 @@ const commandNameFunctionMap = { duplicateAndIncrement: (str) => str + increment(str), duplicateAndDecrement: (str) => str + decrement(str), sequence, + utf8ToChar: (str) => str.match(/\\u[\dA-Fa-f]{4}/g).map((x) => x.slice(2)).map((x) => String.fromCharCode(parseInt(x, 16))).join(""), + charToUtf8: (str) => str.split("").map((x) => `\\u${x.charCodeAt(0).toString(16).padStart(4, '0')}`).join(""), }; const numberFunctionNames = [ "increment", diff --git a/package-lock.json b/package-lock.json index 98e7612..1d866d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "string-manipulation", - "version": "0.5.6", + "version": "0.5.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "string-manipulation", - "version": "0.5.6", + "version": "0.5.7", "dependencies": { "@sindresorhus/slugify": "^0.3.0", "ap-style-title-case": "^1.1.2", diff --git a/package.json b/package.json index 21501a2..4518338 100644 --- a/package.json +++ b/package.json @@ -185,6 +185,16 @@ "title": "Sequence all numbers (starting with first number)", "category": "String Manipulation", "command": "string-manipulation.sequence" + }, + { + "title": "Convert char to UTF8", + "category": "String Manipulation", + "command": "string-manipulation.charToUtf8" + }, + { + "title": "Convert UTF8 to char", + "category": "String Manipulation", + "command": "string-manipulation.utf8ToChar" } ], "submenus": [ @@ -308,6 +318,14 @@ { "command": "string-manipulation.sequence", "group": "7_modification" + }, + { + "command": "string-manipulation.utf8ToChar", + "group": "7_modification" + }, + { + "command": "string-manipulation.charToUtf8", + "group": "7_modification" } ] } diff --git a/test/suite/extension.test.js b/test/suite/extension.test.js index 3a1713b..f5fb7da 100644 --- a/test/suite/extension.test.js +++ b/test/suite/extension.test.js @@ -95,6 +95,8 @@ suite("Extension Test Suite", () => { "a14 b15 c16\n17d 18e 19f 20x y21 22z23", ], ["sequence", "-3 4 5 6 7", "-3 -2 -1 0 1"], + ["utf8ToChar", "\\u0061\\u0062\\u0063\\u4e2d\\u6587\\ud83d\\udc96", "abc中文💖"], + ["charToUtf8", "abc中文💖", "\\u0061\\u0062\\u0063\\u4e2d\\u6587\\ud83d\\udc96"], ]; suite("commandNameFunctionMap outputs correctly for all methods", () => { tests.forEach(