oh-my-customcode 0.1.0 → 0.1.2

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/cli/index.js CHANGED
@@ -69,7 +69,7 @@ var require_argument = __commonJS((exports) => {
69
69
  this._name = name;
70
70
  break;
71
71
  }
72
- if (this._name.length > 3 && this._name.slice(-3) === "...") {
72
+ if (this._name.endsWith("...")) {
73
73
  this.variadic = true;
74
74
  this._name = this._name.slice(0, -3);
75
75
  }
@@ -77,11 +77,12 @@ var require_argument = __commonJS((exports) => {
77
77
  name() {
78
78
  return this._name;
79
79
  }
80
- _concatValue(value, previous) {
80
+ _collectValue(value, previous) {
81
81
  if (previous === this.defaultValue || !Array.isArray(previous)) {
82
82
  return [value];
83
83
  }
84
- return previous.concat(value);
84
+ previous.push(value);
85
+ return previous;
85
86
  }
86
87
  default(value, description) {
87
88
  this.defaultValue = value;
@@ -99,7 +100,7 @@ var require_argument = __commonJS((exports) => {
99
100
  throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
100
101
  }
101
102
  if (this.variadic) {
102
- return this._concatValue(arg, previous);
103
+ return this._collectValue(arg, previous);
103
104
  }
104
105
  return arg;
105
106
  };
@@ -129,10 +130,14 @@ var require_help = __commonJS((exports) => {
129
130
  class Help {
130
131
  constructor() {
131
132
  this.helpWidth = undefined;
133
+ this.minWidthToWrap = 40;
132
134
  this.sortSubcommands = false;
133
135
  this.sortOptions = false;
134
136
  this.showGlobalOptions = false;
135
137
  }
138
+ prepareContext(contextOptions) {
139
+ this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
140
+ }
136
141
  visibleCommands(cmd) {
137
142
  const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
138
143
  const helpCommand = cmd._getHelpCommand();
@@ -207,22 +212,22 @@ var require_help = __commonJS((exports) => {
207
212
  }
208
213
  longestSubcommandTermLength(cmd, helper) {
209
214
  return helper.visibleCommands(cmd).reduce((max, command) => {
210
- return Math.max(max, helper.subcommandTerm(command).length);
215
+ return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
211
216
  }, 0);
212
217
  }
213
218
  longestOptionTermLength(cmd, helper) {
214
219
  return helper.visibleOptions(cmd).reduce((max, option) => {
215
- return Math.max(max, helper.optionTerm(option).length);
220
+ return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
216
221
  }, 0);
217
222
  }
218
223
  longestGlobalOptionTermLength(cmd, helper) {
219
224
  return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
220
- return Math.max(max, helper.optionTerm(option).length);
225
+ return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
221
226
  }, 0);
222
227
  }
223
228
  longestArgumentTermLength(cmd, helper) {
224
229
  return helper.visibleArguments(cmd).reduce((max, argument) => {
225
- return Math.max(max, helper.argumentTerm(argument).length);
230
+ return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
226
231
  }, 0);
227
232
  }
228
233
  commandUsage(cmd) {
@@ -260,7 +265,11 @@ var require_help = __commonJS((exports) => {
260
265
  extraInfo.push(`env: ${option.envVar}`);
261
266
  }
262
267
  if (extraInfo.length > 0) {
263
- return `${option.description} (${extraInfo.join(", ")})`;
268
+ const extraDescription = `(${extraInfo.join(", ")})`;
269
+ if (option.description) {
270
+ return `${option.description} ${extraDescription}`;
271
+ }
272
+ return extraDescription;
264
273
  }
265
274
  return option.description;
266
275
  }
@@ -273,102 +282,202 @@ var require_help = __commonJS((exports) => {
273
282
  extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
274
283
  }
275
284
  if (extraInfo.length > 0) {
276
- const extraDescripton = `(${extraInfo.join(", ")})`;
285
+ const extraDescription = `(${extraInfo.join(", ")})`;
277
286
  if (argument.description) {
278
- return `${argument.description} ${extraDescripton}`;
287
+ return `${argument.description} ${extraDescription}`;
279
288
  }
280
- return extraDescripton;
289
+ return extraDescription;
281
290
  }
282
291
  return argument.description;
283
292
  }
293
+ formatItemList(heading, items, helper) {
294
+ if (items.length === 0)
295
+ return [];
296
+ return [helper.styleTitle(heading), ...items, ""];
297
+ }
298
+ groupItems(unsortedItems, visibleItems, getGroup) {
299
+ const result = new Map;
300
+ unsortedItems.forEach((item) => {
301
+ const group = getGroup(item);
302
+ if (!result.has(group))
303
+ result.set(group, []);
304
+ });
305
+ visibleItems.forEach((item) => {
306
+ const group = getGroup(item);
307
+ if (!result.has(group)) {
308
+ result.set(group, []);
309
+ }
310
+ result.get(group).push(item);
311
+ });
312
+ return result;
313
+ }
284
314
  formatHelp(cmd, helper) {
285
315
  const termWidth = helper.padWidth(cmd, helper);
286
- const helpWidth = helper.helpWidth || 80;
287
- const itemIndentWidth = 2;
288
- const itemSeparatorWidth = 2;
289
- function formatItem(term, description) {
290
- if (description) {
291
- const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
292
- return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
293
- }
294
- return term;
316
+ const helpWidth = helper.helpWidth ?? 80;
317
+ function callFormatItem(term, description) {
318
+ return helper.formatItem(term, termWidth, description, helper);
295
319
  }
296
- function formatList(textArray) {
297
- return textArray.join(`
298
- `).replace(/^/gm, " ".repeat(itemIndentWidth));
299
- }
300
- let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
320
+ let output = [
321
+ `${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
322
+ ""
323
+ ];
301
324
  const commandDescription = helper.commandDescription(cmd);
302
325
  if (commandDescription.length > 0) {
303
326
  output = output.concat([
304
- helper.wrap(commandDescription, helpWidth, 0),
327
+ helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
305
328
  ""
306
329
  ]);
307
330
  }
308
331
  const argumentList = helper.visibleArguments(cmd).map((argument) => {
309
- return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
332
+ return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
310
333
  });
311
- if (argumentList.length > 0) {
312
- output = output.concat(["Arguments:", formatList(argumentList), ""]);
313
- }
314
- const optionList = helper.visibleOptions(cmd).map((option) => {
315
- return formatItem(helper.optionTerm(option), helper.optionDescription(option));
334
+ output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
335
+ const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
336
+ optionGroups.forEach((options, group) => {
337
+ const optionList = options.map((option) => {
338
+ return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
339
+ });
340
+ output = output.concat(this.formatItemList(group, optionList, helper));
316
341
  });
317
- if (optionList.length > 0) {
318
- output = output.concat(["Options:", formatList(optionList), ""]);
319
- }
320
- if (this.showGlobalOptions) {
342
+ if (helper.showGlobalOptions) {
321
343
  const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
322
- return formatItem(helper.optionTerm(option), helper.optionDescription(option));
344
+ return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
323
345
  });
324
- if (globalOptionList.length > 0) {
325
- output = output.concat([
326
- "Global Options:",
327
- formatList(globalOptionList),
328
- ""
329
- ]);
330
- }
346
+ output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
331
347
  }
332
- const commandList = helper.visibleCommands(cmd).map((cmd2) => {
333
- return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
348
+ const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
349
+ commandGroups.forEach((commands, group) => {
350
+ const commandList = commands.map((sub) => {
351
+ return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
352
+ });
353
+ output = output.concat(this.formatItemList(group, commandList, helper));
334
354
  });
335
- if (commandList.length > 0) {
336
- output = output.concat(["Commands:", formatList(commandList), ""]);
337
- }
338
355
  return output.join(`
339
356
  `);
340
357
  }
358
+ displayWidth(str) {
359
+ return stripColor(str).length;
360
+ }
361
+ styleTitle(str) {
362
+ return str;
363
+ }
364
+ styleUsage(str) {
365
+ return str.split(" ").map((word) => {
366
+ if (word === "[options]")
367
+ return this.styleOptionText(word);
368
+ if (word === "[command]")
369
+ return this.styleSubcommandText(word);
370
+ if (word[0] === "[" || word[0] === "<")
371
+ return this.styleArgumentText(word);
372
+ return this.styleCommandText(word);
373
+ }).join(" ");
374
+ }
375
+ styleCommandDescription(str) {
376
+ return this.styleDescriptionText(str);
377
+ }
378
+ styleOptionDescription(str) {
379
+ return this.styleDescriptionText(str);
380
+ }
381
+ styleSubcommandDescription(str) {
382
+ return this.styleDescriptionText(str);
383
+ }
384
+ styleArgumentDescription(str) {
385
+ return this.styleDescriptionText(str);
386
+ }
387
+ styleDescriptionText(str) {
388
+ return str;
389
+ }
390
+ styleOptionTerm(str) {
391
+ return this.styleOptionText(str);
392
+ }
393
+ styleSubcommandTerm(str) {
394
+ return str.split(" ").map((word) => {
395
+ if (word === "[options]")
396
+ return this.styleOptionText(word);
397
+ if (word[0] === "[" || word[0] === "<")
398
+ return this.styleArgumentText(word);
399
+ return this.styleSubcommandText(word);
400
+ }).join(" ");
401
+ }
402
+ styleArgumentTerm(str) {
403
+ return this.styleArgumentText(str);
404
+ }
405
+ styleOptionText(str) {
406
+ return str;
407
+ }
408
+ styleArgumentText(str) {
409
+ return str;
410
+ }
411
+ styleSubcommandText(str) {
412
+ return str;
413
+ }
414
+ styleCommandText(str) {
415
+ return str;
416
+ }
341
417
  padWidth(cmd, helper) {
342
418
  return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
343
419
  }
344
- wrap(str, width, indent, minColumnWidth = 40) {
345
- const indents = " \\f\\t\\v   -    \uFEFF";
346
- const manualIndent = new RegExp(`[\\n][${indents}]+`);
347
- if (str.match(manualIndent))
348
- return str;
349
- const columnWidth = width - indent;
350
- if (columnWidth < minColumnWidth)
420
+ preformatted(str) {
421
+ return /\n[^\S\r\n]/.test(str);
422
+ }
423
+ formatItem(term, termWidth, description, helper) {
424
+ const itemIndent = 2;
425
+ const itemIndentStr = " ".repeat(itemIndent);
426
+ if (!description)
427
+ return itemIndentStr + term;
428
+ const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
429
+ const spacerWidth = 2;
430
+ const helpWidth = this.helpWidth ?? 80;
431
+ const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
432
+ let formattedDescription;
433
+ if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
434
+ formattedDescription = description;
435
+ } else {
436
+ const wrappedDescription = helper.boxWrap(description, remainingWidth);
437
+ formattedDescription = wrappedDescription.replace(/\n/g, `
438
+ ` + " ".repeat(termWidth + spacerWidth));
439
+ }
440
+ return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
441
+ ${itemIndentStr}`);
442
+ }
443
+ boxWrap(str, width) {
444
+ if (width < this.minWidthToWrap)
351
445
  return str;
352
- const leadingStr = str.slice(0, indent);
353
- const columnText = str.slice(indent).replace(`\r
354
- `, `
355
- `);
356
- const indentString = " ".repeat(indent);
357
- const zeroWidthSpace = "​";
358
- const breaks = `\\s${zeroWidthSpace}`;
359
- const regex = new RegExp(`
360
- |.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`, "g");
361
- const lines = columnText.match(regex) || [];
362
- return leadingStr + lines.map((line, i) => {
363
- if (line === `
364
- `)
365
- return "";
366
- return (i > 0 ? indentString : "") + line.trimEnd();
367
- }).join(`
446
+ const rawLines = str.split(/\r\n|\n/);
447
+ const chunkPattern = /[\s]*[^\s]+/g;
448
+ const wrappedLines = [];
449
+ rawLines.forEach((line) => {
450
+ const chunks = line.match(chunkPattern);
451
+ if (chunks === null) {
452
+ wrappedLines.push("");
453
+ return;
454
+ }
455
+ let sumChunks = [chunks.shift()];
456
+ let sumWidth = this.displayWidth(sumChunks[0]);
457
+ chunks.forEach((chunk) => {
458
+ const visibleWidth = this.displayWidth(chunk);
459
+ if (sumWidth + visibleWidth <= width) {
460
+ sumChunks.push(chunk);
461
+ sumWidth += visibleWidth;
462
+ return;
463
+ }
464
+ wrappedLines.push(sumChunks.join(""));
465
+ const nextChunk = chunk.trimStart();
466
+ sumChunks = [nextChunk];
467
+ sumWidth = this.displayWidth(nextChunk);
468
+ });
469
+ wrappedLines.push(sumChunks.join(""));
470
+ });
471
+ return wrappedLines.join(`
368
472
  `);
369
473
  }
370
474
  }
475
+ function stripColor(str) {
476
+ const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
477
+ return str.replace(sgrPattern, "");
478
+ }
371
479
  exports.Help = Help;
480
+ exports.stripColor = stripColor;
372
481
  });
373
482
 
374
483
  // node_modules/commander/lib/option.js
@@ -399,6 +508,7 @@ var require_option = __commonJS((exports) => {
399
508
  this.argChoices = undefined;
400
509
  this.conflictsWith = [];
401
510
  this.implied = undefined;
511
+ this.helpGroupHeading = undefined;
402
512
  }
403
513
  default(value, description) {
404
514
  this.defaultValue = value;
@@ -437,11 +547,12 @@ var require_option = __commonJS((exports) => {
437
547
  this.hidden = !!hide;
438
548
  return this;
439
549
  }
440
- _concatValue(value, previous) {
550
+ _collectValue(value, previous) {
441
551
  if (previous === this.defaultValue || !Array.isArray(previous)) {
442
552
  return [value];
443
553
  }
444
- return previous.concat(value);
554
+ previous.push(value);
555
+ return previous;
445
556
  }
446
557
  choices(values) {
447
558
  this.argChoices = values.slice();
@@ -450,7 +561,7 @@ var require_option = __commonJS((exports) => {
450
561
  throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
451
562
  }
452
563
  if (this.variadic) {
453
- return this._concatValue(arg, previous);
564
+ return this._collectValue(arg, previous);
454
565
  }
455
566
  return arg;
456
567
  };
@@ -463,7 +574,14 @@ var require_option = __commonJS((exports) => {
463
574
  return this.short.replace(/^-/, "");
464
575
  }
465
576
  attributeName() {
466
- return camelcase(this.name().replace(/^no-/, ""));
577
+ if (this.negate) {
578
+ return camelcase(this.name().replace(/^no-/, ""));
579
+ }
580
+ return camelcase(this.name());
581
+ }
582
+ helpGroup(heading) {
583
+ this.helpGroupHeading = heading;
584
+ return this;
467
585
  }
468
586
  is(arg) {
469
587
  return this.short === arg || this.long === arg;
@@ -508,14 +626,38 @@ var require_option = __commonJS((exports) => {
508
626
  function splitOptionFlags(flags) {
509
627
  let shortFlag;
510
628
  let longFlag;
511
- const flagParts = flags.split(/[ |,]+/);
512
- if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
629
+ const shortFlagExp = /^-[^-]$/;
630
+ const longFlagExp = /^--[^-]/;
631
+ const flagParts = flags.split(/[ |,]+/).concat("guard");
632
+ if (shortFlagExp.test(flagParts[0]))
513
633
  shortFlag = flagParts.shift();
514
- longFlag = flagParts.shift();
515
- if (!shortFlag && /^-[^-]$/.test(longFlag)) {
634
+ if (longFlagExp.test(flagParts[0]))
635
+ longFlag = flagParts.shift();
636
+ if (!shortFlag && shortFlagExp.test(flagParts[0]))
637
+ shortFlag = flagParts.shift();
638
+ if (!shortFlag && longFlagExp.test(flagParts[0])) {
516
639
  shortFlag = longFlag;
517
- longFlag = undefined;
518
- }
640
+ longFlag = flagParts.shift();
641
+ }
642
+ if (flagParts[0].startsWith("-")) {
643
+ const unsupportedFlag = flagParts[0];
644
+ const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
645
+ if (/^-[^-][^-]/.test(unsupportedFlag))
646
+ throw new Error(`${baseError}
647
+ - a short flag is a single dash and a single character
648
+ - either use a single dash and a single character (for a short flag)
649
+ - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
650
+ if (shortFlagExp.test(unsupportedFlag))
651
+ throw new Error(`${baseError}
652
+ - too many short flags`);
653
+ if (longFlagExp.test(unsupportedFlag))
654
+ throw new Error(`${baseError}
655
+ - too many long flags`);
656
+ throw new Error(`${baseError}
657
+ - unrecognised flag format`);
658
+ }
659
+ if (shortFlag === undefined && longFlag === undefined)
660
+ throw new Error(`option creation failed due to no flags found in '${flags}'.`);
519
661
  return { shortFlag, longFlag };
520
662
  }
521
663
  exports.Option = Option;
@@ -604,7 +746,7 @@ var require_command = __commonJS((exports) => {
604
746
  var process2 = __require("node:process");
605
747
  var { Argument, humanReadableArgName } = require_argument();
606
748
  var { CommanderError } = require_error();
607
- var { Help } = require_help();
749
+ var { Help, stripColor } = require_help();
608
750
  var { Option, DualOptions } = require_option();
609
751
  var { suggestSimilar } = require_suggestSimilar();
610
752
 
@@ -615,7 +757,7 @@ var require_command = __commonJS((exports) => {
615
757
  this.options = [];
616
758
  this.parent = null;
617
759
  this._allowUnknownOption = false;
618
- this._allowExcessArguments = true;
760
+ this._allowExcessArguments = false;
619
761
  this.registeredArguments = [];
620
762
  this._args = this.registeredArguments;
621
763
  this.args = [];
@@ -642,18 +784,25 @@ var require_command = __commonJS((exports) => {
642
784
  this._lifeCycleHooks = {};
643
785
  this._showHelpAfterError = false;
644
786
  this._showSuggestionAfterError = true;
787
+ this._savedState = null;
645
788
  this._outputConfiguration = {
646
789
  writeOut: (str) => process2.stdout.write(str),
647
790
  writeErr: (str) => process2.stderr.write(str),
791
+ outputError: (str, write) => write(str),
648
792
  getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
649
793
  getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
650
- outputError: (str, write) => write(str)
794
+ getOutHasColors: () => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()),
795
+ getErrHasColors: () => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()),
796
+ stripColor: (str) => stripColor(str)
651
797
  };
652
798
  this._hidden = false;
653
799
  this._helpOption = undefined;
654
800
  this._addImplicitHelpCommand = undefined;
655
801
  this._helpCommand = undefined;
656
802
  this._helpConfiguration = {};
803
+ this._helpGroupHeading = undefined;
804
+ this._defaultCommandGroup = undefined;
805
+ this._defaultOptionGroup = undefined;
657
806
  }
658
807
  copyInheritedSettings(sourceCommand) {
659
808
  this._outputConfiguration = sourceCommand._outputConfiguration;
@@ -718,7 +867,10 @@ var require_command = __commonJS((exports) => {
718
867
  configureOutput(configuration) {
719
868
  if (configuration === undefined)
720
869
  return this._outputConfiguration;
721
- Object.assign(this._outputConfiguration, configuration);
870
+ this._outputConfiguration = {
871
+ ...this._outputConfiguration,
872
+ ...configuration
873
+ };
722
874
  return this;
723
875
  }
724
876
  showHelpAfterError(displayHelp = true) {
@@ -749,12 +901,12 @@ var require_command = __commonJS((exports) => {
749
901
  createArgument(name, description) {
750
902
  return new Argument(name, description);
751
903
  }
752
- argument(name, description, fn, defaultValue) {
904
+ argument(name, description, parseArg, defaultValue) {
753
905
  const argument = this.createArgument(name, description);
754
- if (typeof fn === "function") {
755
- argument.default(defaultValue).argParser(fn);
906
+ if (typeof parseArg === "function") {
907
+ argument.default(defaultValue).argParser(parseArg);
756
908
  } else {
757
- argument.default(fn);
909
+ argument.default(parseArg);
758
910
  }
759
911
  this.addArgument(argument);
760
912
  return this;
@@ -767,7 +919,7 @@ var require_command = __commonJS((exports) => {
767
919
  }
768
920
  addArgument(argument) {
769
921
  const previousArgument = this.registeredArguments.slice(-1)[0];
770
- if (previousArgument && previousArgument.variadic) {
922
+ if (previousArgument?.variadic) {
771
923
  throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
772
924
  }
773
925
  if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
@@ -779,10 +931,13 @@ var require_command = __commonJS((exports) => {
779
931
  helpCommand(enableOrNameAndArgs, description) {
780
932
  if (typeof enableOrNameAndArgs === "boolean") {
781
933
  this._addImplicitHelpCommand = enableOrNameAndArgs;
934
+ if (enableOrNameAndArgs && this._defaultCommandGroup) {
935
+ this._initCommandGroup(this._getHelpCommand());
936
+ }
782
937
  return this;
783
938
  }
784
- enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
785
- const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
939
+ const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
940
+ const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
786
941
  const helpDescription = description ?? "display help for command";
787
942
  const helpCommand = this.createCommand(helpName);
788
943
  helpCommand.helpOption(false);
@@ -792,6 +947,8 @@ var require_command = __commonJS((exports) => {
792
947
  helpCommand.description(helpDescription);
793
948
  this._addImplicitHelpCommand = true;
794
949
  this._helpCommand = helpCommand;
950
+ if (enableOrNameAndArgs || description)
951
+ this._initCommandGroup(helpCommand);
795
952
  return this;
796
953
  }
797
954
  addHelpCommand(helpCommand, deprecatedDescription) {
@@ -801,6 +958,7 @@ var require_command = __commonJS((exports) => {
801
958
  }
802
959
  this._addImplicitHelpCommand = true;
803
960
  this._helpCommand = helpCommand;
961
+ this._initCommandGroup(helpCommand);
804
962
  return this;
805
963
  }
806
964
  _getHelpCommand() {
@@ -880,6 +1038,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
880
1038
  throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
881
1039
  - already used by option '${matchingOption.flags}'`);
882
1040
  }
1041
+ this._initOptionGroup(option);
883
1042
  this.options.push(option);
884
1043
  }
885
1044
  _registerCommand(command) {
@@ -892,6 +1051,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
892
1051
  const newCmd = knownBy(command).join("|");
893
1052
  throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
894
1053
  }
1054
+ this._initCommandGroup(command);
895
1055
  this.commands.push(command);
896
1056
  }
897
1057
  addOption(option) {
@@ -914,7 +1074,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
914
1074
  if (val !== null && option.parseArg) {
915
1075
  val = this._callParseArg(option, val, oldValue, invalidValueMessage);
916
1076
  } else if (val !== null && option.variadic) {
917
- val = option._concatValue(val, oldValue);
1077
+ val = option._collectValue(val, oldValue);
918
1078
  }
919
1079
  if (val == null) {
920
1080
  if (option.negate) {
@@ -1079,15 +1239,53 @@ Expecting one of '${allowedValues.join("', '")}'`);
1079
1239
  return userArgs;
1080
1240
  }
1081
1241
  parse(argv, parseOptions) {
1242
+ this._prepareForParse();
1082
1243
  const userArgs = this._prepareUserArgs(argv, parseOptions);
1083
1244
  this._parseCommand([], userArgs);
1084
1245
  return this;
1085
1246
  }
1086
1247
  async parseAsync(argv, parseOptions) {
1248
+ this._prepareForParse();
1087
1249
  const userArgs = this._prepareUserArgs(argv, parseOptions);
1088
1250
  await this._parseCommand([], userArgs);
1089
1251
  return this;
1090
1252
  }
1253
+ _prepareForParse() {
1254
+ if (this._savedState === null) {
1255
+ this.saveStateBeforeParse();
1256
+ } else {
1257
+ this.restoreStateBeforeParse();
1258
+ }
1259
+ }
1260
+ saveStateBeforeParse() {
1261
+ this._savedState = {
1262
+ _name: this._name,
1263
+ _optionValues: { ...this._optionValues },
1264
+ _optionValueSources: { ...this._optionValueSources }
1265
+ };
1266
+ }
1267
+ restoreStateBeforeParse() {
1268
+ if (this._storeOptionsAsProperties)
1269
+ throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
1270
+ - either make a new Command for each call to parse, or stop storing options as properties`);
1271
+ this._name = this._savedState._name;
1272
+ this._scriptPath = null;
1273
+ this.rawArgs = [];
1274
+ this._optionValues = { ...this._savedState._optionValues };
1275
+ this._optionValueSources = { ...this._savedState._optionValueSources };
1276
+ this.args = [];
1277
+ this.processedArgs = [];
1278
+ }
1279
+ _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
1280
+ if (fs.existsSync(executableFile))
1281
+ return;
1282
+ const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
1283
+ const executableMissing = `'${executableFile}' does not exist
1284
+ - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
1285
+ - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
1286
+ - ${executableDirMessage}`;
1287
+ throw new Error(executableMissing);
1288
+ }
1091
1289
  _executeSubCommand(subcommand, args) {
1092
1290
  args = args.slice();
1093
1291
  let launchWithNode = false;
@@ -1111,7 +1309,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1111
1309
  let resolvedScriptPath;
1112
1310
  try {
1113
1311
  resolvedScriptPath = fs.realpathSync(this._scriptPath);
1114
- } catch (err) {
1312
+ } catch {
1115
1313
  resolvedScriptPath = this._scriptPath;
1116
1314
  }
1117
1315
  executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
@@ -1137,6 +1335,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1137
1335
  proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
1138
1336
  }
1139
1337
  } else {
1338
+ this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
1140
1339
  args.unshift(executableFile);
1141
1340
  args = incrementNodeInspectorPort(process2.execArgv).concat(args);
1142
1341
  proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
@@ -1162,12 +1361,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1162
1361
  });
1163
1362
  proc.on("error", (err) => {
1164
1363
  if (err.code === "ENOENT") {
1165
- const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
1166
- const executableMissing = `'${executableFile}' does not exist
1167
- - if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
1168
- - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
1169
- - ${executableDirMessage}`;
1170
- throw new Error(executableMissing);
1364
+ this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
1171
1365
  } else if (err.code === "EACCES") {
1172
1366
  throw new Error(`'${executableFile}' not executable`);
1173
1367
  }
@@ -1185,6 +1379,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1185
1379
  const subCommand = this._findCommand(commandName);
1186
1380
  if (!subCommand)
1187
1381
  this.help({ error: true });
1382
+ subCommand._prepareForParse();
1188
1383
  let promiseChain;
1189
1384
  promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
1190
1385
  promiseChain = this._chainOrCall(promiseChain, () => {
@@ -1254,7 +1449,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1254
1449
  this.processedArgs = processedArgs;
1255
1450
  }
1256
1451
  _chainOrCall(promise, fn) {
1257
- if (promise && promise.then && typeof promise.then === "function") {
1452
+ if (promise?.then && typeof promise.then === "function") {
1258
1453
  return promise.then(() => fn());
1259
1454
  }
1260
1455
  return fn();
@@ -1331,7 +1526,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1331
1526
  promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
1332
1527
  return promiseChain;
1333
1528
  }
1334
- if (this.parent && this.parent.listenerCount(commandEvent)) {
1529
+ if (this.parent?.listenerCount(commandEvent)) {
1335
1530
  checkForUnknownOptions();
1336
1531
  this._processArguments();
1337
1532
  this.parent.emit(commandEvent, operands, unknown);
@@ -1393,24 +1588,31 @@ Expecting one of '${allowedValues.join("', '")}'`);
1393
1588
  cmd._checkForConflictingLocalOptions();
1394
1589
  });
1395
1590
  }
1396
- parseOptions(argv) {
1591
+ parseOptions(args) {
1397
1592
  const operands = [];
1398
1593
  const unknown = [];
1399
1594
  let dest = operands;
1400
- const args = argv.slice();
1401
1595
  function maybeOption(arg) {
1402
1596
  return arg.length > 1 && arg[0] === "-";
1403
1597
  }
1598
+ const negativeNumberArg = (arg) => {
1599
+ if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg))
1600
+ return false;
1601
+ return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
1602
+ };
1404
1603
  let activeVariadicOption = null;
1405
- while (args.length) {
1406
- const arg = args.shift();
1604
+ let activeGroup = null;
1605
+ let i = 0;
1606
+ while (i < args.length || activeGroup) {
1607
+ const arg = activeGroup ?? args[i++];
1608
+ activeGroup = null;
1407
1609
  if (arg === "--") {
1408
1610
  if (dest === unknown)
1409
1611
  dest.push(arg);
1410
- dest.push(...args);
1612
+ dest.push(...args.slice(i));
1411
1613
  break;
1412
1614
  }
1413
- if (activeVariadicOption && !maybeOption(arg)) {
1615
+ if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
1414
1616
  this.emit(`option:${activeVariadicOption.name()}`, arg);
1415
1617
  continue;
1416
1618
  }
@@ -1419,14 +1621,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
1419
1621
  const option = this._findOption(arg);
1420
1622
  if (option) {
1421
1623
  if (option.required) {
1422
- const value = args.shift();
1624
+ const value = args[i++];
1423
1625
  if (value === undefined)
1424
1626
  this.optionMissingArgument(option);
1425
1627
  this.emit(`option:${option.name()}`, value);
1426
1628
  } else if (option.optional) {
1427
1629
  let value = null;
1428
- if (args.length > 0 && !maybeOption(args[0])) {
1429
- value = args.shift();
1630
+ if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
1631
+ value = args[i++];
1430
1632
  }
1431
1633
  this.emit(`option:${option.name()}`, value);
1432
1634
  } else {
@@ -1443,7 +1645,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1443
1645
  this.emit(`option:${option.name()}`, arg.slice(2));
1444
1646
  } else {
1445
1647
  this.emit(`option:${option.name()}`);
1446
- args.unshift(`-${arg.slice(2)}`);
1648
+ activeGroup = `-${arg.slice(2)}`;
1447
1649
  }
1448
1650
  continue;
1449
1651
  }
@@ -1456,31 +1658,24 @@ Expecting one of '${allowedValues.join("', '")}'`);
1456
1658
  continue;
1457
1659
  }
1458
1660
  }
1459
- if (maybeOption(arg)) {
1661
+ if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
1460
1662
  dest = unknown;
1461
1663
  }
1462
1664
  if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
1463
1665
  if (this._findCommand(arg)) {
1464
1666
  operands.push(arg);
1465
- if (args.length > 0)
1466
- unknown.push(...args);
1667
+ unknown.push(...args.slice(i));
1467
1668
  break;
1468
1669
  } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
1469
- operands.push(arg);
1470
- if (args.length > 0)
1471
- operands.push(...args);
1670
+ operands.push(arg, ...args.slice(i));
1472
1671
  break;
1473
1672
  } else if (this._defaultCommandName) {
1474
- unknown.push(arg);
1475
- if (args.length > 0)
1476
- unknown.push(...args);
1673
+ unknown.push(arg, ...args.slice(i));
1477
1674
  break;
1478
1675
  }
1479
1676
  }
1480
1677
  if (this._passThroughOptions) {
1481
- dest.push(arg);
1482
- if (args.length > 0)
1483
- dest.push(...args);
1678
+ dest.push(arg, ...args.slice(i));
1484
1679
  break;
1485
1680
  }
1486
1681
  dest.push(arg);
@@ -1691,6 +1886,32 @@ Expecting one of '${allowedValues.join("', '")}'`);
1691
1886
  this._name = str;
1692
1887
  return this;
1693
1888
  }
1889
+ helpGroup(heading) {
1890
+ if (heading === undefined)
1891
+ return this._helpGroupHeading ?? "";
1892
+ this._helpGroupHeading = heading;
1893
+ return this;
1894
+ }
1895
+ commandsGroup(heading) {
1896
+ if (heading === undefined)
1897
+ return this._defaultCommandGroup ?? "";
1898
+ this._defaultCommandGroup = heading;
1899
+ return this;
1900
+ }
1901
+ optionsGroup(heading) {
1902
+ if (heading === undefined)
1903
+ return this._defaultOptionGroup ?? "";
1904
+ this._defaultOptionGroup = heading;
1905
+ return this;
1906
+ }
1907
+ _initOptionGroup(option) {
1908
+ if (this._defaultOptionGroup && !option.helpGroupHeading)
1909
+ option.helpGroup(this._defaultOptionGroup);
1910
+ }
1911
+ _initCommandGroup(cmd) {
1912
+ if (this._defaultCommandGroup && !cmd.helpGroup())
1913
+ cmd.helpGroup(this._defaultCommandGroup);
1914
+ }
1694
1915
  nameFromFilename(filename) {
1695
1916
  this._name = path.basename(filename, path.extname(filename));
1696
1917
  return this;
@@ -1703,23 +1924,38 @@ Expecting one of '${allowedValues.join("', '")}'`);
1703
1924
  }
1704
1925
  helpInformation(contextOptions) {
1705
1926
  const helper = this.createHelp();
1706
- if (helper.helpWidth === undefined) {
1707
- helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
1708
- }
1709
- return helper.formatHelp(this, helper);
1927
+ const context = this._getOutputContext(contextOptions);
1928
+ helper.prepareContext({
1929
+ error: context.error,
1930
+ helpWidth: context.helpWidth,
1931
+ outputHasColors: context.hasColors
1932
+ });
1933
+ const text = helper.formatHelp(this, helper);
1934
+ if (context.hasColors)
1935
+ return text;
1936
+ return this._outputConfiguration.stripColor(text);
1710
1937
  }
1711
- _getHelpContext(contextOptions) {
1938
+ _getOutputContext(contextOptions) {
1712
1939
  contextOptions = contextOptions || {};
1713
- const context = { error: !!contextOptions.error };
1714
- let write;
1715
- if (context.error) {
1716
- write = (arg) => this._outputConfiguration.writeErr(arg);
1940
+ const error = !!contextOptions.error;
1941
+ let baseWrite;
1942
+ let hasColors;
1943
+ let helpWidth;
1944
+ if (error) {
1945
+ baseWrite = (str) => this._outputConfiguration.writeErr(str);
1946
+ hasColors = this._outputConfiguration.getErrHasColors();
1947
+ helpWidth = this._outputConfiguration.getErrHelpWidth();
1717
1948
  } else {
1718
- write = (arg) => this._outputConfiguration.writeOut(arg);
1719
- }
1720
- context.write = contextOptions.write || write;
1721
- context.command = this;
1722
- return context;
1949
+ baseWrite = (str) => this._outputConfiguration.writeOut(str);
1950
+ hasColors = this._outputConfiguration.getOutHasColors();
1951
+ helpWidth = this._outputConfiguration.getOutHelpWidth();
1952
+ }
1953
+ const write = (str) => {
1954
+ if (!hasColors)
1955
+ str = this._outputConfiguration.stripColor(str);
1956
+ return baseWrite(str);
1957
+ };
1958
+ return { error, write, hasColors, helpWidth };
1723
1959
  }
1724
1960
  outputHelp(contextOptions) {
1725
1961
  let deprecatedCallback;
@@ -1727,35 +1963,44 @@ Expecting one of '${allowedValues.join("', '")}'`);
1727
1963
  deprecatedCallback = contextOptions;
1728
1964
  contextOptions = undefined;
1729
1965
  }
1730
- const context = this._getHelpContext(contextOptions);
1731
- this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
1732
- this.emit("beforeHelp", context);
1733
- let helpInformation = this.helpInformation(context);
1966
+ const outputContext = this._getOutputContext(contextOptions);
1967
+ const eventContext = {
1968
+ error: outputContext.error,
1969
+ write: outputContext.write,
1970
+ command: this
1971
+ };
1972
+ this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
1973
+ this.emit("beforeHelp", eventContext);
1974
+ let helpInformation = this.helpInformation({ error: outputContext.error });
1734
1975
  if (deprecatedCallback) {
1735
1976
  helpInformation = deprecatedCallback(helpInformation);
1736
1977
  if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
1737
1978
  throw new Error("outputHelp callback must return a string or a Buffer");
1738
1979
  }
1739
1980
  }
1740
- context.write(helpInformation);
1981
+ outputContext.write(helpInformation);
1741
1982
  if (this._getHelpOption()?.long) {
1742
1983
  this.emit(this._getHelpOption().long);
1743
1984
  }
1744
- this.emit("afterHelp", context);
1745
- this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", context));
1985
+ this.emit("afterHelp", eventContext);
1986
+ this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
1746
1987
  }
1747
1988
  helpOption(flags, description) {
1748
1989
  if (typeof flags === "boolean") {
1749
1990
  if (flags) {
1750
- this._helpOption = this._helpOption ?? undefined;
1991
+ if (this._helpOption === null)
1992
+ this._helpOption = undefined;
1993
+ if (this._defaultOptionGroup) {
1994
+ this._initOptionGroup(this._getHelpOption());
1995
+ }
1751
1996
  } else {
1752
1997
  this._helpOption = null;
1753
1998
  }
1754
1999
  return this;
1755
2000
  }
1756
- flags = flags ?? "-h, --help";
1757
- description = description ?? "display help for command";
1758
- this._helpOption = this.createOption(flags, description);
2001
+ this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
2002
+ if (flags || description)
2003
+ this._initOptionGroup(this._helpOption);
1759
2004
  return this;
1760
2005
  }
1761
2006
  _getHelpOption() {
@@ -1766,11 +2011,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
1766
2011
  }
1767
2012
  addHelpOption(option) {
1768
2013
  this._helpOption = option;
2014
+ this._initOptionGroup(option);
1769
2015
  return this;
1770
2016
  }
1771
2017
  help(contextOptions) {
1772
2018
  this.outputHelp(contextOptions);
1773
- let exitCode = process2.exitCode || 0;
2019
+ let exitCode = Number(process2.exitCode ?? 0);
1774
2020
  if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
1775
2021
  exitCode = 1;
1776
2022
  }
@@ -1835,7 +2081,15 @@ Expecting one of '${allowedValues.join("', '")}'`);
1835
2081
  return arg;
1836
2082
  });
1837
2083
  }
2084
+ function useColor() {
2085
+ if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
2086
+ return false;
2087
+ if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== undefined)
2088
+ return true;
2089
+ return;
2090
+ }
1838
2091
  exports.Command = Command;
2092
+ exports.useColor = useColor;
1839
2093
  });
1840
2094
 
1841
2095
  // node_modules/commander/index.js
@@ -8948,8 +9202,7 @@ var looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
8948
9202
  }
8949
9203
  return matched;
8950
9204
  };
8951
- var deepFind = function(obj, path) {
8952
- let keySeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ".";
9205
+ var deepFind = (obj, path, keySeparator = ".") => {
8953
9206
  if (!obj)
8954
9207
  return;
8955
9208
  if (obj[path]) {
@@ -9001,39 +9254,25 @@ var consoleLogger = {
9001
9254
  };
9002
9255
 
9003
9256
  class Logger {
9004
- constructor(concreteLogger) {
9005
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9257
+ constructor(concreteLogger, options = {}) {
9006
9258
  this.init(concreteLogger, options);
9007
9259
  }
9008
- init(concreteLogger) {
9009
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9260
+ init(concreteLogger, options = {}) {
9010
9261
  this.prefix = options.prefix || "i18next:";
9011
9262
  this.logger = concreteLogger || consoleLogger;
9012
9263
  this.options = options;
9013
9264
  this.debug = options.debug;
9014
9265
  }
9015
- log() {
9016
- for (var _len = arguments.length, args = new Array(_len), _key = 0;_key < _len; _key++) {
9017
- args[_key] = arguments[_key];
9018
- }
9266
+ log(...args) {
9019
9267
  return this.forward(args, "log", "", true);
9020
9268
  }
9021
- warn() {
9022
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0;_key2 < _len2; _key2++) {
9023
- args[_key2] = arguments[_key2];
9024
- }
9269
+ warn(...args) {
9025
9270
  return this.forward(args, "warn", "", true);
9026
9271
  }
9027
- error() {
9028
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0;_key3 < _len3; _key3++) {
9029
- args[_key3] = arguments[_key3];
9030
- }
9272
+ error(...args) {
9031
9273
  return this.forward(args, "error", "");
9032
9274
  }
9033
- deprecate() {
9034
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0;_key4 < _len4; _key4++) {
9035
- args[_key4] = arguments[_key4];
9036
- }
9275
+ deprecate(...args) {
9037
9276
  return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
9038
9277
  }
9039
9278
  forward(args, lvl, prefix, debugOnly) {
@@ -9081,14 +9320,10 @@ class EventEmitter {
9081
9320
  }
9082
9321
  this.observers[event].delete(listener);
9083
9322
  }
9084
- emit(event) {
9085
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1;_key < _len; _key++) {
9086
- args[_key - 1] = arguments[_key];
9087
- }
9323
+ emit(event, ...args) {
9088
9324
  if (this.observers[event]) {
9089
9325
  const cloned = Array.from(this.observers[event].entries());
9090
- cloned.forEach((_ref) => {
9091
- let [observer, numTimesAdded] = _ref;
9326
+ cloned.forEach(([observer, numTimesAdded]) => {
9092
9327
  for (let i = 0;i < numTimesAdded; i++) {
9093
9328
  observer(...args);
9094
9329
  }
@@ -9096,8 +9331,7 @@ class EventEmitter {
9096
9331
  }
9097
9332
  if (this.observers["*"]) {
9098
9333
  const cloned = Array.from(this.observers["*"].entries());
9099
- cloned.forEach((_ref2) => {
9100
- let [observer, numTimesAdded] = _ref2;
9334
+ cloned.forEach(([observer, numTimesAdded]) => {
9101
9335
  for (let i = 0;i < numTimesAdded; i++) {
9102
9336
  observer.apply(observer, [event, ...args]);
9103
9337
  }
@@ -9107,11 +9341,10 @@ class EventEmitter {
9107
9341
  }
9108
9342
 
9109
9343
  class ResourceStore extends EventEmitter {
9110
- constructor(data) {
9111
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
9112
- ns: ["translation"],
9113
- defaultNS: "translation"
9114
- };
9344
+ constructor(data, options = {
9345
+ ns: ["translation"],
9346
+ defaultNS: "translation"
9347
+ }) {
9115
9348
  super();
9116
9349
  this.data = data || {};
9117
9350
  this.options = options;
@@ -9133,8 +9366,7 @@ class ResourceStore extends EventEmitter {
9133
9366
  this.options.ns.splice(index, 1);
9134
9367
  }
9135
9368
  }
9136
- getResource(lng, ns, key) {
9137
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
9369
+ getResource(lng, ns, key, options = {}) {
9138
9370
  const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
9139
9371
  const ignoreJSONStructure = options.ignoreJSONStructure !== undefined ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
9140
9372
  let path;
@@ -9162,10 +9394,9 @@ class ResourceStore extends EventEmitter {
9162
9394
  return result;
9163
9395
  return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
9164
9396
  }
9165
- addResource(lng, ns, key, value) {
9166
- let options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
9167
- silent: false
9168
- };
9397
+ addResource(lng, ns, key, value, options = {
9398
+ silent: false
9399
+ }) {
9169
9400
  const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
9170
9401
  let path = [lng, ns];
9171
9402
  if (key)
@@ -9180,10 +9411,9 @@ class ResourceStore extends EventEmitter {
9180
9411
  if (!options.silent)
9181
9412
  this.emit("added", lng, ns, key, value);
9182
9413
  }
9183
- addResources(lng, ns, resources) {
9184
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
9185
- silent: false
9186
- };
9414
+ addResources(lng, ns, resources, options = {
9415
+ silent: false
9416
+ }) {
9187
9417
  for (const m in resources) {
9188
9418
  if (isString(resources[m]) || Array.isArray(resources[m]))
9189
9419
  this.addResource(lng, ns, m, resources[m], {
@@ -9193,11 +9423,10 @@ class ResourceStore extends EventEmitter {
9193
9423
  if (!options.silent)
9194
9424
  this.emit("added", lng, ns, resources);
9195
9425
  }
9196
- addResourceBundle(lng, ns, resources, deep, overwrite) {
9197
- let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {
9198
- silent: false,
9199
- skipCopy: false
9200
- };
9426
+ addResourceBundle(lng, ns, resources, deep, overwrite, options = {
9427
+ silent: false,
9428
+ skipCopy: false
9429
+ }) {
9201
9430
  let path = [lng, ns];
9202
9431
  if (lng.indexOf(".") > -1) {
9203
9432
  path = lng.split(".");
@@ -9260,12 +9489,32 @@ var postProcessor = {
9260
9489
  return value;
9261
9490
  }
9262
9491
  };
9492
+ var PATH_KEY = Symbol("i18next/PATH_KEY");
9493
+ function createProxy() {
9494
+ const state = [];
9495
+ const handler = Object.create(null);
9496
+ let proxy;
9497
+ handler.get = (target, key) => {
9498
+ proxy?.revoke?.();
9499
+ if (key === PATH_KEY)
9500
+ return state;
9501
+ state.push(key);
9502
+ proxy = Proxy.revocable(target, handler);
9503
+ return proxy.proxy;
9504
+ };
9505
+ return Proxy.revocable(Object.create(null), handler).proxy;
9506
+ }
9507
+ function keysFromSelector(selector, opts) {
9508
+ const {
9509
+ [PATH_KEY]: path
9510
+ } = selector(createProxy());
9511
+ return path.join(opts?.keySeparator ?? ".");
9512
+ }
9263
9513
  var checkedLoadedFor = {};
9264
9514
  var shouldHandleAsObject = (res) => !isString(res) && typeof res !== "boolean" && typeof res !== "number";
9265
9515
 
9266
9516
  class Translator extends EventEmitter {
9267
- constructor(services) {
9268
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9517
+ constructor(services, options = {}) {
9269
9518
  super();
9270
9519
  copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
9271
9520
  this.options = options;
@@ -9278,24 +9527,31 @@ class Translator extends EventEmitter {
9278
9527
  if (lng)
9279
9528
  this.language = lng;
9280
9529
  }
9281
- exists(key) {
9282
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
9283
- interpolation: {}
9530
+ exists(key, o = {
9531
+ interpolation: {}
9532
+ }) {
9533
+ const opt = {
9534
+ ...o
9284
9535
  };
9285
- if (key == null) {
9536
+ if (key == null)
9537
+ return false;
9538
+ const resolved = this.resolve(key, opt);
9539
+ if (resolved?.res === undefined)
9540
+ return false;
9541
+ const isObject = shouldHandleAsObject(resolved.res);
9542
+ if (opt.returnObjects === false && isObject) {
9286
9543
  return false;
9287
9544
  }
9288
- const resolved = this.resolve(key, options);
9289
- return resolved?.res !== undefined;
9545
+ return true;
9290
9546
  }
9291
- extractFromKey(key, options) {
9292
- let nsSeparator = options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
9547
+ extractFromKey(key, opt) {
9548
+ let nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
9293
9549
  if (nsSeparator === undefined)
9294
9550
  nsSeparator = ":";
9295
- const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
9296
- let namespaces = options.ns || this.options.defaultNS || [];
9551
+ const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
9552
+ let namespaces = opt.ns || this.options.defaultNS || [];
9297
9553
  const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
9298
- const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
9554
+ const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
9299
9555
  if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
9300
9556
  const m = key.match(this.interpolator.nestingRegexp);
9301
9557
  if (m && m.length > 0) {
@@ -9314,32 +9570,42 @@ class Translator extends EventEmitter {
9314
9570
  namespaces: isString(namespaces) ? [namespaces] : namespaces
9315
9571
  };
9316
9572
  }
9317
- translate(keys, options, lastKey) {
9318
- if (typeof options !== "object" && this.options.overloadTranslationOptionHandler) {
9319
- options = this.options.overloadTranslationOptionHandler(arguments);
9573
+ translate(keys, o, lastKey) {
9574
+ let opt = typeof o === "object" ? {
9575
+ ...o
9576
+ } : o;
9577
+ if (typeof opt !== "object" && this.options.overloadTranslationOptionHandler) {
9578
+ opt = this.options.overloadTranslationOptionHandler(arguments);
9320
9579
  }
9321
- if (typeof options === "object")
9322
- options = {
9323
- ...options
9580
+ if (typeof opt === "object")
9581
+ opt = {
9582
+ ...opt
9324
9583
  };
9325
- if (!options)
9326
- options = {};
9584
+ if (!opt)
9585
+ opt = {};
9327
9586
  if (keys == null)
9328
9587
  return "";
9588
+ if (typeof keys === "function")
9589
+ keys = keysFromSelector(keys, {
9590
+ ...this.options,
9591
+ ...opt
9592
+ });
9329
9593
  if (!Array.isArray(keys))
9330
9594
  keys = [String(keys)];
9331
- const returnDetails = options.returnDetails !== undefined ? options.returnDetails : this.options.returnDetails;
9332
- const keySeparator = options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
9595
+ const returnDetails = opt.returnDetails !== undefined ? opt.returnDetails : this.options.returnDetails;
9596
+ const keySeparator = opt.keySeparator !== undefined ? opt.keySeparator : this.options.keySeparator;
9333
9597
  const {
9334
9598
  key,
9335
9599
  namespaces
9336
- } = this.extractFromKey(keys[keys.length - 1], options);
9600
+ } = this.extractFromKey(keys[keys.length - 1], opt);
9337
9601
  const namespace = namespaces[namespaces.length - 1];
9338
- const lng = options.lng || this.language;
9339
- const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
9602
+ let nsSeparator = opt.nsSeparator !== undefined ? opt.nsSeparator : this.options.nsSeparator;
9603
+ if (nsSeparator === undefined)
9604
+ nsSeparator = ":";
9605
+ const lng = opt.lng || this.language;
9606
+ const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
9340
9607
  if (lng?.toLowerCase() === "cimode") {
9341
9608
  if (appendNamespaceToCIMode) {
9342
- const nsSeparator = options.nsSeparator || this.options.nsSeparator;
9343
9609
  if (returnDetails) {
9344
9610
  return {
9345
9611
  res: `${namespace}${nsSeparator}${key}`,
@@ -9347,7 +9613,7 @@ class Translator extends EventEmitter {
9347
9613
  exactUsedKey: key,
9348
9614
  usedLng: lng,
9349
9615
  usedNS: namespace,
9350
- usedParams: this.getUsedParamsDetails(options)
9616
+ usedParams: this.getUsedParamsDetails(opt)
9351
9617
  };
9352
9618
  }
9353
9619
  return `${namespace}${nsSeparator}${key}`;
@@ -9359,26 +9625,26 @@ class Translator extends EventEmitter {
9359
9625
  exactUsedKey: key,
9360
9626
  usedLng: lng,
9361
9627
  usedNS: namespace,
9362
- usedParams: this.getUsedParamsDetails(options)
9628
+ usedParams: this.getUsedParamsDetails(opt)
9363
9629
  };
9364
9630
  }
9365
9631
  return key;
9366
9632
  }
9367
- const resolved = this.resolve(keys, options);
9633
+ const resolved = this.resolve(keys, opt);
9368
9634
  let res = resolved?.res;
9369
9635
  const resUsedKey = resolved?.usedKey || key;
9370
9636
  const resExactUsedKey = resolved?.exactUsedKey || key;
9371
9637
  const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
9372
- const joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
9638
+ const joinArrays = opt.joinArrays !== undefined ? opt.joinArrays : this.options.joinArrays;
9373
9639
  const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
9374
- const needsPluralHandling = options.count !== undefined && !isString(options.count);
9375
- const hasDefaultValue = Translator.hasDefaultValue(options);
9376
- const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : "";
9377
- const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
9640
+ const needsPluralHandling = opt.count !== undefined && !isString(opt.count);
9641
+ const hasDefaultValue = Translator.hasDefaultValue(opt);
9642
+ const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : "";
9643
+ const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, {
9378
9644
  ordinal: false
9379
9645
  }) : "";
9380
- const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0;
9381
- const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
9646
+ const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
9647
+ const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
9382
9648
  let resForObjHndl = res;
9383
9649
  if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
9384
9650
  resForObjHndl = defaultValue;
@@ -9386,17 +9652,17 @@ class Translator extends EventEmitter {
9386
9652
  const handleAsObject = shouldHandleAsObject(resForObjHndl);
9387
9653
  const resType = Object.prototype.toString.apply(resForObjHndl);
9388
9654
  if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
9389
- if (!options.returnObjects && !this.options.returnObjects) {
9655
+ if (!opt.returnObjects && !this.options.returnObjects) {
9390
9656
  if (!this.options.returnedObjectHandler) {
9391
9657
  this.logger.warn("accessing an object - but returnObjects options is not enabled!");
9392
9658
  }
9393
9659
  const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
9394
- ...options,
9660
+ ...opt,
9395
9661
  ns: namespaces
9396
9662
  }) : `key '${key} (${this.language})' returned an object instead of string.`;
9397
9663
  if (returnDetails) {
9398
9664
  resolved.res = r;
9399
- resolved.usedParams = this.getUsedParamsDetails(options);
9665
+ resolved.usedParams = this.getUsedParamsDetails(opt);
9400
9666
  return resolved;
9401
9667
  }
9402
9668
  return r;
@@ -9410,7 +9676,7 @@ class Translator extends EventEmitter {
9410
9676
  const deepKey = `${newKeyToUse}${keySeparator}${m}`;
9411
9677
  if (hasDefaultValue && !res) {
9412
9678
  copy2[m] = this.translate(deepKey, {
9413
- ...options,
9679
+ ...opt,
9414
9680
  defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : undefined,
9415
9681
  ...{
9416
9682
  joinArrays: false,
@@ -9419,7 +9685,7 @@ class Translator extends EventEmitter {
9419
9685
  });
9420
9686
  } else {
9421
9687
  copy2[m] = this.translate(deepKey, {
9422
- ...options,
9688
+ ...opt,
9423
9689
  ...{
9424
9690
  joinArrays: false,
9425
9691
  ns: namespaces
@@ -9435,7 +9701,7 @@ class Translator extends EventEmitter {
9435
9701
  } else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
9436
9702
  res = res.join(joinArrays);
9437
9703
  if (res)
9438
- res = this.extendTranslation(res, keys, options, lastKey);
9704
+ res = this.extendTranslation(res, keys, opt, lastKey);
9439
9705
  } else {
9440
9706
  let usedDefault = false;
9441
9707
  let usedKey = false;
@@ -9447,48 +9713,48 @@ class Translator extends EventEmitter {
9447
9713
  usedKey = true;
9448
9714
  res = key;
9449
9715
  }
9450
- const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
9716
+ const missingKeyNoValueFallbackToKey = opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
9451
9717
  const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? undefined : res;
9452
9718
  const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
9453
9719
  if (usedKey || usedDefault || updateMissing) {
9454
9720
  this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
9455
9721
  if (keySeparator) {
9456
9722
  const fk = this.resolve(key, {
9457
- ...options,
9723
+ ...opt,
9458
9724
  keySeparator: false
9459
9725
  });
9460
9726
  if (fk && fk.res)
9461
9727
  this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
9462
9728
  }
9463
9729
  let lngs = [];
9464
- const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
9730
+ const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
9465
9731
  if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
9466
9732
  for (let i = 0;i < fallbackLngs.length; i++) {
9467
9733
  lngs.push(fallbackLngs[i]);
9468
9734
  }
9469
9735
  } else if (this.options.saveMissingTo === "all") {
9470
- lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
9736
+ lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
9471
9737
  } else {
9472
- lngs.push(options.lng || this.language);
9738
+ lngs.push(opt.lng || this.language);
9473
9739
  }
9474
9740
  const send = (l, k, specificDefaultValue) => {
9475
9741
  const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
9476
9742
  if (this.options.missingKeyHandler) {
9477
- this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
9743
+ this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
9478
9744
  } else if (this.backendConnector?.saveMissing) {
9479
- this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
9745
+ this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
9480
9746
  }
9481
9747
  this.emit("missingKey", l, namespace, k, res);
9482
9748
  };
9483
9749
  if (this.options.saveMissing) {
9484
9750
  if (this.options.saveMissingPlurals && needsPluralHandling) {
9485
9751
  lngs.forEach((language) => {
9486
- const suffixes = this.pluralResolver.getSuffixes(language, options);
9487
- if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
9752
+ const suffixes = this.pluralResolver.getSuffixes(language, opt);
9753
+ if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
9488
9754
  suffixes.push(`${this.options.pluralSeparator}zero`);
9489
9755
  }
9490
9756
  suffixes.forEach((suffix) => {
9491
- send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
9757
+ send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
9492
9758
  });
9493
9759
  });
9494
9760
  } else {
@@ -9496,90 +9762,86 @@ class Translator extends EventEmitter {
9496
9762
  }
9497
9763
  }
9498
9764
  }
9499
- res = this.extendTranslation(res, keys, options, resolved, lastKey);
9500
- if (usedKey && res === key && this.options.appendNamespaceToMissingKey)
9501
- res = `${namespace}:${key}`;
9765
+ res = this.extendTranslation(res, keys, opt, resolved, lastKey);
9766
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
9767
+ res = `${namespace}${nsSeparator}${key}`;
9768
+ }
9502
9769
  if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
9503
- res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : undefined);
9770
+ res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : undefined, opt);
9504
9771
  }
9505
9772
  }
9506
9773
  if (returnDetails) {
9507
9774
  resolved.res = res;
9508
- resolved.usedParams = this.getUsedParamsDetails(options);
9775
+ resolved.usedParams = this.getUsedParamsDetails(opt);
9509
9776
  return resolved;
9510
9777
  }
9511
9778
  return res;
9512
9779
  }
9513
- extendTranslation(res, key, options, resolved, lastKey) {
9514
- var _this = this;
9780
+ extendTranslation(res, key, opt, resolved, lastKey) {
9515
9781
  if (this.i18nFormat?.parse) {
9516
9782
  res = this.i18nFormat.parse(res, {
9517
9783
  ...this.options.interpolation.defaultVariables,
9518
- ...options
9519
- }, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
9784
+ ...opt
9785
+ }, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
9520
9786
  resolved
9521
9787
  });
9522
- } else if (!options.skipInterpolation) {
9523
- if (options.interpolation)
9788
+ } else if (!opt.skipInterpolation) {
9789
+ if (opt.interpolation)
9524
9790
  this.interpolator.init({
9525
- ...options,
9791
+ ...opt,
9526
9792
  ...{
9527
9793
  interpolation: {
9528
9794
  ...this.options.interpolation,
9529
- ...options.interpolation
9795
+ ...opt.interpolation
9530
9796
  }
9531
9797
  }
9532
9798
  });
9533
- const skipOnVariables = isString(res) && (options?.interpolation?.skipOnVariables !== undefined ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
9799
+ const skipOnVariables = isString(res) && (opt?.interpolation?.skipOnVariables !== undefined ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
9534
9800
  let nestBef;
9535
9801
  if (skipOnVariables) {
9536
9802
  const nb = res.match(this.interpolator.nestingRegexp);
9537
9803
  nestBef = nb && nb.length;
9538
9804
  }
9539
- let data = options.replace && !isString(options.replace) ? options.replace : options;
9805
+ let data = opt.replace && !isString(opt.replace) ? opt.replace : opt;
9540
9806
  if (this.options.interpolation.defaultVariables)
9541
9807
  data = {
9542
9808
  ...this.options.interpolation.defaultVariables,
9543
9809
  ...data
9544
9810
  };
9545
- res = this.interpolator.interpolate(res, data, options.lng || this.language || resolved.usedLng, options);
9811
+ res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
9546
9812
  if (skipOnVariables) {
9547
9813
  const na = res.match(this.interpolator.nestingRegexp);
9548
9814
  const nestAft = na && na.length;
9549
9815
  if (nestBef < nestAft)
9550
- options.nest = false;
9551
- }
9552
- if (!options.lng && resolved && resolved.res)
9553
- options.lng = this.language || resolved.usedLng;
9554
- if (options.nest !== false)
9555
- res = this.interpolator.nest(res, function() {
9556
- for (var _len = arguments.length, args = new Array(_len), _key = 0;_key < _len; _key++) {
9557
- args[_key] = arguments[_key];
9558
- }
9559
- if (lastKey?.[0] === args[0] && !options.context) {
9560
- _this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
9816
+ opt.nest = false;
9817
+ }
9818
+ if (!opt.lng && resolved && resolved.res)
9819
+ opt.lng = this.language || resolved.usedLng;
9820
+ if (opt.nest !== false)
9821
+ res = this.interpolator.nest(res, (...args) => {
9822
+ if (lastKey?.[0] === args[0] && !opt.context) {
9823
+ this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
9561
9824
  return null;
9562
9825
  }
9563
- return _this.translate(...args, key);
9564
- }, options);
9565
- if (options.interpolation)
9826
+ return this.translate(...args, key);
9827
+ }, opt);
9828
+ if (opt.interpolation)
9566
9829
  this.interpolator.reset();
9567
9830
  }
9568
- const postProcess = options.postProcess || this.options.postProcess;
9831
+ const postProcess = opt.postProcess || this.options.postProcess;
9569
9832
  const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
9570
- if (res != null && postProcessorNames?.length && options.applyPostProcessor !== false) {
9833
+ if (res != null && postProcessorNames?.length && opt.applyPostProcessor !== false) {
9571
9834
  res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
9572
9835
  i18nResolved: {
9573
9836
  ...resolved,
9574
- usedParams: this.getUsedParamsDetails(options)
9837
+ usedParams: this.getUsedParamsDetails(opt)
9575
9838
  },
9576
- ...options
9577
- } : options, this);
9839
+ ...opt
9840
+ } : opt, this);
9578
9841
  }
9579
9842
  return res;
9580
9843
  }
9581
- resolve(keys) {
9582
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9844
+ resolve(keys, opt = {}) {
9583
9845
  let found;
9584
9846
  let usedKey;
9585
9847
  let exactUsedKey;
@@ -9590,16 +9852,16 @@ class Translator extends EventEmitter {
9590
9852
  keys.forEach((k) => {
9591
9853
  if (this.isValidLookup(found))
9592
9854
  return;
9593
- const extracted = this.extractFromKey(k, options);
9855
+ const extracted = this.extractFromKey(k, opt);
9594
9856
  const key = extracted.key;
9595
9857
  usedKey = key;
9596
9858
  let namespaces = extracted.namespaces;
9597
9859
  if (this.options.fallbackNS)
9598
9860
  namespaces = namespaces.concat(this.options.fallbackNS);
9599
- const needsPluralHandling = options.count !== undefined && !isString(options.count);
9600
- const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0;
9601
- const needsContextHandling = options.context !== undefined && (isString(options.context) || typeof options.context === "number") && options.context !== "";
9602
- const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
9861
+ const needsPluralHandling = opt.count !== undefined && !isString(opt.count);
9862
+ const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
9863
+ const needsContextHandling = opt.context !== undefined && (isString(opt.context) || typeof opt.context === "number") && opt.context !== "";
9864
+ const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
9603
9865
  namespaces.forEach((ns) => {
9604
9866
  if (this.isValidLookup(found))
9605
9867
  return;
@@ -9614,30 +9876,30 @@ class Translator extends EventEmitter {
9614
9876
  usedLng = code;
9615
9877
  const finalKeys = [key];
9616
9878
  if (this.i18nFormat?.addLookupKeys) {
9617
- this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
9879
+ this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
9618
9880
  } else {
9619
9881
  let pluralSuffix;
9620
9882
  if (needsPluralHandling)
9621
- pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
9883
+ pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
9622
9884
  const zeroSuffix = `${this.options.pluralSeparator}zero`;
9623
9885
  const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
9624
9886
  if (needsPluralHandling) {
9625
- finalKeys.push(key + pluralSuffix);
9626
- if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
9887
+ if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
9627
9888
  finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
9628
9889
  }
9890
+ finalKeys.push(key + pluralSuffix);
9629
9891
  if (needsZeroSuffixLookup) {
9630
9892
  finalKeys.push(key + zeroSuffix);
9631
9893
  }
9632
9894
  }
9633
9895
  if (needsContextHandling) {
9634
- const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
9896
+ const contextKey = `${key}${this.options.contextSeparator || "_"}${opt.context}`;
9635
9897
  finalKeys.push(contextKey);
9636
9898
  if (needsPluralHandling) {
9637
- finalKeys.push(contextKey + pluralSuffix);
9638
- if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
9899
+ if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
9639
9900
  finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
9640
9901
  }
9902
+ finalKeys.push(contextKey + pluralSuffix);
9641
9903
  if (needsZeroSuffixLookup) {
9642
9904
  finalKeys.push(contextKey + zeroSuffix);
9643
9905
  }
@@ -9648,7 +9910,7 @@ class Translator extends EventEmitter {
9648
9910
  while (possibleKey = finalKeys.pop()) {
9649
9911
  if (!this.isValidLookup(found)) {
9650
9912
  exactUsedKey = possibleKey;
9651
- found = this.getResource(code, ns, possibleKey, options);
9913
+ found = this.getResource(code, ns, possibleKey, opt);
9652
9914
  }
9653
9915
  }
9654
9916
  });
@@ -9665,14 +9927,12 @@ class Translator extends EventEmitter {
9665
9927
  isValidLookup(res) {
9666
9928
  return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
9667
9929
  }
9668
- getResource(code, ns, key) {
9669
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
9930
+ getResource(code, ns, key, options = {}) {
9670
9931
  if (this.i18nFormat?.getResource)
9671
9932
  return this.i18nFormat.getResource(code, ns, key, options);
9672
9933
  return this.resourceStore.getResource(code, ns, key, options);
9673
9934
  }
9674
- getUsedParamsDetails() {
9675
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
9935
+ getUsedParamsDetails(options = {}) {
9676
9936
  const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
9677
9937
  const useOptionsReplaceForData = options.replace && !isString(options.replace);
9678
9938
  let data = useOptionsReplaceForData ? options.replace : options;
@@ -9770,6 +10030,9 @@ class LanguageUtil {
9770
10030
  codes.forEach((code) => {
9771
10031
  if (found)
9772
10032
  return;
10033
+ const lngScOnly = this.getScriptPartFromCode(code);
10034
+ if (this.isSupportedCode(lngScOnly))
10035
+ return found = lngScOnly;
9773
10036
  const lngOnly = this.getLanguagePartFromCode(code);
9774
10037
  if (this.isSupportedCode(lngOnly))
9775
10038
  return found = lngOnly;
@@ -9812,7 +10075,7 @@ class LanguageUtil {
9812
10075
  return found || [];
9813
10076
  }
9814
10077
  toResolveHierarchy(code, fallbackCode) {
9815
- const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
10078
+ const fallbackCodes = this.getFallbackCodes((fallbackCode === false ? [] : fallbackCode) || this.options.fallbackLng || [], code);
9816
10079
  const codes = [];
9817
10080
  const addCode = (c) => {
9818
10081
  if (!c)
@@ -9856,21 +10119,16 @@ var dummyRule = {
9856
10119
  };
9857
10120
 
9858
10121
  class PluralResolver {
9859
- constructor(languageUtils) {
9860
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10122
+ constructor(languageUtils, options = {}) {
9861
10123
  this.languageUtils = languageUtils;
9862
10124
  this.options = options;
9863
10125
  this.logger = baseLogger.create("pluralResolver");
9864
10126
  this.pluralRulesCache = {};
9865
10127
  }
9866
- addRule(lng, obj) {
9867
- this.rules[lng] = obj;
9868
- }
9869
10128
  clearCache() {
9870
10129
  this.pluralRulesCache = {};
9871
10130
  }
9872
- getRule(code) {
9873
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10131
+ getRule(code, options = {}) {
9874
10132
  const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
9875
10133
  const type = options.ordinal ? "ordinal" : "cardinal";
9876
10134
  const cacheKey = JSON.stringify({
@@ -9898,19 +10156,16 @@ class PluralResolver {
9898
10156
  this.pluralRulesCache[cacheKey] = rule;
9899
10157
  return rule;
9900
10158
  }
9901
- needsPlural(code) {
9902
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10159
+ needsPlural(code, options = {}) {
9903
10160
  let rule = this.getRule(code, options);
9904
10161
  if (!rule)
9905
10162
  rule = this.getRule("dev", options);
9906
10163
  return rule?.resolvedOptions().pluralCategories.length > 1;
9907
10164
  }
9908
- getPluralFormsOfKey(code, key) {
9909
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10165
+ getPluralFormsOfKey(code, key, options = {}) {
9910
10166
  return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
9911
10167
  }
9912
- getSuffixes(code) {
9913
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10168
+ getSuffixes(code, options = {}) {
9914
10169
  let rule = this.getRule(code, options);
9915
10170
  if (!rule)
9916
10171
  rule = this.getRule("dev", options);
@@ -9918,8 +10173,7 @@ class PluralResolver {
9918
10173
  return [];
9919
10174
  return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
9920
10175
  }
9921
- getSuffix(code, count) {
9922
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10176
+ getSuffix(code, count, options = {}) {
9923
10177
  const rule = this.getRule(code, options);
9924
10178
  if (rule) {
9925
10179
  return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
@@ -9928,9 +10182,7 @@ class PluralResolver {
9928
10182
  return this.getSuffix("dev", count, options);
9929
10183
  }
9930
10184
  }
9931
- var deepFindWithDefaults = function(data, defaultData, key) {
9932
- let keySeparator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ".";
9933
- let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
10185
+ var deepFindWithDefaults = (data, defaultData, key, keySeparator = ".", ignoreJSONStructure = true) => {
9934
10186
  let path = getPathWithDefaults(data, defaultData, key);
9935
10187
  if (!path && ignoreJSONStructure && isString(key)) {
9936
10188
  path = deepFind(data, key, keySeparator);
@@ -9942,15 +10194,13 @@ var deepFindWithDefaults = function(data, defaultData, key) {
9942
10194
  var regexSafe = (val) => val.replace(/\$/g, "$$$$");
9943
10195
 
9944
10196
  class Interpolator {
9945
- constructor() {
9946
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10197
+ constructor(options = {}) {
9947
10198
  this.logger = baseLogger.create("interpolator");
9948
10199
  this.options = options;
9949
10200
  this.format = options?.interpolation?.format || ((value) => value);
9950
10201
  this.init(options);
9951
10202
  }
9952
- init() {
9953
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10203
+ init(options = {}) {
9954
10204
  if (!options.interpolation)
9955
10205
  options.interpolation = {
9956
10206
  escapeValue: true
@@ -10003,7 +10253,7 @@ class Interpolator {
10003
10253
  };
10004
10254
  this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
10005
10255
  this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
10006
- this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
10256
+ this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
10007
10257
  }
10008
10258
  interpolate(str, data, lng, options) {
10009
10259
  let match;
@@ -10075,8 +10325,7 @@ class Interpolator {
10075
10325
  });
10076
10326
  return str;
10077
10327
  }
10078
- nest(str, fc) {
10079
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10328
+ nest(str, fc, options = {}) {
10080
10329
  let match;
10081
10330
  let value;
10082
10331
  let clonedOptions;
@@ -10116,12 +10365,10 @@ class Interpolator {
10116
10365
  clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
10117
10366
  clonedOptions.applyPostProcessor = false;
10118
10367
  delete clonedOptions.defaultValue;
10119
- let doReduce = false;
10120
- if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
10121
- const r = match[1].split(this.formatSeparator).map((elem) => elem.trim());
10122
- match[1] = r.shift();
10123
- formatters = r;
10124
- doReduce = true;
10368
+ const keyEndIndex = /{.*}/.test(match[1]) ? match[1].lastIndexOf("}") + 1 : match[1].indexOf(this.formatSeparator);
10369
+ if (keyEndIndex !== -1) {
10370
+ formatters = match[1].slice(keyEndIndex).split(this.formatSeparator).map((elem) => elem.trim()).filter(Boolean);
10371
+ match[1] = match[1].slice(0, keyEndIndex);
10125
10372
  }
10126
10373
  value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
10127
10374
  if (value && match[0] === str && !isString(value))
@@ -10132,7 +10379,7 @@ class Interpolator {
10132
10379
  this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
10133
10380
  value = "";
10134
10381
  }
10135
- if (doReduce) {
10382
+ if (formatters.length) {
10136
10383
  value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
10137
10384
  ...options,
10138
10385
  interpolationkey: match[1].trim()
@@ -10183,69 +10430,69 @@ var parseFormatStr = (formatStr) => {
10183
10430
  };
10184
10431
  var createCachedFormatter = (fn) => {
10185
10432
  const cache = {};
10186
- return (val, lng, options) => {
10187
- let optForCache = options;
10188
- if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
10433
+ return (v, l, o) => {
10434
+ let optForCache = o;
10435
+ if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) {
10189
10436
  optForCache = {
10190
10437
  ...optForCache,
10191
- [options.interpolationkey]: undefined
10438
+ [o.interpolationkey]: undefined
10192
10439
  };
10193
10440
  }
10194
- const key = lng + JSON.stringify(optForCache);
10195
- let formatter = cache[key];
10196
- if (!formatter) {
10197
- formatter = fn(getCleanedCode(lng), options);
10198
- cache[key] = formatter;
10441
+ const key = l + JSON.stringify(optForCache);
10442
+ let frm = cache[key];
10443
+ if (!frm) {
10444
+ frm = fn(getCleanedCode(l), o);
10445
+ cache[key] = frm;
10199
10446
  }
10200
- return formatter(val);
10447
+ return frm(v);
10201
10448
  };
10202
10449
  };
10450
+ var createNonCachedFormatter = (fn) => (v, l, o) => fn(getCleanedCode(l), o)(v);
10203
10451
 
10204
10452
  class Formatter {
10205
- constructor() {
10206
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10453
+ constructor(options = {}) {
10207
10454
  this.logger = baseLogger.create("formatter");
10208
10455
  this.options = options;
10456
+ this.init(options);
10457
+ }
10458
+ init(services, options = {
10459
+ interpolation: {}
10460
+ }) {
10461
+ this.formatSeparator = options.interpolation.formatSeparator || ",";
10462
+ const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
10209
10463
  this.formats = {
10210
- number: createCachedFormatter((lng, opt) => {
10464
+ number: cf((lng, opt) => {
10211
10465
  const formatter = new Intl.NumberFormat(lng, {
10212
10466
  ...opt
10213
10467
  });
10214
10468
  return (val) => formatter.format(val);
10215
10469
  }),
10216
- currency: createCachedFormatter((lng, opt) => {
10470
+ currency: cf((lng, opt) => {
10217
10471
  const formatter = new Intl.NumberFormat(lng, {
10218
10472
  ...opt,
10219
10473
  style: "currency"
10220
10474
  });
10221
10475
  return (val) => formatter.format(val);
10222
10476
  }),
10223
- datetime: createCachedFormatter((lng, opt) => {
10477
+ datetime: cf((lng, opt) => {
10224
10478
  const formatter = new Intl.DateTimeFormat(lng, {
10225
10479
  ...opt
10226
10480
  });
10227
10481
  return (val) => formatter.format(val);
10228
10482
  }),
10229
- relativetime: createCachedFormatter((lng, opt) => {
10483
+ relativetime: cf((lng, opt) => {
10230
10484
  const formatter = new Intl.RelativeTimeFormat(lng, {
10231
10485
  ...opt
10232
10486
  });
10233
10487
  return (val) => formatter.format(val, opt.range || "day");
10234
10488
  }),
10235
- list: createCachedFormatter((lng, opt) => {
10489
+ list: cf((lng, opt) => {
10236
10490
  const formatter = new Intl.ListFormat(lng, {
10237
10491
  ...opt
10238
10492
  });
10239
10493
  return (val) => formatter.format(val);
10240
10494
  })
10241
10495
  };
10242
- this.init(options);
10243
- }
10244
- init(services) {
10245
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
10246
- interpolation: {}
10247
- };
10248
- this.formatSeparator = options.interpolation.formatSeparator || ",";
10249
10496
  }
10250
10497
  add(name, fc) {
10251
10498
  this.formats[name.toLowerCase().trim()] = fc;
@@ -10253,8 +10500,7 @@ class Formatter {
10253
10500
  addCached(name, fc) {
10254
10501
  this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
10255
10502
  }
10256
- format(value, format, lng) {
10257
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
10503
+ format(value, format, lng, options = {}) {
10258
10504
  const formats = format.split(this.formatSeparator);
10259
10505
  if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f) => f.indexOf(")") > -1)) {
10260
10506
  const lastIndex = formats.findIndex((f) => f.indexOf(")") > -1);
@@ -10295,8 +10541,7 @@ var removePending = (q, name) => {
10295
10541
  };
10296
10542
 
10297
10543
  class Connector extends EventEmitter {
10298
- constructor(backend, store, services) {
10299
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
10544
+ constructor(backend, store, services, options = {}) {
10300
10545
  super();
10301
10546
  this.backend = backend;
10302
10547
  this.store = store;
@@ -10402,10 +10647,7 @@ class Connector extends EventEmitter {
10402
10647
  this.emit("loaded", loaded);
10403
10648
  this.queue = this.queue.filter((q) => !q.done);
10404
10649
  }
10405
- read(lng, ns, fcName) {
10406
- let tried = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
10407
- let wait = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : this.retryTimeout;
10408
- let callback = arguments.length > 5 ? arguments[5] : undefined;
10650
+ read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
10409
10651
  if (!lng.length)
10410
10652
  return callback(null, {});
10411
10653
  if (this.readingCalls >= this.maxParallelReads) {
@@ -10450,9 +10692,7 @@ class Connector extends EventEmitter {
10450
10692
  }
10451
10693
  return fc(lng, ns, resolver);
10452
10694
  }
10453
- prepareLoading(languages, namespaces) {
10454
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10455
- let callback = arguments.length > 3 ? arguments[3] : undefined;
10695
+ prepareLoading(languages, namespaces, options = {}, callback) {
10456
10696
  if (!this.backend) {
10457
10697
  this.logger.warn("No backend was added via i18next.use. Will not load resources.");
10458
10698
  return callback && callback();
@@ -10479,8 +10719,7 @@ class Connector extends EventEmitter {
10479
10719
  reload: true
10480
10720
  }, callback);
10481
10721
  }
10482
- loadOne(name) {
10483
- let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
10722
+ loadOne(name, prefix = "") {
10484
10723
  const s = name.split("|");
10485
10724
  const lng = s[0];
10486
10725
  const ns = s[1];
@@ -10492,9 +10731,7 @@ class Connector extends EventEmitter {
10492
10731
  this.loaded(name, err, data);
10493
10732
  });
10494
10733
  }
10495
- saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
10496
- let options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
10497
- let clb = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : () => {};
10734
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {}) {
10498
10735
  if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
10499
10736
  this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
10500
10737
  return;
@@ -10593,7 +10830,8 @@ var get = () => ({
10593
10830
  nestingOptionsSeparator: ",",
10594
10831
  maxReplaces: 1000,
10595
10832
  skipOnVariables: true
10596
- }
10833
+ },
10834
+ cacheInBuiltFormats: true
10597
10835
  });
10598
10836
  var transformOptions = (options) => {
10599
10837
  if (isString(options.ns))
@@ -10620,9 +10858,7 @@ var bindMemberFunctions = (inst) => {
10620
10858
  };
10621
10859
 
10622
10860
  class I18n extends EventEmitter {
10623
- constructor() {
10624
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10625
- let callback = arguments.length > 1 ? arguments[1] : undefined;
10861
+ constructor(options = {}, callback) {
10626
10862
  super();
10627
10863
  this.options = transformOptions(options);
10628
10864
  this.services = {};
@@ -10641,10 +10877,7 @@ class I18n extends EventEmitter {
10641
10877
  }, 0);
10642
10878
  }
10643
10879
  }
10644
- init() {
10645
- var _this = this;
10646
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10647
- let callback = arguments.length > 1 ? arguments[1] : undefined;
10880
+ init(options = {}, callback) {
10648
10881
  this.isInitializing = true;
10649
10882
  if (typeof options === "function") {
10650
10883
  callback = options;
@@ -10673,6 +10906,13 @@ class I18n extends EventEmitter {
10673
10906
  if (options.nsSeparator !== undefined) {
10674
10907
  this.options.userDefinedNsSeparator = options.nsSeparator;
10675
10908
  }
10909
+ if (typeof this.options.overloadTranslationOptionHandler !== "function") {
10910
+ this.options.overloadTranslationOptionHandler = defOpts.overloadTranslationOptionHandler;
10911
+ }
10912
+ if (this.options.debug === true) {
10913
+ if (typeof console !== "undefined")
10914
+ console.warn("i18next is maintained with support from locize.com — consider powering your project with managed localization (AI, CDN, integrations): https://locize.com");
10915
+ }
10676
10916
  const createClassOnDemand = (ClassOrObject) => {
10677
10917
  if (!ClassOrObject)
10678
10918
  return null;
@@ -10702,9 +10942,14 @@ class I18n extends EventEmitter {
10702
10942
  prepend: this.options.pluralSeparator,
10703
10943
  simplifyPluralSuffix: this.options.simplifyPluralSuffix
10704
10944
  });
10945
+ const usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
10946
+ if (usingLegacyFormatFunction) {
10947
+ this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
10948
+ }
10705
10949
  if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
10706
10950
  s.formatter = createClassOnDemand(formatter);
10707
- s.formatter.init(s, this.options);
10951
+ if (s.formatter.init)
10952
+ s.formatter.init(s, this.options);
10708
10953
  this.options.interpolation.format = s.formatter.format.bind(s.formatter);
10709
10954
  }
10710
10955
  s.interpolator = new Interpolator(this.options);
@@ -10712,11 +10957,8 @@ class I18n extends EventEmitter {
10712
10957
  hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
10713
10958
  };
10714
10959
  s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
10715
- s.backendConnector.on("*", function(event) {
10716
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1;_key < _len; _key++) {
10717
- args[_key - 1] = arguments[_key];
10718
- }
10719
- _this.emit(event, ...args);
10960
+ s.backendConnector.on("*", (event, ...args) => {
10961
+ this.emit(event, ...args);
10720
10962
  });
10721
10963
  if (this.modules.languageDetector) {
10722
10964
  s.languageDetector = createClassOnDemand(this.modules.languageDetector);
@@ -10729,11 +10971,8 @@ class I18n extends EventEmitter {
10729
10971
  s.i18nFormat.init(this);
10730
10972
  }
10731
10973
  this.translator = new Translator(this.services, this.options);
10732
- this.translator.on("*", function(event) {
10733
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1;_key2 < _len2; _key2++) {
10734
- args[_key2 - 1] = arguments[_key2];
10735
- }
10736
- _this.emit(event, ...args);
10974
+ this.translator.on("*", (event, ...args) => {
10975
+ this.emit(event, ...args);
10737
10976
  });
10738
10977
  this.modules.external.forEach((m) => {
10739
10978
  if (m.init)
@@ -10753,15 +10992,13 @@ class I18n extends EventEmitter {
10753
10992
  }
10754
10993
  const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
10755
10994
  storeApi.forEach((fcName) => {
10756
- this[fcName] = function() {
10757
- return _this.store[fcName](...arguments);
10758
- };
10995
+ this[fcName] = (...args) => this.store[fcName](...args);
10759
10996
  });
10760
10997
  const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
10761
10998
  storeApiChained.forEach((fcName) => {
10762
- this[fcName] = function() {
10763
- _this.store[fcName](...arguments);
10764
- return _this;
10999
+ this[fcName] = (...args) => {
11000
+ this.store[fcName](...args);
11001
+ return this;
10765
11002
  };
10766
11003
  });
10767
11004
  const deferred = defer();
@@ -10788,8 +11025,7 @@ class I18n extends EventEmitter {
10788
11025
  }
10789
11026
  return deferred;
10790
11027
  }
10791
- loadResources(language) {
10792
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
11028
+ loadResources(language, callback = noop) {
10793
11029
  let usedCallback = callback;
10794
11030
  const usedLng = isString(language) ? language : this.language;
10795
11031
  if (typeof language === "function")
@@ -10891,9 +11127,12 @@ class I18n extends EventEmitter {
10891
11127
  break;
10892
11128
  }
10893
11129
  }
11130
+ if (!this.resolvedLanguage && this.languages.indexOf(l) < 0 && this.store.hasLanguageSomeTranslations(l)) {
11131
+ this.resolvedLanguage = l;
11132
+ this.languages.unshift(l);
11133
+ }
10894
11134
  }
10895
11135
  changeLanguage(lng, callback) {
10896
- var _this2 = this;
10897
11136
  this.isLanguageChangingTo = lng;
10898
11137
  const deferred = defer();
10899
11138
  this.emit("languageChanging", lng);
@@ -10905,26 +11144,25 @@ class I18n extends EventEmitter {
10905
11144
  };
10906
11145
  const done = (err, l) => {
10907
11146
  if (l) {
10908
- setLngProps(l);
10909
- this.translator.changeLanguage(l);
10910
- this.isLanguageChangingTo = undefined;
10911
- this.emit("languageChanged", l);
10912
- this.logger.log("languageChanged", l);
11147
+ if (this.isLanguageChangingTo === lng) {
11148
+ setLngProps(l);
11149
+ this.translator.changeLanguage(l);
11150
+ this.isLanguageChangingTo = undefined;
11151
+ this.emit("languageChanged", l);
11152
+ this.logger.log("languageChanged", l);
11153
+ }
10913
11154
  } else {
10914
11155
  this.isLanguageChangingTo = undefined;
10915
11156
  }
10916
- deferred.resolve(function() {
10917
- return _this2.t(...arguments);
10918
- });
11157
+ deferred.resolve((...args) => this.t(...args));
10919
11158
  if (callback)
10920
- callback(err, function() {
10921
- return _this2.t(...arguments);
10922
- });
11159
+ callback(err, (...args) => this.t(...args));
10923
11160
  };
10924
11161
  const setLng = (lngs) => {
10925
11162
  if (!lng && !lngs && this.services.languageDetector)
10926
11163
  lngs = [];
10927
- const l = isString(lngs) ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
11164
+ const fl = isString(lngs) ? lngs : lngs && lngs[0];
11165
+ const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
10928
11166
  if (l) {
10929
11167
  if (!this.language) {
10930
11168
  setLngProps(l);
@@ -10951,32 +11189,40 @@ class I18n extends EventEmitter {
10951
11189
  return deferred;
10952
11190
  }
10953
11191
  getFixedT(lng, ns, keyPrefix) {
10954
- var _this3 = this;
10955
- const fixedT = function(key, opts) {
10956
- let options;
11192
+ const fixedT = (key, opts, ...rest) => {
11193
+ let o;
10957
11194
  if (typeof opts !== "object") {
10958
- for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2;_key3 < _len3; _key3++) {
10959
- rest[_key3 - 2] = arguments[_key3];
10960
- }
10961
- options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
11195
+ o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
10962
11196
  } else {
10963
- options = {
11197
+ o = {
10964
11198
  ...opts
10965
11199
  };
10966
11200
  }
10967
- options.lng = options.lng || fixedT.lng;
10968
- options.lngs = options.lngs || fixedT.lngs;
10969
- options.ns = options.ns || fixedT.ns;
10970
- if (options.keyPrefix !== "")
10971
- options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
10972
- const keySeparator = _this3.options.keySeparator || ".";
11201
+ o.lng = o.lng || fixedT.lng;
11202
+ o.lngs = o.lngs || fixedT.lngs;
11203
+ o.ns = o.ns || fixedT.ns;
11204
+ if (o.keyPrefix !== "")
11205
+ o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
11206
+ const keySeparator = this.options.keySeparator || ".";
10973
11207
  let resultKey;
10974
- if (options.keyPrefix && Array.isArray(key)) {
10975
- resultKey = key.map((k) => `${options.keyPrefix}${keySeparator}${k}`);
11208
+ if (o.keyPrefix && Array.isArray(key)) {
11209
+ resultKey = key.map((k) => {
11210
+ if (typeof k === "function")
11211
+ k = keysFromSelector(k, {
11212
+ ...this.options,
11213
+ ...opts
11214
+ });
11215
+ return `${o.keyPrefix}${keySeparator}${k}`;
11216
+ });
10976
11217
  } else {
10977
- resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
11218
+ if (typeof key === "function")
11219
+ key = keysFromSelector(key, {
11220
+ ...this.options,
11221
+ ...opts
11222
+ });
11223
+ resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
10978
11224
  }
10979
- return _this3.t(resultKey, options);
11225
+ return this.t(resultKey, o);
10980
11226
  };
10981
11227
  if (isString(lng)) {
10982
11228
  fixedT.lng = lng;
@@ -10987,23 +11233,16 @@ class I18n extends EventEmitter {
10987
11233
  fixedT.keyPrefix = keyPrefix;
10988
11234
  return fixedT;
10989
11235
  }
10990
- t() {
10991
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0;_key4 < _len4; _key4++) {
10992
- args[_key4] = arguments[_key4];
10993
- }
11236
+ t(...args) {
10994
11237
  return this.translator?.translate(...args);
10995
11238
  }
10996
- exists() {
10997
- for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0;_key5 < _len5; _key5++) {
10998
- args[_key5] = arguments[_key5];
10999
- }
11239
+ exists(...args) {
11000
11240
  return this.translator?.exists(...args);
11001
11241
  }
11002
11242
  setDefaultNamespace(ns) {
11003
11243
  this.options.defaultNS = ns;
11004
11244
  }
11005
- hasLoadedNamespace(ns) {
11006
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
11245
+ hasLoadedNamespace(ns, options = {}) {
11007
11246
  if (!this.isInitialized) {
11008
11247
  this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
11009
11248
  return false;
@@ -11078,18 +11317,26 @@ class I18n extends EventEmitter {
11078
11317
  lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
11079
11318
  if (!lng)
11080
11319
  return "rtl";
11320
+ try {
11321
+ const l = new Intl.Locale(lng);
11322
+ if (l && l.getTextInfo) {
11323
+ const ti = l.getTextInfo();
11324
+ if (ti && ti.direction)
11325
+ return ti.direction;
11326
+ }
11327
+ } catch (e) {}
11081
11328
  const rtlLngs = ["ar", "shu", "sqr", "ssh", "xaa", "yhd", "yud", "aao", "abh", "abv", "acm", "acq", "acw", "acx", "acy", "adf", "ads", "aeb", "aec", "afb", "ajp", "apc", "apd", "arb", "arq", "ars", "ary", "arz", "auz", "avl", "ayh", "ayl", "ayn", "ayp", "bbz", "pga", "he", "iw", "ps", "pbt", "pbu", "pst", "prp", "prd", "ug", "ur", "ydd", "yds", "yih", "ji", "yi", "hbo", "men", "xmn", "fa", "jpr", "peo", "pes", "prs", "dv", "sam", "ckb"];
11082
11329
  const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
11330
+ if (lng.toLowerCase().indexOf("-latn") > 1)
11331
+ return "ltr";
11083
11332
  return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
11084
11333
  }
11085
- static createInstance() {
11086
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11087
- let callback = arguments.length > 1 ? arguments[1] : undefined;
11088
- return new I18n(options, callback);
11334
+ static createInstance(options = {}, callback) {
11335
+ const instance = new I18n(options, callback);
11336
+ instance.createInstance = I18n.createInstance;
11337
+ return instance;
11089
11338
  }
11090
- cloneInstance() {
11091
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11092
- let callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
11339
+ cloneInstance(options = {}, callback = noop) {
11093
11340
  const forkResourceStore = options.forkResourceStore;
11094
11341
  if (forkResourceStore)
11095
11342
  delete options.forkResourceStore;
@@ -11119,21 +11366,32 @@ class I18n extends EventEmitter {
11119
11366
  prev[l] = {
11120
11367
  ...this.store.data[l]
11121
11368
  };
11122
- return Object.keys(prev[l]).reduce((acc, n) => {
11369
+ prev[l] = Object.keys(prev[l]).reduce((acc, n) => {
11123
11370
  acc[n] = {
11124
11371
  ...prev[l][n]
11125
11372
  };
11126
11373
  return acc;
11127
- }, {});
11374
+ }, prev[l]);
11375
+ return prev;
11128
11376
  }, {});
11129
11377
  clone.store = new ResourceStore(clonedData, mergedOptions);
11130
11378
  clone.services.resourceStore = clone.store;
11131
11379
  }
11380
+ if (options.interpolation) {
11381
+ const defOpts = get();
11382
+ const mergedInterpolation = {
11383
+ ...defOpts.interpolation,
11384
+ ...this.options.interpolation,
11385
+ ...options.interpolation
11386
+ };
11387
+ const mergedForInterpolator = {
11388
+ ...mergedOptions,
11389
+ interpolation: mergedInterpolation
11390
+ };
11391
+ clone.services.interpolator = new Interpolator(mergedForInterpolator);
11392
+ }
11132
11393
  clone.translator = new Translator(clone.services, mergedOptions);
11133
- clone.translator.on("*", function(event) {
11134
- for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1;_key6 < _len6; _key6++) {
11135
- args[_key6 - 1] = arguments[_key6];
11136
- }
11394
+ clone.translator.on("*", (event, ...args) => {
11137
11395
  clone.emit(event, ...args);
11138
11396
  });
11139
11397
  clone.init(mergedOptions, callback);
@@ -11154,7 +11412,6 @@ class I18n extends EventEmitter {
11154
11412
  }
11155
11413
  }
11156
11414
  var instance = I18n.createInstance();
11157
- instance.createInstance = I18n.createInstance;
11158
11415
  var createInstance = instance.createInstance;
11159
11416
  var dir = instance.dir;
11160
11417
  var init = instance.init;
@@ -11169,13 +11426,6 @@ var setDefaultNamespace = instance.setDefaultNamespace;
11169
11426
  var hasLoadedNamespace = instance.hasLoadedNamespace;
11170
11427
  var loadNamespaces = instance.loadNamespaces;
11171
11428
  var loadLanguages = instance.loadLanguages;
11172
-
11173
- // src/i18n/types.ts
11174
- var SUPPORTED_LANGUAGES = [
11175
- { code: "en", name: "English", nativeName: "English" },
11176
- { code: "ko", name: "Korean", nativeName: "한국어" }
11177
- ];
11178
- var DEFAULT_LANGUAGE = "en";
11179
11429
  // src/i18n/locales/en.json
11180
11430
  var en_default = {
11181
11431
  common: {
@@ -11671,6 +11921,13 @@ var ko_default = {
11671
11921
  }
11672
11922
  };
11673
11923
 
11924
+ // src/i18n/types.ts
11925
+ var SUPPORTED_LANGUAGES = [
11926
+ { code: "en", name: "English", nativeName: "English" },
11927
+ { code: "ko", name: "Korean", nativeName: "한국어" }
11928
+ ];
11929
+ var DEFAULT_LANGUAGE = "en";
11930
+
11674
11931
  // src/i18n/index.ts
11675
11932
  function detectLanguage() {
11676
11933
  const envLang = process.env.LANG || process.env.LC_ALL || process.env.LC_MESSAGES || "";
@@ -11981,7 +12238,7 @@ async function checkIndexFiles(targetDir) {
11981
12238
  try {
11982
12239
  const content = await fs.readFile(indexFile, "utf-8");
11983
12240
  $parse(content);
11984
- } catch (error) {
12241
+ } catch (_error) {
11985
12242
  invalidFiles.push(indexFile);
11986
12243
  }
11987
12244
  }
@@ -12036,7 +12293,7 @@ async function checkSkills(targetDir) {
12036
12293
  fixable: false
12037
12294
  };
12038
12295
  }
12039
- async function fixBrokenSymlinks(targetDir, brokenSymlinks) {
12296
+ async function fixBrokenSymlinks(_targetDir, brokenSymlinks) {
12040
12297
  let fixed = 0;
12041
12298
  for (const symlink of brokenSymlinks) {
12042
12299
  try {
@@ -12898,7 +13155,7 @@ async function initCommand(options) {
12898
13155
  }
12899
13156
 
12900
13157
  // src/cli/list.ts
12901
- import { basename as basename2, dirname as dirname3, join as join5, relative } from "node:path";
13158
+ import { basename as basename2, dirname as dirname2, join as join5, relative } from "node:path";
12902
13159
  var ALLOWED_TOP_LEVEL_KEYS = new Set(["name", "type", "description", "version", "category"]);
12903
13160
  function parseKeyValue(line) {
12904
13161
  const colonIndex = line.indexOf(":");
@@ -13016,7 +13273,7 @@ async function getAgents(targetDir) {
13016
13273
  try {
13017
13274
  const agentMdFiles = await listFiles(agentsDir, { recursive: true, pattern: "AGENT.md" });
13018
13275
  const agents = await Promise.all(agentMdFiles.map(async (agentMdPath) => {
13019
- const agentDir = dirname3(agentMdPath);
13276
+ const agentDir = dirname2(agentMdPath);
13020
13277
  const indexYamlPath = join5(agentDir, "index.yaml");
13021
13278
  const { description: yamlDesc, version } = await tryReadIndexYamlMetadata(indexYamlPath);
13022
13279
  const description = yamlDesc ?? await tryExtractMarkdownDescription(agentMdPath);
@@ -13040,7 +13297,7 @@ async function getSkills(targetDir) {
13040
13297
  try {
13041
13298
  const skillMdFiles = await listFiles(skillsDir, { recursive: true, pattern: "SKILL.md" });
13042
13299
  const skills = await Promise.all(skillMdFiles.map(async (skillMdPath) => {
13043
- const skillDir = dirname3(skillMdPath);
13300
+ const skillDir = dirname2(skillMdPath);
13044
13301
  const indexYamlPath = join5(skillDir, "index.yaml");
13045
13302
  const { description, version } = await tryReadIndexYamlMetadata(indexYamlPath);
13046
13303
  return {
@@ -13212,7 +13469,7 @@ async function checkUpdateAvailable() {
13212
13469
  }
13213
13470
  return current.version !== latest.version;
13214
13471
  }
13215
- async function applyUpdates(options) {
13472
+ async function applyUpdates(_options) {
13216
13473
  const updatedComponents = [];
13217
13474
  return updatedComponents;
13218
13475
  }