diff --git a/source/Capitalize.popclipext/Config.js b/source/Capitalize.popclipext/Config.js deleted file mode 100644 index e00f02ac..00000000 --- a/source/Capitalize.popclipext/Config.js +++ /dev/null @@ -1,6 +0,0 @@ -define({ - identifier: "com.pilotmoon.popclip.extension.capitalize", - name: "Capitalize", - icon: "square filled Ab", - action: require('capitalize.js'), -}); \ No newline at end of file diff --git a/source/Capitalize.popclipext/Config.json b/source/Capitalize.popclipext/Config.json index 9099514d..906f58fb 100644 --- a/source/Capitalize.popclipext/Config.json +++ b/source/Capitalize.popclipext/Config.json @@ -1,9 +1,8 @@ { - "identifier" : "com.pilotmoon.popclip.extension.capitalize", "name" : "Capitalize Words", - "popclipVersion" : 3543, + "identifier" : "xcom.pilotmoon.popclip.extension.capitalize", "description" : "Start each selected word with a capital letter.", - "note": "Updated for macOS 12.0 Monterey.", - "icon" : "capitalize.png", - "title" : "Capitalize" + "icon" : "square filled Ab", + "popclipVersion" : 4151, + "module": "capitalize.js" } \ No newline at end of file diff --git a/source/Capitalize.popclipext/capitalize.js b/source/Capitalize.popclipext/capitalize.js index a81f6c2b..cbcdaad6 100644 --- a/source/Capitalize.popclipext/capitalize.js +++ b/source/Capitalize.popclipext/capitalize.js @@ -1,38 +1,37 @@ -function capitalizeWord(text) { - text = text.toLowerCase(); // first letter uppercase, others lowercase - return text.substr(0, 1).toUpperCase() + text.substr(1); +function capitalizeWord(text) { + text = text.toLowerCase(); // first letter uppercase, others lowercase + return text.substr(0, 1).toUpperCase() + text.substr(1); } -function capitalizeAll(text) { - const regex=/(\p{L}+['’]\p{L}+|\p{L}+)/gu; // split into something approximating words - return text.replace(regex, (match) => capitalizeWord(match)); +function capitalizeAll(text) { + const regex = /(\p{L}+['’]\p{L}+|\p{L}+)/gu; // split into something approximating words + return text.replace(regex, (match) => capitalizeWord(match)); } -if (typeof(define) !== 'undefined') { // when running in popclip, export the function - define(() => { - return (selection) => { - popclip.pasteText(capitalizeAll(selection.text)); - } - }) -} -else { // when running in jsc, perform tests - function test() { - const data = [ - ["blah", "Blah"], - ["BLAH", "Blah"], - ["'BLAH-blah'", "'Blah-Blah'"], - ["\"BLAH-blah'", "\"Blah-Blah'"], - [" BLAH (blah-more", " Blah (Blah-More"], - ["élan güt написанная!", "Élan Güt Написанная!"], - ['"Nick\'s best dog\'s fur"', '"Nick\'s Best Dog\'s Fur"'], - ["Nick's best dog's fur", "Nick's Best Dog's Fur"], - ["😀nick's best dog’s fur", "😀Nick's Best Dog’s Fur"], - ]; - data.forEach((pair) => { - const [input, output]=pair; - const result=capitalizeAll(input); - print(`${output===result?'pass ':'fail *'} ${input} => ${result} (expected: ${output})`); - }); - } - test(); +exports.action = (input) => { + popclip.pasteText(capitalizeAll(input.text)); +}; + +function test() { + const data = [ + ["blah", "Blah"], + ["BLAH", "Blah"], + ["'BLAH-blah'", "'Blah-Blah'"], + ["\"BLAH-blah'", "\"Blah-Blah'"], + [" BLAH (blah-more", " Blah (Blah-More"], + ["élan güt написанная!", "Élan Güt Написанная!"], + ["\"Nick's best dog's fur\"", "\"Nick's Best Dog's Fur\""], + ["Nick's best dog's fur", "Nick's Best Dog's Fur"], + ["😀nick's best dog’s fur", "😀Nick's Best Dog’s Fur"], + ]; + data.forEach((pair) => { + const [input, output] = pair; + const result = capitalizeAll(input); + print( + `${ + output === result ? "pass " : "fail *" + } ${input} => ${result} (expected: ${output})`, + ); + }); } +test(); diff --git a/source/Capitalize.popclipext/capitalize.png b/source/Capitalize.popclipext/capitalize.png deleted file mode 100644 index 027a9950..00000000 Binary files a/source/Capitalize.popclipext/capitalize.png and /dev/null differ