* Create bundle filenames to spec

* Better cp437 vs utf8 vs other encoding support
* Add some CP437 and related utils
This commit is contained in:
Bryan Ashby 2020-05-02 13:34:28 -06:00
parent 1f1813c14a
commit 8817113364
No known key found for this signature in database
GPG key ID: B49EB437951D2542
5 changed files with 191 additions and 25 deletions

View file

@ -13,6 +13,7 @@ exports.pad = pad;
exports.insert = insert;
exports.replaceAt = replaceAt;
exports.isPrintable = isPrintable;
exports.containsNonLatinCodepoints = containsNonLatinCodepoints;
exports.stripAllLineFeeds = stripAllLineFeeds;
exports.debugEscapedString = debugEscapedString;
exports.stringFromNullTermBuffer = stringFromNullTermBuffer;
@ -196,6 +197,20 @@ function isPrintable(s) {
return !RE_NON_PRINTABLE.test(s);
}
const NonLatinCodePointsRegExp = /[^\u0000-\u00ff]/;
function containsNonLatinCodepoints(s) {
if (!s.length) {
return false;
}
if (s.charCodeAt(0) > 255) {
return true;
}
return NonLatinCodepointsRegEx.test(s);
}
function stripAllLineFeeds(s) {
return s.replace(/\r?\n|[\r\u2028\u2029]/g, '');
}