@code-pushup/utils 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +11 -1
- package/package.json +1 -1
- package/src/index.d.ts +1 -1
package/index.js
CHANGED
|
@@ -548,7 +548,8 @@ function pluralize(text) {
|
|
|
548
548
|
return `${text}s`;
|
|
549
549
|
}
|
|
550
550
|
function formatBytes(bytes, decimals = 2) {
|
|
551
|
-
|
|
551
|
+
bytes = Math.max(bytes, 0);
|
|
552
|
+
if (!bytes)
|
|
552
553
|
return "0 B";
|
|
553
554
|
const k = 1024;
|
|
554
555
|
const dm = decimals < 0 ? 0 : decimals;
|
|
@@ -1403,6 +1404,14 @@ function deepClone(obj) {
|
|
|
1403
1404
|
}
|
|
1404
1405
|
return cloned;
|
|
1405
1406
|
}
|
|
1407
|
+
function factorOf(items, filterFn) {
|
|
1408
|
+
const itemCount = items.length;
|
|
1409
|
+
if (!itemCount) {
|
|
1410
|
+
return 1;
|
|
1411
|
+
}
|
|
1412
|
+
const filterCount = items.filter(filterFn).length;
|
|
1413
|
+
return filterCount === 0 ? 1 : (itemCount - filterCount) / itemCount;
|
|
1414
|
+
}
|
|
1406
1415
|
|
|
1407
1416
|
// packages/utils/src/lib/scoring.ts
|
|
1408
1417
|
function calculateScore(refs, scoreFn) {
|
|
@@ -1499,6 +1508,7 @@ export {
|
|
|
1499
1508
|
distinct,
|
|
1500
1509
|
ensureDirectoryExists,
|
|
1501
1510
|
executeProcess,
|
|
1511
|
+
factorOf,
|
|
1502
1512
|
findLineNumberInText,
|
|
1503
1513
|
formatBytes,
|
|
1504
1514
|
formatDuration,
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { reportToStdout } from './lib/report-to-stdout';
|
|
|
7
7
|
export { ScoredReport, scoreReport } from './lib/scoring';
|
|
8
8
|
export { readJsonFile, readTextFile, toUnixPath, ensureDirectoryExists, FileResult, MultipleFileResults, logMultipleFileResults, importEsmModule, pluginWorkDir, crawlFileSystem, findLineNumberInText, } from './lib/file-system';
|
|
9
9
|
export { verboseUtils } from './lib/verbose-utils';
|
|
10
|
-
export { toArray, objectToKeys, objectToEntries, countOccurrences, distinct, } from './lib/transformation';
|
|
10
|
+
export { toArray, objectToKeys, objectToEntries, countOccurrences, distinct, factorOf, } from './lib/transformation';
|
|
11
11
|
export { slugify, pluralize, pluralizeToken, formatBytes, formatDuration, } from './lib/formatting';
|
|
12
12
|
export { NEW_LINE } from './lib/md';
|
|
13
13
|
export { logMultipleResults } from './lib/log-results';
|