xlsform2lstsv 0.2.0 → 0.2.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.
@@ -686,11 +686,34 @@ export class XLSFormToTSVConverter {
686
686
  }
687
687
  // Use the answer class from the type mapping
688
688
  const answerClass = lsType.answerClass || (xfTypeInfo.base === 'select_multiple' ? 'SQ' : 'A');
689
+ // Pre-compute sanitized choice names
690
+ const choiceNames = [];
689
691
  for (const choice of choices) {
690
- // Auto-generate name if missing (matches LimeSurvey behavior)
691
- const choiceName = choice.name && choice.name.trim() !== ''
692
- ? this.sanitizeAnswerCode(choice.name.trim())
693
- : (answerClass === 'SQ' ? `SQ${this.subquestionSeq++}` : `A${this.answerSeq++}`);
692
+ const rawName = choice.name && choice.name.trim() !== '' ? choice.name.trim() : '';
693
+ choiceNames.push(rawName
694
+ ? this.sanitizeAnswerCode(rawName)
695
+ : (answerClass === 'SQ' ? `SQ${this.subquestionSeq++}` : `A${this.answerSeq++}`));
696
+ }
697
+ // Resolve duplicate names by appending a counter suffix
698
+ const usedNames = new Set();
699
+ for (let i = 0; i < choiceNames.length; i++) {
700
+ let name = choiceNames[i];
701
+ if (usedNames.has(name)) {
702
+ let counter = 1;
703
+ let candidate;
704
+ do {
705
+ const suffix = String(counter);
706
+ candidate = name.substring(0, 5 - suffix.length) + suffix;
707
+ counter++;
708
+ } while (usedNames.has(candidate));
709
+ console.warn(`Duplicate answer code "${name}" resolved to "${candidate}"`);
710
+ choiceNames[i] = candidate;
711
+ }
712
+ usedNames.add(choiceNames[i]);
713
+ }
714
+ for (let i = 0; i < choices.length; i++) {
715
+ const choice = choices[i];
716
+ const choiceName = choiceNames[i];
694
717
  // Add answer for each language
695
718
  for (const lang of this.availableLanguages) {
696
719
  this.bufferRow({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xlsform2lstsv",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Convert XLSForm surveys to LimeSurvey TSV format",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",