From 1d44cf0ccc62b3f743242b2104754c23f6193936 Mon Sep 17 00:00:00 2001 From: ptrcnull Date: Thu, 29 Dec 2022 12:31:42 +0100 Subject: [PATCH] node-print: upgrade to 9 --- node-print/APKBUILD | 4 ++-- node-print/index.js | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/node-print/APKBUILD b/node-print/APKBUILD index 257c207..53dc686 100644 --- a/node-print/APKBUILD +++ b/node-print/APKBUILD @@ -1,7 +1,7 @@ # Contributor: Patrycja Rosa # Maintainer: Patrycja Rosa pkgname=node-print -pkgver=8 +pkgver=9 pkgrel=0 pkgdesc="another terrible javascript engine wrapper" url="https://git.ddd.rip/ptrcnull/ptrcports" @@ -43,5 +43,5 @@ package() { sha512sums=" b3dfdeb49637be33d2e2718c5abcf35a87dd55023918c99341273c3b38bd6685189d1f786451a742c47c5f3bc3b58555decb58e2a3a018c9b9ee92043f8fac03 np -4e80247d16485e2ca4e0d4e92523a5a99727dba20e5c3e64737d74676853d1a92278d54bccf5d4a5d159dc282f95cd484b3e7bbc206b0675d7b50e37c428f125 index.js +78e8f576fe7d13394c08fc7746817cfaf61ff76fd779f09fb0ace9ac72a5fd7202479624b50f1b4b03375aae86685a8da9d7e7c034dc69ee4b5fb336ee37fdb1 index.js " diff --git a/node-print/index.js b/node-print/index.js index 86e3364..c39f20d 100644 --- a/node-print/index.js +++ b/node-print/index.js @@ -17,6 +17,11 @@ String.prototype.reverse = function() { return this.split('').reverse().join('') } +String.prototype.includesAny = function(strings) { + if (!(strings instanceof Array)) throw new TypeError('strings must be an Array') + return strings.some(x => this.includes(x)) +} + String.prototype.tryParseJSON = function() { const str = this.trim() if ( @@ -55,8 +60,17 @@ global.exec = (command, args, options) => { 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) + .map(x => Object.fromEntries(x.lines().map(e => [e.at(0), e.slice(2)]))) + .map(pkg => ({ + ...pkg, + S: Number(pkg.S), + I: Number(pkg.I), + t: new Date(Number(pkg.t) * 1000), + i: pkg.i?.split(' '), + D: pkg.D?.split(' '), + p: pkg.p?.split(' ') + })) + .map(Object.prune) Array.prototype.sum = function(def = 0) { return this.reduce((a, b) => a + b, def) @@ -90,6 +104,10 @@ Array.prototype.chunks = function(chunkSize) { .map((_, i) => this.slice(i * chunkSize, (i + 1) * chunkSize)) } +Array.prototype.transpose = function() { + return new Array(this[0].length).fill().map((_, i) => this.map(x => x[i])) +} + Set.prototype.union = function(other) { if (!other || !(other instanceof Set)) throw new TypeError('other must be a Set') return new Set([...this, ...other]) @@ -118,3 +136,19 @@ Number.prototype.toXY = function(width) { if (!(width && typeof width === 'number')) throw new TypeError('width must be a Number') return [ this % width, Math.floor(this / width) ] } + +global.sed = function(filename, cb) { + let content = fs.readFileSync(filename, 'utf-8') + content = cb(content) + fs.writeFileSync(filename, content, 'utf-8') +} + +Object.prune = function(obj) { + if (typeof obj !== 'object') throw new TypeError('obj must be an object') + for (let key of Object.keys(obj)) { + if (obj[key] === undefined) { + delete obj[key] + } + } + return obj +}