@code-pushup/utils 0.12.10 → 0.13.0

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 CHANGED
@@ -1,9 +1,3 @@
1
- // packages/utils/src/lib/execute-process.ts
2
- import { spawn } from "node:child_process";
3
-
4
- // packages/utils/src/lib/reports/utils.ts
5
- import { join as join2 } from "node:path";
6
-
7
1
  // packages/models/src/lib/audit.ts
8
2
  import { z as z2 } from "zod";
9
3
 
@@ -550,6 +544,12 @@ var reportSchema = packageVersionSchema({
550
544
  })
551
545
  );
552
546
 
547
+ // packages/utils/src/lib/execute-process.ts
548
+ import { spawn } from "node:child_process";
549
+
550
+ // packages/utils/src/lib/reports/utils.ts
551
+ import { join as join2 } from "node:path";
552
+
553
553
  // packages/utils/src/lib/file-system.ts
554
554
  import { bundleRequire } from "bundle-require";
555
555
  import chalk from "chalk";
@@ -1410,6 +1410,7 @@ function withColor({ score, text }) {
1410
1410
  }
1411
1411
 
1412
1412
  // packages/utils/src/lib/transform.ts
1413
+ import { platform } from "node:os";
1413
1414
  function toArray(val) {
1414
1415
  return Array.isArray(val) ? val : [val];
1415
1416
  }
@@ -1473,6 +1474,33 @@ function toUnixPath(path, options) {
1473
1474
  }
1474
1475
  return unixPath;
1475
1476
  }
1477
+ function toUnixNewlines(text) {
1478
+ return platform() === "win32" ? text.replace(/\r\n/g, "\n") : text;
1479
+ }
1480
+ function capitalize(text) {
1481
+ return `${text.charAt(0).toLocaleUpperCase()}${text.slice(
1482
+ 1
1483
+ )}`;
1484
+ }
1485
+ function toNumberPrecision(value, decimalPlaces) {
1486
+ return Number(
1487
+ `${Math.round(
1488
+ Number.parseFloat(`${value}e${decimalPlaces}`)
1489
+ )}e-${decimalPlaces}`
1490
+ );
1491
+ }
1492
+ function toOrdinal(value) {
1493
+ if (value % 10 === 1 && value % 100 !== 11) {
1494
+ return `${value}st`;
1495
+ }
1496
+ if (value % 10 === 2 && value % 100 !== 12) {
1497
+ return `${value}nd`;
1498
+ }
1499
+ if (value % 10 === 3 && value % 100 !== 13) {
1500
+ return `${value}rd`;
1501
+ }
1502
+ return `${value}th`;
1503
+ }
1476
1504
 
1477
1505
  // packages/utils/src/lib/reports/scoring.ts
1478
1506
  function scoreReport(report) {
@@ -1635,6 +1663,7 @@ export {
1635
1663
  README_LINK,
1636
1664
  TERMINAL_WIDTH,
1637
1665
  calcDuration,
1666
+ capitalize,
1638
1667
  compareIssueSeverity,
1639
1668
  countOccurrences,
1640
1669
  crawlFileSystem,
@@ -1642,6 +1671,7 @@ export {
1642
1671
  distinct,
1643
1672
  ensureDirectoryExists,
1644
1673
  executeProcess,
1674
+ exists,
1645
1675
  factorOf,
1646
1676
  fileExists,
1647
1677
  findLineNumberInText,
@@ -1671,6 +1701,9 @@ export {
1671
1701
  slugify,
1672
1702
  sortReport,
1673
1703
  toArray,
1704
+ toNumberPrecision,
1705
+ toOrdinal,
1706
+ toUnixNewlines,
1674
1707
  toUnixPath,
1675
1708
  truncateDescription,
1676
1709
  truncateIssueMessage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/utils",
3
- "version": "0.12.10",
3
+ "version": "0.13.0",
4
4
  "dependencies": {
5
5
  "@code-pushup/models": "*",
6
6
  "bundle-require": "^4.0.1",
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { exists } from '@code-pushup/models';
1
2
  export { ProcessConfig, ProcessError, ProcessObserver, ProcessResult, executeProcess, } from './lib/execute-process';
2
3
  export { CrawlFileSystemOptions, FileResult, MultipleFileResults, crawlFileSystem, directoryExists, ensureDirectoryExists, fileExists, findLineNumberInText, importEsmModule, logMultipleFileResults, pluginWorkDir, readJsonFile, readTextFile, } from './lib/file-system';
3
4
  export { formatBytes, formatDuration, pluralize, pluralizeToken, slugify, truncateDescription, truncateIssueMessage, truncateText, truncateTitle, } from './lib/formatting';
@@ -6,11 +7,11 @@ export { groupByStatus } from './lib/group-by-status';
6
7
  export { isPromiseFulfilledResult, isPromiseRejectedResult, } from './lib/guards';
7
8
  export { logMultipleResults } from './lib/log-results';
8
9
  export { ProgressBar, getProgressBar } from './lib/progress';
10
+ export { TERMINAL_WIDTH } from './lib/reports/constants';
9
11
  export { generateMdReport } from './lib/reports/generate-md-report';
10
12
  export { generateStdoutSummary } from './lib/reports/generate-stdout-summary';
11
13
  export { ScoredReport, scoreReport } from './lib/reports/scoring';
12
14
  export { sortReport } from './lib/reports/sorting';
13
15
  export { CODE_PUSHUP_DOMAIN, FOOTER_PREFIX, README_LINK, calcDuration, compareIssueSeverity, loadReport, } from './lib/reports/utils';
14
- export { TERMINAL_WIDTH } from './lib/reports/constants';
15
- export { CliArgsObject, countOccurrences, distinct, factorOf, objectToCliArgs, objectToEntries, objectToKeys, toArray, toUnixPath, } from './lib/transform';
16
+ export { CliArgsObject, capitalize, countOccurrences, distinct, factorOf, objectToCliArgs, objectToEntries, objectToKeys, toArray, toNumberPrecision, toOrdinal, toUnixNewlines, toUnixPath, } from './lib/transform';
16
17
  export { verboseUtils } from './lib/verbose-utils';
@@ -2,6 +2,7 @@ export declare function toArray<T>(val: T | T[]): T[];
2
2
  export declare function objectToKeys<T extends object>(obj: T): (keyof T)[];
3
3
  export declare function objectToEntries<T extends object>(obj: T): [keyof T, T[keyof T]][];
4
4
  export declare function countOccurrences<T extends PropertyKey>(values: T[]): Partial<Record<T, number>>;
5
+ export declare function exists<T>(value: T): value is NonNullable<T>;
5
6
  export declare function distinct<T extends string | number | boolean>(array: T[]): T[];
6
7
  export declare function deepClone<T>(obj: T): T;
7
8
  export declare function factorOf<T>(items: T[], filterFn: (i: T) => boolean): number;
@@ -24,4 +25,8 @@ export declare function objectToCliArgs<T extends object = Record<string, Argume
24
25
  export declare function toUnixPath(path: string, options?: {
25
26
  toRelative?: boolean;
26
27
  }): string;
28
+ export declare function toUnixNewlines(text: string): string;
29
+ export declare function capitalize<T extends string>(text: T): Capitalize<T>;
30
+ export declare function toNumberPrecision(value: number, decimalPlaces: number): number;
31
+ export declare function toOrdinal(value: number): string;
27
32
  export {};