Added byte truncate script to repo. Fixed yargs not enforcing choices.

This commit is contained in:
DebaucheryLibrarian 2024-09-11 05:16:57 +02:00
parent e44f617d9e
commit c30006f361
2 changed files with 25 additions and 2 deletions

View File

@ -59,11 +59,11 @@ function getArgs() {
})
.option('after-indexed', {
describe: 'Only include posts after the oldest or the latest entry in the index',
options: ['oldest', 'latest'],
choices: ['oldest', 'latest'],
})
.option('before-indexed', {
describe: 'Only include posts before the oldest or the latest entry in the index',
options: ['oldest', 'latest'],
choices: ['oldest', 'latest'],
})
.option('redownload', {
describe: 'Ignore index file and force a redownload of everything in the selection. Does not affect [before|after]-indexed',

View File

@ -0,0 +1,23 @@
'use strict';
function truncateBytes(str, limit) {
if (Buffer.from(str).length <= limit) {
return str;
}
let acc = '';
for (let i = 0; i < str.length; i++) {
const newString = acc + str.charAt(i);
if (Buffer.from(newString).length > limit) {
break;
}
acc = newString;
}
return acc;
}
module.exports = truncateBytes;