compostjs 0.0.8 → 0.0.12
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/README.md +4 -4
- package/dist/fable_modules/fable-library-js.4.28.0/Array.d.ts +123 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Array.js +1242 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Async.d.ts +26 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Async.js +145 -0
- package/dist/fable_modules/fable-library-js.4.28.0/AsyncBuilder.d.ts +59 -0
- package/dist/fable_modules/fable-library-js.4.28.0/AsyncBuilder.js +183 -0
- package/dist/fable_modules/fable-library-js.4.28.0/BigInt.d.ts +115 -0
- package/dist/fable_modules/fable-library-js.4.28.0/BigInt.js +283 -0
- package/dist/fable_modules/fable-library-js.4.28.0/BitConverter.d.ts +27 -0
- package/dist/fable_modules/fable-library-js.4.28.0/BitConverter.js +138 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Boolean.d.ts +3 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Boolean.js +21 -0
- package/dist/fable_modules/fable-library-js.4.28.0/CHANGELOG.md +100 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Char.d.ts +65 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Char.js +169 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Choice.d.ts +121 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Choice.js +184 -0
- package/dist/fable_modules/fable-library-js.4.28.0/CollectionUtil.d.ts +7 -0
- package/dist/fable_modules/fable-library-js.4.28.0/CollectionUtil.js +182 -0
- package/dist/fable_modules/fable-library-js.4.28.0/ConditionalWeakTable.d.ts +9 -0
- package/dist/fable_modules/fable-library-js.4.28.0/ConditionalWeakTable.js +21 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Date.d.ts +70 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Date.js +748 -0
- package/dist/fable_modules/fable-library-js.4.28.0/DateOffset.d.ts +63 -0
- package/dist/fable_modules/fable-library-js.4.28.0/DateOffset.js +268 -0
- package/dist/fable_modules/fable-library-js.4.28.0/DateOnly.d.ts +18 -0
- package/dist/fable_modules/fable-library-js.4.28.0/DateOnly.js +124 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Decimal.d.ts +45 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Decimal.js +212 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Double.d.ts +11 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Double.js +46 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Encoding.d.ts +12 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Encoding.js +173 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Event.d.ts +31 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Event.js +93 -0
- package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Collections.d.ts +7 -0
- package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Collections.js +27 -0
- package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.CompilerServices.d.ts +12 -0
- package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.CompilerServices.js +27 -0
- package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.d.ts +17 -0
- package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.js +69 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Global.d.ts +24 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Global.js +8 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Guid.d.ts +10 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Guid.js +142 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Int32.d.ts +28 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Int32.js +135 -0
- package/dist/fable_modules/fable-library-js.4.28.0/List.d.ts +143 -0
- package/dist/fable_modules/fable-library-js.4.28.0/List.js +1273 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Long.d.ts +3 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Long.js +46 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MailboxProcessor.d.ts +25 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MailboxProcessor.js +93 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Map.d.ts +178 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Map.js +1396 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MapUtil.d.ts +12 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MapUtil.js +127 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MutableMap.d.ts +52 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MutableMap.js +327 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MutableSet.d.ts +39 -0
- package/dist/fable_modules/fable-library-js.4.28.0/MutableSet.js +233 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Native.d.ts +2 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Native.js +8 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Numeric.d.ts +19 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Numeric.js +71 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Observable.d.ts +32 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Observable.js +113 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Option.d.ts +28 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Option.js +96 -0
- package/dist/fable_modules/fable-library-js.4.28.0/README.md +3 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Random.d.ts +37 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Random.js +170 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Range.d.ts +12 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Range.js +45 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Reflection.d.ts +119 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Reflection.js +461 -0
- package/dist/fable_modules/fable-library-js.4.28.0/RegExp.d.ts +10 -0
- package/dist/fable_modules/fable-library-js.4.28.0/RegExp.js +131 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Result.d.ts +37 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Result.js +165 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Seq.d.ts +165 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Seq.js +1378 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Seq2.d.ts +18 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Seq2.js +111 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Set.d.ts +190 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Set.js +1789 -0
- package/dist/fable_modules/fable-library-js.4.28.0/String.d.ts +58 -0
- package/dist/fable_modules/fable-library-js.4.28.0/String.js +554 -0
- package/dist/fable_modules/fable-library-js.4.28.0/System.Collections.Generic.d.ts +79 -0
- package/dist/fable_modules/fable-library-js.4.28.0/System.Collections.Generic.js +317 -0
- package/dist/fable_modules/fable-library-js.4.28.0/System.Text.d.ts +38 -0
- package/dist/fable_modules/fable-library-js.4.28.0/System.Text.js +162 -0
- package/dist/fable_modules/fable-library-js.4.28.0/SystemException.d.ts +5 -0
- package/dist/fable_modules/fable-library-js.4.28.0/SystemException.js +5 -0
- package/dist/fable_modules/fable-library-js.4.28.0/TimeOnly.d.ts +15 -0
- package/dist/fable_modules/fable-library-js.4.28.0/TimeOnly.js +122 -0
- package/dist/fable_modules/fable-library-js.4.28.0/TimeSpan.d.ts +34 -0
- package/dist/fable_modules/fable-library-js.4.28.0/TimeSpan.js +177 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Timer.d.ts +19 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Timer.js +67 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Types.d.ts +58 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Types.js +208 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Unicode.13.0.0.d.ts +2 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Unicode.13.0.0.js +4 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Uri.d.ts +31 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Uri.js +159 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Util.d.ts +210 -0
- package/dist/fable_modules/fable-library-js.4.28.0/Util.js +769 -0
- package/dist/fable_modules/fable-library-js.4.28.0/big.d.ts +338 -0
- package/dist/fable_modules/fable-library-js.4.28.0/lib/big.d.ts +5 -0
- package/dist/fable_modules/fable-library-js.4.28.0/lib/big.js +825 -0
- package/dist/fable_modules/fable-library-js.4.28.0/package.json +24 -0
- package/dist/fable_modules/project_cracked.json +1 -0
- package/package.json +6 -5
- package/.claude/settings.local.json +0 -11
- package/dist/fable-library.2.10.1/Array.js +0 -1336
- package/dist/fable-library.2.10.1/Async.js +0 -121
- package/dist/fable-library.2.10.1/AsyncBuilder.js +0 -200
- package/dist/fable-library.2.10.1/Date.js +0 -501
- package/dist/fable-library.2.10.1/Decimal.js +0 -208
- package/dist/fable-library.2.10.1/Event.js +0 -193
- package/dist/fable-library.2.10.1/Int32.js +0 -157
- package/dist/fable-library.2.10.1/List.js +0 -1234
- package/dist/fable-library.2.10.1/Long.js +0 -155
- package/dist/fable-library.2.10.1/Map.js +0 -1292
- package/dist/fable-library.2.10.1/MutableMap.js +0 -360
- package/dist/fable-library.2.10.1/MutableSet.js +0 -279
- package/dist/fable-library.2.10.1/Observable.js +0 -131
- package/dist/fable-library.2.10.1/Option.js +0 -118
- package/dist/fable-library.2.10.1/Reflection.js +0 -345
- package/dist/fable-library.2.10.1/RegExp.js +0 -118
- package/dist/fable-library.2.10.1/Seq.js +0 -917
- package/dist/fable-library.2.10.1/Set.js +0 -1692
- package/dist/fable-library.2.10.1/String.js +0 -679
- package/dist/fable-library.2.10.1/Types.js +0 -308
- package/dist/fable-library.2.10.1/Util.js +0 -761
- package/dist/helpers.js +0 -31
- package/dist/lib/big.js +0 -905
- package/dist/lib/long.js +0 -1375
- package/index.html +0 -49
|
@@ -1,679 +0,0 @@
|
|
|
1
|
-
import { toString as dateToString } from "./Date";
|
|
2
|
-
import Decimal from "./Decimal";
|
|
3
|
-
import Long, * as _Long from "./Long";
|
|
4
|
-
import { escape } from "./RegExp";
|
|
5
|
-
const fsFormatRegExp = /(^|[^%])%([0+\- ]*)(\d+)?(?:\.(\d+))?(\w)/;
|
|
6
|
-
const formatRegExp = /\{(\d+)(,-?\d+)?(?:\:([a-zA-Z])(\d{0,2})|\:(.+?))?\}/g; // RFC 4122 compliant. From https://stackoverflow.com/a/13653180/3922220
|
|
7
|
-
// const guidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
8
|
-
// Relax GUID parsing, see #1637
|
|
9
|
-
|
|
10
|
-
const guidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/; // These are used for formatting and only take longs and decimals into account (no bigint)
|
|
11
|
-
|
|
12
|
-
function isNumeric(x) {
|
|
13
|
-
return typeof x === "number" || x instanceof Long || x instanceof Decimal;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function isLessThan(x, y) {
|
|
17
|
-
if (x instanceof Long) {
|
|
18
|
-
return _Long.compare(x, y) < 0;
|
|
19
|
-
} else if (x instanceof Decimal) {
|
|
20
|
-
return x.cmp(y) < 0;
|
|
21
|
-
} else {
|
|
22
|
-
return x < y;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function multiply(x, y) {
|
|
27
|
-
if (x instanceof Long) {
|
|
28
|
-
return _Long.op_Multiply(x, y);
|
|
29
|
-
} else if (x instanceof Decimal) {
|
|
30
|
-
return x.mul(y);
|
|
31
|
-
} else {
|
|
32
|
-
return x * y;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function toFixed(x, dp) {
|
|
37
|
-
if (x instanceof Long) {
|
|
38
|
-
return String(x) + 0 .toFixed(dp).substr(1);
|
|
39
|
-
} else {
|
|
40
|
-
return x.toFixed(dp);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function toPrecision(x, sd) {
|
|
45
|
-
if (x instanceof Long) {
|
|
46
|
-
return String(x) + 0 .toPrecision(sd).substr(1);
|
|
47
|
-
} else {
|
|
48
|
-
return x.toPrecision(sd);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function toExponential(x, dp) {
|
|
53
|
-
if (x instanceof Long) {
|
|
54
|
-
return String(x) + 0 .toExponential(dp).substr(1);
|
|
55
|
-
} else {
|
|
56
|
-
return x.toExponential(dp);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function cmp(x, y, ic) {
|
|
61
|
-
function isIgnoreCase(i) {
|
|
62
|
-
return i === true || i === 1
|
|
63
|
-
/* CurrentCultureIgnoreCase */
|
|
64
|
-
|| i === 3
|
|
65
|
-
/* InvariantCultureIgnoreCase */
|
|
66
|
-
|| i === 5
|
|
67
|
-
/* OrdinalIgnoreCase */
|
|
68
|
-
;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function isOrdinal(i) {
|
|
72
|
-
return i === 4
|
|
73
|
-
/* Ordinal */
|
|
74
|
-
|| i === 5
|
|
75
|
-
/* OrdinalIgnoreCase */
|
|
76
|
-
;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (x == null) {
|
|
80
|
-
return y == null ? 0 : -1;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (y == null) {
|
|
84
|
-
return 1;
|
|
85
|
-
} // everything is bigger than null
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (isOrdinal(ic)) {
|
|
89
|
-
if (isIgnoreCase(ic)) {
|
|
90
|
-
x = x.toLowerCase();
|
|
91
|
-
y = y.toLowerCase();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return x === y ? 0 : x < y ? -1 : 1;
|
|
95
|
-
} else {
|
|
96
|
-
if (isIgnoreCase(ic)) {
|
|
97
|
-
x = x.toLocaleLowerCase();
|
|
98
|
-
y = y.toLocaleLowerCase();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return x.localeCompare(y);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function compare(...args) {
|
|
106
|
-
switch (args.length) {
|
|
107
|
-
case 2:
|
|
108
|
-
return cmp(args[0], args[1], false);
|
|
109
|
-
|
|
110
|
-
case 3:
|
|
111
|
-
return cmp(args[0], args[1], args[2]);
|
|
112
|
-
|
|
113
|
-
case 4:
|
|
114
|
-
return cmp(args[0], args[1], args[2] === true);
|
|
115
|
-
|
|
116
|
-
case 5:
|
|
117
|
-
return cmp(args[0].substr(args[1], args[4]), args[2].substr(args[3], args[4]), false);
|
|
118
|
-
|
|
119
|
-
case 6:
|
|
120
|
-
return cmp(args[0].substr(args[1], args[4]), args[2].substr(args[3], args[4]), args[5]);
|
|
121
|
-
|
|
122
|
-
case 7:
|
|
123
|
-
return cmp(args[0].substr(args[1], args[4]), args[2].substr(args[3], args[4]), args[5] === true);
|
|
124
|
-
|
|
125
|
-
default:
|
|
126
|
-
throw new Error("String.compare: Unsupported number of parameters");
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
export function compareOrdinal(x, y) {
|
|
130
|
-
return cmp(x, y, 4
|
|
131
|
-
/* Ordinal */
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
export function compareTo(x, y) {
|
|
135
|
-
return cmp(x, y, 0
|
|
136
|
-
/* CurrentCulture */
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
export function startsWith(str, pattern, ic) {
|
|
140
|
-
if (str.length >= pattern.length) {
|
|
141
|
-
return cmp(str.substr(0, pattern.length), pattern, ic) === 0;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
export function indexOfAny(str, anyOf, ...args) {
|
|
147
|
-
if (str == null || str === "") {
|
|
148
|
-
return -1;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const startIndex = args.length > 0 ? args[0] : 0;
|
|
152
|
-
|
|
153
|
-
if (startIndex < 0) {
|
|
154
|
-
throw new Error("Start index cannot be negative");
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const length = args.length > 1 ? args[1] : str.length - startIndex;
|
|
158
|
-
|
|
159
|
-
if (length < 0) {
|
|
160
|
-
throw new Error("Length cannot be negative");
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (length > str.length - startIndex) {
|
|
164
|
-
throw new Error("Invalid startIndex and length");
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
str = str.substr(startIndex, length);
|
|
168
|
-
|
|
169
|
-
for (const c of anyOf) {
|
|
170
|
-
const index = str.indexOf(c);
|
|
171
|
-
|
|
172
|
-
if (index > -1) {
|
|
173
|
-
return index + startIndex;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return -1;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function toHex(x) {
|
|
181
|
-
if (x instanceof Long) {
|
|
182
|
-
return _Long.toString(x.unsigned ? x : _Long.fromBytes(_Long.toBytes(x), true), 16);
|
|
183
|
-
} else {
|
|
184
|
-
return (Number(x) >>> 0).toString(16);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export function printf(input) {
|
|
189
|
-
return {
|
|
190
|
-
input,
|
|
191
|
-
cont: fsFormat(input)
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
export function toConsole(arg) {
|
|
195
|
-
// Don't remove the lambda here, see #1357
|
|
196
|
-
return arg.cont(x => {
|
|
197
|
-
console.log(x);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
export function toConsoleError(arg) {
|
|
201
|
-
return arg.cont(x => {
|
|
202
|
-
console.error(x);
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
export function toText(arg) {
|
|
206
|
-
return arg.cont(x => x);
|
|
207
|
-
}
|
|
208
|
-
export function toFail(arg) {
|
|
209
|
-
return arg.cont(x => {
|
|
210
|
-
throw new Error(x);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function formatOnce(str2, rep) {
|
|
215
|
-
return str2.replace(fsFormatRegExp, (_, prefix, flags, padLength, precision, format) => {
|
|
216
|
-
let sign = "";
|
|
217
|
-
|
|
218
|
-
if (isNumeric(rep)) {
|
|
219
|
-
if (format.toLowerCase() !== "x") {
|
|
220
|
-
if (isLessThan(rep, 0)) {
|
|
221
|
-
rep = multiply(rep, -1);
|
|
222
|
-
sign = "-";
|
|
223
|
-
} else {
|
|
224
|
-
if (flags.indexOf(" ") >= 0) {
|
|
225
|
-
sign = " ";
|
|
226
|
-
} else if (flags.indexOf("+") >= 0) {
|
|
227
|
-
sign = "+";
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
precision = precision == null ? null : parseInt(precision, 10);
|
|
233
|
-
|
|
234
|
-
switch (format) {
|
|
235
|
-
case "f":
|
|
236
|
-
case "F":
|
|
237
|
-
precision = precision != null ? precision : 6;
|
|
238
|
-
rep = toFixed(rep, precision);
|
|
239
|
-
break;
|
|
240
|
-
|
|
241
|
-
case "g":
|
|
242
|
-
case "G":
|
|
243
|
-
rep = precision != null ? toPrecision(rep, precision) : toPrecision(rep);
|
|
244
|
-
break;
|
|
245
|
-
|
|
246
|
-
case "e":
|
|
247
|
-
case "E":
|
|
248
|
-
rep = precision != null ? toExponential(rep, precision) : toExponential(rep);
|
|
249
|
-
break;
|
|
250
|
-
|
|
251
|
-
case "x":
|
|
252
|
-
rep = toHex(rep);
|
|
253
|
-
break;
|
|
254
|
-
|
|
255
|
-
case "X":
|
|
256
|
-
rep = toHex(rep).toUpperCase();
|
|
257
|
-
break;
|
|
258
|
-
|
|
259
|
-
default:
|
|
260
|
-
// AOid
|
|
261
|
-
rep = String(rep);
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
padLength = parseInt(padLength, 10);
|
|
267
|
-
|
|
268
|
-
if (!isNaN(padLength)) {
|
|
269
|
-
const zeroFlag = flags.indexOf("0") >= 0; // Use '0' for left padding
|
|
270
|
-
|
|
271
|
-
const minusFlag = flags.indexOf("-") >= 0; // Right padding
|
|
272
|
-
|
|
273
|
-
const ch = minusFlag || !zeroFlag ? " " : "0";
|
|
274
|
-
|
|
275
|
-
if (ch === "0") {
|
|
276
|
-
rep = padLeft(rep, padLength - sign.length, ch, minusFlag);
|
|
277
|
-
rep = sign + rep;
|
|
278
|
-
} else {
|
|
279
|
-
rep = padLeft(sign + rep, padLength, ch, minusFlag);
|
|
280
|
-
}
|
|
281
|
-
} else {
|
|
282
|
-
rep = sign + rep;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const once = prefix + rep;
|
|
286
|
-
return once.replace(/%/g, "%%");
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function createPrinter(str, cont) {
|
|
291
|
-
return (...args) => {
|
|
292
|
-
// Make a copy as the function may be used several times
|
|
293
|
-
let strCopy = str;
|
|
294
|
-
|
|
295
|
-
for (const arg of args) {
|
|
296
|
-
strCopy = formatOnce(strCopy, arg);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return fsFormatRegExp.test(strCopy) ? createPrinter(strCopy, cont) : cont(strCopy.replace(/%%/g, "%"));
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export function fsFormat(str) {
|
|
304
|
-
return cont => {
|
|
305
|
-
return fsFormatRegExp.test(str) ? createPrinter(str, cont) : cont(str);
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
export function format(str, ...args) {
|
|
309
|
-
if (typeof str === "object" && args.length > 0) {
|
|
310
|
-
// Called with culture info
|
|
311
|
-
str = args[0];
|
|
312
|
-
args.shift();
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
return str.replace(formatRegExp, (_, idx, padLength, format, precision, pattern) => {
|
|
316
|
-
let rep = args[idx];
|
|
317
|
-
|
|
318
|
-
if (isNumeric(rep)) {
|
|
319
|
-
precision = precision == null ? null : parseInt(precision, 10);
|
|
320
|
-
|
|
321
|
-
switch (format) {
|
|
322
|
-
case "f":
|
|
323
|
-
case "F":
|
|
324
|
-
precision = precision != null ? precision : 2;
|
|
325
|
-
rep = toFixed(rep, precision);
|
|
326
|
-
break;
|
|
327
|
-
|
|
328
|
-
case "g":
|
|
329
|
-
case "G":
|
|
330
|
-
rep = precision != null ? toPrecision(rep, precision) : toPrecision(rep);
|
|
331
|
-
break;
|
|
332
|
-
|
|
333
|
-
case "e":
|
|
334
|
-
case "E":
|
|
335
|
-
rep = precision != null ? toExponential(rep, precision) : toExponential(rep);
|
|
336
|
-
break;
|
|
337
|
-
|
|
338
|
-
case "p":
|
|
339
|
-
case "P":
|
|
340
|
-
precision = precision != null ? precision : 2;
|
|
341
|
-
rep = toFixed(multiply(rep, 100), precision) + " %";
|
|
342
|
-
break;
|
|
343
|
-
|
|
344
|
-
case "d":
|
|
345
|
-
case "D":
|
|
346
|
-
rep = precision != null ? padLeft(String(rep), precision, "0") : String(rep);
|
|
347
|
-
break;
|
|
348
|
-
|
|
349
|
-
case "x":
|
|
350
|
-
case "X":
|
|
351
|
-
rep = precision != null ? padLeft(toHex(rep), precision, "0") : toHex(rep);
|
|
352
|
-
|
|
353
|
-
if (format === "X") {
|
|
354
|
-
rep = rep.toUpperCase();
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
break;
|
|
358
|
-
|
|
359
|
-
default:
|
|
360
|
-
if (pattern) {
|
|
361
|
-
let sign = "";
|
|
362
|
-
rep = pattern.replace(/(0+)(\.0+)?/, (_, intPart, decimalPart) => {
|
|
363
|
-
if (isLessThan(rep, 0)) {
|
|
364
|
-
rep = multiply(rep, -1);
|
|
365
|
-
sign = "-";
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
rep = toFixed(rep, decimalPart != null ? decimalPart.length - 1 : 0);
|
|
369
|
-
return padLeft(rep, (intPart || "").length - sign.length + (decimalPart != null ? decimalPart.length : 0), "0");
|
|
370
|
-
});
|
|
371
|
-
rep = sign + rep;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
} else if (rep instanceof Date) {
|
|
376
|
-
rep = dateToString(rep, pattern || format);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
padLength = parseInt((padLength || " ").substring(1), 10);
|
|
380
|
-
|
|
381
|
-
if (!isNaN(padLength)) {
|
|
382
|
-
rep = padLeft(String(rep), Math.abs(padLength), " ", padLength < 0);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
return rep;
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
export function endsWith(str, search) {
|
|
389
|
-
const idx = str.lastIndexOf(search);
|
|
390
|
-
return idx >= 0 && idx === str.length - search.length;
|
|
391
|
-
}
|
|
392
|
-
export function initialize(n, f) {
|
|
393
|
-
if (n < 0) {
|
|
394
|
-
throw new Error("String length must be non-negative");
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const xs = new Array(n);
|
|
398
|
-
|
|
399
|
-
for (let i = 0; i < n; i++) {
|
|
400
|
-
xs[i] = f(i);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
return xs.join("");
|
|
404
|
-
}
|
|
405
|
-
export function insert(str, startIndex, value) {
|
|
406
|
-
if (startIndex < 0 || startIndex > str.length) {
|
|
407
|
-
throw new Error("startIndex is negative or greater than the length of this instance.");
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
return str.substring(0, startIndex) + value + str.substring(startIndex);
|
|
411
|
-
}
|
|
412
|
-
export function isNullOrEmpty(str) {
|
|
413
|
-
return typeof str !== "string" || str.length === 0;
|
|
414
|
-
}
|
|
415
|
-
export function isNullOrWhiteSpace(str) {
|
|
416
|
-
return typeof str !== "string" || /^\s*$/.test(str);
|
|
417
|
-
}
|
|
418
|
-
export function concat(...xs) {
|
|
419
|
-
return xs.map(x => String(x)).join("");
|
|
420
|
-
}
|
|
421
|
-
export function join(delimiter, xs) {
|
|
422
|
-
if (Array.isArray(xs)) {
|
|
423
|
-
return xs.join(delimiter);
|
|
424
|
-
} else {
|
|
425
|
-
return Array.from(xs).join(delimiter);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
export function joinWithIndices(delimiter, xs, startIndex, count) {
|
|
429
|
-
const endIndexPlusOne = startIndex + count;
|
|
430
|
-
|
|
431
|
-
if (endIndexPlusOne > xs.length) {
|
|
432
|
-
throw new Error("Index and count must refer to a location within the buffer.");
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return xs.slice(startIndex, endIndexPlusOne).join(delimiter);
|
|
436
|
-
}
|
|
437
|
-
/** Validates UUID as specified in RFC4122 (versions 1-5). Trims braces. */
|
|
438
|
-
|
|
439
|
-
export function validateGuid(str, doNotThrow) {
|
|
440
|
-
const trimmedAndLowered = trim(str, "{", "}").toLowerCase();
|
|
441
|
-
|
|
442
|
-
if (guidRegex.test(trimmedAndLowered)) {
|
|
443
|
-
return doNotThrow ? [true, trimmedAndLowered] : trimmedAndLowered;
|
|
444
|
-
} else if (doNotThrow) {
|
|
445
|
-
return [false, "00000000-0000-0000-0000-000000000000"];
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
throw new Error("Guid should contain 32 digits with 4 dashes: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");
|
|
449
|
-
} // From https://gist.github.com/LeverOne/1308368
|
|
450
|
-
|
|
451
|
-
export function newGuid() {
|
|
452
|
-
let b = "";
|
|
453
|
-
|
|
454
|
-
for (let a = 0; a++ < 36;) {
|
|
455
|
-
b += a * 51 & 52 ? (a ^ 15 ? 8 ^ Math.random() * (a ^ 20 ? 16 : 4) : 4).toString(16) : "-";
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
return b;
|
|
459
|
-
} // Maps for number <-> hex string conversion
|
|
460
|
-
|
|
461
|
-
let _convertMapsInitialized = false;
|
|
462
|
-
|
|
463
|
-
let _byteToHex;
|
|
464
|
-
|
|
465
|
-
let _hexToByte;
|
|
466
|
-
|
|
467
|
-
function initConvertMaps() {
|
|
468
|
-
_byteToHex = new Array(256);
|
|
469
|
-
_hexToByte = {};
|
|
470
|
-
|
|
471
|
-
for (let i = 0; i < 256; i++) {
|
|
472
|
-
_byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
|
473
|
-
_hexToByte[_byteToHex[i]] = i;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
_convertMapsInitialized = true;
|
|
477
|
-
}
|
|
478
|
-
/** Parse a UUID into it's component bytes */
|
|
479
|
-
// Adapted from https://github.com/zefferus/uuid-parse
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
export function guidToArray(s) {
|
|
483
|
-
if (!_convertMapsInitialized) {
|
|
484
|
-
initConvertMaps();
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
let i = 0;
|
|
488
|
-
const buf = new Uint8Array(16);
|
|
489
|
-
s.toLowerCase().replace(/[0-9a-f]{2}/g, oct => {
|
|
490
|
-
switch (i) {
|
|
491
|
-
// .NET saves first three byte groups with different endianness
|
|
492
|
-
// See https://stackoverflow.com/a/16722909/3922220
|
|
493
|
-
case 0:
|
|
494
|
-
case 1:
|
|
495
|
-
case 2:
|
|
496
|
-
case 3:
|
|
497
|
-
buf[3 - i++] = _hexToByte[oct];
|
|
498
|
-
break;
|
|
499
|
-
|
|
500
|
-
case 4:
|
|
501
|
-
case 5:
|
|
502
|
-
buf[9 - i++] = _hexToByte[oct];
|
|
503
|
-
break;
|
|
504
|
-
|
|
505
|
-
case 6:
|
|
506
|
-
case 7:
|
|
507
|
-
buf[13 - i++] = _hexToByte[oct];
|
|
508
|
-
break;
|
|
509
|
-
|
|
510
|
-
case 8:
|
|
511
|
-
case 9:
|
|
512
|
-
case 10:
|
|
513
|
-
case 11:
|
|
514
|
-
case 12:
|
|
515
|
-
case 13:
|
|
516
|
-
case 14:
|
|
517
|
-
case 15:
|
|
518
|
-
buf[i++] = _hexToByte[oct];
|
|
519
|
-
break;
|
|
520
|
-
}
|
|
521
|
-
}); // Zero out remaining bytes if string was short
|
|
522
|
-
|
|
523
|
-
while (i < 16) {
|
|
524
|
-
buf[i++] = 0;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
return buf;
|
|
528
|
-
}
|
|
529
|
-
/** Convert UUID byte array into a string */
|
|
530
|
-
|
|
531
|
-
export function arrayToGuid(buf) {
|
|
532
|
-
if (buf.length !== 16) {
|
|
533
|
-
throw new Error("Byte array for GUID must be exactly 16 bytes long");
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
if (!_convertMapsInitialized) {
|
|
537
|
-
initConvertMaps();
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
const guid = _byteToHex[buf[3]] + _byteToHex[buf[2]] + _byteToHex[buf[1]] + _byteToHex[buf[0]] + "-" + _byteToHex[buf[5]] + _byteToHex[buf[4]] + "-" + _byteToHex[buf[7]] + _byteToHex[buf[6]] + "-" + _byteToHex[buf[8]] + _byteToHex[buf[9]] + "-" + _byteToHex[buf[10]] + _byteToHex[buf[11]] + _byteToHex[buf[12]] + _byteToHex[buf[13]] + _byteToHex[buf[14]] + _byteToHex[buf[15]];
|
|
541
|
-
return guid;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
function notSupported(name) {
|
|
545
|
-
throw new Error("The environment doesn't support '" + name + "', please use a polyfill.");
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
export function toBase64String(inArray) {
|
|
549
|
-
let str = "";
|
|
550
|
-
|
|
551
|
-
for (let i = 0; i < inArray.length; i++) {
|
|
552
|
-
str += String.fromCharCode(inArray[i]);
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
return typeof btoa === "function" ? btoa(str) : notSupported("btoa");
|
|
556
|
-
}
|
|
557
|
-
export function fromBase64String(b64Encoded) {
|
|
558
|
-
const binary = typeof atob === "function" ? atob(b64Encoded) : notSupported("atob");
|
|
559
|
-
const bytes = new Uint8Array(binary.length);
|
|
560
|
-
|
|
561
|
-
for (let i = 0; i < binary.length; i++) {
|
|
562
|
-
bytes[i] = binary.charCodeAt(i);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
return bytes;
|
|
566
|
-
}
|
|
567
|
-
export function padLeft(str, len, ch, isRight) {
|
|
568
|
-
ch = ch || " ";
|
|
569
|
-
len = len - str.length;
|
|
570
|
-
|
|
571
|
-
for (let i = 0; i < len; i++) {
|
|
572
|
-
str = isRight ? str + ch : ch + str;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
return str;
|
|
576
|
-
}
|
|
577
|
-
export function padRight(str, len, ch) {
|
|
578
|
-
return padLeft(str, len, ch, true);
|
|
579
|
-
}
|
|
580
|
-
export function remove(str, startIndex, count) {
|
|
581
|
-
if (startIndex >= str.length) {
|
|
582
|
-
throw new Error("startIndex must be less than length of string");
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
if (typeof count === "number" && startIndex + count > str.length) {
|
|
586
|
-
throw new Error("Index and count must refer to a location within the string.");
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
return str.slice(0, startIndex) + (typeof count === "number" ? str.substr(startIndex + count) : "");
|
|
590
|
-
}
|
|
591
|
-
export function replace(str, search, replace) {
|
|
592
|
-
return str.replace(new RegExp(escape(search), "g"), replace);
|
|
593
|
-
}
|
|
594
|
-
export function replicate(n, x) {
|
|
595
|
-
return initialize(n, () => x);
|
|
596
|
-
}
|
|
597
|
-
export function getCharAtIndex(input, index) {
|
|
598
|
-
if (index < 0 || index >= input.length) {
|
|
599
|
-
throw new Error("Index was outside the bounds of the array.");
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
return input[index];
|
|
603
|
-
}
|
|
604
|
-
export function split(str, splitters, count, removeEmpty) {
|
|
605
|
-
count = typeof count === "number" ? count : undefined;
|
|
606
|
-
removeEmpty = typeof removeEmpty === "number" ? removeEmpty : undefined;
|
|
607
|
-
|
|
608
|
-
if (count && count < 0) {
|
|
609
|
-
throw new Error("Count cannot be less than zero");
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
if (count === 0) {
|
|
613
|
-
return [];
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
if (!Array.isArray(splitters)) {
|
|
617
|
-
if (removeEmpty === 0) {
|
|
618
|
-
return str.split(splitters, count);
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
const len = arguments.length;
|
|
622
|
-
splitters = Array(len - 1);
|
|
623
|
-
|
|
624
|
-
for (let key = 1; key < len; key++) {
|
|
625
|
-
splitters[key - 1] = arguments[key];
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
splitters = splitters.map(x => escape(x));
|
|
630
|
-
splitters = splitters.length > 0 ? splitters : [" "];
|
|
631
|
-
let i = 0;
|
|
632
|
-
const splits = [];
|
|
633
|
-
const reg = new RegExp(splitters.join("|"), "g");
|
|
634
|
-
|
|
635
|
-
while (count == null || count > 1) {
|
|
636
|
-
const m = reg.exec(str);
|
|
637
|
-
|
|
638
|
-
if (m === null) {
|
|
639
|
-
break;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
if (!removeEmpty || m.index - i > 0) {
|
|
643
|
-
count = count != null ? count - 1 : count;
|
|
644
|
-
splits.push(str.substring(i, m.index));
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
i = reg.lastIndex;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
if (!removeEmpty || str.length - i > 0) {
|
|
651
|
-
splits.push(str.substring(i));
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
return splits;
|
|
655
|
-
}
|
|
656
|
-
export function trim(str, ...chars) {
|
|
657
|
-
if (chars.length === 0) {
|
|
658
|
-
return str.trim();
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
const pattern = "[" + escape(chars.join("")) + "]+";
|
|
662
|
-
return str.replace(new RegExp("^" + pattern), "").replace(new RegExp(pattern + "$"), "");
|
|
663
|
-
}
|
|
664
|
-
export function trimStart(str, ...chars) {
|
|
665
|
-
return chars.length === 0 ? str.trimStart() : str.replace(new RegExp("^[" + escape(chars.join("")) + "]+"), "");
|
|
666
|
-
}
|
|
667
|
-
export function trimEnd(str, ...chars) {
|
|
668
|
-
return chars.length === 0 ? str.trimEnd() : str.replace(new RegExp("[" + escape(chars.join("")) + "]+$"), "");
|
|
669
|
-
}
|
|
670
|
-
export function filter(pred, x) {
|
|
671
|
-
return x.split("").filter(c => pred(c)).join("");
|
|
672
|
-
}
|
|
673
|
-
export function substring(str, startIndex, length) {
|
|
674
|
-
if (startIndex + (length || 0) > str.length) {
|
|
675
|
-
throw new Error("Invalid startIndex and/or length");
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
return length != null ? str.substr(startIndex, length) : str.substr(startIndex);
|
|
679
|
-
}
|