-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·46 lines (34 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env node
import clipboardy from 'clipboardy'
import 'colors'
// Read input from args
let text = process.argv.slice(2).join(' ').trim()
// Read input from clipboard
let clipboardUsed = false
if (!text) {
text = clipboardy.readSync().trim()
clipboardUsed = !!text
}
if (text) {
const trollcased = text.replace(/[a-zA-Z]/g, trollCaseLetters).replace(/\?/g, replaceQuestionMarks)
if (clipboardUsed) {
clipboardy.writeSync(trollcased)
}
console.log(trollcased)
} else {
console.error('No text found to trollcase (checked args, stdin & clipboard).'.red)
}
function trollCaseLetters(match) {
if (typeof trollCaseLetters.up === 'undefined') {
trollCaseLetters.up = match == match.toUpperCase()
}
trollCaseLetters.up = !trollCaseLetters.up
return trollCaseLetters.up ? match.toUpperCase() : match.toLowerCase()
}
function replaceQuestionMarks() {
if (typeof replaceQuestionMarks.up === 'undefined') {
replaceQuestionMarks.up = true
}
replaceQuestionMarks.up = !replaceQuestionMarks.up
return replaceQuestionMarks.up ? '?' : '¿'
}