Skip to content

Commit

Permalink
feat(random): ɹǝzᴉɯopuɐɹ ♻
Browse files Browse the repository at this point in the history
  • Loading branch information
xero committed Jul 31, 2024
1 parent 15ef5da commit 877c8b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sofancy

fun unicode font tool
a fun unicode font tool

## demo

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

```
usage: sofancy [-f (font) | -t] string
usage: sofancy [-f (font) | -t | -r] string
flags:
-f|--font (font) : output in a single font
-t|--titles : display titles in output
-r|--random : pick a random font (clobbers -f)
examples:
sofancy -f wide aesthetics
aesthetics
sofancy -t some string | fzf | xsel -i
git commit -m "style(docs): $(sofancy -f bolditalic STYLIN)"
git commit -m "$(sofancy -tr message | sed 's/^.* /docs: /')"
```

## install

clone and install
```
git clone git@github.com:xero/sofancy.git sofancy
Expand All @@ -75,7 +78,8 @@ use `npm` to globally install

`npm i -g sofancy`

### note
### notes

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.


Expand Down
16 changes: 13 additions & 3 deletions sofancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,7 @@ const fonts = {
"?": "\uff1f"
}
};
let font = titles = false;
let font = titles = random = false;

function unicodereverse(s) {
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;
Expand Down Expand Up @@ -1816,6 +1816,10 @@ function walk(txt, f) {

function getfancy(txt) {
(txt === '') && usage();
if (random) {
var keys = Object.keys(fonts);
font = keys[Math.floor(Math.random() * keys.length)];
}
if (font) {
fonts.hasOwnProperty(font) ? walk(txt, font) : usage('unknown font');
} else {
Expand All @@ -1837,6 +1841,10 @@ function setArgs() {
type: "boolean",
short: "t",
},
random: {
type: "boolean",
short: "r",
}
};
try {
const { values, positionals } = parseArgs({
Expand All @@ -1846,6 +1854,7 @@ function setArgs() {
});
font = values.font || false;
titles = values.titles || false;
random = values.random || false;
getfancy(positionals.join(" "));
} catch (e) {
usage();
Expand All @@ -1854,17 +1863,18 @@ function setArgs() {

function usage(msg) {
(msg) && console.log(`error: ${msg}\n`);
console.log(`usage: sofancy [-f (font) | -t] string
console.log(`usage: sofancy [-f (font) | -t | -r] string
flags:
-f|--font (font) : output in a single font
-t|--titles : display titles in output
-r|--random : pick a random font (clobbers -f)
examples:
sofancy -f wide aesthetics
aesthetics
sofancy -t some string | fzf | xsel -i
git commit -m "$(sofancy -f bolditalic STYLIN)"
git commit -m "$(sofancy -tr message | sed 's/^.* /docs: /')"
`);
process.exit();
}
Expand Down

0 comments on commit 877c8b8

Please # to comment.