@glutinum/cli 0.14.0 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/dist/Glutinum.Converter/FsharpAST.js +38 -4
  2. package/dist/Glutinum.Converter/Generate.js +15 -7
  3. package/dist/Glutinum.Converter/GlueAST.js +45 -36
  4. package/dist/Glutinum.Converter/Hosting.js +918 -0
  5. package/dist/Glutinum.Converter/Merge.js +218 -82
  6. package/dist/Glutinum.Converter/Packages.js +44 -8
  7. package/dist/Glutinum.Converter/Printer.js +77 -49
  8. package/dist/Glutinum.Converter/Read.js +8 -8
  9. package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +7 -7
  10. package/dist/Glutinum.Converter/Reader/Declaration.js +26 -26
  11. package/dist/Glutinum.Converter/Reader/Documentation.js +37 -36
  12. package/dist/Glutinum.Converter/Reader/ExportAssignment.js +5 -5
  13. package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +31 -19
  14. package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +6 -7
  15. package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +36 -29
  16. package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +3 -3
  17. package/dist/Glutinum.Converter/Reader/MappedTypeNode.js +82 -4
  18. package/dist/Glutinum.Converter/Reader/ModuleDeclaration.js +3 -3
  19. package/dist/Glutinum.Converter/Reader/Node.js +20 -20
  20. package/dist/Glutinum.Converter/Reader/Parameters.js +7 -7
  21. package/dist/Glutinum.Converter/Reader/TypeAliasDeclaration.js +5 -5
  22. package/dist/Glutinum.Converter/Reader/TypeNode.js +291 -232
  23. package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +8 -8
  24. package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +108 -40
  25. package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +2 -2
  26. package/dist/Glutinum.Converter/Reader/Types.js +6 -6
  27. package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +7 -6
  28. package/dist/Glutinum.Converter/Reader/Utils.js +106 -56
  29. package/dist/Glutinum.Converter/Transform.js +2057 -700
  30. package/dist/Glutinum.Converter/TypeScript.Extensions.js +194 -202
  31. package/dist/Glutinum.Converter/Utils/Naming.js +7 -0
  32. package/dist/Glutinum.Converter/Utils/String.js +2 -2
  33. package/dist/Program.js +38 -26
  34. package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs +89 -0
  35. package/dist/fable_modules/Fable.Promise.3.2.1/AsyncIterable.fs.js +105 -0
  36. package/dist/fable_modules/Fable.Promise.3.2.1/Fable.Promise.fableproj +25 -0
  37. package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs +842 -0
  38. package/dist/fable_modules/Fable.Promise.3.2.1/Promise.fs.js +232 -0
  39. package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs +31 -0
  40. package/dist/fable_modules/Fable.Promise.3.2.1/PromiseImpl.fs.js +20 -0
  41. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs +235 -0
  42. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Array.fs.js +384 -0
  43. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AssemblyInfo.fs +19 -0
  44. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs +287 -0
  45. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Async.fs.js +128 -0
  46. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOption.fs +127 -0
  47. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs +174 -0
  48. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionCE.fs.js +37 -0
  49. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncOptionOp.fs +24 -0
  50. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResult.fs +483 -0
  51. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs +201 -0
  52. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultCE.fs.js +18 -0
  53. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOp.fs +24 -0
  54. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs +87 -0
  55. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOption.fs.js +26 -0
  56. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs +236 -0
  57. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionCE.fs.js +18 -0
  58. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncResultOptionOp.fs +24 -0
  59. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidation.fs +185 -0
  60. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs +186 -0
  61. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationCE.fs.js +18 -0
  62. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/AsyncValidationOp.fs +35 -0
  63. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/FsToolkit.ErrorHandling.fableproj +69 -0
  64. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs +276 -0
  65. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/List.fs.js +364 -0
  66. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Nullness.fs +81 -0
  67. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Option.fs +462 -0
  68. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs +139 -0
  69. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionCE.fs.js +48 -0
  70. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/OptionOp.fs +21 -0
  71. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs +88 -0
  72. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResult.fs.js +30 -0
  73. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs +200 -0
  74. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncResultCE.fs.js +18 -0
  75. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidation.fs +34 -0
  76. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs +244 -0
  77. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ParallelAsyncValidationCE.fs.js +18 -0
  78. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs +731 -0
  79. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Result.fs.js +45 -0
  80. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs +140 -0
  81. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultCE.fs.js +23 -0
  82. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOp.fs +45 -0
  83. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs +201 -0
  84. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOption.fs.js +65 -0
  85. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs +135 -0
  86. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionCE.fs.js +18 -0
  87. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ResultOptionOp.fs +57 -0
  88. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs +503 -0
  89. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Seq.fs.js +295 -0
  90. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/Validation.fs +167 -0
  91. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs +142 -0
  92. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationCE.fs.js +18 -0
  93. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValidationOp.fs +35 -0
  94. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueOption.fs +148 -0
  95. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOption.fs +102 -0
  96. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionCE.fs +587 -0
  97. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/ValueTaskValueOptionOp.fs +10 -0
  98. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
  99. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Debug/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  100. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/.NETCoreApp,Version=v9.0.AssemblyAttributes.fs +3 -0
  101. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/net9.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  102. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/.NETStandard,Version=v2.0.AssemblyAttributes.fs +3 -0
  103. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.0/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  104. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/.NETStandard,Version=v2.1.AssemblyAttributes.fs +3 -0
  105. package/dist/fable_modules/FsToolkit.ErrorHandling.5.2.0/obj/Release/netstandard2.1/FsToolkit.ErrorHandling.AssemblyInfo.fs +20 -0
  106. package/dist/fable_modules/fable-library-js.5.17.2/Array.js +1348 -0
  107. package/dist/fable_modules/fable-library-js.5.17.2/Async.js +163 -0
  108. package/dist/fable_modules/fable-library-js.5.17.2/AsyncBuilder.js +204 -0
  109. package/dist/fable_modules/fable-library-js.5.17.2/BigInt.js +307 -0
  110. package/dist/fable_modules/fable-library-js.5.17.2/BitConverter.js +138 -0
  111. package/dist/fable_modules/fable-library-js.5.17.2/Boolean.js +22 -0
  112. package/dist/fable_modules/fable-library-js.5.17.2/CHANGELOG.md +348 -0
  113. package/dist/fable_modules/fable-library-js.5.17.2/Char.js +202 -0
  114. package/dist/fable_modules/fable-library-js.5.17.2/Choice.js +184 -0
  115. package/dist/fable_modules/fable-library-js.5.17.2/CollectionUtil.js +182 -0
  116. package/dist/fable_modules/fable-library-js.5.17.2/ConditionalWeakTable.js +21 -0
  117. package/dist/fable_modules/fable-library-js.5.17.2/Date.js +834 -0
  118. package/dist/fable_modules/fable-library-js.5.17.2/DateOffset.js +252 -0
  119. package/dist/fable_modules/fable-library-js.5.17.2/DateOnly.js +124 -0
  120. package/dist/fable_modules/fable-library-js.5.17.2/DateOnlyTemporal.js +146 -0
  121. package/dist/fable_modules/fable-library-js.5.17.2/DateTimeFormat.js +523 -0
  122. package/dist/fable_modules/fable-library-js.5.17.2/DateTimeOffsetTemporal.js +283 -0
  123. package/dist/fable_modules/fable-library-js.5.17.2/DateTimeTemporal.js +243 -0
  124. package/dist/fable_modules/fable-library-js.5.17.2/Decimal.js +238 -0
  125. package/dist/fable_modules/fable-library-js.5.17.2/Directory.js +11 -0
  126. package/dist/fable_modules/fable-library-js.5.17.2/Double.js +53 -0
  127. package/dist/fable_modules/fable-library-js.5.17.2/Encoding.js +185 -0
  128. package/dist/fable_modules/fable-library-js.5.17.2/Environment.js +3 -0
  129. package/dist/fable_modules/fable-library-js.5.17.2/Event.js +102 -0
  130. package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Collections.js +45 -0
  131. package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.CompilerServices.js +27 -0
  132. package/dist/fable_modules/fable-library-js.5.17.2/FSharp.Core.js +156 -0
  133. package/dist/fable_modules/fable-library-js.5.17.2/File.js +27 -0
  134. package/dist/fable_modules/fable-library-js.5.17.2/Global.js +29 -0
  135. package/dist/fable_modules/fable-library-js.5.17.2/Guid.js +163 -0
  136. package/dist/fable_modules/fable-library-js.5.17.2/Int32.js +135 -0
  137. package/dist/fable_modules/fable-library-js.5.17.2/List.js +1337 -0
  138. package/dist/fable_modules/fable-library-js.5.17.2/Long.js +38 -0
  139. package/dist/fable_modules/fable-library-js.5.17.2/MailboxProcessor.js +100 -0
  140. package/dist/fable_modules/fable-library-js.5.17.2/Map.js +1400 -0
  141. package/dist/fable_modules/fable-library-js.5.17.2/MapUtil.js +130 -0
  142. package/dist/fable_modules/fable-library-js.5.17.2/MutableMap.js +339 -0
  143. package/dist/fable_modules/fable-library-js.5.17.2/MutableSet.js +233 -0
  144. package/dist/fable_modules/fable-library-js.5.17.2/Native.js +14 -0
  145. package/dist/fable_modules/fable-library-js.5.17.2/Numeric.js +112 -0
  146. package/dist/fable_modules/fable-library-js.5.17.2/Observable.js +115 -0
  147. package/dist/fable_modules/fable-library-js.5.17.2/Option.js +87 -0
  148. package/dist/fable_modules/fable-library-js.5.17.2/Path.js +31 -0
  149. package/dist/fable_modules/fable-library-js.5.17.2/README.md +3 -0
  150. package/dist/fable_modules/fable-library-js.5.17.2/Random.js +172 -0
  151. package/dist/fable_modules/fable-library-js.5.17.2/Range.js +45 -0
  152. package/dist/fable_modules/fable-library-js.5.17.2/Reflection.js +489 -0
  153. package/dist/fable_modules/fable-library-js.5.17.2/RegExp.js +170 -0
  154. package/dist/fable_modules/fable-library-js.5.17.2/Result.js +165 -0
  155. package/dist/fable_modules/fable-library-js.5.17.2/Seq.js +1504 -0
  156. package/dist/fable_modules/fable-library-js.5.17.2/Seq2.js +111 -0
  157. package/dist/fable_modules/fable-library-js.5.17.2/Set.js +1829 -0
  158. package/dist/fable_modules/fable-library-js.5.17.2/String.js +731 -0
  159. package/dist/fable_modules/fable-library-js.5.17.2/System.Collections.Generic.js +333 -0
  160. package/dist/fable_modules/fable-library-js.5.17.2/System.Text.js +200 -0
  161. package/dist/fable_modules/fable-library-js.5.17.2/System.js +289 -0
  162. package/dist/fable_modules/fable-library-js.5.17.2/Task.js +27 -0
  163. package/dist/fable_modules/fable-library-js.5.17.2/TaskBuilder.js +72 -0
  164. package/dist/fable_modules/fable-library-js.5.17.2/TimeOnly.js +122 -0
  165. package/dist/fable_modules/fable-library-js.5.17.2/TimeOnlyTemporal.js +142 -0
  166. package/dist/fable_modules/fable-library-js.5.17.2/TimeSpan.js +180 -0
  167. package/dist/fable_modules/fable-library-js.5.17.2/TimeSpanTemporal.js +259 -0
  168. package/dist/fable_modules/fable-library-js.5.17.2/Timer.js +67 -0
  169. package/dist/fable_modules/fable-library-js.5.17.2/Types.js +198 -0
  170. package/dist/fable_modules/fable-library-js.5.17.2/Unicode.13.0.0.js +4 -0
  171. package/dist/fable_modules/fable-library-js.5.17.2/Uri.js +165 -0
  172. package/dist/fable_modules/fable-library-js.5.17.2/Util.js +807 -0
  173. package/dist/fable_modules/fable-library-js.5.17.2/big.d.ts +338 -0
  174. package/dist/fable_modules/fable-library-js.5.17.2/lib/big.js +829 -0
  175. package/dist/fable_modules/fable-library-js.5.17.2/package.json +24 -0
  176. package/dist/fable_modules/fable-library-js.5.17.2/quotation.js +682 -0
  177. package/package.json +2 -2
  178. package/dist/Glutinum.Converter/TypeScript.js +0 -12
  179. package/src/Glutinum.Converter/js/bootstrap.js +0 -123
  180. package/src/Glutinum.Converter/js/host.js +0 -144
  181. package/src/Glutinum.Converter/js/npm.js +0 -137
  182. package/src/Glutinum.Converter/js/resolve.js +0 -402
@@ -0,0 +1,731 @@
1
+ import { toString as dateToString } from "./Date.js";
2
+ import { compare as numericCompare, divide, isNumeric, isIntegral, multiply, toExponential, toFixed, toHex, toPrecision } from "./Numeric.js";
3
+ import { escape } from "./RegExp.js";
4
+ import { toString } from "./Types.js";
5
+ import { Exception } from "./Util.js";
6
+ // Temporal date/time values (only present under --test:js-temporal) are not JS Dates. To avoid
7
+ // importing the side-effecting Temporal runtime modules into this core file — which would pull
8
+ // them into every bundle — they advertise a .NET-style formatter through this well-known symbol,
9
+ // attached to their prototype when (and only when) those modules are loaded.
10
+ const dateTimeFormattableSymbol = Symbol.for("Fable.DateTimeFormattable");
11
+ function isNetDateFormattable(rep) {
12
+ return rep != null && typeof rep[dateTimeFormattableSymbol] === "function";
13
+ }
14
+ function formatDateLike(rep, format) {
15
+ return rep instanceof Date ? dateToString(rep, format) : rep[dateTimeFormattableSymbol](format);
16
+ }
17
+ const fsFormatRegExp = /(^|[^%])%([0+\- ]*)(\*|\d+)?(?:\.(\d+))?(\w)/g;
18
+ const interpolateRegExp = /(?:(^|[^%])%([0+\- ]*)(\d+)?(?:\.(\d+))?(\w))?%P\(\)/g;
19
+ const formatRegExp = /\{(\d+)(,-?\d+)?(?:\:([a-zA-Z])(\d{0,2})|\:(.+?))?\}/g;
20
+ function isLessThan(x, y) {
21
+ return numericCompare(x, y) < 0;
22
+ }
23
+ export const StringComparison = {
24
+ CurrentCulture: 0,
25
+ CurrentCultureIgnoreCase: 1,
26
+ InvariantCulture: 2,
27
+ InvariantCultureIgnoreCase: 3,
28
+ Ordinal: 4,
29
+ OrdinalIgnoreCase: 5,
30
+ };
31
+ function cmp(x, y, ic) {
32
+ function isIgnoreCase(i) {
33
+ return i === true ||
34
+ i === StringComparison.CurrentCultureIgnoreCase ||
35
+ i === StringComparison.InvariantCultureIgnoreCase ||
36
+ i === StringComparison.OrdinalIgnoreCase;
37
+ }
38
+ function isOrdinal(i) {
39
+ return i === StringComparison.Ordinal ||
40
+ i === StringComparison.OrdinalIgnoreCase;
41
+ }
42
+ if (x == null) {
43
+ return y == null ? 0 : -1;
44
+ }
45
+ if (y == null) {
46
+ return 1;
47
+ } // everything is bigger than null
48
+ if (isOrdinal(ic)) {
49
+ if (isIgnoreCase(ic)) {
50
+ x = x.toLowerCase();
51
+ y = y.toLowerCase();
52
+ }
53
+ return (x === y) ? 0 : (x < y ? -1 : 1);
54
+ }
55
+ else {
56
+ if (isIgnoreCase(ic)) {
57
+ x = x.toLocaleLowerCase();
58
+ y = y.toLocaleLowerCase();
59
+ }
60
+ return x.localeCompare(y);
61
+ }
62
+ }
63
+ export function compare(...args) {
64
+ switch (args.length) {
65
+ case 2: return cmp(args[0], args[1], false);
66
+ case 3: return cmp(args[0], args[1], args[2]);
67
+ case 4: return cmp(args[0], args[1], args[2] === true);
68
+ case 5: return cmp(args[0].slice(args[1], args[1] + args[4]), args[2].slice(args[3], args[3] + args[4]), false);
69
+ case 6: return cmp(args[0].slice(args[1], args[1] + args[4]), args[2].slice(args[3], args[3] + args[4]), args[5]);
70
+ case 7: return cmp(args[0].slice(args[1], args[1] + args[4]), args[2].slice(args[3], args[3] + args[4]), args[5] === true);
71
+ default: throw new Exception("String.compare: Unsupported number of parameters");
72
+ }
73
+ }
74
+ export function compareOrdinal(x, y) {
75
+ return cmp(x, y, StringComparison.Ordinal);
76
+ }
77
+ export function compareTo(x, y) {
78
+ return cmp(x, y, StringComparison.CurrentCulture);
79
+ }
80
+ export function startsWith(str, pattern, ic) {
81
+ if (ic === StringComparison.Ordinal) { // to avoid substring allocation
82
+ return str.startsWith(pattern);
83
+ }
84
+ if (str.length >= pattern.length) {
85
+ return cmp(str.slice(0, pattern.length), pattern, ic) === 0;
86
+ }
87
+ return false;
88
+ }
89
+ export function endsWith(str, pattern, ic) {
90
+ if (ic === StringComparison.Ordinal) { // to avoid substring allocation
91
+ return str.endsWith(pattern);
92
+ }
93
+ if (str.length >= pattern.length) {
94
+ return cmp(str.slice(str.length - pattern.length), pattern, ic) === 0;
95
+ }
96
+ return false;
97
+ }
98
+ export function contains(str, pattern, ic) {
99
+ if (ic === StringComparison.Ordinal) { // fast path
100
+ return str.includes(pattern);
101
+ }
102
+ const len = pattern.length;
103
+ for (let i = 0; i <= str.length - len; i++) {
104
+ if (cmp(str.slice(i, i + len), pattern, ic) === 0) {
105
+ return true;
106
+ }
107
+ }
108
+ return false;
109
+ }
110
+ export function indexOf(str, searchValue, comparison, startIndex = 0) {
111
+ if (comparison === StringComparison.Ordinal) { // fast path
112
+ return str.indexOf(searchValue, startIndex);
113
+ }
114
+ const len = searchValue.length;
115
+ for (let i = Math.max(startIndex, 0); i <= str.length - len; i++) {
116
+ if (cmp(str.slice(i, i + len), searchValue, comparison) === 0) {
117
+ return i;
118
+ }
119
+ }
120
+ return -1;
121
+ }
122
+ export function lastIndexOf(str, searchValue, comparison, startIndex = str.length - 1) {
123
+ if (comparison === StringComparison.Ordinal) { // fast path
124
+ return str.lastIndexOf(searchValue, startIndex);
125
+ }
126
+ const len = searchValue.length;
127
+ for (let i = Math.min(startIndex, str.length - len); i >= 0; i--) {
128
+ if (cmp(str.slice(i, i + len), searchValue, comparison) === 0) {
129
+ return i;
130
+ }
131
+ }
132
+ return -1;
133
+ }
134
+ export function indexOfAny(str, anyOf, ...args) {
135
+ if (str == null || str === "") {
136
+ return -1;
137
+ }
138
+ const startIndex = (args.length > 0) ? args[0] : 0;
139
+ if (startIndex < 0) {
140
+ throw new Exception("Start index cannot be negative");
141
+ }
142
+ const length = (args.length > 1) ? args[1] : str.length - startIndex;
143
+ if (length < 0) {
144
+ throw new Exception("Length cannot be negative");
145
+ }
146
+ if (startIndex + length > str.length) {
147
+ throw new Exception("Invalid startIndex and length");
148
+ }
149
+ const endIndex = startIndex + length;
150
+ const anyOfAsStr = "".concat.apply("", anyOf);
151
+ for (let i = startIndex; i < endIndex; i++) {
152
+ if (anyOfAsStr.indexOf(str[i]) > -1) {
153
+ return i;
154
+ }
155
+ }
156
+ return -1;
157
+ }
158
+ export function printf(input) {
159
+ return {
160
+ input,
161
+ cont: fsFormat(input),
162
+ };
163
+ }
164
+ export function interpolate(str, values) {
165
+ let valIdx = 0;
166
+ let strIdx = 0;
167
+ let result = "";
168
+ interpolateRegExp.lastIndex = 0;
169
+ let match = interpolateRegExp.exec(str);
170
+ while (match) {
171
+ // The first group corresponds to the no-escape char (^|[^%]), the actual pattern starts in the next char
172
+ // Note: we don't use negative lookbehind because some browsers don't support it yet
173
+ const matchIndex = match.index + (match[1] || "").length;
174
+ result += str.substring(strIdx, matchIndex).replace(/%%/g, "%");
175
+ const [, , flags, padLength, precision, format] = match;
176
+ // Save interpolateRegExp.lastIndex before running formatReplacement because the values
177
+ // may also involve interpolation and make use of interpolateRegExp (see #3078)
178
+ strIdx = interpolateRegExp.lastIndex;
179
+ result += formatReplacement(values[valIdx++], flags, padLength, precision, format);
180
+ // Move interpolateRegExp.lastIndex one char behind to make sure we match the no-escape char next time
181
+ interpolateRegExp.lastIndex = strIdx - 1;
182
+ match = interpolateRegExp.exec(str);
183
+ }
184
+ result += str.substring(strIdx).replace(/%%/g, "%");
185
+ return result;
186
+ }
187
+ function continuePrint(cont, arg) {
188
+ return typeof arg === "string" ? cont(arg) : arg.cont(cont);
189
+ }
190
+ export function toConsole(arg) {
191
+ // Don't remove the lambda here, see #1357
192
+ return continuePrint((x) => console.log(x), arg);
193
+ }
194
+ export function toConsoleError(arg) {
195
+ return continuePrint((x) => console.error(x), arg);
196
+ }
197
+ export function toText(arg) {
198
+ return continuePrint((x) => x, arg);
199
+ }
200
+ export function toFail(arg) {
201
+ return continuePrint((x) => {
202
+ throw new Exception(x);
203
+ }, arg);
204
+ }
205
+ function formatReplacement(rep, flags, padLength, precision, format) {
206
+ let sign = "";
207
+ flags = flags || "";
208
+ format = format || "";
209
+ if (isNumeric(rep)) {
210
+ if (format.toLowerCase() !== "x") {
211
+ if (isLessThan(rep, 0)) {
212
+ rep = multiply(rep, -1);
213
+ sign = "-";
214
+ }
215
+ else {
216
+ if (flags.indexOf(" ") >= 0) {
217
+ sign = " ";
218
+ }
219
+ else if (flags.indexOf("+") >= 0) {
220
+ sign = "+";
221
+ }
222
+ }
223
+ }
224
+ precision = precision == null ? null : parseInt(precision, 10);
225
+ switch (format) {
226
+ case "f":
227
+ case "F":
228
+ precision = precision != null ? precision : 6;
229
+ rep = toFixed(rep, precision);
230
+ break;
231
+ case "g":
232
+ case "G":
233
+ rep = precision != null ? toPrecision(rep, precision) : toPrecision(rep);
234
+ break;
235
+ case "e":
236
+ case "E":
237
+ rep = precision != null ? toExponential(rep, precision) : toExponential(rep);
238
+ break;
239
+ case "x":
240
+ rep = toHex(rep);
241
+ break;
242
+ case "X":
243
+ rep = toHex(rep).toUpperCase();
244
+ break;
245
+ default: // AOid
246
+ rep = String(rep);
247
+ break;
248
+ }
249
+ }
250
+ else if (rep instanceof Date || isNetDateFormattable(rep)) {
251
+ rep = formatDateLike(rep, undefined);
252
+ }
253
+ else if (format === "A" && typeof rep === "string") {
254
+ rep = "\"" + rep + "\"";
255
+ }
256
+ else {
257
+ rep = toString(rep);
258
+ }
259
+ padLength = typeof padLength === "number" ? padLength : parseInt(padLength, 10);
260
+ if (!isNaN(padLength)) {
261
+ const zeroFlag = flags.indexOf("0") >= 0; // Use '0' for left padding
262
+ const minusFlag = flags.indexOf("-") >= 0; // Right padding
263
+ const ch = minusFlag || !zeroFlag ? " " : "0";
264
+ if (ch === "0") {
265
+ rep = pad(rep, padLength - sign.length, ch, minusFlag);
266
+ rep = sign + rep;
267
+ }
268
+ else {
269
+ rep = pad(sign + rep, padLength, ch, minusFlag);
270
+ }
271
+ }
272
+ else {
273
+ rep = sign + rep;
274
+ }
275
+ return rep;
276
+ }
277
+ function createPrinter(cont, _strParts, _matches, _result = "", padArg = -1) {
278
+ return (...args) => {
279
+ // Make copies of the values passed by reference because the function can be used multiple times
280
+ let result = _result;
281
+ const strParts = _strParts.slice();
282
+ const matches = _matches.slice();
283
+ for (const arg of args) {
284
+ const [, , flags, _padLength, precision, format] = matches[0];
285
+ let padLength = _padLength;
286
+ if (padArg >= 0) {
287
+ padLength = padArg;
288
+ padArg = -1;
289
+ }
290
+ else if (padLength === "*") {
291
+ if (arg < 0) {
292
+ throw new Exception("Non-negative number required");
293
+ }
294
+ padArg = arg;
295
+ continue;
296
+ }
297
+ result += strParts[0];
298
+ result += formatReplacement(arg, flags, padLength, precision, format);
299
+ strParts.splice(0, 1);
300
+ matches.splice(0, 1);
301
+ }
302
+ if (matches.length === 0) {
303
+ result += strParts[0];
304
+ return cont(result);
305
+ }
306
+ else {
307
+ return createPrinter(cont, strParts, matches, result, padArg);
308
+ }
309
+ };
310
+ }
311
+ export function fsFormat(str) {
312
+ return (cont) => {
313
+ fsFormatRegExp.lastIndex = 0;
314
+ const strParts = [];
315
+ const matches = [];
316
+ let strIdx = 0;
317
+ let match = fsFormatRegExp.exec(str);
318
+ while (match) {
319
+ // The first group corresponds to the no-escape char (^|[^%]), the actual pattern starts in the next char
320
+ // Note: we don't use negative lookbehind because some browsers don't support it yet
321
+ const matchIndex = match.index + (match[1] || "").length;
322
+ strParts.push(str.substring(strIdx, matchIndex).replace(/%%/g, "%"));
323
+ matches.push(match);
324
+ strIdx = fsFormatRegExp.lastIndex;
325
+ // Likewise we need to move fsFormatRegExp.lastIndex one char behind to make sure we match the no-escape char next time
326
+ fsFormatRegExp.lastIndex -= 1;
327
+ match = fsFormatRegExp.exec(str);
328
+ }
329
+ if (strParts.length === 0) {
330
+ return cont(str.replace(/%%/g, "%"));
331
+ }
332
+ else {
333
+ strParts.push(str.substring(strIdx).replace(/%%/g, "%"));
334
+ return createPrinter(cont, strParts, matches);
335
+ }
336
+ };
337
+ }
338
+ function splitIntAndDecimalPart(value) {
339
+ let [repInt, repDecimal] = value.split(".");
340
+ repDecimal === undefined && (repDecimal = "");
341
+ return {
342
+ integral: repInt,
343
+ decimal: repDecimal
344
+ };
345
+ }
346
+ function thousandSeparate(value) {
347
+ return value.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
348
+ }
349
+ export function format(str, ...args) {
350
+ let str2;
351
+ if (typeof str === "object") {
352
+ // Called with culture info
353
+ str2 = String(args[0]);
354
+ args.shift();
355
+ }
356
+ else {
357
+ str2 = str;
358
+ }
359
+ return str2.replace(formatRegExp, (_, idx, padLength, format, precision, pattern) => {
360
+ if (idx < 0 || idx >= args.length) {
361
+ throw new Exception("Index must be greater or equal to zero and less than the arguments' length.");
362
+ }
363
+ let rep = args[idx];
364
+ let parts;
365
+ if (isNumeric(rep)) {
366
+ precision = precision == "" ? null : parseInt(precision, 10);
367
+ switch (format) {
368
+ case "b":
369
+ case "B":
370
+ if (!isIntegral(rep)) {
371
+ throw new Exception("Format specifier was invalid.");
372
+ }
373
+ rep = (rep >>> 0).toString(2).replace(/^0+/, "").padStart(precision || 1, "0");
374
+ break;
375
+ case "c":
376
+ case "C":
377
+ const isNegative = isLessThan(rep, 0);
378
+ if (isLessThan(rep, 0)) {
379
+ rep = multiply(rep, -1);
380
+ }
381
+ precision = precision == null ? 2 : precision;
382
+ rep = toFixed(rep, precision);
383
+ parts = splitIntAndDecimalPart(rep);
384
+ if (precision > 0) {
385
+ rep = "¤" + thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
386
+ }
387
+ else {
388
+ rep = "¤" + thousandSeparate(parts.integral);
389
+ }
390
+ if (isNegative) {
391
+ rep = "(" + rep + ")";
392
+ }
393
+ break;
394
+ case "d":
395
+ case "D":
396
+ if (!isIntegral(rep)) {
397
+ throw new Exception("Format specifier was invalid.");
398
+ }
399
+ rep = String(rep);
400
+ if (precision != null) {
401
+ if (rep.startsWith("-")) {
402
+ rep = "-" + padLeft(rep.substring(1), precision, "0");
403
+ }
404
+ else {
405
+ rep = padLeft(rep, precision, "0");
406
+ }
407
+ }
408
+ break;
409
+ case "e":
410
+ case "E": {
411
+ precision = precision != null ? precision : 6;
412
+ rep = String(toExponential(rep, precision));
413
+ // .NET always signs the exponent and pads it to at least three digits
414
+ const eIdx = rep.indexOf("e");
415
+ rep = rep.slice(0, eIdx) + format + rep[eIdx + 1] + padLeft(rep.slice(eIdx + 2), 3, "0");
416
+ break;
417
+ }
418
+ case "f":
419
+ case "F":
420
+ precision = precision != null ? precision : 2;
421
+ rep = toFixed(rep, precision);
422
+ if (precision > 0) {
423
+ parts = splitIntAndDecimalPart(rep);
424
+ rep = parts.integral + "." + padRight(parts.decimal, precision, "0");
425
+ }
426
+ break;
427
+ case "g":
428
+ case "G": {
429
+ rep = precision != null ? toPrecision(rep, precision) : toPrecision(rep);
430
+ // Handle exponential notation: only trim trailing zeros from mantissa, not from exponent.
431
+ // .NET G format guarantees an exponent of at least 2 digits with an explicit sign (e.g. "E-07").
432
+ const eIdx = rep.indexOf("e");
433
+ if (eIdx >= 0) {
434
+ const mantissa = trimEnd(trimEnd(rep.slice(0, eIdx), "0"), ".");
435
+ const expSign = rep[eIdx + 1]; // toPrecision always emits "+" or "-"
436
+ const expDigits = rep.slice(eIdx + 2);
437
+ const paddedExpDigits = expDigits.length < 2 ? "0" + expDigits : expDigits;
438
+ const eChar = format === "G" ? "E" : "e";
439
+ rep = mantissa + eChar + expSign + paddedExpDigits;
440
+ }
441
+ else if (rep.indexOf(".") >= 0) {
442
+ rep = trimEnd(trimEnd(rep, "0"), ".");
443
+ }
444
+ break;
445
+ }
446
+ case "n":
447
+ case "N":
448
+ precision = precision != null ? precision : 2;
449
+ rep = toFixed(rep, precision);
450
+ parts = splitIntAndDecimalPart(rep);
451
+ if (precision > 0) {
452
+ rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0");
453
+ }
454
+ else {
455
+ rep = thousandSeparate(parts.integral);
456
+ }
457
+ break;
458
+ case "p":
459
+ case "P":
460
+ precision = precision != null ? precision : 2;
461
+ rep = toFixed(multiply(rep, 100), precision);
462
+ parts = splitIntAndDecimalPart(rep);
463
+ if (precision > 0) {
464
+ rep = thousandSeparate(parts.integral) + "." + padRight(parts.decimal, precision, "0") + " %";
465
+ }
466
+ else {
467
+ rep = thousandSeparate(parts.integral) + " %";
468
+ }
469
+ break;
470
+ case "r":
471
+ case "R":
472
+ throw new Exception("The round-trip format is not supported by Fable");
473
+ case "x":
474
+ case "X":
475
+ if (!isIntegral(rep)) {
476
+ throw new Exception("Format specifier was invalid.");
477
+ }
478
+ precision = precision != null ? precision : 1;
479
+ rep = padLeft(toHex(rep), precision, "0");
480
+ if (format === "X") {
481
+ rep = rep.toUpperCase();
482
+ }
483
+ break;
484
+ default:
485
+ // If we have format and were not able to handle it throw
486
+ // See: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#standard-format-specifiers
487
+ if (format) {
488
+ throw new Exception("Format specifier was invalid.");
489
+ }
490
+ if (pattern) {
491
+ let sign = "";
492
+ const patternStr = pattern;
493
+ // Each `%` scales the value by 100 and is kept as a literal in the output
494
+ const percents = (patternStr.match(/%/g) ?? []).length;
495
+ if (percents > 0) {
496
+ rep = multiply(rep, Math.pow(100, percents));
497
+ }
498
+ // .NET ignores commas placed after the decimal placeholders, hence the trailing group
499
+ rep = patternStr.replace(/([0#,]+)(\.[0#]+)?(,*)/, (_, intPart, decimalPart) => {
500
+ // Commas between the last integer placeholder and the decimal point scale the
501
+ // value down by 1000 each; commas anywhere else only turn on digit grouping
502
+ const scaleCommas = /,*$/.exec(intPart)[0].length;
503
+ if (scaleCommas > 0) {
504
+ intPart = intPart.substring(0, intPart.length - scaleCommas);
505
+ rep = divide(rep, Math.pow(1000, scaleCommas));
506
+ }
507
+ if (isLessThan(rep, 0)) {
508
+ rep = multiply(rep, -1);
509
+ sign = "-";
510
+ }
511
+ decimalPart = decimalPart == null ? "" : decimalPart.substring(1);
512
+ rep = toFixed(rep, Math.max(decimalPart.length, 0));
513
+ let [repInt, repDecimal] = rep.split(".");
514
+ repDecimal || (repDecimal = "");
515
+ const leftZeroes = intPart.replace(/,/g, "").replace(/^#+/, "").length;
516
+ repInt = padLeft(repInt, leftZeroes, "0");
517
+ const rightZeros = decimalPart.replace(/#+$/, "").length;
518
+ if (rightZeros > repDecimal.length) {
519
+ repDecimal = padRight(repDecimal, rightZeros, "0");
520
+ }
521
+ else if (rightZeros < repDecimal.length) {
522
+ repDecimal = repDecimal.substring(0, rightZeros) + repDecimal.substring(rightZeros).replace(/0+$/, "");
523
+ }
524
+ // Thousands separator
525
+ if (intPart.indexOf(",") > 0) {
526
+ const i = repInt.length % 3;
527
+ const thousandGroups = Math.floor(repInt.length / 3);
528
+ let thousands = i > 0 ? repInt.substr(0, i) + (thousandGroups > 0 ? "," : "") : "";
529
+ for (let j = 0; j < thousandGroups; j++) {
530
+ thousands += repInt.substr(i + j * 3, 3) + (j < thousandGroups - 1 ? "," : "");
531
+ }
532
+ repInt = thousands;
533
+ }
534
+ return repDecimal.length > 0 ? repInt + "." + repDecimal : repInt;
535
+ });
536
+ rep = sign + rep;
537
+ }
538
+ }
539
+ }
540
+ else if (rep instanceof Date || isNetDateFormattable(rep)) {
541
+ rep = formatDateLike(rep, pattern || format);
542
+ }
543
+ else {
544
+ rep = toString(rep);
545
+ }
546
+ padLength = parseInt((padLength || " ").substring(1), 10);
547
+ if (!isNaN(padLength)) {
548
+ rep = pad(String(rep), Math.abs(padLength), " ", padLength < 0);
549
+ }
550
+ return rep;
551
+ });
552
+ }
553
+ export function initialize(n, f) {
554
+ if (n < 0) {
555
+ throw new Exception("String length must be non-negative");
556
+ }
557
+ const xs = new Array(n);
558
+ for (let i = 0; i < n; i++) {
559
+ xs[i] = f(i);
560
+ }
561
+ return xs.join("");
562
+ }
563
+ export function insert(str, startIndex, value) {
564
+ if (startIndex < 0 || startIndex > str.length) {
565
+ throw new Exception("startIndex is negative or greater than the length of this instance.");
566
+ }
567
+ return str.substring(0, startIndex) + value + str.substring(startIndex);
568
+ }
569
+ export function isNullOrEmpty(str) {
570
+ return typeof str !== "string" || str.length === 0;
571
+ }
572
+ export function isNullOrWhiteSpace(str) {
573
+ return typeof str !== "string" || /^\s*$/.test(str);
574
+ }
575
+ export function concat(...xs) {
576
+ return xs.map((x) => String(x)).join("");
577
+ }
578
+ export function join(delimiter, xs) {
579
+ if (Array.isArray(xs)) {
580
+ return xs.join(delimiter);
581
+ }
582
+ else {
583
+ return Array.from(xs).join(delimiter);
584
+ }
585
+ }
586
+ export function joinWithIndices(delimiter, xs, startIndex, count) {
587
+ const endIndexPlusOne = startIndex + count;
588
+ if (endIndexPlusOne > xs.length) {
589
+ throw new Exception("Index and count must refer to a location within the buffer.");
590
+ }
591
+ return xs.slice(startIndex, endIndexPlusOne).join(delimiter);
592
+ }
593
+ function notSupported(name) {
594
+ throw new Exception("The environment doesn't support '" + name + "', please use a polyfill.");
595
+ }
596
+ export function toBase64String(inArray) {
597
+ let str = "";
598
+ for (let i = 0; i < inArray.length; i++) {
599
+ str += String.fromCharCode(inArray[i]);
600
+ }
601
+ return typeof btoa === "function" ? btoa(str) : notSupported("btoa");
602
+ }
603
+ export function fromBase64String(b64Encoded) {
604
+ const binary = typeof atob === "function" ? atob(b64Encoded) : notSupported("atob");
605
+ const bytes = new Uint8Array(binary.length);
606
+ for (let i = 0; i < binary.length; i++) {
607
+ bytes[i] = binary.charCodeAt(i);
608
+ }
609
+ return bytes;
610
+ }
611
+ function pad(str, len, ch, isRight) {
612
+ ch = ch || " ";
613
+ len = len - str.length;
614
+ for (let i = 0; i < len; i++) {
615
+ str = isRight ? str + ch : ch + str;
616
+ }
617
+ return str;
618
+ }
619
+ export function padLeft(str, len, ch) {
620
+ return pad(str, len, ch);
621
+ }
622
+ export function padRight(str, len, ch) {
623
+ return pad(str, len, ch, true);
624
+ }
625
+ export function remove(str, startIndex, count) {
626
+ if (startIndex >= str.length) {
627
+ throw new Exception("startIndex must be less than length of string");
628
+ }
629
+ if (typeof count === "number" && (startIndex + count) > str.length) {
630
+ throw new Exception("Index and count must refer to a location within the string.");
631
+ }
632
+ return str.slice(0, startIndex) + (typeof count === "number" ? str.substr(startIndex + count) : "");
633
+ }
634
+ export function replace(str, search, replace) {
635
+ return str.replace(new RegExp(escape(search), "g"), replace);
636
+ }
637
+ export function replicate(n, x) {
638
+ return initialize(n, () => x);
639
+ }
640
+ export function getCharAtIndex(input, index) {
641
+ if (index < 0 || index >= input.length) {
642
+ throw new Exception("Index was outside the bounds of the array.");
643
+ }
644
+ return input[index];
645
+ }
646
+ export function split(str, splitters, count, options) {
647
+ count = typeof count === "number" ? count : undefined;
648
+ options = typeof options === "number" ? options : 0;
649
+ if (count && count < 0) {
650
+ throw new Exception("Count cannot be less than zero");
651
+ }
652
+ if (count === 0) {
653
+ return [];
654
+ }
655
+ const removeEmpty = (options & 1) === 1;
656
+ const trim = (options & 2) === 2;
657
+ splitters = splitters || [];
658
+ splitters = splitters.filter(x => x).map(escape);
659
+ splitters = splitters.length > 0 ? splitters : ["\\s"];
660
+ const splits = [];
661
+ const reg = new RegExp(splitters.join("|"), "g");
662
+ let findSplits = true;
663
+ let i = 0;
664
+ do {
665
+ const match = reg.exec(str);
666
+ if (match === null) {
667
+ const candidate = trim ? str.substring(i).trim() : str.substring(i);
668
+ if (!removeEmpty || candidate.length > 0) {
669
+ splits.push(candidate);
670
+ }
671
+ findSplits = false;
672
+ }
673
+ else {
674
+ const candidate = trim ? str.substring(i, match.index).trim() : str.substring(i, match.index);
675
+ if (!removeEmpty || candidate.length > 0) {
676
+ if (count != null && splits.length + 1 === count) {
677
+ splits.push(trim ? str.substring(i).trim() : str.substring(i));
678
+ findSplits = false;
679
+ }
680
+ else {
681
+ splits.push(candidate);
682
+ }
683
+ }
684
+ i = reg.lastIndex;
685
+ }
686
+ } while (findSplits);
687
+ return splits;
688
+ }
689
+ export function trim(str, ...chars) {
690
+ if (chars.length === 0) {
691
+ return str.trim();
692
+ }
693
+ const pattern = "[" + escape(chars.join("")) + "]+";
694
+ return str.replace(new RegExp("^" + pattern), "").replace(new RegExp(pattern + "$"), "");
695
+ }
696
+ export function trimStart(str, ...chars) {
697
+ return chars.length === 0
698
+ ? str.trimStart()
699
+ : str.replace(new RegExp("^[" + escape(chars.join("")) + "]+"), "");
700
+ }
701
+ export function trimEnd(str, ...chars) {
702
+ return chars.length === 0
703
+ ? str.trimEnd()
704
+ : str.replace(new RegExp("[" + escape(chars.join("")) + "]+$"), "");
705
+ }
706
+ export function filter(pred, x) {
707
+ return x.split("").filter((c) => pred(c)).join("");
708
+ }
709
+ export function substring(str, startIndex, length) {
710
+ if ((startIndex + (length || 0) > str.length)) {
711
+ throw new Exception("Invalid startIndex and/or length");
712
+ }
713
+ return length != null ? str.substr(startIndex, length) : str.substr(startIndex);
714
+ }
715
+ export function toCharArray2(str, startIndex, length) {
716
+ return substring(str, startIndex, length).split("");
717
+ }
718
+ export function fmt(strs, ...args) {
719
+ return ({ strs, args });
720
+ }
721
+ export function fmtWith(fmts) {
722
+ return (strs, ...args) => ({ strs, args, fmts });
723
+ }
724
+ export function getFormat(s) {
725
+ const strs = s.strs.map((value) => value.replace(/{/g, '{{').replace(/}/g, '}}'));
726
+ return s.fmts
727
+ ? strs
728
+ .reduce((acc, newPart, index) => acc + `{${String(index - 1) + s.fmts[index - 1]}}` + newPart)
729
+ : strs
730
+ .reduce((acc, newPart, index) => acc + `{${index - 1}}` + newPart);
731
+ }