Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
wcwidth.js
is a simple javascript porting of wcwidth()
implemented in C
by Markus Kuhn.
wcwidth()
and its string version,
wcswidth()
are defined by IEEE Std 1002.1-2001, a.k.a. POSIX.1-2001, and return the number
of columns used to represent a wide character and string on fixed-width output
devices like terminals. Markus's implementation assumes wide characters to be
encoded in ISO 10646,
which is almost true for JavaScript; almost because JavaScript uses
UCS-2 and has problems with surrogate
pairs. wcwidth.js
converts surrogate pairs to Unicode code points to handle
them correctly.
Following the original implementation, this library defines the column width of an ISO 10646 character as follows:
U+0000
) has a column width of opts.null
(whose
default value is 0);DEL
will lead to a column width of opts.control
(whose default value
is 0);Mn
or Me
) in the Unicode database) have a column width of 0;SOFT HYPHEN
(U+00AD
) has a column width of 1;Cf
in the Unicode database)
and ZERO WIDTH SPACE
(U+200B
) have a column width of 0;U+1160
-U+11FF
) have a
column width of 0;W
) or East Asian Full-width
(F
) category as defined in
Unicode Technical Report #11 have a
column width of 2; andA surrogate high or low value which constitutes no pair is considered to have a column width of 1 according to the behavior of widespread terminals.
See the documentation from the C implementation for details.
wcwidth.js
is simple to use:
var wcwidth = require('wcwidth.js')
wcwidth('한글') // 4
wcwidth('\0') // 0; NUL
wcwidth('\t') // 0; control characters
If you plan to replace NUL
or control characters with, say, ???
before
printing, use wcwidth.config()
that returns a closure to run wcwidth
with
your configuration:
var mywidth = wcwidth.config({
nul: 3,
control: 3
})
mywidth('\0\f') // 6
mywidth('한\t글') // 7
Setting these options to -1 gives a function that returns -1 for a string
containing an instance of NUL
or control characters:
mywidth = wcwidth.config({
nul: 0,
control: -1
})
mywidth('java\0script') // 10
mywidth('java\tscript') // -1
This is useful when detecting if a string has non-printable characters.
Due to the risk of monkey-patching, no String
getter is provided anymore.
Even if discouraged, you can still monkey-patch by yourself as follows:
String.prototype.__defineGetter__('wcwidth', function () {
return wcwidth(this);
})
'한글'.wcwidth // 4
JavaScript has no character type, thus meaningless to have two versions of
wcwidth
while POSIX does for C. wcwidth
also accepts a code value obtained
by charCodeAt()
:
wcwidth('한') // prints 2
wcwidth('글'.charCodeAt(0)) // prints 2
INSTALL.md
explains how to build and install the library. For the copyright
issues, see the accompanying LICENSE.md
file.
If you have a question or suggestion, do not hesitate to contact me via email (woong.jun at gmail.com) or web (http://code.woong.org/).
FAQs
a javascript porting of C's wcwidth()
We found that wcwidth.js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.