1
0
Fork 0
forked from svrjs/svrjs

Drop dependency on "pretty-bytes" module

This commit is contained in:
Dorian Niemiec 2023-09-12 18:27:15 +02:00
parent e048156e18
commit 5a567d09d1
8 changed files with 16 additions and 367 deletions

View file

@ -286,16 +286,6 @@
Run a function exactly one time
</div>
</div>
<div style="width: 100%; background-color: #ccc; border: 1px solid green; text-align: left; margin: 10px 0;">
<div style="float: right;">License: MIT</div>
<div style="font-size: 20px;">
<a href="/licenses/pretty-bytes.txt"><b>pretty-bytes</b></a> (by Sindre Sorhus)
</div>
<div style="font-size: 12px;">
Convert bytes to a human readable string: 1337 → 1.34 kB<br/>
<b>Required by SVR.JS.</b>
</div>
</div>
<div style="width: 100%; background-color: #ccc; border: 1px solid green; text-align: left; margin: 10px 0;">
<div style="float: right;">License: BSD-3</div>
<div style="font-size: 20px;">

View file

@ -1,9 +0,0 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.

66
node_modules/pretty-bytes/index.d.ts generated vendored
View file

@ -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;

76
node_modules/pretty-bytes/index.js generated vendored
View file

@ -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;
};

9
node_modules/pretty-bytes/license generated vendored
View file

@ -1,9 +0,0 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.

View file

@ -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"
}

89
node_modules/pretty-bytes/readme.md generated vendored
View file

@ -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`<br>
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`<br>
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`<br>
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)

16
svr.js
View file

@ -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,13 +501,6 @@ 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";
@ -532,7 +517,6 @@ function sizify(x) {
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() {