Skip to content

Commit 877c8b8

Browse files
committed
feat(random): ɹǝzᴉɯopuɐɹ ♻
1 parent 15ef5da commit 877c8b8

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# sofancy
22

3-
fun unicode font tool
3+
a fun unicode font tool
44

55
## demo
66

@@ -51,19 +51,22 @@ wide You So Fancy
5151
__ῳɛıཞɖ ųŋıƈơɖɛ ʄƖɛҳıŋɠ? 😜__
5252

5353
```
54-
usage: sofancy [-f (font) | -t] string
54+
usage: sofancy [-f (font) | -t | -r] string
5555
5656
flags:
5757
-f|--font (font) : output in a single font
5858
-t|--titles : display titles in output
59+
-r|--random : pick a random font (clobbers -f)
5960
6061
examples:
6162
sofancy -f wide aesthetics
6263
aesthetics
6364
sofancy -t some string | fzf | xsel -i
64-
git commit -m "style(docs): $(sofancy -f bolditalic STYLIN)"
65+
git commit -m "$(sofancy -tr message | sed 's/^.* /docs: /')"
6566
```
67+
6668
## install
69+
6770
clone and install
6871
```
6972
git clone [email protected]:xero/sofancy.git sofancy
@@ -75,7 +78,8 @@ use `npm` to globally install
7578

7679
`npm i -g sofancy`
7780

78-
### note
81+
### notes
82+
7983
on unix systems node "bins" are normally placed in `/usr/local/lib/node` or `/usr/local/lib/node_modules` unless your export a custom `NODE_PATH`. either way, make sure the appropriate directory is in your path.
8084

8185

sofancy.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,7 @@ const fonts = {
17771777
"?": "\uff1f"
17781778
}
17791779
};
1780-
let font = titles = false;
1780+
let font = titles = random = false;
17811781

17821782
function unicodereverse(s) {
17831783
var regexSymbolWithCombiningMarks = /([\0-\u02FF\u0370-\u1AAF\u1B00-\u1DBF\u1E00-\u20CF\u2100-\uD7FF\uE000-\uFE1F\uFE30-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])([\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]+)/g;
@@ -1816,6 +1816,10 @@ function walk(txt, f) {
18161816

18171817
function getfancy(txt) {
18181818
(txt === '') && usage();
1819+
if (random) {
1820+
var keys = Object.keys(fonts);
1821+
font = keys[Math.floor(Math.random() * keys.length)];
1822+
}
18191823
if (font) {
18201824
fonts.hasOwnProperty(font) ? walk(txt, font) : usage('unknown font');
18211825
} else {
@@ -1837,6 +1841,10 @@ function setArgs() {
18371841
type: "boolean",
18381842
short: "t",
18391843
},
1844+
random: {
1845+
type: "boolean",
1846+
short: "r",
1847+
}
18401848
};
18411849
try {
18421850
const { values, positionals } = parseArgs({
@@ -1846,6 +1854,7 @@ function setArgs() {
18461854
});
18471855
font = values.font || false;
18481856
titles = values.titles || false;
1857+
random = values.random || false;
18491858
getfancy(positionals.join(" "));
18501859
} catch (e) {
18511860
usage();
@@ -1854,17 +1863,18 @@ function setArgs() {
18541863

18551864
function usage(msg) {
18561865
(msg) && console.log(`error: ${msg}\n`);
1857-
console.log(`usage: sofancy [-f (font) | -t] string
1866+
console.log(`usage: sofancy [-f (font) | -t | -r] string
18581867
18591868
flags:
18601869
-f|--font (font) : output in a single font
18611870
-t|--titles : display titles in output
1871+
-r|--random : pick a random font (clobbers -f)
18621872
18631873
examples:
18641874
sofancy -f wide aesthetics
18651875
aesthetics
18661876
sofancy -t some string | fzf | xsel -i
1867-
git commit -m "$(sofancy -f bolditalic STYLIN)"
1877+
git commit -m "$(sofancy -tr message | sed 's/^.* /docs: /')"
18681878
`);
18691879
process.exit();
18701880
}

0 commit comments

Comments
 (0)