/usr/lib/nodejs/string-width/index.js is in node-string-width 2.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 'use strict';
const stripAnsi = require('strip-ansi');
const wcwidth = require('wcwidth.js');
module.exports = str => {
if (typeof str !== 'string' || str.length === 0) {
return 0;
}
let width = 0;
str = stripAnsi(str);
for (let i = 0; i < str.length; i++) {
const code = str.codePointAt(i);
// ignore control characters
if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) {
continue;
}
// surrogates
if (code >= 0x10000) {
i++;
}
width += wcwidth(code);
}
return width;
};
|