@code-pushup/utils 0.8.19 → 0.8.21

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.
Files changed (2) hide show
  1. package/index.js +12 -23
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -18,59 +18,48 @@ var MAX_DESCRIPTION_LENGTH = 65536;
18
18
  var MAX_ISSUE_MESSAGE_LENGTH = 1024;
19
19
 
20
20
  // packages/models/src/lib/implementation/utils.ts
21
- var slugRegex = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
21
+ var slugRegex = /^[a-z\d]+(?:-[a-z\d]+)*$/;
22
22
  var filenameRegex = /^(?!.*[ \\/:*?"<>|]).+$/;
23
23
  function hasDuplicateStrings(strings) {
24
- const uniqueStrings = Array.from(new Set(strings));
25
- const duplicatedStrings = strings.filter(
26
- /* @__PURE__ */ ((i) => (v) => uniqueStrings[i] !== v || !++i)(0)
24
+ const sortedStrings = [...strings].sort();
25
+ const duplStrings = sortedStrings.filter(
26
+ (item, index) => index !== 0 && item === sortedStrings[index - 1]
27
27
  );
28
- return duplicatedStrings.length === 0 ? false : duplicatedStrings;
28
+ return duplStrings.length === 0 ? false : [...new Set(duplStrings)];
29
29
  }
30
30
  function hasMissingStrings(toCheck, existing) {
31
31
  const nonExisting = toCheck.filter((s) => !existing.includes(s));
32
32
  return nonExisting.length === 0 ? false : nonExisting;
33
33
  }
34
- function errorItems(items, transform = (items2) => items2.join(", ")) {
35
- const paredItems = items ? items : [];
36
- return transform(paredItems);
34
+ function errorItems(items, transform = (itemArr) => itemArr.join(", ")) {
35
+ return transform(items || []);
37
36
  }
38
37
  function exists(value) {
39
38
  return value != null;
40
39
  }
41
40
  function getMissingRefsForCategories(categories, plugins) {
42
- const missingRefs = [];
43
41
  const auditRefsFromCategory = categories.flatMap(
44
42
  ({ refs }) => refs.filter(({ type }) => type === "audit").map(({ plugin, slug }) => `${plugin}/${slug}`)
45
43
  );
46
44
  const auditRefsFromPlugins = plugins.flatMap(
47
- ({ audits, slug: pluginSlug }) => {
48
- return audits.map(({ slug }) => `${pluginSlug}/${slug}`);
49
- }
45
+ ({ audits, slug: pluginSlug }) => audits.map(({ slug }) => `${pluginSlug}/${slug}`)
50
46
  );
51
47
  const missingAuditRefs = hasMissingStrings(
52
48
  auditRefsFromCategory,
53
49
  auditRefsFromPlugins
54
50
  );
55
- if (Array.isArray(missingAuditRefs) && missingAuditRefs.length > 0) {
56
- missingRefs.push(...missingAuditRefs);
57
- }
58
51
  const groupRefsFromCategory = categories.flatMap(
59
52
  ({ refs }) => refs.filter(({ type }) => type === "group").map(({ plugin, slug }) => `${plugin}#${slug} (group)`)
60
53
  );
61
54
  const groupRefsFromPlugins = plugins.flatMap(
62
- ({ groups, slug: pluginSlug }) => {
63
- return Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : [];
64
- }
55
+ ({ groups, slug: pluginSlug }) => Array.isArray(groups) ? groups.map(({ slug }) => `${pluginSlug}#${slug} (group)`) : []
65
56
  );
66
57
  const missingGroupRefs = hasMissingStrings(
67
58
  groupRefsFromCategory,
68
59
  groupRefsFromPlugins
69
60
  );
70
- if (Array.isArray(missingGroupRefs) && missingGroupRefs.length > 0) {
71
- missingRefs.push(...missingGroupRefs);
72
- }
73
- return missingRefs.length ? missingRefs : false;
61
+ const missingRefs = [missingAuditRefs, missingGroupRefs].filter((refs) => Array.isArray(refs) && refs.length > 0).flat();
62
+ return missingRefs.length > 0 ? missingRefs : false;
74
63
  }
75
64
  function missingRefsForCategoriesErrorMsg(categories, plugins) {
76
65
  const missingRefs = getMissingRefsForCategories(categories, plugins);
@@ -114,7 +103,7 @@ function metaSchema(options) {
114
103
  titleDescription,
115
104
  docsUrlDescription,
116
105
  description
117
- } = options || {};
106
+ } = options ?? {};
118
107
  return z.object(
119
108
  {
120
109
  title: titleSchema(titleDescription),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/utils",
3
- "version": "0.8.19",
3
+ "version": "0.8.21",
4
4
  "dependencies": {
5
5
  "@code-pushup/models": "*",
6
6
  "bundle-require": "^4.0.1",