metal-orm 1.0.76 → 1.0.77

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metal-orm",
3
- "version": "1.0.76",
3
+ "version": "1.0.77",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "engines": {
@@ -70,3 +70,17 @@ export const applyToCompoundHead = (term, { connectors, transformWord } = {}) =>
70
70
  return rebuildFromWords(out, format, original);
71
71
  };
72
72
 
73
+ export const applyToCompoundWords = (term, { connectors, transformWord } = {}) => {
74
+ if (!term || !String(term).trim()) return '';
75
+ const original = String(term).trim();
76
+ const format = detectTextFormat(original);
77
+ const words = splitIntoWords(original, format);
78
+
79
+ const out = words.map(word => {
80
+ const normalized = normalizeLookup(word);
81
+ if (connectors?.has?.(normalized)) return word;
82
+ return transformWord ? transformWord(word) : word;
83
+ });
84
+
85
+ return rebuildFromWords(out, format, original);
86
+ };
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  applyToCompoundHead,
3
+ applyToCompoundWords,
4
+ detectTextFormat,
3
5
  normalizeLookup,
6
+ splitIntoWords,
4
7
  stripDiacritics
5
8
  } from './compound.mjs';
6
9
 
@@ -172,6 +175,14 @@ export const PT_BR_CONNECTORS = Object.freeze(new Set(
172
175
  ].map(normalizeLookup)
173
176
  ));
174
177
 
178
+ const hasConnectorWord = (term, connectors) => {
179
+ if (!term || !String(term).trim()) return false;
180
+ const original = String(term).trim();
181
+ const format = detectTextFormat(original);
182
+ const words = splitIntoWords(original, format);
183
+ return words.some(word => connectors?.has?.(normalizeLookup(word)));
184
+ };
185
+
175
186
  // ═══════════════════════════════════════════════════════════════════════════
176
187
  // INFLECTION RULES
177
188
  // ═══════════════════════════════════════════════════════════════════════════
@@ -348,7 +359,10 @@ export const singularizeWordPtBr = (
348
359
  export const pluralizeRelationPropertyPtBr = (
349
360
  term,
350
361
  { pluralizeWord = pluralizeWordPtBr, connectors = PT_BR_CONNECTORS } = {}
351
- ) => applyToCompoundHead(term, { connectors, transformWord: pluralizeWord });
362
+ ) =>
363
+ hasConnectorWord(term, connectors)
364
+ ? applyToCompoundHead(term, { connectors, transformWord: pluralizeWord })
365
+ : applyToCompoundWords(term, { connectors, transformWord: pluralizeWord });
352
366
 
353
367
  /**
354
368
  * Singularizes a compound property/relation name in Portuguese.
@@ -356,7 +370,10 @@ export const pluralizeRelationPropertyPtBr = (
356
370
  export const singularizeRelationPropertyPtBr = (
357
371
  term,
358
372
  { singularizeWord = singularizeWordPtBr, connectors = PT_BR_CONNECTORS } = {}
359
- ) => applyToCompoundHead(term, { connectors, transformWord: singularizeWord });
373
+ ) =>
374
+ hasConnectorWord(term, connectors)
375
+ ? applyToCompoundHead(term, { connectors, transformWord: singularizeWord })
376
+ : applyToCompoundWords(term, { connectors, transformWord: singularizeWord });
360
377
 
361
378
  // ═══════════════════════════════════════════════════════════════════════════
362
379
  // INFLECTOR FACTORY
@@ -388,4 +405,4 @@ export const createPtBrInflector = ({ customIrregulars = {} } = {}) => {
388
405
  });
389
406
  };
390
407
 
391
- export default createPtBrInflector;
408
+ export default createPtBrInflector;