A little helper for handling strings containing zero width characters, ANSI styling, whitespaces, newlines, 💩, etc.
Installations
npm install printable-characters
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
4.9.1
NPM Version
2.15.11
Score
99.8
Supply Chain
97
Quality
75.9
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
Download Statistics
Total Downloads
84,525,825
Last Day
217,469
Last Week
1,041,540
Last Month
4,755,864
Last Year
51,923,455
GitHub Statistics
20 Stars
104 Commits
6 Forks
5 Watching
1 Branches
3 Contributors
Bundle Size
1.32 kB
Minified
805.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.0.42
Package Id
printable-characters@1.0.42
Unpacked Size
187.12 kB
Size
37.26 kB
File Count
13
NPM Version
2.15.11
Node Version
4.9.1
Total Downloads
Cumulative downloads
Total Downloads
84,525,825
Last day
-10.1%
217,469
Compared to previous day
Last week
-17.3%
1,041,540
Compared to previous week
Last month
6.8%
4,755,864
Compared to previous month
Last year
109.7%
51,923,455
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
printable-characters
A little helper for handling strings containing zero width characters, ANSI styling, whitespaces, newlines, weird Unicode 💩 symbols, etc.
Determining the real (visible) length of a string
1const { strlen } = require ('printable-characters') 2 3strlen ('foo bar') // === 7 4strlen ('\u001b[106mfoo bar\u001b[49m') // === 7
Detecting blank text
1const { isBlank } = require ('printable-characters') 2 3isBlank ('foobar') // === false 4isBlank ('\u001b[106m \t \t \n \u001b[49m') // === true
Obtaining a blank string of the same width
1const { blank } = require ('printable-characters') 2 3blank ('💩') // === ' ' 4blank ('foo') // === ' ' 5blank ('\tfoo \nfoo') // === '\t \n ' 6blank ('\u001b[22m\u001b[1mfoo \t\u001b[39m\u001b[22m')) // === ' \t'
Matching invisible characters
1const { ansiEscapeCodes, zeroWidthCharacters } = require ('printable-characters') 2 3const s = '\u001b[106m' + 'foo' + '\n' + 'bar' + '\u001b[49m' 4 5s.replace (ansiEscapeCodes, '') // === 'foo\nbar' 6 .replace (zeroWidthCharacters, '') // === 'foobar'
Getting the first N visible symbols, preserving the invisible parts
Use for safely truncating strings to maximum width without breaking ANSI codes:
1const { first } = require ('printable-characters') 2 3const s = '\u001b[22mfoobar\u001b[22m' 4 5first (s, 0) // === '\u001b[22m\u001b[22m' 6first (s, 1) // === '\u001b[22mf\u001b[22m' 7first (s, 3) // === '\u001b[22mfoo\u001b[22m' 8first (s, 6) // === '\u001b[22mfoobar\u001b[22m'
Extracting the invisible parts followed by the visible ones (parsing)
1const { partition } = require ('printable-characters') 2 3partition ('') // [ ]) 4partition ('foo') // [['', 'foo'] ]) 5partition ('\u001b[1mfoo') // [['\u001b[1m', 'foo'] ]) 6partition ('\u001b[1mfoo\u0000bar') // [['\u001b[1m', 'foo'], ['\u0000', 'bar'] ]) 7partition ('\u001b[1mfoo\u0000bar\n') // [['\u001b[1m', 'foo'], ['\u0000', 'bar'], ['\n', '']])
Applications
- as-table — a simple function that prints objects as ASCII tables
- string.bullet — ASCII-mode bulleting for the list-style data
- string.ify — a fancy pretty printer for the JavaScript entities
- Ololog! — a better
console.log
for the log-driven debugging junkies!
TODO
Handle multi-component emojis, as in this article:
1assert.equal (strlen ('👩❤️💋👩'), 1) // FAILING, see http://blog.jonnew.com/posts/poo-dot-length-equals-two for possible solution 2assert.equal (blank ('👩❤️💋👩'), ' ') // FAILING, see http://blog.jonnew.com/posts/poo-dot-length-equals-two for possible solution
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: The Unlicense: LICENSE:0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
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
66 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-hr2v-3952-633q
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c
- Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-4hpf-3wq7-5rpr
- Warn: Project is vulnerable to: GHSA-f522-ffg8-j8r6
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-282f-qqgm-c34q
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3
- Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7
- Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-xc7v-wxcw-j472
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/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 MoreOther packages similar to printable-characters
printable-characters-regex
Regex for validating printable characters
printable-characters-plus-directional
A little helper for handling strings containing zero width control characters, ANSI styling, whitespaces, newlines, etc.
unicoderegexp
Regular expressions for various Unicode character classes extracted from XRegExp
univeil
Unveil some Unicode characters that are easily overlooked.