├── .gitignore ├── LICENSE ├── README.md ├── bin.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | sandbox.js 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Mathias Buus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lines-per-second 2 | 3 | CLI tool that counts how many lines per second is written to it 4 | 5 | ``` 6 | npm install -g lines-per-second 7 | ``` 8 | 9 | ## Usage 10 | 11 | ``` sh 12 | # just pipe a program to lps and it will start counting lines written per second 13 | ./some-program-that-prints | lps 14 | ``` 15 | 16 | ## License 17 | 18 | MIT 19 | -------------------------------------------------------------------------------- /bin.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const split = require('split2') 4 | const speedometer = require('speedometer') 5 | const { EOL } = require('os') 6 | 7 | const speed = speedometer() 8 | 9 | let max = 0 10 | const barLength = 15 11 | 12 | process.stdin 13 | .pipe(split(map)) 14 | .pipe(process.stdout) 15 | 16 | function map (line) { 17 | const s = speed(1) 18 | return getBar(s) + ' - ' + s.toFixed(1) + ' lines/s - ' + line + EOL 19 | } 20 | 21 | function getBar (s) { 22 | if (s > max) max = s 23 | const percentage = s / max 24 | const proportion = (percentage * barLength).toFixed(0) 25 | const bar = [] 26 | for (let index = 0; index < barLength; index++) { 27 | bar[index] = index <= proportion ? '█' : '░'; 28 | 29 | } 30 | return bar.join('') 31 | } 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lines-per-second", 3 | "version": "1.1.0", 4 | "description": "CLI tool that counts how many lines per second is written to it", 5 | "main": "bin.js", 6 | "dependencies": { 7 | "speedometer": "^1.1.0", 8 | "split2": "^3.1.1" 9 | }, 10 | "devDependencies": { 11 | "standard": "^13.1.0" 12 | }, 13 | "scripts": { 14 | "test": "standard" 15 | }, 16 | "bin": { 17 | "lps": "./bin.js" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/mafintosh/lines-per-second.git" 22 | }, 23 | "author": "Mathias Buus (@mafintosh)", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/mafintosh/lines-per-second/issues" 27 | }, 28 | "homepage": "https://github.com/mafintosh/lines-per-second" 29 | } 30 | --------------------------------------------------------------------------------