@websolutespa/bom-core 0.3.0 → 0.4.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/dist/index.js CHANGED
@@ -73,14 +73,24 @@ __export(src_exports, {
73
73
  localizeValue: () => localizeValue,
74
74
  localizedToString: () => localizedToString,
75
75
  merge: () => merge,
76
+ pascalCaseToCamelCase: () => pascalCaseToCamelCase,
77
+ pascalCaseToCharCase: () => pascalCaseToCharCase,
78
+ pascalCaseToKebabCase: () => pascalCaseToKebabCase,
79
+ pascalCaseToSnakeCase: () => pascalCaseToSnakeCase,
76
80
  qsDeserialize: () => qsDeserialize,
77
81
  qsSerialize: () => qsSerialize,
78
82
  textToSlug: () => textToSlug,
83
+ toCamelCase: () => toCamelCase,
84
+ toCharCase: () => toCharCase,
79
85
  toDisplayName: () => toDisplayName,
80
86
  toFindParams: () => toFindParams,
87
+ toKebabCase: () => toKebabCase,
88
+ toPascalCase: () => toPascalCase,
81
89
  toPluralName: () => toPluralName,
90
+ toSnakeCase: () => toSnakeCase,
82
91
  toTitleCase: () => toTitleCase,
83
92
  toValidCollectionName: () => toValidCollectionName,
93
+ unknownCaseToPascalCase: () => unknownCaseToPascalCase,
84
94
  withSchema: () => withSchema
85
95
  });
86
96
  module.exports = __toCommonJS(src_exports);
@@ -102,13 +112,14 @@ function getRootCategory(categories) {
102
112
  }
103
113
  }
104
114
  function getParentCategoriesById(id, categories) {
115
+ const rootCategory = getRootCategory(categories);
105
116
  const routeCategories = [];
106
117
  const segments = [];
107
118
  let parentId = id || null;
108
119
  while (parentId != null) {
109
120
  const parentCategory = categories.find((c) => c.id === parentId);
110
121
  if (parentCategory) {
111
- if (parentCategory.slug) {
122
+ if (parentCategory.slug || parentCategory.id === rootCategory?.id) {
112
123
  const segment = { ...parentCategory };
113
124
  segments.unshift(segment);
114
125
  }
@@ -130,7 +141,6 @@ function getParentCategoriesById(id, categories) {
130
141
  function getCategorySegments(item, categories) {
131
142
  const categoryId = asCategoryId(item.category);
132
143
  const segments = getParentCategoriesById(categoryId, categories);
133
- [];
134
144
  if (item.isDefault !== true) {
135
145
  const category = categories.find((x) => x.id === item.category);
136
146
  if (category) {
@@ -197,7 +207,7 @@ function getCollectionDescription(text) {
197
207
  text = toValidCollectionName(text);
198
208
  const displayName = toDisplayName(text);
199
209
  const pluralName = toPluralName(text);
200
- const pluralDisplayName = toPluralName(displayName);
210
+ const pluralDisplayName = toDisplayName(pluralName);
201
211
  const singularName = text;
202
212
  const title = toTitleCase(text);
203
213
  return {
@@ -208,29 +218,30 @@ function getCollectionDescription(text) {
208
218
  title
209
219
  };
210
220
  }
211
- function isValidCollectionDescription(description) {
212
- return description.singularName !== description.pluralName;
213
- }
214
- function toValidCollectionName(text) {
215
- text = text.trim().replace(/\W/g, "_").replace(/^[_]*(.)/, (_, c) => c);
216
- text = camelToSnakeCase(text);
217
- text = text.replace(/__/g, "_");
218
- return text.toLowerCase();
219
- }
220
221
  function camelToSnakeCase(text) {
221
222
  return text.replace(/[A-Z]/g, (letter, index) => {
222
223
  return index > 0 ? `_${letter.toLowerCase()}` : letter.toLowerCase();
223
224
  });
224
225
  }
226
+ function isValidCollectionDescription(description) {
227
+ return description.singularName !== description.pluralName;
228
+ }
225
229
  function toDisplayName(text) {
226
230
  return toTitleCase(text).replace(/\s/g, "");
227
231
  }
228
232
  function toPluralName(text) {
229
- return import_pluralize.default.plural(text);
233
+ const plural = import_pluralize.default.plural(text);
234
+ return plural === text ? `${plural}es` : plural;
230
235
  }
231
236
  function toTitleCase(text) {
232
237
  return text.replace(/^[-_]*(.)/, (_, c) => c.toUpperCase()).replace(/[-_]+(.)/g, (_, c) => " " + c.toUpperCase());
233
238
  }
239
+ function toValidCollectionName(text) {
240
+ text = text.trim().replace(/\W/g, "_").replace(/^[_]*(.)/, (_, c) => c);
241
+ text = camelToSnakeCase(text);
242
+ text = text.replace(/__/g, "_");
243
+ return text.toLowerCase();
244
+ }
234
245
 
235
246
  // src/consoleWarn/consoleWarn.ts
236
247
  var warningStack = {};
@@ -250,6 +261,56 @@ function consoleWarn(message, component) {
250
261
  console.warn(log);
251
262
  }
252
263
 
264
+ // src/utils/babelCase.ts
265
+ function unknownCaseToPascalCase(unknownCase) {
266
+ const pascalCase = unknownCase.replace(
267
+ /(^[a-zA-Z])|(\W|_)+(\w?)([a-z0-9]*)?/g,
268
+ (m, g1, g2, g3, g4) => (g1 ? g1.toUpperCase() : "") + (g3 ? g3.toUpperCase() : "") + (g4 ? g4.toLowerCase() : "")
269
+ );
270
+ return pascalCase;
271
+ }
272
+ function pascalCaseToCamelCase(pascalCase) {
273
+ const camelCase = pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
274
+ return camelCase;
275
+ }
276
+ function pascalCaseToCharCase(pascalCase, char = "-") {
277
+ const charCase = pascalCase.replace(
278
+ /([A-Z]+)/g,
279
+ (m, g1, index) => (index > 0 ? char : "") + m
280
+ ).toLowerCase();
281
+ return charCase;
282
+ }
283
+ function pascalCaseToKebabCase(pascalCase) {
284
+ const kebabCase = pascalCaseToCharCase(pascalCase, "-");
285
+ return kebabCase;
286
+ }
287
+ function pascalCaseToSnakeCase(pascalCase) {
288
+ const kebabCase = pascalCaseToCharCase(pascalCase, "_");
289
+ return kebabCase;
290
+ }
291
+ function toPascalCase(unknownCase) {
292
+ const pascalCase = unknownCaseToPascalCase(unknownCase);
293
+ return pascalCase;
294
+ }
295
+ function toCamelCase(unknownCase) {
296
+ const pascalCase = unknownCaseToPascalCase(unknownCase);
297
+ const camelCase = pascalCaseToCamelCase(pascalCase);
298
+ return camelCase;
299
+ }
300
+ function toCharCase(unknownCase, char = "-") {
301
+ const pascalCase = unknownCaseToPascalCase(unknownCase);
302
+ const charCase = pascalCaseToCharCase(pascalCase, char);
303
+ return charCase;
304
+ }
305
+ function toKebabCase(unknownCase) {
306
+ const kebabCase = toCharCase(unknownCase, "-");
307
+ return kebabCase;
308
+ }
309
+ function toSnakeCase(unknownCase) {
310
+ const snakeCase = toCharCase(unknownCase, "_");
311
+ return snakeCase;
312
+ }
313
+
253
314
  // src/utils/enumToList.ts
254
315
  function enumToList(enumeration, separatorRegex = /_/g) {
255
316
  const array = Object.keys(enumeration);
@@ -561,6 +622,16 @@ var JsonService = class {
561
622
  return items;
562
623
  }
563
624
  // ^ sort
625
+ // limit
626
+ /*
627
+ protected limitCollection_<B extends T = T>(items: B[], limit?: number): B[] {
628
+ if (limit) {
629
+ items = items.slice(0, Math.min(limit, items.length));
630
+ }
631
+ return items;
632
+ }
633
+ */
634
+ // ^ limit
564
635
  // pagination
565
636
  paginatedItems_(items, page = 1, limit = 10) {
566
637
  const totalDocs = items.length;
@@ -912,13 +983,23 @@ var RedirectReason = /* @__PURE__ */ ((RedirectReason2) => {
912
983
  localizeValue,
913
984
  localizedToString,
914
985
  merge,
986
+ pascalCaseToCamelCase,
987
+ pascalCaseToCharCase,
988
+ pascalCaseToKebabCase,
989
+ pascalCaseToSnakeCase,
915
990
  qsDeserialize,
916
991
  qsSerialize,
917
992
  textToSlug,
993
+ toCamelCase,
994
+ toCharCase,
918
995
  toDisplayName,
919
996
  toFindParams,
997
+ toKebabCase,
998
+ toPascalCase,
920
999
  toPluralName,
1000
+ toSnakeCase,
921
1001
  toTitleCase,
922
1002
  toValidCollectionName,
1003
+ unknownCaseToPascalCase,
923
1004
  withSchema
924
1005
  });
package/dist/index.mjs CHANGED
@@ -15,13 +15,14 @@ function getRootCategory(categories) {
15
15
  }
16
16
  }
17
17
  function getParentCategoriesById(id, categories) {
18
+ const rootCategory = getRootCategory(categories);
18
19
  const routeCategories = [];
19
20
  const segments = [];
20
21
  let parentId = id || null;
21
22
  while (parentId != null) {
22
23
  const parentCategory = categories.find((c) => c.id === parentId);
23
24
  if (parentCategory) {
24
- if (parentCategory.slug) {
25
+ if (parentCategory.slug || parentCategory.id === rootCategory?.id) {
25
26
  const segment = { ...parentCategory };
26
27
  segments.unshift(segment);
27
28
  }
@@ -43,7 +44,6 @@ function getParentCategoriesById(id, categories) {
43
44
  function getCategorySegments(item, categories) {
44
45
  const categoryId = asCategoryId(item.category);
45
46
  const segments = getParentCategoriesById(categoryId, categories);
46
- [];
47
47
  if (item.isDefault !== true) {
48
48
  const category = categories.find((x) => x.id === item.category);
49
49
  if (category) {
@@ -110,7 +110,7 @@ function getCollectionDescription(text) {
110
110
  text = toValidCollectionName(text);
111
111
  const displayName = toDisplayName(text);
112
112
  const pluralName = toPluralName(text);
113
- const pluralDisplayName = toPluralName(displayName);
113
+ const pluralDisplayName = toDisplayName(pluralName);
114
114
  const singularName = text;
115
115
  const title = toTitleCase(text);
116
116
  return {
@@ -121,29 +121,30 @@ function getCollectionDescription(text) {
121
121
  title
122
122
  };
123
123
  }
124
- function isValidCollectionDescription(description) {
125
- return description.singularName !== description.pluralName;
126
- }
127
- function toValidCollectionName(text) {
128
- text = text.trim().replace(/\W/g, "_").replace(/^[_]*(.)/, (_, c) => c);
129
- text = camelToSnakeCase(text);
130
- text = text.replace(/__/g, "_");
131
- return text.toLowerCase();
132
- }
133
124
  function camelToSnakeCase(text) {
134
125
  return text.replace(/[A-Z]/g, (letter, index) => {
135
126
  return index > 0 ? `_${letter.toLowerCase()}` : letter.toLowerCase();
136
127
  });
137
128
  }
129
+ function isValidCollectionDescription(description) {
130
+ return description.singularName !== description.pluralName;
131
+ }
138
132
  function toDisplayName(text) {
139
133
  return toTitleCase(text).replace(/\s/g, "");
140
134
  }
141
135
  function toPluralName(text) {
142
- return pluralize.plural(text);
136
+ const plural = pluralize.plural(text);
137
+ return plural === text ? `${plural}es` : plural;
143
138
  }
144
139
  function toTitleCase(text) {
145
140
  return text.replace(/^[-_]*(.)/, (_, c) => c.toUpperCase()).replace(/[-_]+(.)/g, (_, c) => " " + c.toUpperCase());
146
141
  }
142
+ function toValidCollectionName(text) {
143
+ text = text.trim().replace(/\W/g, "_").replace(/^[_]*(.)/, (_, c) => c);
144
+ text = camelToSnakeCase(text);
145
+ text = text.replace(/__/g, "_");
146
+ return text.toLowerCase();
147
+ }
147
148
 
148
149
  // src/consoleWarn/consoleWarn.ts
149
150
  var warningStack = {};
@@ -163,6 +164,56 @@ function consoleWarn(message, component) {
163
164
  console.warn(log);
164
165
  }
165
166
 
167
+ // src/utils/babelCase.ts
168
+ function unknownCaseToPascalCase(unknownCase) {
169
+ const pascalCase = unknownCase.replace(
170
+ /(^[a-zA-Z])|(\W|_)+(\w?)([a-z0-9]*)?/g,
171
+ (m, g1, g2, g3, g4) => (g1 ? g1.toUpperCase() : "") + (g3 ? g3.toUpperCase() : "") + (g4 ? g4.toLowerCase() : "")
172
+ );
173
+ return pascalCase;
174
+ }
175
+ function pascalCaseToCamelCase(pascalCase) {
176
+ const camelCase = pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
177
+ return camelCase;
178
+ }
179
+ function pascalCaseToCharCase(pascalCase, char = "-") {
180
+ const charCase = pascalCase.replace(
181
+ /([A-Z]+)/g,
182
+ (m, g1, index) => (index > 0 ? char : "") + m
183
+ ).toLowerCase();
184
+ return charCase;
185
+ }
186
+ function pascalCaseToKebabCase(pascalCase) {
187
+ const kebabCase = pascalCaseToCharCase(pascalCase, "-");
188
+ return kebabCase;
189
+ }
190
+ function pascalCaseToSnakeCase(pascalCase) {
191
+ const kebabCase = pascalCaseToCharCase(pascalCase, "_");
192
+ return kebabCase;
193
+ }
194
+ function toPascalCase(unknownCase) {
195
+ const pascalCase = unknownCaseToPascalCase(unknownCase);
196
+ return pascalCase;
197
+ }
198
+ function toCamelCase(unknownCase) {
199
+ const pascalCase = unknownCaseToPascalCase(unknownCase);
200
+ const camelCase = pascalCaseToCamelCase(pascalCase);
201
+ return camelCase;
202
+ }
203
+ function toCharCase(unknownCase, char = "-") {
204
+ const pascalCase = unknownCaseToPascalCase(unknownCase);
205
+ const charCase = pascalCaseToCharCase(pascalCase, char);
206
+ return charCase;
207
+ }
208
+ function toKebabCase(unknownCase) {
209
+ const kebabCase = toCharCase(unknownCase, "-");
210
+ return kebabCase;
211
+ }
212
+ function toSnakeCase(unknownCase) {
213
+ const snakeCase = toCharCase(unknownCase, "_");
214
+ return snakeCase;
215
+ }
216
+
166
217
  // src/utils/enumToList.ts
167
218
  function enumToList(enumeration, separatorRegex = /_/g) {
168
219
  const array = Object.keys(enumeration);
@@ -474,6 +525,16 @@ var JsonService = class {
474
525
  return items;
475
526
  }
476
527
  // ^ sort
528
+ // limit
529
+ /*
530
+ protected limitCollection_<B extends T = T>(items: B[], limit?: number): B[] {
531
+ if (limit) {
532
+ items = items.slice(0, Math.min(limit, items.length));
533
+ }
534
+ return items;
535
+ }
536
+ */
537
+ // ^ limit
477
538
  // pagination
478
539
  paginatedItems_(items, page = 1, limit = 10) {
479
540
  const totalDocs = items.length;
@@ -824,13 +885,23 @@ export {
824
885
  localizeValue,
825
886
  localizedToString,
826
887
  merge,
888
+ pascalCaseToCamelCase,
889
+ pascalCaseToCharCase,
890
+ pascalCaseToKebabCase,
891
+ pascalCaseToSnakeCase,
827
892
  qsDeserialize,
828
893
  qsSerialize,
829
894
  textToSlug,
895
+ toCamelCase,
896
+ toCharCase,
830
897
  toDisplayName,
831
898
  toFindParams,
899
+ toKebabCase,
900
+ toPascalCase,
832
901
  toPluralName,
902
+ toSnakeCase,
833
903
  toTitleCase,
834
904
  toValidCollectionName,
905
+ unknownCaseToPascalCase,
835
906
  withSchema
836
907
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-core",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Core module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -26,19 +26,19 @@
26
26
  "pluralize": "latest"
27
27
  },
28
28
  "peerDependencies": {
29
- "next": ">= 12.3.2"
29
+ "next": ">= 13.4.19"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@websolutespa/bom-cli": "*",
33
33
  "@websolutespa/test": "*",
34
34
  "@websolutespa/tsconfig": "*",
35
- "eslint": "^8.36.0",
35
+ "eslint": "^8.46.0",
36
36
  "eslint-config-websolute": "*",
37
37
  "npm-run-all": "^4.1.5",
38
38
  "raw-loader": "^4.0.2",
39
39
  "ts-node": "^10.9.1",
40
40
  "tsup": "^6.7.0",
41
- "typescript": "^4.8.4"
41
+ "typescript": "^5.1.6"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"