-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
36 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
Binary file not shown.