diff --git a/README.md b/README.md index 9466b1f..d8ad413 100644 --- a/README.md +++ b/README.md @@ -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 ''` 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. diff --git a/Reverse.png b/Reverse.png new file mode 100644 index 0000000..ce3cc02 Binary files /dev/null and b/Reverse.png differ diff --git a/transform.js b/transform.js index 931b2dc..d3b69dd 100755 --- a/transform.js +++ b/transform.js @@ -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', @@ -196,6 +204,10 @@ function run(argv) { name: 'Decode URI', transform: toDecodedURI, }, + r: { + name: 'Reverse', + transform: toReversed, + } }; const REQUIRED_ARGUMENT = ' (?:\'.*?\'|".*?")';