Installations
npm install @elfo/draftlog
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
16.14.0
NPM Version
8.3.1
Score
71.4
Supply Chain
99.3
Quality
75.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
ivanseidel
Download Statistics
Total Downloads
306
Last Day
1
Last Week
8
Last Month
16
Last Year
62
GitHub Statistics
1,250 Stars
43 Commits
33 Forks
24 Watching
1 Branches
4 Contributors
Bundle Size
2.74 kB
Minified
1.00 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.14
Package Id
@elfo/draftlog@1.0.14
Unpacked Size
15.87 kB
Size
6.47 kB
File Count
12
NPM Version
8.3.1
Node Version
16.14.0
Total Downloads
Cumulative downloads
Total Downloads
306
Last day
0%
1
Compared to previous day
Last week
700%
8
Compared to previous week
Last month
60%
16
Compared to previous month
Last year
-30.3%
62
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
1
Because Logging can be pretty and fun
Installation
$ npm install draftlog
What it does
It allows you to re-write a line of your log after being written. Just like post 'updating'.
This is the building block for any dynamic element such as progress bars
, loading status
,
animations
, checkboxes
and so on.
It does that by keeping track of the current lines of code written through the stream
, and
moving the cursor up to the line of the LogDraft
you created previously, and updating its content.
Look in the examples folders to see how easy it is, to create anything. No strict and fixed widgets are given to you. Instead, use your creativity with this tool to create anything you want! Share the results later with an example ;)
Looking for CUTE Unicode chars? Check out Unicute.
How the HECK is that even possible?
Usage
1// Setup 2const DraftLog = require('draftlog') 3DraftLog(console) 4 5// Or, in a single line: 6require('draftlog').into(console) 7 8// Account for manual line breaks with: 9require('draftlog').into(console).addLineListener(process.stdin)
To create a updatable log, use the draft
method injected into the provided console
:
1// Create a Draft log 2var update = console.draft('Hi, my name is') 3 4// You can call logs after it 5console.log('Something else') 6 7// Use the received callback to update it as many times as you want 8update('Hi, my name is Ivan!')
Here are some interesting examples:
1// Prints a clock incrementing one every second in the same line 2var draft = console.draft() 3var elapsed = 1 4setInterval( () => { 5 draft('Elapsed', elapsed++, 'seconds') 6}, 1000) 7 8console.log('It doesn`t matter') 9console.log('How \n many \n lines \n it uses')
Or maybe, to show an flow process?
1function someAsyncFunction(){ 2 var TAG = '[someAsyncFunction]' 3 var log = console.draft(TAG, 'init') 4 5 function a() { 6 setTimeout(() => { 7 log(TAG, 'calling b') 8 b() 9 }, 500) 10 } 11 12 function b() { 13 setTimeout(() => { 14 log(TAG, 'finished') 15 }) 16 } 17}
You can create your own progress bar, just like "that":
1require('draftlog').into(console) 2 3// Input progess goes from 0 to 100 4function ProgressBar(progress) { 5 // Make it 50 characters length 6 var units = Math.round(progress / 2) 7 return '[' + '='.repeat(units) + ' '.repeat(50 - units) + '] ' + progress + '%' 8} 9 10var barLine = console.draft('Starting download...') 11downloadFile(function (progress) { 12 barLine(ProgressBar(progress)) 13}) 14 15// Will show something like: (being updated in realtime) 16// [============================ ] 56%
Learn from examples!
We have a few of them ready for you to use! Take a look at the examples folder.
Remember to replace require('../')
with require('draftlog')
.
Also, install chalk
to get colors on your terminal ;)
Important things to know
Because of the way Terminals are built, it is not possible to update a text outside the viewing area of the terminal.
That said, DraftLogs are setup to automagically be rewritten on a new line if they reach the end of the viewport.
Note that, you can disable that behavior, by setting DraftLog.defaults.canReWrite = false
Also, if the NodeJS environment cannot detect the number of rows of your terminal automatically, it will use
the default height on DraftLog.defaults.maximumLinesUp
. Modify that if needed.
When using into(console).addLineListener(process.stdin)
, your code will no longer exit
automatically, because the stream is being "read". To stop your own code, you can call
process.exit(0)
or pause the stream when you want with: process.stdin.pause()
.
Discouragements
This library is awesome for development, cli
tools and what ever you want to created, that is NOT an
optimized "slave" server. Please, disable it passing true
as a second parameter to the DraftLog initialization:
1// Disable Initialization (true = production; false = development) 2DraftLog(console, true) 3// Or, with one line require-init: 4require('draftlog').into(console, true)
Creator
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.txt:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0
Reason
Found 3/27 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More