donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
96 lines • 3.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VerbConverter = void 0;
/**
* Converts a camelCase command to a present-tense action.
* Example: "inputText" -> "Inputting text"
*/
class VerbConverter {
static toPresentTenseAction(input) {
// Split camel case into words
const words = VerbConverter.splitCamelCase(input);
if (!words.length) {
return '';
}
// Convert first word to present participle
const firstWord = words[0];
const presentParticiple = VerbConverter.toPresentParticiple(firstWord);
// Lowercase the rest of the words
for (let i = 1; i < words.length; i++) {
words[i] = words[i].toLowerCase();
}
// Combine words
words[0] = VerbConverter.capitalize(presentParticiple);
return words.join(' ');
}
static splitCamelCase(s) {
const matches = s.match(/([A-Z]?[a-z]+|[A-Z]+(?![a-z]))/g);
return matches ?? [];
}
static toPresentParticiple(verb) {
verb = verb.toLowerCase();
const len = verb.length;
// Special cases
const specialCases = {
be: 'being',
die: 'dying',
lie: 'lying',
tie: 'tying',
see: 'seeing',
};
if (verb in specialCases) {
return specialCases[verb];
}
// For verbs ending with "ie", change "ie" to "y" and add "ing"
if (verb.endsWith('ie')) {
return `${verb.slice(0, -2)}ying`;
}
// For verbs ending with "e", drop the "e" and add "ing"
if (verb.endsWith('e') &&
!verb.endsWith('ee') &&
!verb.endsWith('ye') &&
!verb.endsWith('oe')) {
return `${verb.slice(0, -1)}ing`;
}
// For one-syllable verbs ending with consonant-vowel-consonant,
// double the final consonant and add "ing"
if (VerbConverter.isCVC(verb)) {
return `${verb}${verb.charAt(len - 1)}ing`;
}
// For verbs ending with "c", add "king"
if (verb.endsWith('c')) {
return `${verb}king`;
}
// Default case: just add "ing"
return `${verb}ing`;
}
static isCVC(verb) {
if (verb.length < 3)
return false;
if (VerbConverter.countVowels(verb) !== 1)
return false;
const c1 = verb.charAt(verb.length - 3);
const c2 = verb.charAt(verb.length - 2);
const c3 = verb.charAt(verb.length - 1);
return (VerbConverter.isConsonant(c1) &&
VerbConverter.isVowel(c2) &&
VerbConverter.isConsonant(c3) &&
!['w', 'x', 'y'].includes(c3));
}
static countVowels(s) {
return [...s].filter((c) => VerbConverter.isVowel(c)).length;
}
static isVowel(c) {
return 'aeiou'.includes(c.toLowerCase());
}
static isConsonant(c) {
return /[a-zA-Z]/.test(c) && !VerbConverter.isVowel(c);
}
static capitalize(s) {
if (!s)
return s;
return s.charAt(0).toUpperCase() + s.slice(1);
}
}
exports.VerbConverter = VerbConverter;
//# sourceMappingURL=VerbConverter.js.map