Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
bits = '0'.repeat(bitlen - bits.length) + bits
bitstr += bits
}
const value = Long.fromString(bitstr, true, 2)
// convert to LITTLE_ENDIAN
let leHex = ''
const bytes = littleEndian ? value.toBytesLE() : value.toBytesBE()
for(const b of bytes) {
const n = Number(b).toString(16)
leHex += (n.length === 1 ? '0' : '') + n
}
const ulName = Long.fromString(leHex, true, 16).toString()
// console.log('encodeName', name, value.toString(), ulName.toString(), JSON.stringify(bitstr.split(/(.....)/).slice(1)))
return ulName.toString()
}
if(name.length > 12)
throw new TypeError('A name can be up to 12 characters long')
let bitstr = ''
for(let i = 0; i <= 12; i++) { // process all 64 bits (even if name is short)
const c = i < name.length ? charidx(name[i]) : 0
const bitlen = i < 12 ? 5 : 4
let bits = Number(c).toString(2)
if(bits.length > bitlen) {
throw new TypeError('Invalid name ' + name)
}
bits = '0'.repeat(bitlen - bits.length) + bits
bitstr += bits
}
const value = Long.fromString(bitstr, true, 2)
// convert to LITTLE_ENDIAN
let leHex = ''
const bytes = littleEndian ? value.toBytesLE() : value.toBytesBE()
for(const b of bytes) {
const n = Number(b).toString(16)
leHex += (n.length === 1 ? '0' : '') + n
}
const ulName = Long.fromString(leHex, true, 16).toString()
// console.log('encodeName', name, value.toString(), ulName.toString(), JSON.stringify(bitstr.split(/(.....)/).slice(1)))
return ulName.toString()
}
// remove trailing zeros
while (/0$/.test(value)) {
value = value.substring(0, value.length - 1);
}
if (/\.$/.test(value)) {
// remove trailing dot
value = value.substring(0, value.length - 1);
}
if (value === '') {
value = '0';
}
let long_string = Long.fromString(value, unsigned).toString();
if (long_string !== value.trim()) {
throw new Error(`overflow ${field_name} ${value}`);
}
return;
}
if (typeof value === 'number') {
if (value > MAX_SAFE_INT || value < MIN_SAFE_INT) {
throw new Error(`overflow ${field_name} ${value}`);
}
return;
}
function ULong(value, unsigned = true, radix = 10) {
if(typeof value === 'number') {
// Some JSON libs use numbers for values under 53 bits or strings for larger.
// Accomidate but double-check it..
if(value > Number.MAX_SAFE_INTEGER)
throw new TypeError('value parameter overflow')
value = Long.fromString(String(value), unsigned, radix)
} else if(typeof value === 'string') {
value = Long.fromString(value, unsigned, radix)
} else if(!Long.isLong(value)) {
throw new TypeError('value parameter is a requied Long, Number or String')
}
return value
}
}
});
// take negative rshares, divide by 2, truncate 10 digits (plus neg sign), count digits.
// creates a cheap log10, stake-based flag weight. 1 = approx $400 of downvoting stake; 2 = $4,000; etc
const flagWeight = Math.max(
String(neg_rshares.div(2)).length - minDigits - 1,
0
);
// post must have non-trivial negative rshares to be grayed out. (more than 10 digits)
const grayThreshold = -(Math.pow(10, minDigits) - 1);
const meetsGrayThreshold = net_rshares_adj.compare(grayThreshold) < 0;
// to be eligible for deletion, a comment must have non-positive rshares and no replies
const hasPositiveRshares = Long.fromString(
String(content.get('net_rshares'))
).gt(Long.ZERO);
const allowDelete = !hasPositiveRshares && content.get('children') === 0;
// Expecting this to come from SCOT data.
const hasPendingPayout =
(content.has('vote_rshares') &&
parsePayoutAmount(content.get('vote_rshares')) > 0) ||
parsePayoutAmount(content.get('pending_payout_value')) >= 0.02;
const authorRepLog10 = repLog10(content.get('author_reputation'));
const gray =
!hasPendingPayout && (authorRepLog10 < 1 || meetsGrayThreshold);
const hide = !hasPendingPayout && authorRepLog10 < 0; // rephide
// Combine tags+category to check nsfw status
const json = content.get('json_metadata');
function netRshares(a) {
return Long.fromString(String(a.get('net_rshares')));
}
function countUpvotes(a) {
decodeNameHex: (hex, littleEndian = true) =>
decodeName(Long.fromString(hex, true, 16).toString(), littleEndian),
DecimalString,
to_long(value, field_name=""){
if (this.is_empty(value) ){ return value; }
if (Long.isLong(value) ){ return value; }
this.no_overflow64(value, field_name);
if (typeof value === "number") {
value = ""+value;
}
return Long.fromString(value);
},
to_long(value, field_name=""){
if (is_empty(value) ){ return value; }
if (Long.isLong(value) ){ return value; }
_my.no_overflow64(value, field_name);
if (typeof value === "number") {
value = ""+value;
}
return Long.fromString(value);
},