Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: "lts/*"
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
prefs.plist
node_modules/
bundle
2 changes: 1 addition & 1 deletion .zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ rm -fv ./*.alfredworkflow
# zip
workflowName=$(plutil -extract 'name' raw -o - info.plist | tr " " "-")
# ".*" excludes the dotfiles (glob pattern, not regex)
zip --quiet -r "$workflowName.alfredworkflow" . -x ".*" "doc*/*" "prefs.plist" "info-original.plist" "*.md" "*.alfredworkflow" "*.gif"
zip --quiet -r "$workflowName.alfredworkflow" . -x ".*" "doc*/*" "prefs.plist" "info-original.plist" "*.md" "*.alfredworkflow" "*.gif" "node_modules"
echo "new $workflowName.alfredworkflow file created."

# restore original
Expand Down
184 changes: 3 additions & 181 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
<integer>68</integer>
<integer>0</integer>
<key>keyword</key>
<string>{var:keyword}</string>
<key>queuedelaycustom</key>
Expand All @@ -130,189 +130,11 @@
<key>runningsubtext</key>
<string></string>
<key>script</key>
<string>function run(argv) {
const input = argv[0];

const WORD = /[a-zA-Z0-9]+/g;
const COMMAND_SEPARATOR = '/';

let items = [];

const toPascalCase = (string = '') =&gt; {
const words = string.match(WORD);
return (words || [])
.map((word) =&gt; `${word.charAt(0).toUpperCase()}${word.slice(1)}`)
.join('');
};

const toLowerCase = (string = '') =&gt; {
return string.toLowerCase();
};

const toUpperCase = (string = '') =&gt; {
return string.toUpperCase();
};

const toCamelCase = (string = '') =&gt; {
const words = string.match(WORD);
return (words || []).map((word, index) =&gt; {
if (index === 0) {
return `${word.charAt(0).toLowerCase()}${word.slice(1)}`;
}
return `${word.charAt(0).toUpperCase()}${word.slice(1)}`;
}).join('');
};

const toKebapCase = (string = '') =&gt; {
const words = string.match(WORD);
return (words || []).join('-');
};

const toSnakeCase = (string = '') =&gt; {
const words = string.match(WORD);
return (words || []).join('_');
};

const toTrimmed = (string = '') =&gt; {
return string.trim();
};

const toPrettyJSON = (string = '') =&gt; {
try {
return JSON.stringify(JSON.parse(string), null, 2);
} catch {
throw new Error('Invalid JSON');
}
};

const commands = {
l: {
name: 'Lowercase',
transform: toLowerCase,
},
u: {
name: 'Uppercase',
transform: toUpperCase,
},
c: {
name: 'Camelcase',
transform: toCamelCase,
},
p: {
name: 'Pascalcase',
transform: toPascalCase,
},
k: {
name: 'Kebapcase',
transform: toKebapCase,
},
s: {
name: 'Snakecase',
transform: toSnakeCase,
},
t: {
name: 'Trim',
transform: toTrimmed,
},
j: {
name: 'Prettify JSON',
transform: toPrettyJSON,
},
};

const runTransforms = (input, commandsSequence) =&gt; {
if (Array.isArray(commandsSequence) &amp;&amp; commandsSequence.length &gt; 0) {
try {
const transformed = commandsSequence.reduce((result, command) =&gt; {
const transformer = commands[command];
if (transformer) {
return transformer.transform(result);
}
return result
}, input);
return transformed;
} catch {

}
}

return [input, []];
};

const getCommandSequencePath = (commandsSequence) =&gt; {
if (Array.isArray(commandsSequence) &amp;&amp; commandsSequence.length &gt; 0) {
return commandsSequence.reduce((result, command) =&gt; {
const transformer = commands[command];
if (transformer) {
result.push(transformer.name);
}
return result
}, []);
}
};

const isMultilined = (string = '') =&gt; /\n+/.test(string);

const inputSplitted = (input || '').split(COMMAND_SEPARATOR);

const string = inputSplitted.length &gt; 2
? inputSplitted.slice(0, inputSplitted.length - 1).join(COMMAND_SEPARATOR)
: inputSplitted[0];
const commandsSequence = inputSplitted[1] ? inputSplitted[1].split('') : undefined;

if (commandsSequence) {
const path = getCommandSequencePath(commandsSequence);
const subtitle = path.join('→');
const icon = {
path: './Chained.png',
};
try {
const chainResult = runTransforms(string, commandsSequence);
items = [{
uid: 'chained',
title: isMultilined(chainResult) ? 'Multiline output' : chainResult,
subtitle,
arg: chainResult,
icon,
}];
} catch {
items = [{
uid: 'error',
title: 'Error',
subtitle,
arg: string,
icon,
}];
}
} else {
items = Object.values(commands).map((command) =&gt; {
try {
const transformed = command.transform(string);

return {
uid: command.name.toLowerCase(),
title: isMultilined(transformed) ? 'Multiline output' : transformed,
subtitle: command.name,
arg: transformed,
icon: {
path: `./${command.name}.png`,
},
};
} catch {
return {};
}
});
}

return JSON.stringify({
items,
});
}
</string>
<string></string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string>./transform.js</string>
<string>bundle/transform.js</string>
<key>subtext</key>
<string></string>
<key>title</key>
Expand Down
Loading