@code-pushup/utils 0.29.0 → 0.30.0-alpha

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
@@ -1288,7 +1288,7 @@ var ProcessError = class extends Error {
1288
1288
  }
1289
1289
  };
1290
1290
  function executeProcess(cfg) {
1291
- const { observer, cwd, command, args, alwaysResolve = false } = cfg;
1291
+ const { observer, cwd, command, args, ignoreExitCode = false } = cfg;
1292
1292
  const { onStdout, onError, onComplete } = observer ?? {};
1293
1293
  const date = (/* @__PURE__ */ new Date()).toISOString();
1294
1294
  const start = performance.now();
@@ -1308,7 +1308,7 @@ function executeProcess(cfg) {
1308
1308
  });
1309
1309
  process2.on("close", (code) => {
1310
1310
  const timings = { date, duration: calcDuration(start) };
1311
- if (code === 0 || alwaysResolve) {
1311
+ if (code === 0 || ignoreExitCode) {
1312
1312
  onComplete?.();
1313
1313
  resolve({ code, stdout, stderr, ...timings });
1314
1314
  } else {
@@ -1343,6 +1343,9 @@ function objectToKeys(obj) {
1343
1343
  function objectToEntries(obj) {
1344
1344
  return Object.entries(obj);
1345
1345
  }
1346
+ function objectFromEntries(entries) {
1347
+ return Object.fromEntries(entries);
1348
+ }
1346
1349
  function countOccurrences(values) {
1347
1350
  return values.reduce(
1348
1351
  (acc, value) => ({ ...acc, [value]: (acc[value] ?? 0) + 1 }),
@@ -1396,11 +1399,23 @@ function toUnixPath(path) {
1396
1399
  function toUnixNewlines(text) {
1397
1400
  return platform() === "win32" ? text.replace(/\r\n/g, "\n") : text;
1398
1401
  }
1402
+ function fromJsonLines(jsonLines) {
1403
+ const unifiedNewLines = toUnixNewlines(jsonLines).trim();
1404
+ return JSON.parse(`[${unifiedNewLines.split("\n").join(",")}]`);
1405
+ }
1406
+ function toJsonLines(json) {
1407
+ return json.map((item) => JSON.stringify(item)).join("\n");
1408
+ }
1399
1409
  function capitalize(text) {
1400
1410
  return `${text.charAt(0).toLocaleUpperCase()}${text.slice(
1401
1411
  1
1402
1412
  )}`;
1403
1413
  }
1414
+ function apostrophize(text, upperCase) {
1415
+ const lastCharMatch = text.match(/(\w)\W*$/);
1416
+ const lastChar = lastCharMatch?.[1] ?? "";
1417
+ return `${text}'${lastChar.toLocaleLowerCase() === "s" ? "" : upperCase ? "S" : "s"}`;
1418
+ }
1404
1419
  function toNumberPrecision(value, decimalPlaces) {
1405
1420
  return Number(
1406
1421
  `${Math.round(
@@ -2206,6 +2221,7 @@ export {
2206
2221
  ProcessError,
2207
2222
  README_LINK,
2208
2223
  TERMINAL_WIDTH,
2224
+ apostrophize,
2209
2225
  calcDuration,
2210
2226
  capitalize,
2211
2227
  compareIssueSeverity,
@@ -2224,6 +2240,7 @@ export {
2224
2240
  formatBytes,
2225
2241
  formatDuration,
2226
2242
  formatGitPath,
2243
+ fromJsonLines,
2227
2244
  generateMdReport,
2228
2245
  generateMdReportsDiff,
2229
2246
  getCurrentBranchOrTag,
@@ -2242,6 +2259,7 @@ export {
2242
2259
  logMultipleResults,
2243
2260
  logStdoutSummary,
2244
2261
  matchArrayItemsByKey,
2262
+ objectFromEntries,
2245
2263
  objectToCliArgs,
2246
2264
  objectToEntries,
2247
2265
  objectToKeys,
@@ -2257,6 +2275,7 @@ export {
2257
2275
  sortReport,
2258
2276
  toArray,
2259
2277
  toGitPath,
2278
+ toJsonLines,
2260
2279
  toNumberPrecision,
2261
2280
  toOrdinal,
2262
2281
  toUnixNewlines,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/utils",
3
- "version": "0.29.0",
3
+ "version": "0.30.0-alpha",
4
4
  "dependencies": {
5
5
  "@code-pushup/models": "*",
6
6
  "bundle-require": "^4.0.1",
package/src/index.d.ts CHANGED
@@ -19,5 +19,5 @@ export { scoreReport } from './lib/reports/scoring';
19
19
  export { sortReport } from './lib/reports/sorting';
20
20
  export { ScoredCategoryConfig, ScoredGroup, ScoredReport, } from './lib/reports/types';
21
21
  export { calcDuration, compareIssueSeverity, loadReport, } from './lib/reports/utils';
22
- export { CliArgsObject, capitalize, countOccurrences, distinct, factorOf, objectToCliArgs, objectToEntries, objectToKeys, toArray, toNumberPrecision, toOrdinal, toUnixNewlines, toUnixPath, } from './lib/transform';
22
+ export { CliArgsObject, apostrophize, capitalize, countOccurrences, distinct, factorOf, fromJsonLines, objectFromEntries, objectToCliArgs, objectToEntries, objectToKeys, toArray, toJsonLines, toNumberPrecision, toOrdinal, toUnixNewlines, toUnixPath, } from './lib/transform';
23
23
  export { verboseUtils } from './lib/verbose-utils';
@@ -71,7 +71,7 @@ export type ProcessConfig = {
71
71
  args?: string[];
72
72
  cwd?: string;
73
73
  observer?: ProcessObserver;
74
- alwaysResolve?: boolean;
74
+ ignoreExitCode?: boolean;
75
75
  };
76
76
  /**
77
77
  * Process observer object. Contains the onStdout, error and complete function.
@@ -1,6 +1,7 @@
1
1
  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
+ export declare function objectFromEntries<K extends PropertyKey, V>(entries: [K, V][]): Record<K, V>;
4
5
  export declare function countOccurrences<T extends PropertyKey>(values: T[]): Partial<Record<T, number>>;
5
6
  export declare function exists<T>(value: T): value is NonNullable<T>;
6
7
  export declare function distinct<T extends string | number | boolean>(array: T[]): T[];
@@ -24,7 +25,10 @@ Record<string, ArgumentValue | undefined> | {
24
25
  export declare function objectToCliArgs<T extends object = Record<string, ArgumentValue>>(params?: CliArgsObject<T>): string[];
25
26
  export declare function toUnixPath(path: string): string;
26
27
  export declare function toUnixNewlines(text: string): string;
28
+ export declare function fromJsonLines<T = unknown>(jsonLines: string): T;
29
+ export declare function toJsonLines<T>(json: T[]): string;
27
30
  export declare function capitalize<T extends string>(text: T): Capitalize<T>;
31
+ export declare function apostrophize(text: string, upperCase?: boolean): string;
28
32
  export declare function toNumberPrecision(value: number, decimalPlaces: number): number;
29
33
  export declare function toOrdinal(value: number): string;
30
34
  export {};