From 5a567d09d151f7088eaa58e49ae47158ac9fdfd2 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Tue, 12 Sep 2023 18:27:15 +0200 Subject: [PATCH] Drop dependency on "pretty-bytes" module --- licenses/index.html | 10 --- licenses/pretty-bytes.txt | 9 --- node_modules/pretty-bytes/index.d.ts | 66 ------------------- node_modules/pretty-bytes/index.js | 76 ---------------------- node_modules/pretty-bytes/license | 9 --- node_modules/pretty-bytes/package.json | 76 ---------------------- node_modules/pretty-bytes/readme.md | 89 -------------------------- svr.js | 48 +++++--------- 8 files changed, 16 insertions(+), 367 deletions(-) delete mode 100644 licenses/pretty-bytes.txt delete mode 100755 node_modules/pretty-bytes/index.d.ts delete mode 100755 node_modules/pretty-bytes/index.js delete mode 100755 node_modules/pretty-bytes/license delete mode 100755 node_modules/pretty-bytes/package.json delete mode 100755 node_modules/pretty-bytes/readme.md diff --git a/licenses/index.html b/licenses/index.html index 7d655b3..4aa0b50 100644 --- a/licenses/index.html +++ b/licenses/index.html @@ -286,16 +286,6 @@ Run a function exactly one time -
-
License: MIT
-
- pretty-bytes (by Sindre Sorhus) -
-
- Convert bytes to a human readable string: 1337 → 1.34 kB
- Required by SVR.JS. -
-
License: BSD-3
diff --git a/licenses/pretty-bytes.txt b/licenses/pretty-bytes.txt deleted file mode 100644 index e7af2f7..0000000 --- a/licenses/pretty-bytes.txt +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) Sindre Sorhus (sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/pretty-bytes/index.d.ts b/node_modules/pretty-bytes/index.d.ts deleted file mode 100755 index 9a64626..0000000 --- a/node_modules/pretty-bytes/index.d.ts +++ /dev/null @@ -1,66 +0,0 @@ -declare namespace prettyBytes { - interface Options { - /** - Include plus sign for positive numbers. If the difference is exactly zero a space character will be prepended instead for better alignment. - - @default false - */ - readonly signed?: boolean; - - /** - - If `false`: Output won't be localized. - - If `true`: Localize the output using the system/browser locale. - - If `string`: Expects a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …) - - __Note:__ Localization should generally work in browsers. Node.js needs to be [built](https://github.com/nodejs/node/wiki/Intl) with `full-icu` or `system-icu`. Alternatively, the [`full-icu`](https://github.com/unicode-org/full-icu-npm) module can be used to provide support at runtime. - - @default false - */ - readonly locale?: boolean | string; - - /** - Format the number as [bits](https://en.wikipedia.org/wiki/Bit) instead of [bytes](https://en.wikipedia.org/wiki/Byte). This can be useful when, for example, referring to [bit rate](https://en.wikipedia.org/wiki/Bit_rate). - - @default false - - ``` - import prettyBytes = require('pretty-bytes'); - - prettyBytes(1337, {bits: true}); - //=> '1.34 kbit' - ``` - */ - readonly bits?: boolean; - } -} - -/** -Convert bytes to a human readable string: `1337` → `1.34 kB`. - -@param number - The number to format. - -@example -``` -import prettyBytes = require('pretty-bytes'); - -prettyBytes(1337); -//=> '1.34 kB' - -prettyBytes(100); -//=> '100 B' - -// Display file size differences -prettyBytes(42, {signed: true}); -//=> '+42 B' - -// Localized output using German locale -prettyBytes(1337, {locale: 'de'}); -//=> '1,34 kB' -``` -*/ -declare function prettyBytes( - number: number, - options?: prettyBytes.Options -): string; - -export = prettyBytes; diff --git a/node_modules/pretty-bytes/index.js b/node_modules/pretty-bytes/index.js deleted file mode 100755 index b7a0bac..0000000 --- a/node_modules/pretty-bytes/index.js +++ /dev/null @@ -1,76 +0,0 @@ -'use strict'; - -const BYTE_UNITS = [ - 'B', - 'kB', - 'MB', - 'GB', - 'TB', - 'PB', - 'EB', - 'ZB', - 'YB' -]; - -const BIT_UNITS = [ - 'b', - 'kbit', - 'Mbit', - 'Gbit', - 'Tbit', - 'Pbit', - 'Ebit', - 'Zbit', - 'Ybit' -]; - -/* -Formats the given number using `Number#toLocaleString`. -- If locale is a string, the value is expected to be a locale-key (for example: `de`). -- If locale is true, the system default locale is used for translation. -- If no value for locale is specified, the number is returned unmodified. -*/ -const toLocaleString = (number, locale) => { - let result = number; - if (typeof locale === 'string') { - result = number.toLocaleString(locale); - } else if (locale === true) { - result = number.toLocaleString(); - } - - return result; -}; - -module.exports = (number, options) => { - if (!Number.isFinite(number)) { - throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`); - } - - options = Object.assign({bits: false}, options); - const UNITS = options.bits ? BIT_UNITS : BYTE_UNITS; - - if (options.signed && number === 0) { - return ' 0 ' + UNITS[0]; - } - - const isNegative = number < 0; - const prefix = isNegative ? '-' : (options.signed ? '+' : ''); - - if (isNegative) { - number = -number; - } - - if (number < 1) { - const numberString = toLocaleString(number, options.locale); - return prefix + numberString + ' ' + UNITS[0]; - } - - const exponent = Math.min(Math.floor(Math.log10(number) / 3), UNITS.length - 1); - // eslint-disable-next-line unicorn/prefer-exponentiation-operator - number = Number((number / Math.pow(1000, exponent)).toPrecision(3)); - const numberString = toLocaleString(number, options.locale); - - const unit = UNITS[exponent]; - - return prefix + numberString + ' ' + unit; -}; diff --git a/node_modules/pretty-bytes/license b/node_modules/pretty-bytes/license deleted file mode 100755 index e7af2f7..0000000 --- a/node_modules/pretty-bytes/license +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) Sindre Sorhus (sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/pretty-bytes/package.json b/node_modules/pretty-bytes/package.json deleted file mode 100755 index 9f4af15..0000000 --- a/node_modules/pretty-bytes/package.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "_from": "pretty-bytes@^5.3.0", - "_id": "pretty-bytes@5.3.0", - "_inBundle": false, - "_integrity": "sha512-hjGrh+P926p4R4WbaB6OckyRtO0F0/lQBiT+0gnxjV+5kjPBrfVBFCsCLbMqVQeydvIoouYTCmmEURiH3R1Bdg==", - "_location": "/pretty-bytes", - "_phantomChildren": {}, - "_requested": { - "type": "range", - "registry": true, - "raw": "pretty-bytes@^5.3.0", - "name": "pretty-bytes", - "escapedName": "pretty-bytes", - "rawSpec": "^5.3.0", - "saveSpec": null, - "fetchSpec": "^5.3.0" - }, - "_requiredBy": [ - "/autocannon" - ], - "_resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.3.0.tgz", - "_shasum": "f2849e27db79fb4d6cfe24764fc4134f165989f2", - "_spec": "pretty-bytes@^5.3.0", - "_where": "/media/serveradmin/Server/developement/node_modules/autocannon", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "bugs": { - "url": "https://github.com/sindresorhus/pretty-bytes/issues" - }, - "bundleDependencies": false, - "deprecated": false, - "description": "Convert bytes to a human readable string: 1337 → 1.34 kB", - "devDependencies": { - "ava": "^1.4.1", - "full-icu": "^1.2.1", - "tsd": "^0.7.2", - "xo": "^0.24.0" - }, - "engines": { - "node": ">=6" - }, - "files": [ - "index.js", - "index.d.ts" - ], - "homepage": "https://github.com/sindresorhus/pretty-bytes#readme", - "keywords": [ - "pretty", - "bytes", - "byte", - "filesize", - "size", - "file", - "human", - "humanized", - "readable", - "si", - "data", - "locale", - "localization", - "localized" - ], - "license": "MIT", - "name": "pretty-bytes", - "repository": { - "type": "git", - "url": "git+https://github.com/sindresorhus/pretty-bytes.git" - }, - "scripts": { - "test": "xo && NODE_ICU_DATA=node_modules/full-icu ava && tsd" - }, - "version": "5.3.0" -} diff --git a/node_modules/pretty-bytes/readme.md b/node_modules/pretty-bytes/readme.md deleted file mode 100755 index 0f77498..0000000 --- a/node_modules/pretty-bytes/readme.md +++ /dev/null @@ -1,89 +0,0 @@ -# pretty-bytes [![Build Status](https://travis-ci.org/sindresorhus/pretty-bytes.svg?branch=master)](https://travis-ci.org/sindresorhus/pretty-bytes) - -> Convert bytes to a human readable string: `1337` → `1.34 kB` - -Useful for displaying file sizes for humans. - -*Note that it uses base-10 (e.g. kilobyte). -[Read about the difference between kilobyte and kibibyte.](https://web.archive.org/web/20150324153922/https://pacoup.com/2009/05/26/kb-kb-kib-whats-up-with-that/)* - - -## Install - -``` -$ npm install pretty-bytes -``` - - -## Usage - -```js -const prettyBytes = require('pretty-bytes'); - -prettyBytes(1337); -//=> '1.34 kB' - -prettyBytes(100); -//=> '100 B' - -// Display with units of bits -prettyBytes(1337, {bits: true}); -//=> '1.34 kbit' - -// Display file size differences -prettyBytes(42, {signed: true}); -//=> '+42 B' - -// Localized output using German locale -prettyBytes(1337, {locale: 'de'}); -//=> '1,34 kB' -``` - - -## API - -### prettyBytes(number, [options]) - -#### number - -Type: `number` - -The number to format. - -#### options - -Type: `object` - -##### signed - -Type: `boolean`
-Default: `false` - -Include plus sign for positive numbers. If the difference is exactly zero a space character will be prepended instead for better alignment. - -##### bits - -Type: `boolean`
-Default: `false` - -Format the number as [bits](https://en.wikipedia.org/wiki/Bit) instead of [bytes](https://en.wikipedia.org/wiki/Byte). This can be useful when, for example, referring to [bit rate](https://en.wikipedia.org/wiki/Bit_rate). - -##### locale - -Type: `boolean` `string`
-Default: `false` *(No localization)* - -- If `true`: Localize the output using the system/browser locale. -- If `string`: Expects a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …) - -**Note:** Localization should generally work in browsers. Node.js needs to be [built](https://github.com/nodejs/node/wiki/Intl) with `full-icu` or `system-icu`. Alternatively, the [`full-icu`](https://github.com/unicode-org/full-icu-npm) module can be used to provide support at runtime. - - -## Related - -- [pretty-bytes-cli](https://github.com/sindresorhus/pretty-bytes-cli) - CLI for this module - - -## License - -MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/svr.js b/svr.js index b4bcde5..a76d263 100644 --- a/svr.js +++ b/svr.js @@ -435,14 +435,6 @@ try { _errored: err }; } -var prettyBytes = undefined; -try { - prettyBytes = require("pretty-bytes"); -} catch (err) { - prettyBytes = { - _errored: err - }; -} var http2 = {}; try { http2 = require("http2"); @@ -509,30 +501,22 @@ var modFiles = fs.readdirSync(__dirname + "/mods").sort(); var modInfos = []; function sizify(x) { - try { - if (prettyBytes._errored) throw prettyBytes._errored; - return prettyBytes(parseInt(x), { - minimumFractionDigits: 0, - maximumFractionDigits: 2 - }).replace(/ /g, "").replace(/B/ig, "").replace(/k/g, "K"); - } catch (err) { - if (x < 1000) return x.toString(); - if (x < 10000) return (Math.round(x / 10) / 100).toString() + "K"; - if (x < 100000) return (Math.round(x / 100) / 10).toString() + "K"; - if (x < 1000000) return (Math.round(x / 1000)).toString() + "K"; - if (x < 10000000) return (Math.round(x / 10000) / 100).toString() + "M"; - if (x < 100000000) return (Math.round(x / 100000) / 10).toString() + "M"; - if (x < 1000000000) return (Math.round(x / 1000000)).toString() + "M"; - if (x < 10000000000) return (Math.round(x / 10000000) / 100).toString() + "G"; - if (x < 100000000000) return (Math.round(x / 100000000) / 10).toString() + "G"; - if (x < 1000000000000) return (Math.round(x / 1000000000)).toString() + "G"; - if (x < 10000000000000) return (Math.round(x / 10000000000) / 100).toString() + "T"; - if (x < 100000000000000) return (Math.round(x / 100000000000) / 10).toString() + "T"; - if (x < 1000000000000000) return (Math.round(x / 1000000000000)).toString() + "T"; - if (x < 10000000000000000) return (Math.round(x / 10000000000000) / 100).toString() + "P"; - if (x < 100000000000000000) return (Math.round(x / 100000000000000) / 10).toString() + "P"; - return (Math.round(x / 1000000000000000)).toString() + "P"; - } + if (x < 1000) return x.toString(); + if (x < 10000) return (Math.round(x / 10) / 100).toString() + "K"; + if (x < 100000) return (Math.round(x / 100) / 10).toString() + "K"; + if (x < 1000000) return (Math.round(x / 1000)).toString() + "K"; + if (x < 10000000) return (Math.round(x / 10000) / 100).toString() + "M"; + if (x < 100000000) return (Math.round(x / 100000) / 10).toString() + "M"; + if (x < 1000000000) return (Math.round(x / 1000000)).toString() + "M"; + if (x < 10000000000) return (Math.round(x / 10000000) / 100).toString() + "G"; + if (x < 100000000000) return (Math.round(x / 100000000) / 10).toString() + "G"; + if (x < 1000000000000) return (Math.round(x / 1000000000)).toString() + "G"; + if (x < 10000000000000) return (Math.round(x / 10000000000) / 100).toString() + "T"; + if (x < 100000000000000) return (Math.round(x / 100000000000) / 10).toString() + "T"; + if (x < 1000000000000000) return (Math.round(x / 1000000000000)).toString() + "T"; + if (x < 10000000000000000) return (Math.round(x / 10000000000000) / 100).toString() + "P"; + if (x < 100000000000000000) return (Math.round(x / 100000000000000) / 10).toString() + "P"; + return (Math.round(x / 1000000000000000)).toString() + "P"; } function getOS() {