Skip to content

Commit

Permalink
Update Sentence Case and Uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
pilotmoon committed May 10, 2024
1 parent 58d5b26 commit caade37
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 100 deletions.
7 changes: 0 additions & 7 deletions source/SentenceCase.popclipext/Config.js

This file was deleted.

20 changes: 6 additions & 14 deletions source/SentenceCase.popclipext/Config.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
{
"Actions" : [
{
"After" : "paste-result",
"Image File" : "sentence-case.png",
"Script Interpreter" : "\/usr\/bin\/php",
"Shell Script File" : "sentence-case.php",
"Title" : "Sentence Case"
}
],
"Extension Description" : "Start each selected sentence with a capital letter.",
"Extension Identifier" : "com.pilotmoon.popclip.extension.sentence-case",
"Extension Name" : "Sentence Case",
"Note": "Updated for macOS 12.0 Monterey.",
"popclipVersion" : 3543
"name" : "Sentence Case",
"identifier" : "com.pilotmoon.popclip.extension.sentence-case",
"description" : "Start each selected sentence with a capital letter.",
"icon": "square filled S",
"popclip version" : 4151,
"module": "sentence-case.js"
}
57 changes: 28 additions & 29 deletions source/SentenceCase.popclipext/sentence-case.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
function sentenceCase(text) {
const regex=/(^\s*\p{L}{1}|[.?!]\s+\p{L}{1})/gu; // split into something approximating sentences
text = text.toLowerCase();
return text.replace(regex, (match) => match.toUpperCase());
function sentenceCase(text) {
const regex = /(^\s*\p{L}{1}|[.?!]\s+\p{L}{1})/gu; // split into something approximating sentences
text = text.toLowerCase();
return text.replace(regex, (match) => match.toUpperCase());
}

if (typeof(define) !== 'undefined') { // when running in popclip, export the function
define(() => {
return (selection) => {
popclip.pasteText(sentenceCase(selection.text));
}
})
}
else { // when running in jsc, perform tests
function test() {
const data=[
["blah", "Blah"],
["BLAH. blah.", "Blah. Blah."],
[" BLAH blah? BHAL.\nff", " Blah blah? Bhal.\nFf"],
["BLAH (blah-more", "Blah (blah-more"],
["élan fdf? написанная! OK", "Élan fdf? Написанная! Ok"],

["Nick's best dog's fur", "Nick's best dog's fur"],
];
data.forEach((pair) => {
const [input, output]=pair;
const result=sentenceCase(input);
print(`${output===result?'pass ':'fail *'} ${input} => ${result} (expected: ${output})`);
});
}
test();
exports.action = (input) => {
popclip.pasteText(sentenceCase(input.text));
};

function test() {
const data = [
["blah", "Blah"],
["BLAH. blah.", "Blah. Blah."],
[" BLAH blah? BHAL.\nff", " Blah blah? Bhal.\nFf"],
["BLAH (blah-more", "Blah (blah-more"],
["élan fdf? написанная! OK", "Élan fdf? Написанная! Ok"],

["Nick's best dog's fur", "Nick's best dog's fur"],
];
data.forEach((pair) => {
const [input, output] = pair;
const result = sentenceCase(input);
print(
`${
output === result ? "pass " : "fail *"
} ${input} => ${result} (expected: ${output})`,
);
});
}
// test();
26 changes: 0 additions & 26 deletions source/SentenceCase.popclipext/sentence-case.php

This file was deleted.

Binary file removed source/SentenceCase.popclipext/sentence-case.png
Binary file not shown.
18 changes: 10 additions & 8 deletions source/Uppercase.popclipext/Config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
define({
identifier: "com.pilotmoon.popclip.extension.uppercase",
name: "Uppercase",
icon: "square filled AB",
action: (selection) => {
popclip.pasteText(selection.text.toUpperCase());
}
})
// #popclip
// name: Uppercase
// #identifier: com.pilotmoon.popclip.extension.uppercase
// description: Make the selected text ALL UPPERCASE.
// icon: "square filled AB"
// popclip version: 4151

exports.action = (input) => {
popclip.pasteText(input.text.toUpperCase());
};
16 changes: 0 additions & 16 deletions source/Uppercase.popclipext/Config.json

This file was deleted.

Binary file removed source/Uppercase.popclipext/uppercase.png
Binary file not shown.

0 comments on commit caade37

Please sign in to comment.