Skip to content

Commit a5848cc

Browse files
authored
feat: use slugify package for slugify command (#21)
1 parent 23fd2aa commit a5848cc

File tree

7 files changed

+543
-191
lines changed

7 files changed

+543
-191
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ jobs:
2222
uses: actions/setup-node@v3
2323
with:
2424
node-version: "lts/*"
25+
- name: Install dependencies
26+
run: npm install
27+
- name: Build
28+
run: npm run build
2529
- name: Release
2630
env:
2731
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.DS_Store
22
prefs.plist
3+
node_modules/
4+
bundle

.zip.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ rm -fv ./*.alfredworkflow
4444
# zip
4545
workflowName=$(plutil -extract 'name' raw -o - info.plist | tr " " "-")
4646
# ".*" excludes the dotfiles (glob pattern, not regex)
47-
zip --quiet -r "$workflowName.alfredworkflow" . -x ".*" "doc*/*" "prefs.plist" "info-original.plist" "*.md" "*.alfredworkflow" "*.gif"
47+
zip --quiet -r "$workflowName.alfredworkflow" . -x ".*" "doc*/*" "prefs.plist" "info-original.plist" "*.md" "*.alfredworkflow" "*.gif" "node_modules"
4848
echo "new $workflowName.alfredworkflow file created."
4949

5050
# restore original

info.plist

Lines changed: 3 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
<key>argumenttype</key>
117117
<integer>1</integer>
118118
<key>escaping</key>
119-
<integer>68</integer>
119+
<integer>0</integer>
120120
<key>keyword</key>
121121
<string>{var:keyword}</string>
122122
<key>queuedelaycustom</key>
@@ -130,189 +130,11 @@
130130
<key>runningsubtext</key>
131131
<string></string>
132132
<key>script</key>
133-
<string>function run(argv) {
134-
const input = argv[0];
135-
136-
const WORD = /[a-zA-Z0-9]+/g;
137-
const COMMAND_SEPARATOR = '/';
138-
139-
let items = [];
140-
141-
const toPascalCase = (string = '') =&gt; {
142-
const words = string.match(WORD);
143-
return (words || [])
144-
.map((word) =&gt; `${word.charAt(0).toUpperCase()}${word.slice(1)}`)
145-
.join('');
146-
};
147-
148-
const toLowerCase = (string = '') =&gt; {
149-
return string.toLowerCase();
150-
};
151-
152-
const toUpperCase = (string = '') =&gt; {
153-
return string.toUpperCase();
154-
};
155-
156-
const toCamelCase = (string = '') =&gt; {
157-
const words = string.match(WORD);
158-
return (words || []).map((word, index) =&gt; {
159-
if (index === 0) {
160-
return `${word.charAt(0).toLowerCase()}${word.slice(1)}`;
161-
}
162-
return `${word.charAt(0).toUpperCase()}${word.slice(1)}`;
163-
}).join('');
164-
};
165-
166-
const toKebapCase = (string = '') =&gt; {
167-
const words = string.match(WORD);
168-
return (words || []).join('-');
169-
};
170-
171-
const toSnakeCase = (string = '') =&gt; {
172-
const words = string.match(WORD);
173-
return (words || []).join('_');
174-
};
175-
176-
const toTrimmed = (string = '') =&gt; {
177-
return string.trim();
178-
};
179-
180-
const toPrettyJSON = (string = '') =&gt; {
181-
try {
182-
return JSON.stringify(JSON.parse(string), null, 2);
183-
} catch {
184-
throw new Error('Invalid JSON');
185-
}
186-
};
187-
188-
const commands = {
189-
l: {
190-
name: 'Lowercase',
191-
transform: toLowerCase,
192-
},
193-
u: {
194-
name: 'Uppercase',
195-
transform: toUpperCase,
196-
},
197-
c: {
198-
name: 'Camelcase',
199-
transform: toCamelCase,
200-
},
201-
p: {
202-
name: 'Pascalcase',
203-
transform: toPascalCase,
204-
},
205-
k: {
206-
name: 'Kebapcase',
207-
transform: toKebapCase,
208-
},
209-
s: {
210-
name: 'Snakecase',
211-
transform: toSnakeCase,
212-
},
213-
t: {
214-
name: 'Trim',
215-
transform: toTrimmed,
216-
},
217-
j: {
218-
name: 'Prettify JSON',
219-
transform: toPrettyJSON,
220-
},
221-
};
222-
223-
const runTransforms = (input, commandsSequence) =&gt; {
224-
if (Array.isArray(commandsSequence) &amp;&amp; commandsSequence.length &gt; 0) {
225-
try {
226-
const transformed = commandsSequence.reduce((result, command) =&gt; {
227-
const transformer = commands[command];
228-
if (transformer) {
229-
return transformer.transform(result);
230-
}
231-
return result
232-
}, input);
233-
return transformed;
234-
} catch {
235-
236-
}
237-
}
238-
239-
return [input, []];
240-
};
241-
242-
const getCommandSequencePath = (commandsSequence) =&gt; {
243-
if (Array.isArray(commandsSequence) &amp;&amp; commandsSequence.length &gt; 0) {
244-
return commandsSequence.reduce((result, command) =&gt; {
245-
const transformer = commands[command];
246-
if (transformer) {
247-
result.push(transformer.name);
248-
}
249-
return result
250-
}, []);
251-
}
252-
};
253-
254-
const isMultilined = (string = '') =&gt; /\n+/.test(string);
255-
256-
const inputSplitted = (input || '').split(COMMAND_SEPARATOR);
257-
258-
const string = inputSplitted.length &gt; 2
259-
? inputSplitted.slice(0, inputSplitted.length - 1).join(COMMAND_SEPARATOR)
260-
: inputSplitted[0];
261-
const commandsSequence = inputSplitted[1] ? inputSplitted[1].split('') : undefined;
262-
263-
if (commandsSequence) {
264-
const path = getCommandSequencePath(commandsSequence);
265-
const subtitle = path.join('→');
266-
const icon = {
267-
path: './Chained.png',
268-
};
269-
try {
270-
const chainResult = runTransforms(string, commandsSequence);
271-
items = [{
272-
uid: 'chained',
273-
title: isMultilined(chainResult) ? 'Multiline output' : chainResult,
274-
subtitle,
275-
arg: chainResult,
276-
icon,
277-
}];
278-
} catch {
279-
items = [{
280-
uid: 'error',
281-
title: 'Error',
282-
subtitle,
283-
arg: string,
284-
icon,
285-
}];
286-
}
287-
} else {
288-
items = Object.values(commands).map((command) =&gt; {
289-
try {
290-
const transformed = command.transform(string);
291-
292-
return {
293-
uid: command.name.toLowerCase(),
294-
title: isMultilined(transformed) ? 'Multiline output' : transformed,
295-
subtitle: command.name,
296-
arg: transformed,
297-
icon: {
298-
path: `./${command.name}.png`,
299-
},
300-
};
301-
} catch {
302-
return {};
303-
}
304-
});
305-
}
306-
307-
return JSON.stringify({
308-
items,
309-
});
310-
}
311-
</string>
133+
<string></string>
312134
<key>scriptargtype</key>
313135
<integer>1</integer>
314136
<key>scriptfile</key>
315-
<string>./transform.js</string>
137+
<string>bundle/transform.js</string>
316138
<key>subtext</key>
317139
<string></string>
318140
<key>title</key>

0 commit comments

Comments
 (0)