2022-08-27 11:01:43 +00:00
|
|
|
global.stdin = () => {
|
|
|
|
const fs = require('fs')
|
|
|
|
const out = fs.readFileSync(0).toString()
|
2022-10-11 11:16:01 +00:00
|
|
|
return out.tryParseJSON()
|
2022-08-27 11:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object.prototype.map = function(cb) {
|
|
|
|
return cb(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
String.prototype.lines = function() {
|
|
|
|
let res = this.split("\n")
|
|
|
|
return res.at(-1) === '' ? res.slice(0, -1) : res
|
|
|
|
}
|
2022-08-27 12:08:44 +00:00
|
|
|
|
|
|
|
String.prototype.reverse = function() {
|
|
|
|
return this.split('').reverse().join('')
|
|
|
|
}
|
2022-10-11 11:16:01 +00:00
|
|
|
|
|
|
|
String.prototype.tryParseJSON = function() {
|
|
|
|
const str = this.trim()
|
|
|
|
if (
|
|
|
|
(str.at(0) === '{' && str.at(-1) === '}') ||
|
|
|
|
(str.at(0) === '[' && str.at(-1) === ']')
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
return JSON.parse(str)
|
|
|
|
} catch (err) {
|
|
|
|
return this.toString()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.toString()
|
|
|
|
}
|
|
|
|
|
|
|
|
Buffer.prototype.tryParseJSON = function() {
|
|
|
|
const out = this.toString().tryParseJSON()
|
|
|
|
if (typeof out === 'string') {
|
|
|
|
return this
|
|
|
|
} else {
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
global.exec = (command, args, options) => {
|
|
|
|
const child_process = require('child_process')
|
|
|
|
const res = child_process.spawnSync(command, args, options)
|
2022-11-08 09:12:26 +00:00
|
|
|
res.stdout = res.stdout?.tryParseJSON()
|
|
|
|
res.stderr = res.stderr?.tryParseJSON()
|
2022-10-11 11:16:01 +00:00
|
|
|
return res
|
|
|
|
}
|
2022-11-08 09:12:26 +00:00
|
|
|
|
|
|
|
/* wow it's almost like it's my own package and i can include whatever garbage i want :) */
|
|
|
|
/* not writing a test for that tho */
|
|
|
|
global.apkindex = () => stdin()
|
|
|
|
.split("\n\n")
|
|
|
|
.filter(str => str.length)
|
|
|
|
.map(x => Object.fromEntries(x.split("\n").map(e => [e.at(0), e.slice(2)])))
|
|
|
|
.filter(Boolean)
|