Skip to content

Commit

Permalink
feat: add reverse command (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
colomolo authored Apr 21, 2024
1 parent e3e9d45 commit 4cb124b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Inverse of `/e`.

See [`decodeURI` on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)

### Reverse `/r`
Reverse string.

## Commands with args (uppercased)
### Slugify `/S '<replacement>'`
Remove all non-word and non-digit chars and merge words with specified *replacement* string. If no *replacement* argument is provided, Slugify uses `-` char as an argument.
Expand Down
Binary file added Reverse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ function run(argv) {
return decodeURI(string);
};

const toReversed = (string = '') => {
let reversed = '';
for (let i = string.length - 1; i >= 0; i--) {
reversed += string[i];
}
return reversed;
};

const noArgCommands = {
l: {
name: 'Lowercase',
Expand Down Expand Up @@ -196,6 +204,10 @@ function run(argv) {
name: 'Decode URI',
transform: toDecodedURI,
},
r: {
name: 'Reverse',
transform: toReversed,
}
};

const REQUIRED_ARGUMENT = ' (?:\'.*?\'|".*?")';
Expand Down

0 comments on commit 4cb124b

Please sign in to comment.