Created
October 1, 2021 11:05
-
-
Save juliantcook/d49c61a9ee4e8423822b98b3a3ee0dbe to your computer and use it in GitHub Desktop.
Remove consecutive spaces. Usage to oneline formatted json: `pbpaste | oneline.js | remove-space.js | pbcopy`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| /** | |
| * remove more than one consecutive space | |
| */ | |
| const readable = process.stdin; | |
| readable.on('readable', () => { | |
| let chunk; | |
| let prevCharSpace = false; | |
| while (null !== (chunk = readable.read())) { | |
| for (const char of `${chunk}`) { | |
| if (!(char === ' ' && prevCharSpace)) { | |
| process.stdout.write(char); | |
| } | |
| prevCharSpace = char === ' '; | |
| } | |
| } | |
| }); | |
| readable.on('end', () => { | |
| process.stdout.write('\n'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment