This repository has been archived on 2023-01-08. You can view files and clone it, but cannot push or open issues or pull requests.
ptrcports/node-print/index.js
ptrcnull ec4d208c8a node-print: upgrade to 5
fixes a **critical** bug

also a random shitpost
2022-11-08 10:12:45 +01:00

60 lines
1.4 KiB
JavaScript

global.stdin = () => {
const fs = require('fs')
const out = fs.readFileSync(0).toString()
return out.tryParseJSON()
}
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
}
String.prototype.reverse = function() {
return this.split('').reverse().join('')
}
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)
res.stdout = res.stdout?.tryParseJSON()
res.stderr = res.stderr?.tryParseJSON()
return res
}
/* 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)