From e322afd0db1153fefb555cb186601475df4c71e2 Mon Sep 17 00:00:00 2001 From: ptrcnull Date: Fri, 28 Apr 2023 05:11:30 +0200 Subject: [PATCH] node-print: upgrade to 11 --- node-print/APKBUILD | 4 ++-- node-print/index.js | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/node-print/APKBUILD b/node-print/APKBUILD index 3af34f1..dc39063 100644 --- a/node-print/APKBUILD +++ b/node-print/APKBUILD @@ -1,7 +1,7 @@ # Contributor: Patrycja Rosa # Maintainer: Patrycja Rosa pkgname=node-print -pkgver=10 +pkgver=11 pkgrel=0 pkgdesc="another terrible javascript engine wrapper" url="https://git.ddd.rip/ptrcnull/ptrcports" @@ -43,5 +43,5 @@ package() { sha512sums=" b3dfdeb49637be33d2e2718c5abcf35a87dd55023918c99341273c3b38bd6685189d1f786451a742c47c5f3bc3b58555decb58e2a3a018c9b9ee92043f8fac03 np -85ad9dfdfc32afa606855d0484fa43bdc52c0d2f66e8702e98ebc37621e3f961a3939fdb4b21e4518505160b9fb1a52c70ad9185c81e484374f94b52b4f26a13 index.js +3355f0f044726a75111f7a2788c5eb6150e44c7f9b4789973a6dda9ac980bc6133677067007e9c40f4c576ad2f8365922f98eda422e690a12775025eb788b584 index.js " diff --git a/node-print/index.js b/node-print/index.js index d334de8..2dc25ed 100644 --- a/node-print/index.js +++ b/node-print/index.js @@ -1,5 +1,7 @@ +const fs = require('fs') +const child_process = require('child_process') + global.stdin = () => { - const fs = require('fs') const out = fs.readFileSync(0).toString() return out.tryParseJSON() } @@ -8,6 +10,8 @@ Object.prototype.map = function(cb) { return cb(this) } +Object.prototype.apply = Object.prototype.map + String.prototype.lines = function() { let res = this.split("\n") return res.at(-1) === '' ? res.slice(0, -1) : res @@ -48,10 +52,18 @@ Buffer.prototype.tryParseJSON = function() { } 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() + res.orFail = function() { + if (res.status !== 0) { + const cmd = [ + command, + ...((args && Array.isArray(args)) ? args : []) + ].join(' ') + throw new Error(`command '${cmd}' exited with code ${res.status}`) + } + } return res } @@ -86,8 +98,8 @@ Array.prototype.product = function(def = 1) { return this.reduce((a, b) => a * b, def) } -Array.prototype.sortNum = function() { - return this.sort((a, b) => a - b) +Array.prototype.sortNum = function(getter = (x => x)) { + return this.sort((a, b) => getter(a) - getter(b)) } Array.prototype.partition = function(compareFn) {