@jiangzhx/adcli 0.1.1 → 0.1.3
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 +115 -27
- package/dist/cli.js +2748 -48
- package/docs/commands.md +150 -10
- package/package.json +17 -1
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,2046 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// @bun
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
function __accessProp(key) {
|
|
9
|
+
return this[key];
|
|
10
|
+
}
|
|
11
|
+
var __toESMCache_node;
|
|
12
|
+
var __toESMCache_esm;
|
|
13
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
14
|
+
var canCache = mod != null && typeof mod === "object";
|
|
15
|
+
if (canCache) {
|
|
16
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
17
|
+
var cached = cache.get(mod);
|
|
18
|
+
if (cached)
|
|
19
|
+
return cached;
|
|
20
|
+
}
|
|
21
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
22
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
+
for (let key of __getOwnPropNames(mod))
|
|
24
|
+
if (!__hasOwnProp.call(to, key))
|
|
25
|
+
__defProp(to, key, {
|
|
26
|
+
get: __accessProp.bind(mod, key),
|
|
27
|
+
enumerable: true
|
|
28
|
+
});
|
|
29
|
+
if (canCache)
|
|
30
|
+
cache.set(mod, to);
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
34
|
+
|
|
35
|
+
// node_modules/.bun/bignumber.js@9.3.1/node_modules/bignumber.js/bignumber.js
|
|
36
|
+
var require_bignumber = __commonJS((exports, module) => {
|
|
37
|
+
(function(globalObject) {
|
|
38
|
+
var BigNumber, isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i, mathceil = Math.ceil, mathfloor = Math.floor, bignumberError = "[BigNumber Error] ", tooManyDigits = bignumberError + "Number primitive has more than 15 significant digits: ", BASE = 100000000000000, LOG_BASE = 14, MAX_SAFE_INTEGER = 9007199254740991, POWS_TEN = [1, 10, 100, 1000, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 10000000000, 100000000000, 1000000000000, 10000000000000], SQRT_BASE = 1e7, MAX = 1e9;
|
|
39
|
+
function clone(configObject) {
|
|
40
|
+
var div, convertBase, parseNumeric, P = BigNumber2.prototype = { constructor: BigNumber2, toString: null, valueOf: null }, ONE = new BigNumber2(1), DECIMAL_PLACES = 20, ROUNDING_MODE = 4, TO_EXP_NEG = -7, TO_EXP_POS = 21, MIN_EXP = -1e7, MAX_EXP = 1e7, CRYPTO = false, MODULO_MODE = 1, POW_PRECISION = 0, FORMAT = {
|
|
41
|
+
prefix: "",
|
|
42
|
+
groupSize: 3,
|
|
43
|
+
secondaryGroupSize: 0,
|
|
44
|
+
groupSeparator: ",",
|
|
45
|
+
decimalSeparator: ".",
|
|
46
|
+
fractionGroupSize: 0,
|
|
47
|
+
fractionGroupSeparator: " ",
|
|
48
|
+
suffix: ""
|
|
49
|
+
}, ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz", alphabetHasNormalDecimalDigits = true;
|
|
50
|
+
function BigNumber2(v, b) {
|
|
51
|
+
var alphabet, c, caseChanged, e, i, isNum, len, str, x = this;
|
|
52
|
+
if (!(x instanceof BigNumber2))
|
|
53
|
+
return new BigNumber2(v, b);
|
|
54
|
+
if (b == null) {
|
|
55
|
+
if (v && v._isBigNumber === true) {
|
|
56
|
+
x.s = v.s;
|
|
57
|
+
if (!v.c || v.e > MAX_EXP) {
|
|
58
|
+
x.c = x.e = null;
|
|
59
|
+
} else if (v.e < MIN_EXP) {
|
|
60
|
+
x.c = [x.e = 0];
|
|
61
|
+
} else {
|
|
62
|
+
x.e = v.e;
|
|
63
|
+
x.c = v.c.slice();
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if ((isNum = typeof v == "number") && v * 0 == 0) {
|
|
68
|
+
x.s = 1 / v < 0 ? (v = -v, -1) : 1;
|
|
69
|
+
if (v === ~~v) {
|
|
70
|
+
for (e = 0, i = v;i >= 10; i /= 10, e++)
|
|
71
|
+
;
|
|
72
|
+
if (e > MAX_EXP) {
|
|
73
|
+
x.c = x.e = null;
|
|
74
|
+
} else {
|
|
75
|
+
x.e = e;
|
|
76
|
+
x.c = [v];
|
|
77
|
+
}
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
str = String(v);
|
|
81
|
+
} else {
|
|
82
|
+
if (!isNumeric.test(str = String(v)))
|
|
83
|
+
return parseNumeric(x, str, isNum);
|
|
84
|
+
x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
|
|
85
|
+
}
|
|
86
|
+
if ((e = str.indexOf(".")) > -1)
|
|
87
|
+
str = str.replace(".", "");
|
|
88
|
+
if ((i = str.search(/e/i)) > 0) {
|
|
89
|
+
if (e < 0)
|
|
90
|
+
e = i;
|
|
91
|
+
e += +str.slice(i + 1);
|
|
92
|
+
str = str.substring(0, i);
|
|
93
|
+
} else if (e < 0) {
|
|
94
|
+
e = str.length;
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
98
|
+
if (b == 10 && alphabetHasNormalDecimalDigits) {
|
|
99
|
+
x = new BigNumber2(v);
|
|
100
|
+
return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
|
|
101
|
+
}
|
|
102
|
+
str = String(v);
|
|
103
|
+
if (isNum = typeof v == "number") {
|
|
104
|
+
if (v * 0 != 0)
|
|
105
|
+
return parseNumeric(x, str, isNum, b);
|
|
106
|
+
x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
|
|
107
|
+
if (BigNumber2.DEBUG && str.replace(/^0\.0*|\./, "").length > 15) {
|
|
108
|
+
throw Error(tooManyDigits + v);
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
|
|
112
|
+
}
|
|
113
|
+
alphabet = ALPHABET.slice(0, b);
|
|
114
|
+
e = i = 0;
|
|
115
|
+
for (len = str.length;i < len; i++) {
|
|
116
|
+
if (alphabet.indexOf(c = str.charAt(i)) < 0) {
|
|
117
|
+
if (c == ".") {
|
|
118
|
+
if (i > e) {
|
|
119
|
+
e = len;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
} else if (!caseChanged) {
|
|
123
|
+
if (str == str.toUpperCase() && (str = str.toLowerCase()) || str == str.toLowerCase() && (str = str.toUpperCase())) {
|
|
124
|
+
caseChanged = true;
|
|
125
|
+
i = -1;
|
|
126
|
+
e = 0;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return parseNumeric(x, String(v), isNum, b);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
isNum = false;
|
|
134
|
+
str = convertBase(str, b, 10, x.s);
|
|
135
|
+
if ((e = str.indexOf(".")) > -1)
|
|
136
|
+
str = str.replace(".", "");
|
|
137
|
+
else
|
|
138
|
+
e = str.length;
|
|
139
|
+
}
|
|
140
|
+
for (i = 0;str.charCodeAt(i) === 48; i++)
|
|
141
|
+
;
|
|
142
|
+
for (len = str.length;str.charCodeAt(--len) === 48; )
|
|
143
|
+
;
|
|
144
|
+
if (str = str.slice(i, ++len)) {
|
|
145
|
+
len -= i;
|
|
146
|
+
if (isNum && BigNumber2.DEBUG && len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
|
|
147
|
+
throw Error(tooManyDigits + x.s * v);
|
|
148
|
+
}
|
|
149
|
+
if ((e = e - i - 1) > MAX_EXP) {
|
|
150
|
+
x.c = x.e = null;
|
|
151
|
+
} else if (e < MIN_EXP) {
|
|
152
|
+
x.c = [x.e = 0];
|
|
153
|
+
} else {
|
|
154
|
+
x.e = e;
|
|
155
|
+
x.c = [];
|
|
156
|
+
i = (e + 1) % LOG_BASE;
|
|
157
|
+
if (e < 0)
|
|
158
|
+
i += LOG_BASE;
|
|
159
|
+
if (i < len) {
|
|
160
|
+
if (i)
|
|
161
|
+
x.c.push(+str.slice(0, i));
|
|
162
|
+
for (len -= LOG_BASE;i < len; ) {
|
|
163
|
+
x.c.push(+str.slice(i, i += LOG_BASE));
|
|
164
|
+
}
|
|
165
|
+
i = LOG_BASE - (str = str.slice(i)).length;
|
|
166
|
+
} else {
|
|
167
|
+
i -= len;
|
|
168
|
+
}
|
|
169
|
+
for (;i--; str += "0")
|
|
170
|
+
;
|
|
171
|
+
x.c.push(+str);
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
x.c = [x.e = 0];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
BigNumber2.clone = clone;
|
|
178
|
+
BigNumber2.ROUND_UP = 0;
|
|
179
|
+
BigNumber2.ROUND_DOWN = 1;
|
|
180
|
+
BigNumber2.ROUND_CEIL = 2;
|
|
181
|
+
BigNumber2.ROUND_FLOOR = 3;
|
|
182
|
+
BigNumber2.ROUND_HALF_UP = 4;
|
|
183
|
+
BigNumber2.ROUND_HALF_DOWN = 5;
|
|
184
|
+
BigNumber2.ROUND_HALF_EVEN = 6;
|
|
185
|
+
BigNumber2.ROUND_HALF_CEIL = 7;
|
|
186
|
+
BigNumber2.ROUND_HALF_FLOOR = 8;
|
|
187
|
+
BigNumber2.EUCLID = 9;
|
|
188
|
+
BigNumber2.config = BigNumber2.set = function(obj) {
|
|
189
|
+
var p, v;
|
|
190
|
+
if (obj != null) {
|
|
191
|
+
if (typeof obj == "object") {
|
|
192
|
+
if (obj.hasOwnProperty(p = "DECIMAL_PLACES")) {
|
|
193
|
+
v = obj[p];
|
|
194
|
+
intCheck(v, 0, MAX, p);
|
|
195
|
+
DECIMAL_PLACES = v;
|
|
196
|
+
}
|
|
197
|
+
if (obj.hasOwnProperty(p = "ROUNDING_MODE")) {
|
|
198
|
+
v = obj[p];
|
|
199
|
+
intCheck(v, 0, 8, p);
|
|
200
|
+
ROUNDING_MODE = v;
|
|
201
|
+
}
|
|
202
|
+
if (obj.hasOwnProperty(p = "EXPONENTIAL_AT")) {
|
|
203
|
+
v = obj[p];
|
|
204
|
+
if (v && v.pop) {
|
|
205
|
+
intCheck(v[0], -MAX, 0, p);
|
|
206
|
+
intCheck(v[1], 0, MAX, p);
|
|
207
|
+
TO_EXP_NEG = v[0];
|
|
208
|
+
TO_EXP_POS = v[1];
|
|
209
|
+
} else {
|
|
210
|
+
intCheck(v, -MAX, MAX, p);
|
|
211
|
+
TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (obj.hasOwnProperty(p = "RANGE")) {
|
|
215
|
+
v = obj[p];
|
|
216
|
+
if (v && v.pop) {
|
|
217
|
+
intCheck(v[0], -MAX, -1, p);
|
|
218
|
+
intCheck(v[1], 1, MAX, p);
|
|
219
|
+
MIN_EXP = v[0];
|
|
220
|
+
MAX_EXP = v[1];
|
|
221
|
+
} else {
|
|
222
|
+
intCheck(v, -MAX, MAX, p);
|
|
223
|
+
if (v) {
|
|
224
|
+
MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
|
|
225
|
+
} else {
|
|
226
|
+
throw Error(bignumberError + p + " cannot be zero: " + v);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (obj.hasOwnProperty(p = "CRYPTO")) {
|
|
231
|
+
v = obj[p];
|
|
232
|
+
if (v === !!v) {
|
|
233
|
+
if (v) {
|
|
234
|
+
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) {
|
|
235
|
+
CRYPTO = v;
|
|
236
|
+
} else {
|
|
237
|
+
CRYPTO = !v;
|
|
238
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
CRYPTO = v;
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
throw Error(bignumberError + p + " not true or false: " + v);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (obj.hasOwnProperty(p = "MODULO_MODE")) {
|
|
248
|
+
v = obj[p];
|
|
249
|
+
intCheck(v, 0, 9, p);
|
|
250
|
+
MODULO_MODE = v;
|
|
251
|
+
}
|
|
252
|
+
if (obj.hasOwnProperty(p = "POW_PRECISION")) {
|
|
253
|
+
v = obj[p];
|
|
254
|
+
intCheck(v, 0, MAX, p);
|
|
255
|
+
POW_PRECISION = v;
|
|
256
|
+
}
|
|
257
|
+
if (obj.hasOwnProperty(p = "FORMAT")) {
|
|
258
|
+
v = obj[p];
|
|
259
|
+
if (typeof v == "object")
|
|
260
|
+
FORMAT = v;
|
|
261
|
+
else
|
|
262
|
+
throw Error(bignumberError + p + " not an object: " + v);
|
|
263
|
+
}
|
|
264
|
+
if (obj.hasOwnProperty(p = "ALPHABET")) {
|
|
265
|
+
v = obj[p];
|
|
266
|
+
if (typeof v == "string" && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
|
|
267
|
+
alphabetHasNormalDecimalDigits = v.slice(0, 10) == "0123456789";
|
|
268
|
+
ALPHABET = v;
|
|
269
|
+
} else {
|
|
270
|
+
throw Error(bignumberError + p + " invalid: " + v);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} else {
|
|
274
|
+
throw Error(bignumberError + "Object expected: " + obj);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
DECIMAL_PLACES,
|
|
279
|
+
ROUNDING_MODE,
|
|
280
|
+
EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
|
|
281
|
+
RANGE: [MIN_EXP, MAX_EXP],
|
|
282
|
+
CRYPTO,
|
|
283
|
+
MODULO_MODE,
|
|
284
|
+
POW_PRECISION,
|
|
285
|
+
FORMAT,
|
|
286
|
+
ALPHABET
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
BigNumber2.isBigNumber = function(v) {
|
|
290
|
+
if (!v || v._isBigNumber !== true)
|
|
291
|
+
return false;
|
|
292
|
+
if (!BigNumber2.DEBUG)
|
|
293
|
+
return true;
|
|
294
|
+
var i, n, c = v.c, e = v.e, s = v.s;
|
|
295
|
+
out:
|
|
296
|
+
if ({}.toString.call(c) == "[object Array]") {
|
|
297
|
+
if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
|
|
298
|
+
if (c[0] === 0) {
|
|
299
|
+
if (e === 0 && c.length === 1)
|
|
300
|
+
return true;
|
|
301
|
+
break out;
|
|
302
|
+
}
|
|
303
|
+
i = (e + 1) % LOG_BASE;
|
|
304
|
+
if (i < 1)
|
|
305
|
+
i += LOG_BASE;
|
|
306
|
+
if (String(c[0]).length == i) {
|
|
307
|
+
for (i = 0;i < c.length; i++) {
|
|
308
|
+
n = c[i];
|
|
309
|
+
if (n < 0 || n >= BASE || n !== mathfloor(n))
|
|
310
|
+
break out;
|
|
311
|
+
}
|
|
312
|
+
if (n !== 0)
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
} else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
throw Error(bignumberError + "Invalid BigNumber: " + v);
|
|
320
|
+
};
|
|
321
|
+
BigNumber2.maximum = BigNumber2.max = function() {
|
|
322
|
+
return maxOrMin(arguments, -1);
|
|
323
|
+
};
|
|
324
|
+
BigNumber2.minimum = BigNumber2.min = function() {
|
|
325
|
+
return maxOrMin(arguments, 1);
|
|
326
|
+
};
|
|
327
|
+
BigNumber2.random = function() {
|
|
328
|
+
var pow2_53 = 9007199254740992;
|
|
329
|
+
var random53bitInt = Math.random() * pow2_53 & 2097151 ? function() {
|
|
330
|
+
return mathfloor(Math.random() * pow2_53);
|
|
331
|
+
} : function() {
|
|
332
|
+
return (Math.random() * 1073741824 | 0) * 8388608 + (Math.random() * 8388608 | 0);
|
|
333
|
+
};
|
|
334
|
+
return function(dp) {
|
|
335
|
+
var a, b, e, k, v, i = 0, c = [], rand = new BigNumber2(ONE);
|
|
336
|
+
if (dp == null)
|
|
337
|
+
dp = DECIMAL_PLACES;
|
|
338
|
+
else
|
|
339
|
+
intCheck(dp, 0, MAX);
|
|
340
|
+
k = mathceil(dp / LOG_BASE);
|
|
341
|
+
if (CRYPTO) {
|
|
342
|
+
if (crypto.getRandomValues) {
|
|
343
|
+
a = crypto.getRandomValues(new Uint32Array(k *= 2));
|
|
344
|
+
for (;i < k; ) {
|
|
345
|
+
v = a[i] * 131072 + (a[i + 1] >>> 11);
|
|
346
|
+
if (v >= 9000000000000000) {
|
|
347
|
+
b = crypto.getRandomValues(new Uint32Array(2));
|
|
348
|
+
a[i] = b[0];
|
|
349
|
+
a[i + 1] = b[1];
|
|
350
|
+
} else {
|
|
351
|
+
c.push(v % 100000000000000);
|
|
352
|
+
i += 2;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
i = k / 2;
|
|
356
|
+
} else if (crypto.randomBytes) {
|
|
357
|
+
a = crypto.randomBytes(k *= 7);
|
|
358
|
+
for (;i < k; ) {
|
|
359
|
+
v = (a[i] & 31) * 281474976710656 + a[i + 1] * 1099511627776 + a[i + 2] * 4294967296 + a[i + 3] * 16777216 + (a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
|
|
360
|
+
if (v >= 9000000000000000) {
|
|
361
|
+
crypto.randomBytes(7).copy(a, i);
|
|
362
|
+
} else {
|
|
363
|
+
c.push(v % 100000000000000);
|
|
364
|
+
i += 7;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
i = k / 7;
|
|
368
|
+
} else {
|
|
369
|
+
CRYPTO = false;
|
|
370
|
+
throw Error(bignumberError + "crypto unavailable");
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (!CRYPTO) {
|
|
374
|
+
for (;i < k; ) {
|
|
375
|
+
v = random53bitInt();
|
|
376
|
+
if (v < 9000000000000000)
|
|
377
|
+
c[i++] = v % 100000000000000;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
k = c[--i];
|
|
381
|
+
dp %= LOG_BASE;
|
|
382
|
+
if (k && dp) {
|
|
383
|
+
v = POWS_TEN[LOG_BASE - dp];
|
|
384
|
+
c[i] = mathfloor(k / v) * v;
|
|
385
|
+
}
|
|
386
|
+
for (;c[i] === 0; c.pop(), i--)
|
|
387
|
+
;
|
|
388
|
+
if (i < 0) {
|
|
389
|
+
c = [e = 0];
|
|
390
|
+
} else {
|
|
391
|
+
for (e = -1;c[0] === 0; c.splice(0, 1), e -= LOG_BASE)
|
|
392
|
+
;
|
|
393
|
+
for (i = 1, v = c[0];v >= 10; v /= 10, i++)
|
|
394
|
+
;
|
|
395
|
+
if (i < LOG_BASE)
|
|
396
|
+
e -= LOG_BASE - i;
|
|
397
|
+
}
|
|
398
|
+
rand.e = e;
|
|
399
|
+
rand.c = c;
|
|
400
|
+
return rand;
|
|
401
|
+
};
|
|
402
|
+
}();
|
|
403
|
+
BigNumber2.sum = function() {
|
|
404
|
+
var i = 1, args = arguments, sum = new BigNumber2(args[0]);
|
|
405
|
+
for (;i < args.length; )
|
|
406
|
+
sum = sum.plus(args[i++]);
|
|
407
|
+
return sum;
|
|
408
|
+
};
|
|
409
|
+
convertBase = function() {
|
|
410
|
+
var decimal = "0123456789";
|
|
411
|
+
function toBaseOut(str, baseIn, baseOut, alphabet) {
|
|
412
|
+
var j, arr = [0], arrL, i = 0, len = str.length;
|
|
413
|
+
for (;i < len; ) {
|
|
414
|
+
for (arrL = arr.length;arrL--; arr[arrL] *= baseIn)
|
|
415
|
+
;
|
|
416
|
+
arr[0] += alphabet.indexOf(str.charAt(i++));
|
|
417
|
+
for (j = 0;j < arr.length; j++) {
|
|
418
|
+
if (arr[j] > baseOut - 1) {
|
|
419
|
+
if (arr[j + 1] == null)
|
|
420
|
+
arr[j + 1] = 0;
|
|
421
|
+
arr[j + 1] += arr[j] / baseOut | 0;
|
|
422
|
+
arr[j] %= baseOut;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return arr.reverse();
|
|
427
|
+
}
|
|
428
|
+
return function(str, baseIn, baseOut, sign, callerIsToString) {
|
|
429
|
+
var alphabet, d, e, k, r, x, xc, y, i = str.indexOf("."), dp = DECIMAL_PLACES, rm = ROUNDING_MODE;
|
|
430
|
+
if (i >= 0) {
|
|
431
|
+
k = POW_PRECISION;
|
|
432
|
+
POW_PRECISION = 0;
|
|
433
|
+
str = str.replace(".", "");
|
|
434
|
+
y = new BigNumber2(baseIn);
|
|
435
|
+
x = y.pow(str.length - i);
|
|
436
|
+
POW_PRECISION = k;
|
|
437
|
+
y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, "0"), 10, baseOut, decimal);
|
|
438
|
+
y.e = y.c.length;
|
|
439
|
+
}
|
|
440
|
+
xc = toBaseOut(str, baseIn, baseOut, callerIsToString ? (alphabet = ALPHABET, decimal) : (alphabet = decimal, ALPHABET));
|
|
441
|
+
e = k = xc.length;
|
|
442
|
+
for (;xc[--k] == 0; xc.pop())
|
|
443
|
+
;
|
|
444
|
+
if (!xc[0])
|
|
445
|
+
return alphabet.charAt(0);
|
|
446
|
+
if (i < 0) {
|
|
447
|
+
--e;
|
|
448
|
+
} else {
|
|
449
|
+
x.c = xc;
|
|
450
|
+
x.e = e;
|
|
451
|
+
x.s = sign;
|
|
452
|
+
x = div(x, y, dp, rm, baseOut);
|
|
453
|
+
xc = x.c;
|
|
454
|
+
r = x.r;
|
|
455
|
+
e = x.e;
|
|
456
|
+
}
|
|
457
|
+
d = e + dp + 1;
|
|
458
|
+
i = xc[d];
|
|
459
|
+
k = baseOut / 2;
|
|
460
|
+
r = r || d < 0 || xc[d + 1] != null;
|
|
461
|
+
r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : i > k || i == k && (rm == 4 || r || rm == 6 && xc[d - 1] & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
462
|
+
if (d < 1 || !xc[0]) {
|
|
463
|
+
str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
|
|
464
|
+
} else {
|
|
465
|
+
xc.length = d;
|
|
466
|
+
if (r) {
|
|
467
|
+
for (--baseOut;++xc[--d] > baseOut; ) {
|
|
468
|
+
xc[d] = 0;
|
|
469
|
+
if (!d) {
|
|
470
|
+
++e;
|
|
471
|
+
xc = [1].concat(xc);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
for (k = xc.length;!xc[--k]; )
|
|
476
|
+
;
|
|
477
|
+
for (i = 0, str = "";i <= k; str += alphabet.charAt(xc[i++]))
|
|
478
|
+
;
|
|
479
|
+
str = toFixedPoint(str, e, alphabet.charAt(0));
|
|
480
|
+
}
|
|
481
|
+
return str;
|
|
482
|
+
};
|
|
483
|
+
}();
|
|
484
|
+
div = function() {
|
|
485
|
+
function multiply(x, k, base) {
|
|
486
|
+
var m, temp, xlo, xhi, carry = 0, i = x.length, klo = k % SQRT_BASE, khi = k / SQRT_BASE | 0;
|
|
487
|
+
for (x = x.slice();i--; ) {
|
|
488
|
+
xlo = x[i] % SQRT_BASE;
|
|
489
|
+
xhi = x[i] / SQRT_BASE | 0;
|
|
490
|
+
m = khi * xlo + xhi * klo;
|
|
491
|
+
temp = klo * xlo + m % SQRT_BASE * SQRT_BASE + carry;
|
|
492
|
+
carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
|
|
493
|
+
x[i] = temp % base;
|
|
494
|
+
}
|
|
495
|
+
if (carry)
|
|
496
|
+
x = [carry].concat(x);
|
|
497
|
+
return x;
|
|
498
|
+
}
|
|
499
|
+
function compare2(a, b, aL, bL) {
|
|
500
|
+
var i, cmp;
|
|
501
|
+
if (aL != bL) {
|
|
502
|
+
cmp = aL > bL ? 1 : -1;
|
|
503
|
+
} else {
|
|
504
|
+
for (i = cmp = 0;i < aL; i++) {
|
|
505
|
+
if (a[i] != b[i]) {
|
|
506
|
+
cmp = a[i] > b[i] ? 1 : -1;
|
|
507
|
+
break;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return cmp;
|
|
512
|
+
}
|
|
513
|
+
function subtract(a, b, aL, base) {
|
|
514
|
+
var i = 0;
|
|
515
|
+
for (;aL--; ) {
|
|
516
|
+
a[aL] -= i;
|
|
517
|
+
i = a[aL] < b[aL] ? 1 : 0;
|
|
518
|
+
a[aL] = i * base + a[aL] - b[aL];
|
|
519
|
+
}
|
|
520
|
+
for (;!a[0] && a.length > 1; a.splice(0, 1))
|
|
521
|
+
;
|
|
522
|
+
}
|
|
523
|
+
return function(x, y, dp, rm, base) {
|
|
524
|
+
var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0, yL, yz, s = x.s == y.s ? 1 : -1, xc = x.c, yc = y.c;
|
|
525
|
+
if (!xc || !xc[0] || !yc || !yc[0]) {
|
|
526
|
+
return new BigNumber2(!x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN : xc && xc[0] == 0 || !yc ? s * 0 : s / 0);
|
|
527
|
+
}
|
|
528
|
+
q = new BigNumber2(s);
|
|
529
|
+
qc = q.c = [];
|
|
530
|
+
e = x.e - y.e;
|
|
531
|
+
s = dp + e + 1;
|
|
532
|
+
if (!base) {
|
|
533
|
+
base = BASE;
|
|
534
|
+
e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
|
|
535
|
+
s = s / LOG_BASE | 0;
|
|
536
|
+
}
|
|
537
|
+
for (i = 0;yc[i] == (xc[i] || 0); i++)
|
|
538
|
+
;
|
|
539
|
+
if (yc[i] > (xc[i] || 0))
|
|
540
|
+
e--;
|
|
541
|
+
if (s < 0) {
|
|
542
|
+
qc.push(1);
|
|
543
|
+
more = true;
|
|
544
|
+
} else {
|
|
545
|
+
xL = xc.length;
|
|
546
|
+
yL = yc.length;
|
|
547
|
+
i = 0;
|
|
548
|
+
s += 2;
|
|
549
|
+
n = mathfloor(base / (yc[0] + 1));
|
|
550
|
+
if (n > 1) {
|
|
551
|
+
yc = multiply(yc, n, base);
|
|
552
|
+
xc = multiply(xc, n, base);
|
|
553
|
+
yL = yc.length;
|
|
554
|
+
xL = xc.length;
|
|
555
|
+
}
|
|
556
|
+
xi = yL;
|
|
557
|
+
rem = xc.slice(0, yL);
|
|
558
|
+
remL = rem.length;
|
|
559
|
+
for (;remL < yL; rem[remL++] = 0)
|
|
560
|
+
;
|
|
561
|
+
yz = yc.slice();
|
|
562
|
+
yz = [0].concat(yz);
|
|
563
|
+
yc0 = yc[0];
|
|
564
|
+
if (yc[1] >= base / 2)
|
|
565
|
+
yc0++;
|
|
566
|
+
do {
|
|
567
|
+
n = 0;
|
|
568
|
+
cmp = compare2(yc, rem, yL, remL);
|
|
569
|
+
if (cmp < 0) {
|
|
570
|
+
rem0 = rem[0];
|
|
571
|
+
if (yL != remL)
|
|
572
|
+
rem0 = rem0 * base + (rem[1] || 0);
|
|
573
|
+
n = mathfloor(rem0 / yc0);
|
|
574
|
+
if (n > 1) {
|
|
575
|
+
if (n >= base)
|
|
576
|
+
n = base - 1;
|
|
577
|
+
prod = multiply(yc, n, base);
|
|
578
|
+
prodL = prod.length;
|
|
579
|
+
remL = rem.length;
|
|
580
|
+
while (compare2(prod, rem, prodL, remL) == 1) {
|
|
581
|
+
n--;
|
|
582
|
+
subtract(prod, yL < prodL ? yz : yc, prodL, base);
|
|
583
|
+
prodL = prod.length;
|
|
584
|
+
cmp = 1;
|
|
585
|
+
}
|
|
586
|
+
} else {
|
|
587
|
+
if (n == 0) {
|
|
588
|
+
cmp = n = 1;
|
|
589
|
+
}
|
|
590
|
+
prod = yc.slice();
|
|
591
|
+
prodL = prod.length;
|
|
592
|
+
}
|
|
593
|
+
if (prodL < remL)
|
|
594
|
+
prod = [0].concat(prod);
|
|
595
|
+
subtract(rem, prod, remL, base);
|
|
596
|
+
remL = rem.length;
|
|
597
|
+
if (cmp == -1) {
|
|
598
|
+
while (compare2(yc, rem, yL, remL) < 1) {
|
|
599
|
+
n++;
|
|
600
|
+
subtract(rem, yL < remL ? yz : yc, remL, base);
|
|
601
|
+
remL = rem.length;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
} else if (cmp === 0) {
|
|
605
|
+
n++;
|
|
606
|
+
rem = [0];
|
|
607
|
+
}
|
|
608
|
+
qc[i++] = n;
|
|
609
|
+
if (rem[0]) {
|
|
610
|
+
rem[remL++] = xc[xi] || 0;
|
|
611
|
+
} else {
|
|
612
|
+
rem = [xc[xi]];
|
|
613
|
+
remL = 1;
|
|
614
|
+
}
|
|
615
|
+
} while ((xi++ < xL || rem[0] != null) && s--);
|
|
616
|
+
more = rem[0] != null;
|
|
617
|
+
if (!qc[0])
|
|
618
|
+
qc.splice(0, 1);
|
|
619
|
+
}
|
|
620
|
+
if (base == BASE) {
|
|
621
|
+
for (i = 1, s = qc[0];s >= 10; s /= 10, i++)
|
|
622
|
+
;
|
|
623
|
+
round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
|
|
624
|
+
} else {
|
|
625
|
+
q.e = e;
|
|
626
|
+
q.r = +more;
|
|
627
|
+
}
|
|
628
|
+
return q;
|
|
629
|
+
};
|
|
630
|
+
}();
|
|
631
|
+
function format(n, i, rm, id) {
|
|
632
|
+
var c0, e, ne, len, str;
|
|
633
|
+
if (rm == null)
|
|
634
|
+
rm = ROUNDING_MODE;
|
|
635
|
+
else
|
|
636
|
+
intCheck(rm, 0, 8);
|
|
637
|
+
if (!n.c)
|
|
638
|
+
return n.toString();
|
|
639
|
+
c0 = n.c[0];
|
|
640
|
+
ne = n.e;
|
|
641
|
+
if (i == null) {
|
|
642
|
+
str = coeffToString(n.c);
|
|
643
|
+
str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS) ? toExponential(str, ne) : toFixedPoint(str, ne, "0");
|
|
644
|
+
} else {
|
|
645
|
+
n = round(new BigNumber2(n), i, rm);
|
|
646
|
+
e = n.e;
|
|
647
|
+
str = coeffToString(n.c);
|
|
648
|
+
len = str.length;
|
|
649
|
+
if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
|
|
650
|
+
for (;len < i; str += "0", len++)
|
|
651
|
+
;
|
|
652
|
+
str = toExponential(str, e);
|
|
653
|
+
} else {
|
|
654
|
+
i -= ne + (id === 2 && e > ne);
|
|
655
|
+
str = toFixedPoint(str, e, "0");
|
|
656
|
+
if (e + 1 > len) {
|
|
657
|
+
if (--i > 0)
|
|
658
|
+
for (str += ".";i--; str += "0")
|
|
659
|
+
;
|
|
660
|
+
} else {
|
|
661
|
+
i += e - len;
|
|
662
|
+
if (i > 0) {
|
|
663
|
+
if (e + 1 == len)
|
|
664
|
+
str += ".";
|
|
665
|
+
for (;i--; str += "0")
|
|
666
|
+
;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return n.s < 0 && c0 ? "-" + str : str;
|
|
672
|
+
}
|
|
673
|
+
function maxOrMin(args, n) {
|
|
674
|
+
var k, y, i = 1, x = new BigNumber2(args[0]);
|
|
675
|
+
for (;i < args.length; i++) {
|
|
676
|
+
y = new BigNumber2(args[i]);
|
|
677
|
+
if (!y.s || (k = compare(x, y)) === n || k === 0 && x.s === n) {
|
|
678
|
+
x = y;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return x;
|
|
682
|
+
}
|
|
683
|
+
function normalise(n, c, e) {
|
|
684
|
+
var i = 1, j = c.length;
|
|
685
|
+
for (;!c[--j]; c.pop())
|
|
686
|
+
;
|
|
687
|
+
for (j = c[0];j >= 10; j /= 10, i++)
|
|
688
|
+
;
|
|
689
|
+
if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
|
|
690
|
+
n.c = n.e = null;
|
|
691
|
+
} else if (e < MIN_EXP) {
|
|
692
|
+
n.c = [n.e = 0];
|
|
693
|
+
} else {
|
|
694
|
+
n.e = e;
|
|
695
|
+
n.c = c;
|
|
696
|
+
}
|
|
697
|
+
return n;
|
|
698
|
+
}
|
|
699
|
+
parseNumeric = function() {
|
|
700
|
+
var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i, dotAfter = /^([^.]+)\.$/, dotBefore = /^\.([^.]+)$/, isInfinityOrNaN = /^-?(Infinity|NaN)$/, whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
|
701
|
+
return function(x, str, isNum, b) {
|
|
702
|
+
var base, s = isNum ? str : str.replace(whitespaceOrPlus, "");
|
|
703
|
+
if (isInfinityOrNaN.test(s)) {
|
|
704
|
+
x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
|
|
705
|
+
} else {
|
|
706
|
+
if (!isNum) {
|
|
707
|
+
s = s.replace(basePrefix, function(m, p1, p2) {
|
|
708
|
+
base = (p2 = p2.toLowerCase()) == "x" ? 16 : p2 == "b" ? 2 : 8;
|
|
709
|
+
return !b || b == base ? p1 : m;
|
|
710
|
+
});
|
|
711
|
+
if (b) {
|
|
712
|
+
base = b;
|
|
713
|
+
s = s.replace(dotAfter, "$1").replace(dotBefore, "0.$1");
|
|
714
|
+
}
|
|
715
|
+
if (str != s)
|
|
716
|
+
return new BigNumber2(s, base);
|
|
717
|
+
}
|
|
718
|
+
if (BigNumber2.DEBUG) {
|
|
719
|
+
throw Error(bignumberError + "Not a" + (b ? " base " + b : "") + " number: " + str);
|
|
720
|
+
}
|
|
721
|
+
x.s = null;
|
|
722
|
+
}
|
|
723
|
+
x.c = x.e = null;
|
|
724
|
+
};
|
|
725
|
+
}();
|
|
726
|
+
function round(x, sd, rm, r) {
|
|
727
|
+
var d, i, j, k, n, ni, rd, xc = x.c, pows10 = POWS_TEN;
|
|
728
|
+
if (xc) {
|
|
729
|
+
out: {
|
|
730
|
+
for (d = 1, k = xc[0];k >= 10; k /= 10, d++)
|
|
731
|
+
;
|
|
732
|
+
i = sd - d;
|
|
733
|
+
if (i < 0) {
|
|
734
|
+
i += LOG_BASE;
|
|
735
|
+
j = sd;
|
|
736
|
+
n = xc[ni = 0];
|
|
737
|
+
rd = mathfloor(n / pows10[d - j - 1] % 10);
|
|
738
|
+
} else {
|
|
739
|
+
ni = mathceil((i + 1) / LOG_BASE);
|
|
740
|
+
if (ni >= xc.length) {
|
|
741
|
+
if (r) {
|
|
742
|
+
for (;xc.length <= ni; xc.push(0))
|
|
743
|
+
;
|
|
744
|
+
n = rd = 0;
|
|
745
|
+
d = 1;
|
|
746
|
+
i %= LOG_BASE;
|
|
747
|
+
j = i - LOG_BASE + 1;
|
|
748
|
+
} else {
|
|
749
|
+
break out;
|
|
750
|
+
}
|
|
751
|
+
} else {
|
|
752
|
+
n = k = xc[ni];
|
|
753
|
+
for (d = 1;k >= 10; k /= 10, d++)
|
|
754
|
+
;
|
|
755
|
+
i %= LOG_BASE;
|
|
756
|
+
j = i - LOG_BASE + d;
|
|
757
|
+
rd = j < 0 ? 0 : mathfloor(n / pows10[d - j - 1] % 10);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
r = r || sd < 0 || xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
|
|
761
|
+
r = rm < 4 ? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 && (i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
762
|
+
if (sd < 1 || !xc[0]) {
|
|
763
|
+
xc.length = 0;
|
|
764
|
+
if (r) {
|
|
765
|
+
sd -= x.e + 1;
|
|
766
|
+
xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
|
|
767
|
+
x.e = -sd || 0;
|
|
768
|
+
} else {
|
|
769
|
+
xc[0] = x.e = 0;
|
|
770
|
+
}
|
|
771
|
+
return x;
|
|
772
|
+
}
|
|
773
|
+
if (i == 0) {
|
|
774
|
+
xc.length = ni;
|
|
775
|
+
k = 1;
|
|
776
|
+
ni--;
|
|
777
|
+
} else {
|
|
778
|
+
xc.length = ni + 1;
|
|
779
|
+
k = pows10[LOG_BASE - i];
|
|
780
|
+
xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
|
|
781
|
+
}
|
|
782
|
+
if (r) {
|
|
783
|
+
for (;; ) {
|
|
784
|
+
if (ni == 0) {
|
|
785
|
+
for (i = 1, j = xc[0];j >= 10; j /= 10, i++)
|
|
786
|
+
;
|
|
787
|
+
j = xc[0] += k;
|
|
788
|
+
for (k = 1;j >= 10; j /= 10, k++)
|
|
789
|
+
;
|
|
790
|
+
if (i != k) {
|
|
791
|
+
x.e++;
|
|
792
|
+
if (xc[0] == BASE)
|
|
793
|
+
xc[0] = 1;
|
|
794
|
+
}
|
|
795
|
+
break;
|
|
796
|
+
} else {
|
|
797
|
+
xc[ni] += k;
|
|
798
|
+
if (xc[ni] != BASE)
|
|
799
|
+
break;
|
|
800
|
+
xc[ni--] = 0;
|
|
801
|
+
k = 1;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
for (i = xc.length;xc[--i] === 0; xc.pop())
|
|
806
|
+
;
|
|
807
|
+
}
|
|
808
|
+
if (x.e > MAX_EXP) {
|
|
809
|
+
x.c = x.e = null;
|
|
810
|
+
} else if (x.e < MIN_EXP) {
|
|
811
|
+
x.c = [x.e = 0];
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
return x;
|
|
815
|
+
}
|
|
816
|
+
function valueOf(n) {
|
|
817
|
+
var str, e = n.e;
|
|
818
|
+
if (e === null)
|
|
819
|
+
return n.toString();
|
|
820
|
+
str = coeffToString(n.c);
|
|
821
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(str, e) : toFixedPoint(str, e, "0");
|
|
822
|
+
return n.s < 0 ? "-" + str : str;
|
|
823
|
+
}
|
|
824
|
+
P.absoluteValue = P.abs = function() {
|
|
825
|
+
var x = new BigNumber2(this);
|
|
826
|
+
if (x.s < 0)
|
|
827
|
+
x.s = 1;
|
|
828
|
+
return x;
|
|
829
|
+
};
|
|
830
|
+
P.comparedTo = function(y, b) {
|
|
831
|
+
return compare(this, new BigNumber2(y, b));
|
|
832
|
+
};
|
|
833
|
+
P.decimalPlaces = P.dp = function(dp, rm) {
|
|
834
|
+
var c, n, v, x = this;
|
|
835
|
+
if (dp != null) {
|
|
836
|
+
intCheck(dp, 0, MAX);
|
|
837
|
+
if (rm == null)
|
|
838
|
+
rm = ROUNDING_MODE;
|
|
839
|
+
else
|
|
840
|
+
intCheck(rm, 0, 8);
|
|
841
|
+
return round(new BigNumber2(x), dp + x.e + 1, rm);
|
|
842
|
+
}
|
|
843
|
+
if (!(c = x.c))
|
|
844
|
+
return null;
|
|
845
|
+
n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
846
|
+
if (v = c[v])
|
|
847
|
+
for (;v % 10 == 0; v /= 10, n--)
|
|
848
|
+
;
|
|
849
|
+
if (n < 0)
|
|
850
|
+
n = 0;
|
|
851
|
+
return n;
|
|
852
|
+
};
|
|
853
|
+
P.dividedBy = P.div = function(y, b) {
|
|
854
|
+
return div(this, new BigNumber2(y, b), DECIMAL_PLACES, ROUNDING_MODE);
|
|
855
|
+
};
|
|
856
|
+
P.dividedToIntegerBy = P.idiv = function(y, b) {
|
|
857
|
+
return div(this, new BigNumber2(y, b), 0, 1);
|
|
858
|
+
};
|
|
859
|
+
P.exponentiatedBy = P.pow = function(n, m) {
|
|
860
|
+
var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y, x = this;
|
|
861
|
+
n = new BigNumber2(n);
|
|
862
|
+
if (n.c && !n.isInteger()) {
|
|
863
|
+
throw Error(bignumberError + "Exponent not an integer: " + valueOf(n));
|
|
864
|
+
}
|
|
865
|
+
if (m != null)
|
|
866
|
+
m = new BigNumber2(m);
|
|
867
|
+
nIsBig = n.e > 14;
|
|
868
|
+
if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
|
|
869
|
+
y = new BigNumber2(Math.pow(+valueOf(x), nIsBig ? n.s * (2 - isOdd(n)) : +valueOf(n)));
|
|
870
|
+
return m ? y.mod(m) : y;
|
|
871
|
+
}
|
|
872
|
+
nIsNeg = n.s < 0;
|
|
873
|
+
if (m) {
|
|
874
|
+
if (m.c ? !m.c[0] : !m.s)
|
|
875
|
+
return new BigNumber2(NaN);
|
|
876
|
+
isModExp = !nIsNeg && x.isInteger() && m.isInteger();
|
|
877
|
+
if (isModExp)
|
|
878
|
+
x = x.mod(m);
|
|
879
|
+
} else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0 ? x.c[0] > 1 || nIsBig && x.c[1] >= 240000000 : x.c[0] < 80000000000000 || nIsBig && x.c[0] <= 99999750000000))) {
|
|
880
|
+
k = x.s < 0 && isOdd(n) ? -0 : 0;
|
|
881
|
+
if (x.e > -1)
|
|
882
|
+
k = 1 / k;
|
|
883
|
+
return new BigNumber2(nIsNeg ? 1 / k : k);
|
|
884
|
+
} else if (POW_PRECISION) {
|
|
885
|
+
k = mathceil(POW_PRECISION / LOG_BASE + 2);
|
|
886
|
+
}
|
|
887
|
+
if (nIsBig) {
|
|
888
|
+
half = new BigNumber2(0.5);
|
|
889
|
+
if (nIsNeg)
|
|
890
|
+
n.s = 1;
|
|
891
|
+
nIsOdd = isOdd(n);
|
|
892
|
+
} else {
|
|
893
|
+
i = Math.abs(+valueOf(n));
|
|
894
|
+
nIsOdd = i % 2;
|
|
895
|
+
}
|
|
896
|
+
y = new BigNumber2(ONE);
|
|
897
|
+
for (;; ) {
|
|
898
|
+
if (nIsOdd) {
|
|
899
|
+
y = y.times(x);
|
|
900
|
+
if (!y.c)
|
|
901
|
+
break;
|
|
902
|
+
if (k) {
|
|
903
|
+
if (y.c.length > k)
|
|
904
|
+
y.c.length = k;
|
|
905
|
+
} else if (isModExp) {
|
|
906
|
+
y = y.mod(m);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
if (i) {
|
|
910
|
+
i = mathfloor(i / 2);
|
|
911
|
+
if (i === 0)
|
|
912
|
+
break;
|
|
913
|
+
nIsOdd = i % 2;
|
|
914
|
+
} else {
|
|
915
|
+
n = n.times(half);
|
|
916
|
+
round(n, n.e + 1, 1);
|
|
917
|
+
if (n.e > 14) {
|
|
918
|
+
nIsOdd = isOdd(n);
|
|
919
|
+
} else {
|
|
920
|
+
i = +valueOf(n);
|
|
921
|
+
if (i === 0)
|
|
922
|
+
break;
|
|
923
|
+
nIsOdd = i % 2;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
x = x.times(x);
|
|
927
|
+
if (k) {
|
|
928
|
+
if (x.c && x.c.length > k)
|
|
929
|
+
x.c.length = k;
|
|
930
|
+
} else if (isModExp) {
|
|
931
|
+
x = x.mod(m);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
if (isModExp)
|
|
935
|
+
return y;
|
|
936
|
+
if (nIsNeg)
|
|
937
|
+
y = ONE.div(y);
|
|
938
|
+
return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
|
|
939
|
+
};
|
|
940
|
+
P.integerValue = function(rm) {
|
|
941
|
+
var n = new BigNumber2(this);
|
|
942
|
+
if (rm == null)
|
|
943
|
+
rm = ROUNDING_MODE;
|
|
944
|
+
else
|
|
945
|
+
intCheck(rm, 0, 8);
|
|
946
|
+
return round(n, n.e + 1, rm);
|
|
947
|
+
};
|
|
948
|
+
P.isEqualTo = P.eq = function(y, b) {
|
|
949
|
+
return compare(this, new BigNumber2(y, b)) === 0;
|
|
950
|
+
};
|
|
951
|
+
P.isFinite = function() {
|
|
952
|
+
return !!this.c;
|
|
953
|
+
};
|
|
954
|
+
P.isGreaterThan = P.gt = function(y, b) {
|
|
955
|
+
return compare(this, new BigNumber2(y, b)) > 0;
|
|
956
|
+
};
|
|
957
|
+
P.isGreaterThanOrEqualTo = P.gte = function(y, b) {
|
|
958
|
+
return (b = compare(this, new BigNumber2(y, b))) === 1 || b === 0;
|
|
959
|
+
};
|
|
960
|
+
P.isInteger = function() {
|
|
961
|
+
return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
|
|
962
|
+
};
|
|
963
|
+
P.isLessThan = P.lt = function(y, b) {
|
|
964
|
+
return compare(this, new BigNumber2(y, b)) < 0;
|
|
965
|
+
};
|
|
966
|
+
P.isLessThanOrEqualTo = P.lte = function(y, b) {
|
|
967
|
+
return (b = compare(this, new BigNumber2(y, b))) === -1 || b === 0;
|
|
968
|
+
};
|
|
969
|
+
P.isNaN = function() {
|
|
970
|
+
return !this.s;
|
|
971
|
+
};
|
|
972
|
+
P.isNegative = function() {
|
|
973
|
+
return this.s < 0;
|
|
974
|
+
};
|
|
975
|
+
P.isPositive = function() {
|
|
976
|
+
return this.s > 0;
|
|
977
|
+
};
|
|
978
|
+
P.isZero = function() {
|
|
979
|
+
return !!this.c && this.c[0] == 0;
|
|
980
|
+
};
|
|
981
|
+
P.minus = function(y, b) {
|
|
982
|
+
var i, j, t, xLTy, x = this, a = x.s;
|
|
983
|
+
y = new BigNumber2(y, b);
|
|
984
|
+
b = y.s;
|
|
985
|
+
if (!a || !b)
|
|
986
|
+
return new BigNumber2(NaN);
|
|
987
|
+
if (a != b) {
|
|
988
|
+
y.s = -b;
|
|
989
|
+
return x.plus(y);
|
|
990
|
+
}
|
|
991
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
992
|
+
if (!xe || !ye) {
|
|
993
|
+
if (!xc || !yc)
|
|
994
|
+
return xc ? (y.s = -b, y) : new BigNumber2(yc ? x : NaN);
|
|
995
|
+
if (!xc[0] || !yc[0]) {
|
|
996
|
+
return yc[0] ? (y.s = -b, y) : new BigNumber2(xc[0] ? x : ROUNDING_MODE == 3 ? -0 : 0);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
xe = bitFloor(xe);
|
|
1000
|
+
ye = bitFloor(ye);
|
|
1001
|
+
xc = xc.slice();
|
|
1002
|
+
if (a = xe - ye) {
|
|
1003
|
+
if (xLTy = a < 0) {
|
|
1004
|
+
a = -a;
|
|
1005
|
+
t = xc;
|
|
1006
|
+
} else {
|
|
1007
|
+
ye = xe;
|
|
1008
|
+
t = yc;
|
|
1009
|
+
}
|
|
1010
|
+
t.reverse();
|
|
1011
|
+
for (b = a;b--; t.push(0))
|
|
1012
|
+
;
|
|
1013
|
+
t.reverse();
|
|
1014
|
+
} else {
|
|
1015
|
+
j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
|
|
1016
|
+
for (a = b = 0;b < j; b++) {
|
|
1017
|
+
if (xc[b] != yc[b]) {
|
|
1018
|
+
xLTy = xc[b] < yc[b];
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
if (xLTy) {
|
|
1024
|
+
t = xc;
|
|
1025
|
+
xc = yc;
|
|
1026
|
+
yc = t;
|
|
1027
|
+
y.s = -y.s;
|
|
1028
|
+
}
|
|
1029
|
+
b = (j = yc.length) - (i = xc.length);
|
|
1030
|
+
if (b > 0)
|
|
1031
|
+
for (;b--; xc[i++] = 0)
|
|
1032
|
+
;
|
|
1033
|
+
b = BASE - 1;
|
|
1034
|
+
for (;j > a; ) {
|
|
1035
|
+
if (xc[--j] < yc[j]) {
|
|
1036
|
+
for (i = j;i && !xc[--i]; xc[i] = b)
|
|
1037
|
+
;
|
|
1038
|
+
--xc[i];
|
|
1039
|
+
xc[j] += BASE;
|
|
1040
|
+
}
|
|
1041
|
+
xc[j] -= yc[j];
|
|
1042
|
+
}
|
|
1043
|
+
for (;xc[0] == 0; xc.splice(0, 1), --ye)
|
|
1044
|
+
;
|
|
1045
|
+
if (!xc[0]) {
|
|
1046
|
+
y.s = ROUNDING_MODE == 3 ? -1 : 1;
|
|
1047
|
+
y.c = [y.e = 0];
|
|
1048
|
+
return y;
|
|
1049
|
+
}
|
|
1050
|
+
return normalise(y, xc, ye);
|
|
1051
|
+
};
|
|
1052
|
+
P.modulo = P.mod = function(y, b) {
|
|
1053
|
+
var q, s, x = this;
|
|
1054
|
+
y = new BigNumber2(y, b);
|
|
1055
|
+
if (!x.c || !y.s || y.c && !y.c[0]) {
|
|
1056
|
+
return new BigNumber2(NaN);
|
|
1057
|
+
} else if (!y.c || x.c && !x.c[0]) {
|
|
1058
|
+
return new BigNumber2(x);
|
|
1059
|
+
}
|
|
1060
|
+
if (MODULO_MODE == 9) {
|
|
1061
|
+
s = y.s;
|
|
1062
|
+
y.s = 1;
|
|
1063
|
+
q = div(x, y, 0, 3);
|
|
1064
|
+
y.s = s;
|
|
1065
|
+
q.s *= s;
|
|
1066
|
+
} else {
|
|
1067
|
+
q = div(x, y, 0, MODULO_MODE);
|
|
1068
|
+
}
|
|
1069
|
+
y = x.minus(q.times(y));
|
|
1070
|
+
if (!y.c[0] && MODULO_MODE == 1)
|
|
1071
|
+
y.s = x.s;
|
|
1072
|
+
return y;
|
|
1073
|
+
};
|
|
1074
|
+
P.multipliedBy = P.times = function(y, b) {
|
|
1075
|
+
var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc, base, sqrtBase, x = this, xc = x.c, yc = (y = new BigNumber2(y, b)).c;
|
|
1076
|
+
if (!xc || !yc || !xc[0] || !yc[0]) {
|
|
1077
|
+
if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
|
|
1078
|
+
y.c = y.e = y.s = null;
|
|
1079
|
+
} else {
|
|
1080
|
+
y.s *= x.s;
|
|
1081
|
+
if (!xc || !yc) {
|
|
1082
|
+
y.c = y.e = null;
|
|
1083
|
+
} else {
|
|
1084
|
+
y.c = [0];
|
|
1085
|
+
y.e = 0;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
return y;
|
|
1089
|
+
}
|
|
1090
|
+
e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
|
|
1091
|
+
y.s *= x.s;
|
|
1092
|
+
xcL = xc.length;
|
|
1093
|
+
ycL = yc.length;
|
|
1094
|
+
if (xcL < ycL) {
|
|
1095
|
+
zc = xc;
|
|
1096
|
+
xc = yc;
|
|
1097
|
+
yc = zc;
|
|
1098
|
+
i = xcL;
|
|
1099
|
+
xcL = ycL;
|
|
1100
|
+
ycL = i;
|
|
1101
|
+
}
|
|
1102
|
+
for (i = xcL + ycL, zc = [];i--; zc.push(0))
|
|
1103
|
+
;
|
|
1104
|
+
base = BASE;
|
|
1105
|
+
sqrtBase = SQRT_BASE;
|
|
1106
|
+
for (i = ycL;--i >= 0; ) {
|
|
1107
|
+
c = 0;
|
|
1108
|
+
ylo = yc[i] % sqrtBase;
|
|
1109
|
+
yhi = yc[i] / sqrtBase | 0;
|
|
1110
|
+
for (k = xcL, j = i + k;j > i; ) {
|
|
1111
|
+
xlo = xc[--k] % sqrtBase;
|
|
1112
|
+
xhi = xc[k] / sqrtBase | 0;
|
|
1113
|
+
m = yhi * xlo + xhi * ylo;
|
|
1114
|
+
xlo = ylo * xlo + m % sqrtBase * sqrtBase + zc[j] + c;
|
|
1115
|
+
c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
|
|
1116
|
+
zc[j--] = xlo % base;
|
|
1117
|
+
}
|
|
1118
|
+
zc[j] = c;
|
|
1119
|
+
}
|
|
1120
|
+
if (c) {
|
|
1121
|
+
++e;
|
|
1122
|
+
} else {
|
|
1123
|
+
zc.splice(0, 1);
|
|
1124
|
+
}
|
|
1125
|
+
return normalise(y, zc, e);
|
|
1126
|
+
};
|
|
1127
|
+
P.negated = function() {
|
|
1128
|
+
var x = new BigNumber2(this);
|
|
1129
|
+
x.s = -x.s || null;
|
|
1130
|
+
return x;
|
|
1131
|
+
};
|
|
1132
|
+
P.plus = function(y, b) {
|
|
1133
|
+
var t, x = this, a = x.s;
|
|
1134
|
+
y = new BigNumber2(y, b);
|
|
1135
|
+
b = y.s;
|
|
1136
|
+
if (!a || !b)
|
|
1137
|
+
return new BigNumber2(NaN);
|
|
1138
|
+
if (a != b) {
|
|
1139
|
+
y.s = -b;
|
|
1140
|
+
return x.minus(y);
|
|
1141
|
+
}
|
|
1142
|
+
var xe = x.e / LOG_BASE, ye = y.e / LOG_BASE, xc = x.c, yc = y.c;
|
|
1143
|
+
if (!xe || !ye) {
|
|
1144
|
+
if (!xc || !yc)
|
|
1145
|
+
return new BigNumber2(a / 0);
|
|
1146
|
+
if (!xc[0] || !yc[0])
|
|
1147
|
+
return yc[0] ? y : new BigNumber2(xc[0] ? x : a * 0);
|
|
1148
|
+
}
|
|
1149
|
+
xe = bitFloor(xe);
|
|
1150
|
+
ye = bitFloor(ye);
|
|
1151
|
+
xc = xc.slice();
|
|
1152
|
+
if (a = xe - ye) {
|
|
1153
|
+
if (a > 0) {
|
|
1154
|
+
ye = xe;
|
|
1155
|
+
t = yc;
|
|
1156
|
+
} else {
|
|
1157
|
+
a = -a;
|
|
1158
|
+
t = xc;
|
|
1159
|
+
}
|
|
1160
|
+
t.reverse();
|
|
1161
|
+
for (;a--; t.push(0))
|
|
1162
|
+
;
|
|
1163
|
+
t.reverse();
|
|
1164
|
+
}
|
|
1165
|
+
a = xc.length;
|
|
1166
|
+
b = yc.length;
|
|
1167
|
+
if (a - b < 0) {
|
|
1168
|
+
t = yc;
|
|
1169
|
+
yc = xc;
|
|
1170
|
+
xc = t;
|
|
1171
|
+
b = a;
|
|
1172
|
+
}
|
|
1173
|
+
for (a = 0;b; ) {
|
|
1174
|
+
a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
|
|
1175
|
+
xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
|
|
1176
|
+
}
|
|
1177
|
+
if (a) {
|
|
1178
|
+
xc = [a].concat(xc);
|
|
1179
|
+
++ye;
|
|
1180
|
+
}
|
|
1181
|
+
return normalise(y, xc, ye);
|
|
1182
|
+
};
|
|
1183
|
+
P.precision = P.sd = function(sd, rm) {
|
|
1184
|
+
var c, n, v, x = this;
|
|
1185
|
+
if (sd != null && sd !== !!sd) {
|
|
1186
|
+
intCheck(sd, 1, MAX);
|
|
1187
|
+
if (rm == null)
|
|
1188
|
+
rm = ROUNDING_MODE;
|
|
1189
|
+
else
|
|
1190
|
+
intCheck(rm, 0, 8);
|
|
1191
|
+
return round(new BigNumber2(x), sd, rm);
|
|
1192
|
+
}
|
|
1193
|
+
if (!(c = x.c))
|
|
1194
|
+
return null;
|
|
1195
|
+
v = c.length - 1;
|
|
1196
|
+
n = v * LOG_BASE + 1;
|
|
1197
|
+
if (v = c[v]) {
|
|
1198
|
+
for (;v % 10 == 0; v /= 10, n--)
|
|
1199
|
+
;
|
|
1200
|
+
for (v = c[0];v >= 10; v /= 10, n++)
|
|
1201
|
+
;
|
|
1202
|
+
}
|
|
1203
|
+
if (sd && x.e + 1 > n)
|
|
1204
|
+
n = x.e + 1;
|
|
1205
|
+
return n;
|
|
1206
|
+
};
|
|
1207
|
+
P.shiftedBy = function(k) {
|
|
1208
|
+
intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
|
1209
|
+
return this.times("1e" + k);
|
|
1210
|
+
};
|
|
1211
|
+
P.squareRoot = P.sqrt = function() {
|
|
1212
|
+
var m, n, r, rep, t, x = this, c = x.c, s = x.s, e = x.e, dp = DECIMAL_PLACES + 4, half = new BigNumber2("0.5");
|
|
1213
|
+
if (s !== 1 || !c || !c[0]) {
|
|
1214
|
+
return new BigNumber2(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
|
|
1215
|
+
}
|
|
1216
|
+
s = Math.sqrt(+valueOf(x));
|
|
1217
|
+
if (s == 0 || s == 1 / 0) {
|
|
1218
|
+
n = coeffToString(c);
|
|
1219
|
+
if ((n.length + e) % 2 == 0)
|
|
1220
|
+
n += "0";
|
|
1221
|
+
s = Math.sqrt(+n);
|
|
1222
|
+
e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
1223
|
+
if (s == 1 / 0) {
|
|
1224
|
+
n = "5e" + e;
|
|
1225
|
+
} else {
|
|
1226
|
+
n = s.toExponential();
|
|
1227
|
+
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
1228
|
+
}
|
|
1229
|
+
r = new BigNumber2(n);
|
|
1230
|
+
} else {
|
|
1231
|
+
r = new BigNumber2(s + "");
|
|
1232
|
+
}
|
|
1233
|
+
if (r.c[0]) {
|
|
1234
|
+
e = r.e;
|
|
1235
|
+
s = e + dp;
|
|
1236
|
+
if (s < 3)
|
|
1237
|
+
s = 0;
|
|
1238
|
+
for (;; ) {
|
|
1239
|
+
t = r;
|
|
1240
|
+
r = half.times(t.plus(div(x, t, dp, 1)));
|
|
1241
|
+
if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
|
|
1242
|
+
if (r.e < e)
|
|
1243
|
+
--s;
|
|
1244
|
+
n = n.slice(s - 3, s + 1);
|
|
1245
|
+
if (n == "9999" || !rep && n == "4999") {
|
|
1246
|
+
if (!rep) {
|
|
1247
|
+
round(t, t.e + DECIMAL_PLACES + 2, 0);
|
|
1248
|
+
if (t.times(t).eq(x)) {
|
|
1249
|
+
r = t;
|
|
1250
|
+
break;
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
dp += 4;
|
|
1254
|
+
s += 4;
|
|
1255
|
+
rep = 1;
|
|
1256
|
+
} else {
|
|
1257
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
1258
|
+
round(r, r.e + DECIMAL_PLACES + 2, 1);
|
|
1259
|
+
m = !r.times(r).eq(x);
|
|
1260
|
+
}
|
|
1261
|
+
break;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
|
|
1267
|
+
};
|
|
1268
|
+
P.toExponential = function(dp, rm) {
|
|
1269
|
+
if (dp != null) {
|
|
1270
|
+
intCheck(dp, 0, MAX);
|
|
1271
|
+
dp++;
|
|
1272
|
+
}
|
|
1273
|
+
return format(this, dp, rm, 1);
|
|
1274
|
+
};
|
|
1275
|
+
P.toFixed = function(dp, rm) {
|
|
1276
|
+
if (dp != null) {
|
|
1277
|
+
intCheck(dp, 0, MAX);
|
|
1278
|
+
dp = dp + this.e + 1;
|
|
1279
|
+
}
|
|
1280
|
+
return format(this, dp, rm);
|
|
1281
|
+
};
|
|
1282
|
+
P.toFormat = function(dp, rm, format2) {
|
|
1283
|
+
var str, x = this;
|
|
1284
|
+
if (format2 == null) {
|
|
1285
|
+
if (dp != null && rm && typeof rm == "object") {
|
|
1286
|
+
format2 = rm;
|
|
1287
|
+
rm = null;
|
|
1288
|
+
} else if (dp && typeof dp == "object") {
|
|
1289
|
+
format2 = dp;
|
|
1290
|
+
dp = rm = null;
|
|
1291
|
+
} else {
|
|
1292
|
+
format2 = FORMAT;
|
|
1293
|
+
}
|
|
1294
|
+
} else if (typeof format2 != "object") {
|
|
1295
|
+
throw Error(bignumberError + "Argument not an object: " + format2);
|
|
1296
|
+
}
|
|
1297
|
+
str = x.toFixed(dp, rm);
|
|
1298
|
+
if (x.c) {
|
|
1299
|
+
var i, arr = str.split("."), g1 = +format2.groupSize, g2 = +format2.secondaryGroupSize, groupSeparator = format2.groupSeparator || "", intPart = arr[0], fractionPart = arr[1], isNeg = x.s < 0, intDigits = isNeg ? intPart.slice(1) : intPart, len = intDigits.length;
|
|
1300
|
+
if (g2) {
|
|
1301
|
+
i = g1;
|
|
1302
|
+
g1 = g2;
|
|
1303
|
+
g2 = i;
|
|
1304
|
+
len -= i;
|
|
1305
|
+
}
|
|
1306
|
+
if (g1 > 0 && len > 0) {
|
|
1307
|
+
i = len % g1 || g1;
|
|
1308
|
+
intPart = intDigits.substr(0, i);
|
|
1309
|
+
for (;i < len; i += g1)
|
|
1310
|
+
intPart += groupSeparator + intDigits.substr(i, g1);
|
|
1311
|
+
if (g2 > 0)
|
|
1312
|
+
intPart += groupSeparator + intDigits.slice(i);
|
|
1313
|
+
if (isNeg)
|
|
1314
|
+
intPart = "-" + intPart;
|
|
1315
|
+
}
|
|
1316
|
+
str = fractionPart ? intPart + (format2.decimalSeparator || "") + ((g2 = +format2.fractionGroupSize) ? fractionPart.replace(new RegExp("\\d{" + g2 + "}\\B", "g"), "$&" + (format2.fractionGroupSeparator || "")) : fractionPart) : intPart;
|
|
1317
|
+
}
|
|
1318
|
+
return (format2.prefix || "") + str + (format2.suffix || "");
|
|
1319
|
+
};
|
|
1320
|
+
P.toFraction = function(md) {
|
|
1321
|
+
var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s, x = this, xc = x.c;
|
|
1322
|
+
if (md != null) {
|
|
1323
|
+
n = new BigNumber2(md);
|
|
1324
|
+
if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
|
|
1325
|
+
throw Error(bignumberError + "Argument " + (n.isInteger() ? "out of range: " : "not an integer: ") + valueOf(n));
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
if (!xc)
|
|
1329
|
+
return new BigNumber2(x);
|
|
1330
|
+
d = new BigNumber2(ONE);
|
|
1331
|
+
n1 = d0 = new BigNumber2(ONE);
|
|
1332
|
+
d1 = n0 = new BigNumber2(ONE);
|
|
1333
|
+
s = coeffToString(xc);
|
|
1334
|
+
e = d.e = s.length - x.e - 1;
|
|
1335
|
+
d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
|
|
1336
|
+
md = !md || n.comparedTo(d) > 0 ? e > 0 ? d : n1 : n;
|
|
1337
|
+
exp = MAX_EXP;
|
|
1338
|
+
MAX_EXP = 1 / 0;
|
|
1339
|
+
n = new BigNumber2(s);
|
|
1340
|
+
n0.c[0] = 0;
|
|
1341
|
+
for (;; ) {
|
|
1342
|
+
q = div(n, d, 0, 1);
|
|
1343
|
+
d2 = d0.plus(q.times(d1));
|
|
1344
|
+
if (d2.comparedTo(md) == 1)
|
|
1345
|
+
break;
|
|
1346
|
+
d0 = d1;
|
|
1347
|
+
d1 = d2;
|
|
1348
|
+
n1 = n0.plus(q.times(d2 = n1));
|
|
1349
|
+
n0 = d2;
|
|
1350
|
+
d = n.minus(q.times(d2 = d));
|
|
1351
|
+
n = d2;
|
|
1352
|
+
}
|
|
1353
|
+
d2 = div(md.minus(d0), d1, 0, 1);
|
|
1354
|
+
n0 = n0.plus(d2.times(n1));
|
|
1355
|
+
d0 = d0.plus(d2.times(d1));
|
|
1356
|
+
n0.s = n1.s = x.s;
|
|
1357
|
+
e = e * 2;
|
|
1358
|
+
r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
1359
|
+
MAX_EXP = exp;
|
|
1360
|
+
return r;
|
|
1361
|
+
};
|
|
1362
|
+
P.toNumber = function() {
|
|
1363
|
+
return +valueOf(this);
|
|
1364
|
+
};
|
|
1365
|
+
P.toPrecision = function(sd, rm) {
|
|
1366
|
+
if (sd != null)
|
|
1367
|
+
intCheck(sd, 1, MAX);
|
|
1368
|
+
return format(this, sd, rm, 2);
|
|
1369
|
+
};
|
|
1370
|
+
P.toString = function(b) {
|
|
1371
|
+
var str, n = this, s = n.s, e = n.e;
|
|
1372
|
+
if (e === null) {
|
|
1373
|
+
if (s) {
|
|
1374
|
+
str = "Infinity";
|
|
1375
|
+
if (s < 0)
|
|
1376
|
+
str = "-" + str;
|
|
1377
|
+
} else {
|
|
1378
|
+
str = "NaN";
|
|
1379
|
+
}
|
|
1380
|
+
} else {
|
|
1381
|
+
if (b == null) {
|
|
1382
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS ? toExponential(coeffToString(n.c), e) : toFixedPoint(coeffToString(n.c), e, "0");
|
|
1383
|
+
} else if (b === 10 && alphabetHasNormalDecimalDigits) {
|
|
1384
|
+
n = round(new BigNumber2(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
|
|
1385
|
+
str = toFixedPoint(coeffToString(n.c), n.e, "0");
|
|
1386
|
+
} else {
|
|
1387
|
+
intCheck(b, 2, ALPHABET.length, "Base");
|
|
1388
|
+
str = convertBase(toFixedPoint(coeffToString(n.c), e, "0"), 10, b, s, true);
|
|
1389
|
+
}
|
|
1390
|
+
if (s < 0 && n.c[0])
|
|
1391
|
+
str = "-" + str;
|
|
1392
|
+
}
|
|
1393
|
+
return str;
|
|
1394
|
+
};
|
|
1395
|
+
P.valueOf = P.toJSON = function() {
|
|
1396
|
+
return valueOf(this);
|
|
1397
|
+
};
|
|
1398
|
+
P._isBigNumber = true;
|
|
1399
|
+
if (configObject != null)
|
|
1400
|
+
BigNumber2.set(configObject);
|
|
1401
|
+
return BigNumber2;
|
|
1402
|
+
}
|
|
1403
|
+
function bitFloor(n) {
|
|
1404
|
+
var i = n | 0;
|
|
1405
|
+
return n > 0 || n === i ? i : i - 1;
|
|
1406
|
+
}
|
|
1407
|
+
function coeffToString(a) {
|
|
1408
|
+
var s, z, i = 1, j = a.length, r = a[0] + "";
|
|
1409
|
+
for (;i < j; ) {
|
|
1410
|
+
s = a[i++] + "";
|
|
1411
|
+
z = LOG_BASE - s.length;
|
|
1412
|
+
for (;z--; s = "0" + s)
|
|
1413
|
+
;
|
|
1414
|
+
r += s;
|
|
1415
|
+
}
|
|
1416
|
+
for (j = r.length;r.charCodeAt(--j) === 48; )
|
|
1417
|
+
;
|
|
1418
|
+
return r.slice(0, j + 1 || 1);
|
|
1419
|
+
}
|
|
1420
|
+
function compare(x, y) {
|
|
1421
|
+
var a, b, xc = x.c, yc = y.c, i = x.s, j = y.s, k = x.e, l = y.e;
|
|
1422
|
+
if (!i || !j)
|
|
1423
|
+
return null;
|
|
1424
|
+
a = xc && !xc[0];
|
|
1425
|
+
b = yc && !yc[0];
|
|
1426
|
+
if (a || b)
|
|
1427
|
+
return a ? b ? 0 : -j : i;
|
|
1428
|
+
if (i != j)
|
|
1429
|
+
return i;
|
|
1430
|
+
a = i < 0;
|
|
1431
|
+
b = k == l;
|
|
1432
|
+
if (!xc || !yc)
|
|
1433
|
+
return b ? 0 : !xc ^ a ? 1 : -1;
|
|
1434
|
+
if (!b)
|
|
1435
|
+
return k > l ^ a ? 1 : -1;
|
|
1436
|
+
j = (k = xc.length) < (l = yc.length) ? k : l;
|
|
1437
|
+
for (i = 0;i < j; i++)
|
|
1438
|
+
if (xc[i] != yc[i])
|
|
1439
|
+
return xc[i] > yc[i] ^ a ? 1 : -1;
|
|
1440
|
+
return k == l ? 0 : k > l ^ a ? 1 : -1;
|
|
1441
|
+
}
|
|
1442
|
+
function intCheck(n, min, max, name) {
|
|
1443
|
+
if (n < min || n > max || n !== mathfloor(n)) {
|
|
1444
|
+
throw Error(bignumberError + (name || "Argument") + (typeof n == "number" ? n < min || n > max ? " out of range: " : " not an integer: " : " not a primitive number: ") + String(n));
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
function isOdd(n) {
|
|
1448
|
+
var k = n.c.length - 1;
|
|
1449
|
+
return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
|
|
1450
|
+
}
|
|
1451
|
+
function toExponential(str, e) {
|
|
1452
|
+
return (str.length > 1 ? str.charAt(0) + "." + str.slice(1) : str) + (e < 0 ? "e" : "e+") + e;
|
|
1453
|
+
}
|
|
1454
|
+
function toFixedPoint(str, e, z) {
|
|
1455
|
+
var len, zs;
|
|
1456
|
+
if (e < 0) {
|
|
1457
|
+
for (zs = z + ".";++e; zs += z)
|
|
1458
|
+
;
|
|
1459
|
+
str = zs + str;
|
|
1460
|
+
} else {
|
|
1461
|
+
len = str.length;
|
|
1462
|
+
if (++e > len) {
|
|
1463
|
+
for (zs = z, e -= len;--e; zs += z)
|
|
1464
|
+
;
|
|
1465
|
+
str += zs;
|
|
1466
|
+
} else if (e < len) {
|
|
1467
|
+
str = str.slice(0, e) + "." + str.slice(e);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
return str;
|
|
1471
|
+
}
|
|
1472
|
+
BigNumber = clone();
|
|
1473
|
+
BigNumber["default"] = BigNumber.BigNumber = BigNumber;
|
|
1474
|
+
if (typeof define == "function" && define.amd) {
|
|
1475
|
+
define(function() {
|
|
1476
|
+
return BigNumber;
|
|
1477
|
+
});
|
|
1478
|
+
} else if (typeof module != "undefined" && module.exports) {
|
|
1479
|
+
module.exports = BigNumber;
|
|
1480
|
+
} else {
|
|
1481
|
+
if (!globalObject) {
|
|
1482
|
+
globalObject = typeof self != "undefined" && self ? self : window;
|
|
1483
|
+
}
|
|
1484
|
+
globalObject.BigNumber = BigNumber;
|
|
1485
|
+
}
|
|
1486
|
+
})(exports);
|
|
1487
|
+
});
|
|
1488
|
+
|
|
1489
|
+
// node_modules/.bun/json-bigint@1.0.0/node_modules/json-bigint/lib/stringify.js
|
|
1490
|
+
var require_stringify = __commonJS((exports, module) => {
|
|
1491
|
+
var BigNumber = require_bignumber();
|
|
1492
|
+
var JSON2 = exports;
|
|
1493
|
+
(function() {
|
|
1494
|
+
function f(n) {
|
|
1495
|
+
return n < 10 ? "0" + n : n;
|
|
1496
|
+
}
|
|
1497
|
+
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = {
|
|
1498
|
+
"\b": "\\b",
|
|
1499
|
+
"\t": "\\t",
|
|
1500
|
+
"\n": "\\n",
|
|
1501
|
+
"\f": "\\f",
|
|
1502
|
+
"\r": "\\r",
|
|
1503
|
+
'"': "\\\"",
|
|
1504
|
+
"\\": "\\\\"
|
|
1505
|
+
}, rep;
|
|
1506
|
+
function quote(string) {
|
|
1507
|
+
escapable.lastIndex = 0;
|
|
1508
|
+
return escapable.test(string) ? '"' + string.replace(escapable, function(a) {
|
|
1509
|
+
var c = meta[a];
|
|
1510
|
+
return typeof c === "string" ? c : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
|
|
1511
|
+
}) + '"' : '"' + string + '"';
|
|
1512
|
+
}
|
|
1513
|
+
function str(key, holder) {
|
|
1514
|
+
var i, k, v, length, mind = gap, partial, value = holder[key], isBigNumber = value != null && (value instanceof BigNumber || BigNumber.isBigNumber(value));
|
|
1515
|
+
if (value && typeof value === "object" && typeof value.toJSON === "function") {
|
|
1516
|
+
value = value.toJSON(key);
|
|
1517
|
+
}
|
|
1518
|
+
if (typeof rep === "function") {
|
|
1519
|
+
value = rep.call(holder, key, value);
|
|
1520
|
+
}
|
|
1521
|
+
switch (typeof value) {
|
|
1522
|
+
case "string":
|
|
1523
|
+
if (isBigNumber) {
|
|
1524
|
+
return value;
|
|
1525
|
+
} else {
|
|
1526
|
+
return quote(value);
|
|
1527
|
+
}
|
|
1528
|
+
case "number":
|
|
1529
|
+
return isFinite(value) ? String(value) : "null";
|
|
1530
|
+
case "boolean":
|
|
1531
|
+
case "null":
|
|
1532
|
+
case "bigint":
|
|
1533
|
+
return String(value);
|
|
1534
|
+
case "object":
|
|
1535
|
+
if (!value) {
|
|
1536
|
+
return "null";
|
|
1537
|
+
}
|
|
1538
|
+
gap += indent;
|
|
1539
|
+
partial = [];
|
|
1540
|
+
if (Object.prototype.toString.apply(value) === "[object Array]") {
|
|
1541
|
+
length = value.length;
|
|
1542
|
+
for (i = 0;i < length; i += 1) {
|
|
1543
|
+
partial[i] = str(i, value) || "null";
|
|
1544
|
+
}
|
|
1545
|
+
v = partial.length === 0 ? "[]" : gap ? `[
|
|
1546
|
+
` + gap + partial.join(`,
|
|
1547
|
+
` + gap) + `
|
|
1548
|
+
` + mind + "]" : "[" + partial.join(",") + "]";
|
|
1549
|
+
gap = mind;
|
|
1550
|
+
return v;
|
|
1551
|
+
}
|
|
1552
|
+
if (rep && typeof rep === "object") {
|
|
1553
|
+
length = rep.length;
|
|
1554
|
+
for (i = 0;i < length; i += 1) {
|
|
1555
|
+
if (typeof rep[i] === "string") {
|
|
1556
|
+
k = rep[i];
|
|
1557
|
+
v = str(k, value);
|
|
1558
|
+
if (v) {
|
|
1559
|
+
partial.push(quote(k) + (gap ? ": " : ":") + v);
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
} else {
|
|
1564
|
+
Object.keys(value).forEach(function(k2) {
|
|
1565
|
+
var v2 = str(k2, value);
|
|
1566
|
+
if (v2) {
|
|
1567
|
+
partial.push(quote(k2) + (gap ? ": " : ":") + v2);
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
v = partial.length === 0 ? "{}" : gap ? `{
|
|
1572
|
+
` + gap + partial.join(`,
|
|
1573
|
+
` + gap) + `
|
|
1574
|
+
` + mind + "}" : "{" + partial.join(",") + "}";
|
|
1575
|
+
gap = mind;
|
|
1576
|
+
return v;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
if (typeof JSON2.stringify !== "function") {
|
|
1580
|
+
JSON2.stringify = function(value, replacer, space) {
|
|
1581
|
+
var i;
|
|
1582
|
+
gap = "";
|
|
1583
|
+
indent = "";
|
|
1584
|
+
if (typeof space === "number") {
|
|
1585
|
+
for (i = 0;i < space; i += 1) {
|
|
1586
|
+
indent += " ";
|
|
1587
|
+
}
|
|
1588
|
+
} else if (typeof space === "string") {
|
|
1589
|
+
indent = space;
|
|
1590
|
+
}
|
|
1591
|
+
rep = replacer;
|
|
1592
|
+
if (replacer && typeof replacer !== "function" && (typeof replacer !== "object" || typeof replacer.length !== "number")) {
|
|
1593
|
+
throw new Error("JSON.stringify");
|
|
1594
|
+
}
|
|
1595
|
+
return str("", { "": value });
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
})();
|
|
1599
|
+
});
|
|
1600
|
+
|
|
1601
|
+
// node_modules/.bun/json-bigint@1.0.0/node_modules/json-bigint/lib/parse.js
|
|
1602
|
+
var require_parse = __commonJS((exports, module) => {
|
|
1603
|
+
var BigNumber = null;
|
|
1604
|
+
var suspectProtoRx = /(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])/;
|
|
1605
|
+
var suspectConstructorRx = /(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)/;
|
|
1606
|
+
var json_parse = function(options) {
|
|
1607
|
+
var _options = {
|
|
1608
|
+
strict: false,
|
|
1609
|
+
storeAsString: false,
|
|
1610
|
+
alwaysParseAsBig: false,
|
|
1611
|
+
useNativeBigInt: false,
|
|
1612
|
+
protoAction: "error",
|
|
1613
|
+
constructorAction: "error"
|
|
1614
|
+
};
|
|
1615
|
+
if (options !== undefined && options !== null) {
|
|
1616
|
+
if (options.strict === true) {
|
|
1617
|
+
_options.strict = true;
|
|
1618
|
+
}
|
|
1619
|
+
if (options.storeAsString === true) {
|
|
1620
|
+
_options.storeAsString = true;
|
|
1621
|
+
}
|
|
1622
|
+
_options.alwaysParseAsBig = options.alwaysParseAsBig === true ? options.alwaysParseAsBig : false;
|
|
1623
|
+
_options.useNativeBigInt = options.useNativeBigInt === true ? options.useNativeBigInt : false;
|
|
1624
|
+
if (typeof options.constructorAction !== "undefined") {
|
|
1625
|
+
if (options.constructorAction === "error" || options.constructorAction === "ignore" || options.constructorAction === "preserve") {
|
|
1626
|
+
_options.constructorAction = options.constructorAction;
|
|
1627
|
+
} else {
|
|
1628
|
+
throw new Error(`Incorrect value for constructorAction option, must be "error", "ignore" or undefined but passed ${options.constructorAction}`);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
if (typeof options.protoAction !== "undefined") {
|
|
1632
|
+
if (options.protoAction === "error" || options.protoAction === "ignore" || options.protoAction === "preserve") {
|
|
1633
|
+
_options.protoAction = options.protoAction;
|
|
1634
|
+
} else {
|
|
1635
|
+
throw new Error(`Incorrect value for protoAction option, must be "error", "ignore" or undefined but passed ${options.protoAction}`);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
var at, ch, escapee = {
|
|
1640
|
+
'"': '"',
|
|
1641
|
+
"\\": "\\",
|
|
1642
|
+
"/": "/",
|
|
1643
|
+
b: "\b",
|
|
1644
|
+
f: "\f",
|
|
1645
|
+
n: `
|
|
1646
|
+
`,
|
|
1647
|
+
r: "\r",
|
|
1648
|
+
t: "\t"
|
|
1649
|
+
}, text, error = function(m) {
|
|
1650
|
+
throw {
|
|
1651
|
+
name: "SyntaxError",
|
|
1652
|
+
message: m,
|
|
1653
|
+
at,
|
|
1654
|
+
text
|
|
1655
|
+
};
|
|
1656
|
+
}, next = function(c) {
|
|
1657
|
+
if (c && c !== ch) {
|
|
1658
|
+
error("Expected '" + c + "' instead of '" + ch + "'");
|
|
1659
|
+
}
|
|
1660
|
+
ch = text.charAt(at);
|
|
1661
|
+
at += 1;
|
|
1662
|
+
return ch;
|
|
1663
|
+
}, number = function() {
|
|
1664
|
+
var number2, string2 = "";
|
|
1665
|
+
if (ch === "-") {
|
|
1666
|
+
string2 = "-";
|
|
1667
|
+
next("-");
|
|
1668
|
+
}
|
|
1669
|
+
while (ch >= "0" && ch <= "9") {
|
|
1670
|
+
string2 += ch;
|
|
1671
|
+
next();
|
|
1672
|
+
}
|
|
1673
|
+
if (ch === ".") {
|
|
1674
|
+
string2 += ".";
|
|
1675
|
+
while (next() && ch >= "0" && ch <= "9") {
|
|
1676
|
+
string2 += ch;
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
if (ch === "e" || ch === "E") {
|
|
1680
|
+
string2 += ch;
|
|
1681
|
+
next();
|
|
1682
|
+
if (ch === "-" || ch === "+") {
|
|
1683
|
+
string2 += ch;
|
|
1684
|
+
next();
|
|
1685
|
+
}
|
|
1686
|
+
while (ch >= "0" && ch <= "9") {
|
|
1687
|
+
string2 += ch;
|
|
1688
|
+
next();
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
number2 = +string2;
|
|
1692
|
+
if (!isFinite(number2)) {
|
|
1693
|
+
error("Bad number");
|
|
1694
|
+
} else {
|
|
1695
|
+
if (BigNumber == null)
|
|
1696
|
+
BigNumber = require_bignumber();
|
|
1697
|
+
if (string2.length > 15)
|
|
1698
|
+
return _options.storeAsString ? string2 : _options.useNativeBigInt ? BigInt(string2) : new BigNumber(string2);
|
|
1699
|
+
else
|
|
1700
|
+
return !_options.alwaysParseAsBig ? number2 : _options.useNativeBigInt ? BigInt(number2) : new BigNumber(number2);
|
|
1701
|
+
}
|
|
1702
|
+
}, string = function() {
|
|
1703
|
+
var hex, i, string2 = "", uffff;
|
|
1704
|
+
if (ch === '"') {
|
|
1705
|
+
var startAt = at;
|
|
1706
|
+
while (next()) {
|
|
1707
|
+
if (ch === '"') {
|
|
1708
|
+
if (at - 1 > startAt)
|
|
1709
|
+
string2 += text.substring(startAt, at - 1);
|
|
1710
|
+
next();
|
|
1711
|
+
return string2;
|
|
1712
|
+
}
|
|
1713
|
+
if (ch === "\\") {
|
|
1714
|
+
if (at - 1 > startAt)
|
|
1715
|
+
string2 += text.substring(startAt, at - 1);
|
|
1716
|
+
next();
|
|
1717
|
+
if (ch === "u") {
|
|
1718
|
+
uffff = 0;
|
|
1719
|
+
for (i = 0;i < 4; i += 1) {
|
|
1720
|
+
hex = parseInt(next(), 16);
|
|
1721
|
+
if (!isFinite(hex)) {
|
|
1722
|
+
break;
|
|
1723
|
+
}
|
|
1724
|
+
uffff = uffff * 16 + hex;
|
|
1725
|
+
}
|
|
1726
|
+
string2 += String.fromCharCode(uffff);
|
|
1727
|
+
} else if (typeof escapee[ch] === "string") {
|
|
1728
|
+
string2 += escapee[ch];
|
|
1729
|
+
} else {
|
|
1730
|
+
break;
|
|
1731
|
+
}
|
|
1732
|
+
startAt = at;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
error("Bad string");
|
|
1737
|
+
}, white = function() {
|
|
1738
|
+
while (ch && ch <= " ") {
|
|
1739
|
+
next();
|
|
1740
|
+
}
|
|
1741
|
+
}, word = function() {
|
|
1742
|
+
switch (ch) {
|
|
1743
|
+
case "t":
|
|
1744
|
+
next("t");
|
|
1745
|
+
next("r");
|
|
1746
|
+
next("u");
|
|
1747
|
+
next("e");
|
|
1748
|
+
return true;
|
|
1749
|
+
case "f":
|
|
1750
|
+
next("f");
|
|
1751
|
+
next("a");
|
|
1752
|
+
next("l");
|
|
1753
|
+
next("s");
|
|
1754
|
+
next("e");
|
|
1755
|
+
return false;
|
|
1756
|
+
case "n":
|
|
1757
|
+
next("n");
|
|
1758
|
+
next("u");
|
|
1759
|
+
next("l");
|
|
1760
|
+
next("l");
|
|
1761
|
+
return null;
|
|
1762
|
+
}
|
|
1763
|
+
error("Unexpected '" + ch + "'");
|
|
1764
|
+
}, value, array = function() {
|
|
1765
|
+
var array2 = [];
|
|
1766
|
+
if (ch === "[") {
|
|
1767
|
+
next("[");
|
|
1768
|
+
white();
|
|
1769
|
+
if (ch === "]") {
|
|
1770
|
+
next("]");
|
|
1771
|
+
return array2;
|
|
1772
|
+
}
|
|
1773
|
+
while (ch) {
|
|
1774
|
+
array2.push(value());
|
|
1775
|
+
white();
|
|
1776
|
+
if (ch === "]") {
|
|
1777
|
+
next("]");
|
|
1778
|
+
return array2;
|
|
1779
|
+
}
|
|
1780
|
+
next(",");
|
|
1781
|
+
white();
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
error("Bad array");
|
|
1785
|
+
}, object = function() {
|
|
1786
|
+
var key, object2 = Object.create(null);
|
|
1787
|
+
if (ch === "{") {
|
|
1788
|
+
next("{");
|
|
1789
|
+
white();
|
|
1790
|
+
if (ch === "}") {
|
|
1791
|
+
next("}");
|
|
1792
|
+
return object2;
|
|
1793
|
+
}
|
|
1794
|
+
while (ch) {
|
|
1795
|
+
key = string();
|
|
1796
|
+
white();
|
|
1797
|
+
next(":");
|
|
1798
|
+
if (_options.strict === true && Object.hasOwnProperty.call(object2, key)) {
|
|
1799
|
+
error('Duplicate key "' + key + '"');
|
|
1800
|
+
}
|
|
1801
|
+
if (suspectProtoRx.test(key) === true) {
|
|
1802
|
+
if (_options.protoAction === "error") {
|
|
1803
|
+
error("Object contains forbidden prototype property");
|
|
1804
|
+
} else if (_options.protoAction === "ignore") {
|
|
1805
|
+
value();
|
|
1806
|
+
} else {
|
|
1807
|
+
object2[key] = value();
|
|
1808
|
+
}
|
|
1809
|
+
} else if (suspectConstructorRx.test(key) === true) {
|
|
1810
|
+
if (_options.constructorAction === "error") {
|
|
1811
|
+
error("Object contains forbidden constructor property");
|
|
1812
|
+
} else if (_options.constructorAction === "ignore") {
|
|
1813
|
+
value();
|
|
1814
|
+
} else {
|
|
1815
|
+
object2[key] = value();
|
|
1816
|
+
}
|
|
1817
|
+
} else {
|
|
1818
|
+
object2[key] = value();
|
|
1819
|
+
}
|
|
1820
|
+
white();
|
|
1821
|
+
if (ch === "}") {
|
|
1822
|
+
next("}");
|
|
1823
|
+
return object2;
|
|
1824
|
+
}
|
|
1825
|
+
next(",");
|
|
1826
|
+
white();
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
error("Bad object");
|
|
1830
|
+
};
|
|
1831
|
+
value = function() {
|
|
1832
|
+
white();
|
|
1833
|
+
switch (ch) {
|
|
1834
|
+
case "{":
|
|
1835
|
+
return object();
|
|
1836
|
+
case "[":
|
|
1837
|
+
return array();
|
|
1838
|
+
case '"':
|
|
1839
|
+
return string();
|
|
1840
|
+
case "-":
|
|
1841
|
+
return number();
|
|
1842
|
+
default:
|
|
1843
|
+
return ch >= "0" && ch <= "9" ? number() : word();
|
|
1844
|
+
}
|
|
1845
|
+
};
|
|
1846
|
+
return function(source, reviver) {
|
|
1847
|
+
var result;
|
|
1848
|
+
text = source + "";
|
|
1849
|
+
at = 0;
|
|
1850
|
+
ch = " ";
|
|
1851
|
+
result = value();
|
|
1852
|
+
white();
|
|
1853
|
+
if (ch) {
|
|
1854
|
+
error("Syntax error");
|
|
1855
|
+
}
|
|
1856
|
+
return typeof reviver === "function" ? function walk(holder, key) {
|
|
1857
|
+
var k, v, value2 = holder[key];
|
|
1858
|
+
if (value2 && typeof value2 === "object") {
|
|
1859
|
+
Object.keys(value2).forEach(function(k2) {
|
|
1860
|
+
v = walk(value2, k2);
|
|
1861
|
+
if (v !== undefined) {
|
|
1862
|
+
value2[k2] = v;
|
|
1863
|
+
} else {
|
|
1864
|
+
delete value2[k2];
|
|
1865
|
+
}
|
|
1866
|
+
});
|
|
1867
|
+
}
|
|
1868
|
+
return reviver.call(holder, key, value2);
|
|
1869
|
+
}({ "": result }, "") : result;
|
|
1870
|
+
};
|
|
1871
|
+
};
|
|
1872
|
+
module.exports = json_parse;
|
|
1873
|
+
});
|
|
3
1874
|
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
1875
|
+
// node_modules/.bun/json-bigint@1.0.0/node_modules/json-bigint/index.js
|
|
1876
|
+
var require_json_bigint = __commonJS((exports, module) => {
|
|
1877
|
+
var json_stringify = require_stringify().stringify;
|
|
1878
|
+
var json_parse = require_parse();
|
|
1879
|
+
module.exports = function(options) {
|
|
1880
|
+
return {
|
|
1881
|
+
parse: json_parse(options),
|
|
1882
|
+
stringify: json_stringify
|
|
1883
|
+
};
|
|
1884
|
+
};
|
|
1885
|
+
module.exports.parse = json_parse();
|
|
1886
|
+
module.exports.stringify = json_stringify;
|
|
1887
|
+
});
|
|
1888
|
+
|
|
1889
|
+
// src/lib/search/cache.ts
|
|
1890
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
1891
|
+
import path2 from "node:path";
|
|
1892
|
+
|
|
1893
|
+
// node_modules/.bun/env-paths@4.0.0/node_modules/env-paths/index.js
|
|
1894
|
+
import path from "node:path";
|
|
1895
|
+
import os from "node:os";
|
|
1896
|
+
import process2 from "node:process";
|
|
1897
|
+
|
|
1898
|
+
// node_modules/.bun/is-safe-filename@0.1.1/node_modules/is-safe-filename/index.js
|
|
1899
|
+
var unsafeFilenameFixtures = Object.freeze([
|
|
1900
|
+
"",
|
|
1901
|
+
" ",
|
|
1902
|
+
".",
|
|
1903
|
+
"..",
|
|
1904
|
+
" .",
|
|
1905
|
+
". ",
|
|
1906
|
+
" ..",
|
|
1907
|
+
".. ",
|
|
1908
|
+
"../",
|
|
1909
|
+
"../foo",
|
|
1910
|
+
"foo/../bar",
|
|
1911
|
+
"foo/bar",
|
|
1912
|
+
"foo\\bar",
|
|
1913
|
+
"foo\x00bar"
|
|
1914
|
+
]);
|
|
1915
|
+
function isSafeFilename(filename) {
|
|
1916
|
+
if (typeof filename !== "string") {
|
|
1917
|
+
return false;
|
|
1918
|
+
}
|
|
1919
|
+
const trimmed = filename.trim();
|
|
1920
|
+
return trimmed !== "" && trimmed !== "." && trimmed !== ".." && !filename.includes("/") && !filename.includes("\\") && !filename.includes("\x00");
|
|
1921
|
+
}
|
|
1922
|
+
function assertSafeFilename(filename) {
|
|
1923
|
+
if (typeof filename !== "string") {
|
|
1924
|
+
throw new TypeError("Expected a string");
|
|
1925
|
+
}
|
|
1926
|
+
if (!isSafeFilename(filename)) {
|
|
1927
|
+
throw new Error(`Unsafe filename: ${JSON.stringify(filename)}`);
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
// node_modules/.bun/env-paths@4.0.0/node_modules/env-paths/index.js
|
|
1932
|
+
var homedir = os.homedir();
|
|
1933
|
+
var tmpdir = os.tmpdir();
|
|
1934
|
+
var { env } = process2;
|
|
1935
|
+
var macos = (name) => {
|
|
1936
|
+
const library = path.join(homedir, "Library");
|
|
1937
|
+
return {
|
|
1938
|
+
data: path.join(library, "Application Support", name),
|
|
1939
|
+
config: path.join(library, "Preferences", name),
|
|
1940
|
+
cache: path.join(library, "Caches", name),
|
|
1941
|
+
log: path.join(library, "Logs", name),
|
|
1942
|
+
temp: path.join(tmpdir, name)
|
|
1943
|
+
};
|
|
1944
|
+
};
|
|
1945
|
+
var windows = (name) => {
|
|
1946
|
+
const appData = env.APPDATA || path.join(homedir, "AppData", "Roaming");
|
|
1947
|
+
const localAppData = env.LOCALAPPDATA || path.join(homedir, "AppData", "Local");
|
|
1948
|
+
return {
|
|
1949
|
+
data: path.join(localAppData, name, "Data"),
|
|
1950
|
+
config: path.join(appData, name, "Config"),
|
|
1951
|
+
cache: path.join(localAppData, name, "Cache"),
|
|
1952
|
+
log: path.join(localAppData, name, "Log"),
|
|
1953
|
+
temp: path.join(tmpdir, name)
|
|
1954
|
+
};
|
|
1955
|
+
};
|
|
1956
|
+
var linux = (name) => {
|
|
1957
|
+
const username = path.basename(homedir);
|
|
1958
|
+
return {
|
|
1959
|
+
data: path.join(env.XDG_DATA_HOME || path.join(homedir, ".local", "share"), name),
|
|
1960
|
+
config: path.join(env.XDG_CONFIG_HOME || path.join(homedir, ".config"), name),
|
|
1961
|
+
cache: path.join(env.XDG_CACHE_HOME || path.join(homedir, ".cache"), name),
|
|
1962
|
+
log: path.join(env.XDG_STATE_HOME || path.join(homedir, ".local", "state"), name),
|
|
1963
|
+
temp: path.join(tmpdir, username, name)
|
|
1964
|
+
};
|
|
1965
|
+
};
|
|
1966
|
+
function envPaths(name, { suffix = "nodejs" } = {}) {
|
|
1967
|
+
assertSafeFilename(name);
|
|
1968
|
+
if (suffix) {
|
|
1969
|
+
name += `-${suffix}`;
|
|
1970
|
+
}
|
|
1971
|
+
assertSafeFilename(name);
|
|
1972
|
+
if (process2.platform === "darwin") {
|
|
1973
|
+
return macos(name);
|
|
1974
|
+
}
|
|
1975
|
+
if (process2.platform === "win32") {
|
|
1976
|
+
return windows(name);
|
|
1977
|
+
}
|
|
1978
|
+
return linux(name);
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
// src/lib/search/cache.ts
|
|
1982
|
+
var defaultSearchIndexUrl = "https://adcli.jiangzhx.com/search-index.json";
|
|
1983
|
+
function getSearchIndexCacheInfo(options = {}) {
|
|
1984
|
+
const cacheDir = options.cacheDir ?? envPaths("adcli", { suffix: "" }).cache;
|
|
1985
|
+
return {
|
|
1986
|
+
cachePath: path2.join(cacheDir, "search-index.json"),
|
|
1987
|
+
indexUrl: options.indexUrl ?? defaultSearchIndexUrl
|
|
1988
|
+
};
|
|
1989
|
+
}
|
|
1990
|
+
async function loadSearchIndex(options = {}) {
|
|
1991
|
+
if (options.index) {
|
|
1992
|
+
return await loadExplicitSearchIndex(options.index, options.fetcher);
|
|
1993
|
+
}
|
|
1994
|
+
const cacheInfo = getSearchIndexCacheInfo(options);
|
|
1995
|
+
if (!options.refresh) {
|
|
1996
|
+
try {
|
|
1997
|
+
return JSON.parse(await readFile(cacheInfo.cachePath, "utf8"));
|
|
1998
|
+
} catch (error) {
|
|
1999
|
+
if (!isNotFoundError(error)) {
|
|
2000
|
+
throw error;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
return await refreshSearchIndex(options);
|
|
2005
|
+
}
|
|
2006
|
+
async function refreshSearchIndex(options = {}) {
|
|
2007
|
+
const cacheInfo = getSearchIndexCacheInfo(options);
|
|
2008
|
+
const index = await fetchSearchIndex(cacheInfo.indexUrl, options.fetcher);
|
|
2009
|
+
await writeCachedSearchIndex(cacheInfo.cachePath, index);
|
|
2010
|
+
return index;
|
|
2011
|
+
}
|
|
2012
|
+
async function loadExplicitSearchIndex(index, fetcher = fetch) {
|
|
2013
|
+
if (/^https?:\/\//i.test(index)) {
|
|
2014
|
+
return await fetchSearchIndex(index, fetcher);
|
|
2015
|
+
}
|
|
2016
|
+
try {
|
|
2017
|
+
return JSON.parse(await readFile(path2.resolve(index), "utf8"));
|
|
2018
|
+
} catch (error) {
|
|
2019
|
+
if (isNotFoundError(error)) {
|
|
2020
|
+
throw new Error(`missing search index: ${path2.relative(process.cwd(), path2.resolve(index))}`);
|
|
2021
|
+
}
|
|
2022
|
+
throw error;
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
async function fetchSearchIndex(indexUrl, fetcher = fetch) {
|
|
2026
|
+
const response = await fetcher(indexUrl);
|
|
2027
|
+
if (!response.ok) {
|
|
2028
|
+
throw new Error(`failed to fetch search index: ${indexUrl} (${response.status})`);
|
|
2029
|
+
}
|
|
2030
|
+
return await response.json();
|
|
2031
|
+
}
|
|
2032
|
+
async function writeCachedSearchIndex(cachePath, index) {
|
|
2033
|
+
await mkdir(path2.dirname(cachePath), { recursive: true });
|
|
2034
|
+
const tempPath = `${cachePath}.${process.pid}.tmp`;
|
|
2035
|
+
await writeFile(tempPath, `${JSON.stringify(index)}
|
|
2036
|
+
`, "utf8");
|
|
2037
|
+
await rename(tempPath, cachePath);
|
|
2038
|
+
}
|
|
2039
|
+
function isNotFoundError(error) {
|
|
2040
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
2041
|
+
}
|
|
7
2042
|
|
|
8
|
-
// node_modules/minisearch/dist/es/index.js
|
|
2043
|
+
// node_modules/.bun/minisearch@7.2.0/node_modules/minisearch/dist/es/index.js
|
|
9
2044
|
var ENTRIES = "ENTRIES";
|
|
10
2045
|
var KEYS = "KEYS";
|
|
11
2046
|
var VALUES = "VALUES";
|
|
@@ -131,9 +2166,9 @@ class SearchableMap {
|
|
|
131
2166
|
if (!prefix.startsWith(this._prefix)) {
|
|
132
2167
|
throw new Error("Mismatched prefix");
|
|
133
2168
|
}
|
|
134
|
-
const [node,
|
|
2169
|
+
const [node, path3] = trackDown(this._tree, prefix.slice(this._prefix.length));
|
|
135
2170
|
if (node === undefined) {
|
|
136
|
-
const [parentNode, key] = last(
|
|
2171
|
+
const [parentNode, key] = last(path3);
|
|
137
2172
|
for (const k of parentNode.keys()) {
|
|
138
2173
|
if (k !== LEAF && k.startsWith(key)) {
|
|
139
2174
|
const node2 = new Map;
|
|
@@ -231,18 +2266,18 @@ class SearchableMap {
|
|
|
231
2266
|
return SearchableMap.from(Object.entries(object));
|
|
232
2267
|
}
|
|
233
2268
|
}
|
|
234
|
-
var trackDown = (tree, key,
|
|
2269
|
+
var trackDown = (tree, key, path3 = []) => {
|
|
235
2270
|
if (key.length === 0 || tree == null) {
|
|
236
|
-
return [tree,
|
|
2271
|
+
return [tree, path3];
|
|
237
2272
|
}
|
|
238
2273
|
for (const k of tree.keys()) {
|
|
239
2274
|
if (k !== LEAF && key.startsWith(k)) {
|
|
240
|
-
|
|
241
|
-
return trackDown(tree.get(k), key.slice(k.length),
|
|
2275
|
+
path3.push([tree, k]);
|
|
2276
|
+
return trackDown(tree.get(k), key.slice(k.length), path3);
|
|
242
2277
|
}
|
|
243
2278
|
}
|
|
244
|
-
|
|
245
|
-
return trackDown(undefined, "",
|
|
2279
|
+
path3.push([tree, key]);
|
|
2280
|
+
return trackDown(undefined, "", path3);
|
|
246
2281
|
};
|
|
247
2282
|
var lookup = (tree, key) => {
|
|
248
2283
|
if (key.length === 0 || tree == null) {
|
|
@@ -285,38 +2320,38 @@ var createPath = (node, key) => {
|
|
|
285
2320
|
return node;
|
|
286
2321
|
};
|
|
287
2322
|
var remove = (tree, key) => {
|
|
288
|
-
const [node,
|
|
2323
|
+
const [node, path3] = trackDown(tree, key);
|
|
289
2324
|
if (node === undefined) {
|
|
290
2325
|
return;
|
|
291
2326
|
}
|
|
292
2327
|
node.delete(LEAF);
|
|
293
2328
|
if (node.size === 0) {
|
|
294
|
-
cleanup(
|
|
2329
|
+
cleanup(path3);
|
|
295
2330
|
} else if (node.size === 1) {
|
|
296
2331
|
const [key2, value] = node.entries().next().value;
|
|
297
|
-
merge(
|
|
2332
|
+
merge(path3, key2, value);
|
|
298
2333
|
}
|
|
299
2334
|
};
|
|
300
|
-
var cleanup = (
|
|
301
|
-
if (
|
|
2335
|
+
var cleanup = (path3) => {
|
|
2336
|
+
if (path3.length === 0) {
|
|
302
2337
|
return;
|
|
303
2338
|
}
|
|
304
|
-
const [node, key] = last(
|
|
2339
|
+
const [node, key] = last(path3);
|
|
305
2340
|
node.delete(key);
|
|
306
2341
|
if (node.size === 0) {
|
|
307
|
-
cleanup(
|
|
2342
|
+
cleanup(path3.slice(0, -1));
|
|
308
2343
|
} else if (node.size === 1) {
|
|
309
2344
|
const [key2, value] = node.entries().next().value;
|
|
310
2345
|
if (key2 !== LEAF) {
|
|
311
|
-
merge(
|
|
2346
|
+
merge(path3.slice(0, -1), key2, value);
|
|
312
2347
|
}
|
|
313
2348
|
}
|
|
314
2349
|
};
|
|
315
|
-
var merge = (
|
|
316
|
-
if (
|
|
2350
|
+
var merge = (path3, key, value) => {
|
|
2351
|
+
if (path3.length === 0) {
|
|
317
2352
|
return;
|
|
318
2353
|
}
|
|
319
|
-
const [node, nodeKey] = last(
|
|
2354
|
+
const [node, nodeKey] = last(path3);
|
|
320
2355
|
node.set(nodeKey + key, value);
|
|
321
2356
|
node.delete(nodeKey);
|
|
322
2357
|
};
|
|
@@ -1273,15 +3308,568 @@ function compact(value) {
|
|
|
1273
3308
|
return value.toLowerCase().replace(/\s+/g, "");
|
|
1274
3309
|
}
|
|
1275
3310
|
|
|
3311
|
+
// packages/oceanengine-ad-open-sdk/dist/runtime/ApiException.js
|
|
3312
|
+
class ApiException extends Error {
|
|
3313
|
+
statusCode;
|
|
3314
|
+
responseBody;
|
|
3315
|
+
headers;
|
|
3316
|
+
constructor(message, options = {}) {
|
|
3317
|
+
super(message);
|
|
3318
|
+
this.name = "ApiException";
|
|
3319
|
+
this.statusCode = options.statusCode;
|
|
3320
|
+
this.responseBody = options.responseBody;
|
|
3321
|
+
this.headers = options.headers;
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
|
|
3325
|
+
// packages/oceanengine-ad-open-sdk/dist/runtime/json.js
|
|
3326
|
+
var import_json_bigint = __toESM(require_json_bigint(), 1);
|
|
3327
|
+
var JSONBigStringParser = import_json_bigint.default({ storeAsString: true });
|
|
3328
|
+
function parseJsonPreservingLargeIntegers(text) {
|
|
3329
|
+
return JSONBigStringParser.parse(text);
|
|
3330
|
+
}
|
|
3331
|
+
|
|
3332
|
+
// packages/oceanengine-ad-open-sdk/dist/runtime/sdk-version.js
|
|
3333
|
+
var SDK_VERSION = "1.1.87";
|
|
3334
|
+
|
|
3335
|
+
// packages/oceanengine-ad-open-sdk/dist/runtime/ApiClient.js
|
|
3336
|
+
class ApiClient {
|
|
3337
|
+
basePath = "https://api.oceanengine.com";
|
|
3338
|
+
fetchImpl;
|
|
3339
|
+
defaultHeaders = new Headers;
|
|
3340
|
+
constructor(options = {}) {
|
|
3341
|
+
this.fetchImpl = options.fetch ?? fetch;
|
|
3342
|
+
if (options.basePath) {
|
|
3343
|
+
this.basePath = options.basePath;
|
|
3344
|
+
}
|
|
3345
|
+
this.setUserAgent("Bytedance Ads Openapi SDK");
|
|
3346
|
+
this.addDefaultHeader("X-Sdk-Language", "node");
|
|
3347
|
+
this.addDefaultHeader("X-Sdk-Version", SDK_VERSION);
|
|
3348
|
+
}
|
|
3349
|
+
getBasePath() {
|
|
3350
|
+
return this.basePath;
|
|
3351
|
+
}
|
|
3352
|
+
setBasePath(basePath) {
|
|
3353
|
+
this.basePath = basePath;
|
|
3354
|
+
return this;
|
|
3355
|
+
}
|
|
3356
|
+
setUserAgent(userAgent) {
|
|
3357
|
+
this.addDefaultHeader("User-Agent", userAgent);
|
|
3358
|
+
return this;
|
|
3359
|
+
}
|
|
3360
|
+
addDefaultHeader(name, value) {
|
|
3361
|
+
this.defaultHeaders.set(name, value);
|
|
3362
|
+
return this;
|
|
3363
|
+
}
|
|
3364
|
+
setAccessToken(token) {
|
|
3365
|
+
this.addDefaultHeader("Access-Token", token);
|
|
3366
|
+
return this;
|
|
3367
|
+
}
|
|
3368
|
+
buildUrl(path3, queryParams = []) {
|
|
3369
|
+
const url = new URL(path3, this.basePath);
|
|
3370
|
+
for (const param of queryParams) {
|
|
3371
|
+
if (param.value == null) {
|
|
3372
|
+
continue;
|
|
3373
|
+
}
|
|
3374
|
+
if (Array.isArray(param.value)) {
|
|
3375
|
+
if (param.collectionFormat === "multi") {
|
|
3376
|
+
for (const value of param.value) {
|
|
3377
|
+
url.searchParams.append(param.name, this.parameterToString(value));
|
|
3378
|
+
}
|
|
3379
|
+
continue;
|
|
3380
|
+
}
|
|
3381
|
+
if (param.collectionFormat !== "csv") {
|
|
3382
|
+
throw new ApiException(`Unsupported collection format for query parameter '${param.name}'`);
|
|
3383
|
+
}
|
|
3384
|
+
url.searchParams.append(param.name, param.value.map((value) => this.parameterToString(value)).join(","));
|
|
3385
|
+
continue;
|
|
3386
|
+
}
|
|
3387
|
+
url.searchParams.append(param.name, this.parameterToString(param.value));
|
|
3388
|
+
}
|
|
3389
|
+
return url;
|
|
3390
|
+
}
|
|
3391
|
+
async request(options) {
|
|
3392
|
+
const response = await this.requestWithHttpInfo(options);
|
|
3393
|
+
return response.data;
|
|
3394
|
+
}
|
|
3395
|
+
async requestWithHttpInfo(options) {
|
|
3396
|
+
const request = this.buildRequest(options);
|
|
3397
|
+
const response = await this.fetchImpl(request);
|
|
3398
|
+
const data = await this.readResponseBody(response, options.responseType);
|
|
3399
|
+
if (!response.ok) {
|
|
3400
|
+
throw new ApiException(`HTTP ${response.status}`, {
|
|
3401
|
+
statusCode: response.status,
|
|
3402
|
+
responseBody: data,
|
|
3403
|
+
headers: response.headers
|
|
3404
|
+
});
|
|
3405
|
+
}
|
|
3406
|
+
return {
|
|
3407
|
+
data,
|
|
3408
|
+
statusCode: response.status,
|
|
3409
|
+
headers: response.headers
|
|
3410
|
+
};
|
|
3411
|
+
}
|
|
3412
|
+
buildRequest(options) {
|
|
3413
|
+
const headers = new Headers(this.defaultHeaders);
|
|
3414
|
+
for (const [name, value] of Object.entries(options.headers ?? {})) {
|
|
3415
|
+
headers.set(name, value);
|
|
3416
|
+
}
|
|
3417
|
+
let body;
|
|
3418
|
+
if (options.method !== "GET" && (options.formParams || options.files)) {
|
|
3419
|
+
const contentType = options.contentType ?? "application/x-www-form-urlencoded";
|
|
3420
|
+
if (contentType === "multipart/form-data") {
|
|
3421
|
+
body = this.buildMultipartFormBody(options.formParams, options.files);
|
|
3422
|
+
} else if (contentType === "application/x-www-form-urlencoded") {
|
|
3423
|
+
headers.set("Content-Type", contentType);
|
|
3424
|
+
const formBody = new URLSearchParams;
|
|
3425
|
+
for (const [name, value] of Object.entries(options.formParams ?? {})) {
|
|
3426
|
+
if (value != null) {
|
|
3427
|
+
formBody.append(name, this.parameterToString(value));
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3430
|
+
body = formBody;
|
|
3431
|
+
} else {
|
|
3432
|
+
throw new ApiException(`Unsupported form content type '${contentType}'`);
|
|
3433
|
+
}
|
|
3434
|
+
} else if (options.method !== "GET" && options.body != null) {
|
|
3435
|
+
const contentType = options.contentType ?? "application/json";
|
|
3436
|
+
headers.set("Content-Type", contentType);
|
|
3437
|
+
body = contentType === "application/json" ? JSON.stringify(options.body) : String(options.body);
|
|
3438
|
+
}
|
|
3439
|
+
return new Request(this.buildUrl(options.path, options.queryParams), {
|
|
3440
|
+
method: options.method,
|
|
3441
|
+
headers,
|
|
3442
|
+
body
|
|
3443
|
+
});
|
|
3444
|
+
}
|
|
3445
|
+
buildMultipartFormBody(formParams = {}, files = {}) {
|
|
3446
|
+
const formBody = new FormData;
|
|
3447
|
+
for (const [name, value] of Object.entries(formParams)) {
|
|
3448
|
+
if (value != null) {
|
|
3449
|
+
formBody.append(name, this.parameterToString(value));
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
for (const [name, value] of Object.entries(files)) {
|
|
3453
|
+
if (value != null) {
|
|
3454
|
+
formBody.append(name, value);
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
return formBody;
|
|
3458
|
+
}
|
|
3459
|
+
async readResponseBody(response, responseType = "json") {
|
|
3460
|
+
if (responseType === "arrayBuffer") {
|
|
3461
|
+
return response.arrayBuffer();
|
|
3462
|
+
}
|
|
3463
|
+
const text = await response.text();
|
|
3464
|
+
if (!text) {
|
|
3465
|
+
return;
|
|
3466
|
+
}
|
|
3467
|
+
if (responseType === "text") {
|
|
3468
|
+
return text;
|
|
3469
|
+
}
|
|
3470
|
+
const contentType = response.headers.get("Content-Type") ?? "";
|
|
3471
|
+
if (contentType.includes("application/json")) {
|
|
3472
|
+
return parseJsonPreservingLargeIntegers(text);
|
|
3473
|
+
}
|
|
3474
|
+
return text;
|
|
3475
|
+
}
|
|
3476
|
+
parameterToString(value) {
|
|
3477
|
+
if (value instanceof Date) {
|
|
3478
|
+
return value.toISOString();
|
|
3479
|
+
}
|
|
3480
|
+
if (typeof value === "object" && value !== null) {
|
|
3481
|
+
return JSON.stringify(value);
|
|
3482
|
+
}
|
|
3483
|
+
return String(value);
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3486
|
+
// packages/oceanengine-ad-open-sdk/dist/apis/Oauth2AdvertiserGetApi.js
|
|
3487
|
+
class Oauth2AdvertiserGetApi {
|
|
3488
|
+
apiClient;
|
|
3489
|
+
constructor(apiClient = new ApiClient) {
|
|
3490
|
+
this.apiClient = apiClient;
|
|
3491
|
+
}
|
|
3492
|
+
getApiClient() {
|
|
3493
|
+
return this.apiClient;
|
|
3494
|
+
}
|
|
3495
|
+
setApiClient(apiClient) {
|
|
3496
|
+
this.apiClient = apiClient;
|
|
3497
|
+
}
|
|
3498
|
+
async openApiOauth2AdvertiserGetGet(request) {
|
|
3499
|
+
const response = await this.openApiOauth2AdvertiserGetGetWithHttpInfo(request);
|
|
3500
|
+
return response.data;
|
|
3501
|
+
}
|
|
3502
|
+
async openApiOauth2AdvertiserGetGetWithHttpInfo(request) {
|
|
3503
|
+
return this.apiClient.requestWithHttpInfo({
|
|
3504
|
+
method: "GET",
|
|
3505
|
+
path: "/open_api/oauth2/advertiser/get/",
|
|
3506
|
+
queryParams: [
|
|
3507
|
+
{ name: "access_token", value: request.accessToken }
|
|
3508
|
+
]
|
|
3509
|
+
});
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
|
|
3513
|
+
// packages/oceanengine-ad-open-sdk/dist/apis/ProjectListV30Api.js
|
|
3514
|
+
class ProjectListV30Api {
|
|
3515
|
+
apiClient;
|
|
3516
|
+
constructor(apiClient = new ApiClient) {
|
|
3517
|
+
this.apiClient = apiClient;
|
|
3518
|
+
}
|
|
3519
|
+
getApiClient() {
|
|
3520
|
+
return this.apiClient;
|
|
3521
|
+
}
|
|
3522
|
+
setApiClient(apiClient) {
|
|
3523
|
+
this.apiClient = apiClient;
|
|
3524
|
+
}
|
|
3525
|
+
async openApiV30ProjectListGet(request) {
|
|
3526
|
+
const response = await this.openApiV30ProjectListGetWithHttpInfo(request);
|
|
3527
|
+
return response.data;
|
|
3528
|
+
}
|
|
3529
|
+
async openApiV30ProjectListGetWithHttpInfo(request) {
|
|
3530
|
+
if (request.advertiserId == null) {
|
|
3531
|
+
throw new ApiException("Missing the required parameter 'advertiserId' when calling openApiV30ProjectListGet");
|
|
3532
|
+
}
|
|
3533
|
+
return this.apiClient.requestWithHttpInfo({
|
|
3534
|
+
method: "GET",
|
|
3535
|
+
path: "/open_api/v3.0/project/list/",
|
|
3536
|
+
queryParams: [
|
|
3537
|
+
{ name: "fields", value: request.fields, collectionFormat: "csv" },
|
|
3538
|
+
{ name: "filtering", value: request.filtering },
|
|
3539
|
+
{ name: "advertiser_id", value: request.advertiserId },
|
|
3540
|
+
{ name: "page", value: request.page },
|
|
3541
|
+
{ name: "page_size", value: request.pageSize }
|
|
3542
|
+
]
|
|
3543
|
+
});
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
|
|
3547
|
+
// packages/oceanengine-ad-open-sdk/dist/apis/PromotionListV30Api.js
|
|
3548
|
+
class PromotionListV30Api {
|
|
3549
|
+
apiClient;
|
|
3550
|
+
constructor(apiClient = new ApiClient) {
|
|
3551
|
+
this.apiClient = apiClient;
|
|
3552
|
+
}
|
|
3553
|
+
getApiClient() {
|
|
3554
|
+
return this.apiClient;
|
|
3555
|
+
}
|
|
3556
|
+
setApiClient(apiClient) {
|
|
3557
|
+
this.apiClient = apiClient;
|
|
3558
|
+
}
|
|
3559
|
+
async openApiV30PromotionListGet(request) {
|
|
3560
|
+
const response = await this.openApiV30PromotionListGetWithHttpInfo(request);
|
|
3561
|
+
return response.data;
|
|
3562
|
+
}
|
|
3563
|
+
async openApiV30PromotionListGetWithHttpInfo(request) {
|
|
3564
|
+
if (request.advertiserId == null) {
|
|
3565
|
+
throw new ApiException("Missing the required parameter 'advertiserId' when calling openApiV30PromotionListGet");
|
|
3566
|
+
}
|
|
3567
|
+
return this.apiClient.requestWithHttpInfo({
|
|
3568
|
+
method: "GET",
|
|
3569
|
+
path: "/open_api/v3.0/promotion/list/",
|
|
3570
|
+
queryParams: [
|
|
3571
|
+
{ name: "advertiser_id", value: request.advertiserId },
|
|
3572
|
+
{ name: "filtering", value: request.filtering },
|
|
3573
|
+
{ name: "fields", value: request.fields, collectionFormat: "csv" },
|
|
3574
|
+
{ name: "including_material_atrributes", value: request.includingMaterialAtrributes },
|
|
3575
|
+
{ name: "page", value: request.page },
|
|
3576
|
+
{ name: "page_size", value: request.pageSize },
|
|
3577
|
+
{ name: "cursor", value: request.cursor },
|
|
3578
|
+
{ name: "count", value: request.count }
|
|
3579
|
+
]
|
|
3580
|
+
});
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
// src/commands/oceanengine/config.ts
|
|
3584
|
+
import { chmod, mkdir as mkdir2, readFile as readFile2, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
|
|
3585
|
+
import path3 from "node:path";
|
|
3586
|
+
function getOceanEngineConfigInfo(options = {}) {
|
|
3587
|
+
const configDir = options.configDir ?? envPaths("adcli", { suffix: "" }).cache;
|
|
3588
|
+
return {
|
|
3589
|
+
configPath: path3.join(configDir, "oceanengine.json")
|
|
3590
|
+
};
|
|
3591
|
+
}
|
|
3592
|
+
async function saveOceanEngineAccessToken(token, options = {}) {
|
|
3593
|
+
const trimmed = token.trim();
|
|
3594
|
+
if (!trimmed) {
|
|
3595
|
+
throw new Error("missing OceanEngine token");
|
|
3596
|
+
}
|
|
3597
|
+
const configInfo = getOceanEngineConfigInfo(options);
|
|
3598
|
+
await mkdir2(path3.dirname(configInfo.configPath), { recursive: true });
|
|
3599
|
+
const tempPath = `${configInfo.configPath}.${process.pid}.tmp`;
|
|
3600
|
+
await writeFile2(tempPath, `${JSON.stringify({ access_token: trimmed })}
|
|
3601
|
+
`, {
|
|
3602
|
+
encoding: "utf8",
|
|
3603
|
+
mode: 384
|
|
3604
|
+
});
|
|
3605
|
+
await rename2(tempPath, configInfo.configPath);
|
|
3606
|
+
await chmod(configInfo.configPath, 384);
|
|
3607
|
+
return configInfo;
|
|
3608
|
+
}
|
|
3609
|
+
async function loadOceanEngineAccessToken(options = {}) {
|
|
3610
|
+
const configInfo = getOceanEngineConfigInfo(options);
|
|
3611
|
+
let config;
|
|
3612
|
+
try {
|
|
3613
|
+
config = JSON.parse(await readFile2(configInfo.configPath, "utf8"));
|
|
3614
|
+
} catch (error) {
|
|
3615
|
+
if (isNotFoundError2(error)) {
|
|
3616
|
+
return;
|
|
3617
|
+
}
|
|
3618
|
+
throw error;
|
|
3619
|
+
}
|
|
3620
|
+
if (typeof config.access_token !== "string" || !config.access_token.trim()) {
|
|
3621
|
+
return;
|
|
3622
|
+
}
|
|
3623
|
+
return config.access_token.trim();
|
|
3624
|
+
}
|
|
3625
|
+
function isNotFoundError2(error) {
|
|
3626
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
3627
|
+
}
|
|
3628
|
+
|
|
3629
|
+
// src/commands/oceanengine/commands.ts
|
|
3630
|
+
async function runOceanEngineCommand(argv, options = {}) {
|
|
3631
|
+
const args = parseOceanEngineArgs(argv);
|
|
3632
|
+
if (args.resource === "auth") {
|
|
3633
|
+
const token2 = args.action;
|
|
3634
|
+
if (!token2) {
|
|
3635
|
+
throw new Error("missing OceanEngine token");
|
|
3636
|
+
}
|
|
3637
|
+
const configInfo = await saveOceanEngineAccessToken(token2, { configDir: options.configDir });
|
|
3638
|
+
return {
|
|
3639
|
+
ok: true,
|
|
3640
|
+
config_path: configInfo.configPath
|
|
3641
|
+
};
|
|
3642
|
+
}
|
|
3643
|
+
const token = await resolveAccessToken(args, options);
|
|
3644
|
+
const apiClient = new ApiClient({ fetch: options.fetch }).setAccessToken(token);
|
|
3645
|
+
if (args.resource === "advertiser" && args.action === "list") {
|
|
3646
|
+
return new Oauth2AdvertiserGetApi(apiClient).openApiOauth2AdvertiserGetGet({ accessToken: token });
|
|
3647
|
+
}
|
|
3648
|
+
if (isProjectListCommand(args)) {
|
|
3649
|
+
const advertiserId = getRequiredId(args, "advertiser-id");
|
|
3650
|
+
return new ProjectListV30Api(apiClient).openApiV30ProjectListGet({
|
|
3651
|
+
advertiserId,
|
|
3652
|
+
fields: parseCsv(args.flags.fields),
|
|
3653
|
+
filtering: parseJsonFlag(args.flags.filtering),
|
|
3654
|
+
page: parseNumberFlag(args.flags.page),
|
|
3655
|
+
pageSize: parseNumberFlag(args.flags["page-size"])
|
|
3656
|
+
});
|
|
3657
|
+
}
|
|
3658
|
+
if (args.resource === "promotion" && args.action === "list") {
|
|
3659
|
+
const advertiserId = getRequiredId(args, "advertiser-id");
|
|
3660
|
+
const filtering = {
|
|
3661
|
+
...parseJsonFlag(args.flags.filtering),
|
|
3662
|
+
...parseProjectFilter(args.flags["project-id"])
|
|
3663
|
+
};
|
|
3664
|
+
return new PromotionListV30Api(apiClient).openApiV30PromotionListGet({
|
|
3665
|
+
advertiserId,
|
|
3666
|
+
filtering: Object.keys(filtering).length > 0 ? filtering : undefined,
|
|
3667
|
+
fields: parseCsv(args.flags.fields),
|
|
3668
|
+
includingMaterialAtrributes: args.flags["including-material-attributes"],
|
|
3669
|
+
page: parseNumberFlag(args.flags.page),
|
|
3670
|
+
pageSize: parseNumberFlag(args.flags["page-size"]),
|
|
3671
|
+
cursor: parseNumberFlag(args.flags.cursor),
|
|
3672
|
+
count: parseNumberFlag(args.flags.count)
|
|
3673
|
+
});
|
|
3674
|
+
}
|
|
3675
|
+
throw new Error(`unknown oceanengine command: ${[args.resource, args.action].filter(Boolean).join(" ")}`);
|
|
3676
|
+
}
|
|
3677
|
+
function formatOceanEngineOutput(payload, json, argv = []) {
|
|
3678
|
+
if (json) {
|
|
3679
|
+
return JSON.stringify(payload, null, 2);
|
|
3680
|
+
}
|
|
3681
|
+
if (isOceanEngineErrorPayload(payload)) {
|
|
3682
|
+
return JSON.stringify(payload, null, 2);
|
|
3683
|
+
}
|
|
3684
|
+
if (argv[0] === "project" && argv[1] === "list") {
|
|
3685
|
+
return formatEntityList(payload, "project_id", ["project_id", "id"], ["name", "project_name"]);
|
|
3686
|
+
}
|
|
3687
|
+
if (argv[0] === "promotion" && argv[1] === "list") {
|
|
3688
|
+
return formatEntityList(payload, "promotion_id", ["promotion_id", "id"], ["name", "promotion_name"]);
|
|
3689
|
+
}
|
|
3690
|
+
return JSON.stringify(payload, null, 2);
|
|
3691
|
+
}
|
|
3692
|
+
function formatOceanEngineError(error) {
|
|
3693
|
+
if (!isRecord(error) || !("responseBody" in error)) {
|
|
3694
|
+
return;
|
|
3695
|
+
}
|
|
3696
|
+
const responseBody = error.responseBody;
|
|
3697
|
+
if (responseBody == null) {
|
|
3698
|
+
return;
|
|
3699
|
+
}
|
|
3700
|
+
if (typeof responseBody === "string") {
|
|
3701
|
+
return responseBody;
|
|
3702
|
+
}
|
|
3703
|
+
return JSON.stringify(responseBody, null, 2);
|
|
3704
|
+
}
|
|
3705
|
+
function parseOceanEngineArgs(argv) {
|
|
3706
|
+
const args = {
|
|
3707
|
+
resource: argv[0],
|
|
3708
|
+
action: argv[1],
|
|
3709
|
+
flags: {}
|
|
3710
|
+
};
|
|
3711
|
+
for (let index = 2;index < argv.length; index += 1) {
|
|
3712
|
+
const value = argv[index];
|
|
3713
|
+
if (!value?.startsWith("--")) {
|
|
3714
|
+
continue;
|
|
3715
|
+
}
|
|
3716
|
+
const name = value.slice(2);
|
|
3717
|
+
const next = argv[index + 1];
|
|
3718
|
+
if (!next || next.startsWith("--")) {
|
|
3719
|
+
args.flags[name] = true;
|
|
3720
|
+
continue;
|
|
3721
|
+
}
|
|
3722
|
+
args.flags[name] = next;
|
|
3723
|
+
index += 1;
|
|
3724
|
+
}
|
|
3725
|
+
return args;
|
|
3726
|
+
}
|
|
3727
|
+
async function resolveAccessToken(args, options) {
|
|
3728
|
+
const explicitToken = getOptionalString(args.flags["access-token"]);
|
|
3729
|
+
if (explicitToken) {
|
|
3730
|
+
return explicitToken;
|
|
3731
|
+
}
|
|
3732
|
+
const env2 = options.env ?? process.env;
|
|
3733
|
+
const envToken = getOptionalString(env2.OCEANENGINE_ACCESS_TOKEN);
|
|
3734
|
+
if (envToken) {
|
|
3735
|
+
return envToken;
|
|
3736
|
+
}
|
|
3737
|
+
const savedToken = await loadOceanEngineAccessToken({ configDir: options.configDir });
|
|
3738
|
+
if (savedToken) {
|
|
3739
|
+
return savedToken;
|
|
3740
|
+
}
|
|
3741
|
+
throw new Error("missing --access-token; run adcli oceanengine auth <token> or set OCEANENGINE_ACCESS_TOKEN");
|
|
3742
|
+
}
|
|
3743
|
+
function getRequiredString(args, flag) {
|
|
3744
|
+
const value = getOptionalString(args.flags[flag]);
|
|
3745
|
+
if (!value) {
|
|
3746
|
+
throw new Error(`missing --${flag}`);
|
|
3747
|
+
}
|
|
3748
|
+
return value;
|
|
3749
|
+
}
|
|
3750
|
+
function getOptionalString(value) {
|
|
3751
|
+
if (typeof value !== "string" || !value) {
|
|
3752
|
+
return;
|
|
3753
|
+
}
|
|
3754
|
+
return value;
|
|
3755
|
+
}
|
|
3756
|
+
function getRequiredId(args, flag) {
|
|
3757
|
+
const value = getRequiredString(args, flag);
|
|
3758
|
+
if (!/^\d+$/.test(value)) {
|
|
3759
|
+
throw new Error(`--${flag} must be an integer id`);
|
|
3760
|
+
}
|
|
3761
|
+
return value;
|
|
3762
|
+
}
|
|
3763
|
+
function parseNumberFlag(value) {
|
|
3764
|
+
if (value == null || value === true) {
|
|
3765
|
+
return;
|
|
3766
|
+
}
|
|
3767
|
+
const parsed = Number(value);
|
|
3768
|
+
if (!Number.isFinite(parsed)) {
|
|
3769
|
+
throw new Error(`numeric flag must be a number: ${value}`);
|
|
3770
|
+
}
|
|
3771
|
+
return parsed;
|
|
3772
|
+
}
|
|
3773
|
+
function parseCsv(value) {
|
|
3774
|
+
if (typeof value !== "string" || !value) {
|
|
3775
|
+
return;
|
|
3776
|
+
}
|
|
3777
|
+
return value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
3778
|
+
}
|
|
3779
|
+
function parseJsonFlag(value) {
|
|
3780
|
+
if (typeof value !== "string" || !value) {
|
|
3781
|
+
return;
|
|
3782
|
+
}
|
|
3783
|
+
return parseJsonPreservingLargeIntegers(value);
|
|
3784
|
+
}
|
|
3785
|
+
function parseProjectFilter(value) {
|
|
3786
|
+
if (typeof value !== "string" || !value) {
|
|
3787
|
+
return {};
|
|
3788
|
+
}
|
|
3789
|
+
if (!/^\d+$/.test(value)) {
|
|
3790
|
+
throw new Error("--project-id must be an integer id");
|
|
3791
|
+
}
|
|
3792
|
+
return { project_id: value };
|
|
3793
|
+
}
|
|
3794
|
+
function isProjectListCommand(args) {
|
|
3795
|
+
return args.resource === "project" && args.action === "list";
|
|
3796
|
+
}
|
|
3797
|
+
function formatEntityList(payload, idHeader, idKeys, nameKeys) {
|
|
3798
|
+
const list = getPayloadList(payload);
|
|
3799
|
+
const header = `${idHeader} name`;
|
|
3800
|
+
if (list.length === 0) {
|
|
3801
|
+
return header;
|
|
3802
|
+
}
|
|
3803
|
+
return [
|
|
3804
|
+
header,
|
|
3805
|
+
...list.map((item) => {
|
|
3806
|
+
const id = getRecordValue(item, idKeys);
|
|
3807
|
+
const name = getRecordValue(item, nameKeys);
|
|
3808
|
+
return `${id} ${name}`;
|
|
3809
|
+
})
|
|
3810
|
+
].join(`
|
|
3811
|
+
`);
|
|
3812
|
+
}
|
|
3813
|
+
function getPayloadList(payload) {
|
|
3814
|
+
if (!isRecord(payload) || !isRecord(payload.data) || !Array.isArray(payload.data.list)) {
|
|
3815
|
+
return [];
|
|
3816
|
+
}
|
|
3817
|
+
return payload.data.list.filter(isRecord);
|
|
3818
|
+
}
|
|
3819
|
+
function getRecordValue(record, keys) {
|
|
3820
|
+
for (const key of keys) {
|
|
3821
|
+
const value = record[key];
|
|
3822
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
3823
|
+
return String(value);
|
|
3824
|
+
}
|
|
3825
|
+
}
|
|
3826
|
+
return "";
|
|
3827
|
+
}
|
|
3828
|
+
function isRecord(value) {
|
|
3829
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3830
|
+
}
|
|
3831
|
+
function isOceanEngineErrorPayload(payload) {
|
|
3832
|
+
return isRecord(payload) && typeof payload.code === "number" && payload.code !== 0;
|
|
3833
|
+
}
|
|
3834
|
+
|
|
1276
3835
|
// src/cli.ts
|
|
1277
|
-
var defaultSearchIndexUrl = "https://adcli.jiangzhx.com/search-index.json";
|
|
1278
3836
|
var help = `adcli
|
|
1279
3837
|
|
|
1280
3838
|
Usage:
|
|
1281
|
-
adcli
|
|
3839
|
+
adcli list [platform] [--json]
|
|
3840
|
+
adcli doc <command>
|
|
3841
|
+
adcli oceanengine <resource> <command>
|
|
3842
|
+
adcli prompt
|
|
3843
|
+
adcli llms
|
|
1282
3844
|
|
|
1283
3845
|
Commands:
|
|
1284
|
-
|
|
3846
|
+
list List supported advertising platforms and capabilities
|
|
3847
|
+
doc Search and sync published advertising API docs
|
|
3848
|
+
oceanengine Call OceanEngine APIs through the generated Node.js SDK
|
|
3849
|
+
prompt Print an AI/Agent instruction prompt for using the docs pack
|
|
3850
|
+
llms Print LLM-readable docs pack entry URLs
|
|
3851
|
+
`;
|
|
3852
|
+
var docHelp = `adcli doc
|
|
3853
|
+
|
|
3854
|
+
Usage:
|
|
3855
|
+
adcli doc search <query> [--platform tencent_ads] [--limit 10] [--json] [--refresh]
|
|
3856
|
+
adcli doc sync
|
|
3857
|
+
|
|
3858
|
+
Commands:
|
|
3859
|
+
search Search published advertising API docs
|
|
3860
|
+
sync Download and cache the latest search index
|
|
3861
|
+
`;
|
|
3862
|
+
var oceanEngineHelp = `adcli oceanengine
|
|
3863
|
+
|
|
3864
|
+
Usage:
|
|
3865
|
+
adcli oceanengine auth <token>
|
|
3866
|
+
adcli oceanengine advertiser list [--access-token token] [--json]
|
|
3867
|
+
adcli oceanengine project list --advertiser-id 123 [--access-token token] [--page 1] [--page-size 20] [--filtering '{"status":"PROJECT_STATUS_ALL"}'] [--json]
|
|
3868
|
+
adcli oceanengine promotion list --advertiser-id 123 [--access-token token] [--project-id 456] [--fields promotion_id,name,status_first] [--filtering '{}'] [--json]
|
|
3869
|
+
|
|
3870
|
+
Environment:
|
|
3871
|
+
Token precedence is --access-token, OCEANENGINE_ACCESS_TOKEN, then the saved token.
|
|
3872
|
+
Project list does not include deleted projects by default; use filtering status PROJECT_STATUS_ALL for all projects.
|
|
1285
3873
|
`;
|
|
1286
3874
|
async function main() {
|
|
1287
3875
|
const args = parseArgs(process.argv.slice(2));
|
|
@@ -1289,6 +3877,44 @@ async function main() {
|
|
|
1289
3877
|
console.log(help.trim());
|
|
1290
3878
|
return;
|
|
1291
3879
|
}
|
|
3880
|
+
if (args.domain === "list") {
|
|
3881
|
+
const index2 = await loadSearchIndex({ index: args.index, refresh: args.refresh });
|
|
3882
|
+
printDocList(index2, args);
|
|
3883
|
+
return;
|
|
3884
|
+
}
|
|
3885
|
+
if (args.domain === "doc" && (!args.command || args.command === "--help" || args.command === "-h" || args.command === "help")) {
|
|
3886
|
+
console.log(docHelp.trim());
|
|
3887
|
+
return;
|
|
3888
|
+
}
|
|
3889
|
+
if (args.domain === "doc" && args.command === "sync") {
|
|
3890
|
+
const index2 = await refreshSearchIndex();
|
|
3891
|
+
const cache = getSearchIndexCacheInfo();
|
|
3892
|
+
console.log(`Synced ${index2.documents.length} docs to ${cache.cachePath}`);
|
|
3893
|
+
return;
|
|
3894
|
+
}
|
|
3895
|
+
if (args.domain === "doc" && args.command === "list") {
|
|
3896
|
+
const index2 = await loadSearchIndex({ index: args.index, refresh: args.refresh });
|
|
3897
|
+
printDocList(index2, args);
|
|
3898
|
+
return;
|
|
3899
|
+
}
|
|
3900
|
+
if (args.domain === "prompt") {
|
|
3901
|
+
printLlms({ ...args, domain: "llms", command: "prompt" });
|
|
3902
|
+
return;
|
|
3903
|
+
}
|
|
3904
|
+
if (args.domain === "llms") {
|
|
3905
|
+
printLlms(args);
|
|
3906
|
+
return;
|
|
3907
|
+
}
|
|
3908
|
+
if (args.domain === "oceanengine") {
|
|
3909
|
+
if (!args.command || args.command === "--help" || args.command === "-h" || args.command === "help") {
|
|
3910
|
+
console.log(oceanEngineHelp.trim());
|
|
3911
|
+
return;
|
|
3912
|
+
}
|
|
3913
|
+
const oceanEngineArgv = [args.command, ...args.query];
|
|
3914
|
+
const payload = await runOceanEngineCommand(oceanEngineArgv);
|
|
3915
|
+
console.log(formatOceanEngineOutput(payload, args.json, oceanEngineArgv));
|
|
3916
|
+
return;
|
|
3917
|
+
}
|
|
1292
3918
|
if (args.domain !== "doc" || args.command !== "search") {
|
|
1293
3919
|
throw new Error(`unknown command: ${[args.domain, args.command].filter(Boolean).join(" ")}`);
|
|
1294
3920
|
}
|
|
@@ -1296,7 +3922,7 @@ async function main() {
|
|
|
1296
3922
|
if (!query) {
|
|
1297
3923
|
throw new Error("missing search query");
|
|
1298
3924
|
}
|
|
1299
|
-
const index = await loadSearchIndex(args.index);
|
|
3925
|
+
const index = await loadSearchIndex({ index: args.index, refresh: args.refresh });
|
|
1300
3926
|
const results = await searchDocuments({
|
|
1301
3927
|
query,
|
|
1302
3928
|
documents: index.documents,
|
|
@@ -1322,14 +3948,102 @@ async function main() {
|
|
|
1322
3948
|
console.log(` Score: ${result.score.toFixed(2)}`);
|
|
1323
3949
|
}
|
|
1324
3950
|
}
|
|
3951
|
+
function printDocList(index, args) {
|
|
3952
|
+
const platformFilter = args.command;
|
|
3953
|
+
const platforms = [...new Set(index.documents.map((document) => document.platform))].sort().filter((platform) => !platformFilter || platform === platformFilter).map((platform) => {
|
|
3954
|
+
const documents = index.documents.filter((document) => document.platform === platform);
|
|
3955
|
+
return {
|
|
3956
|
+
platform,
|
|
3957
|
+
capabilities: [
|
|
3958
|
+
{
|
|
3959
|
+
name: "doc",
|
|
3960
|
+
documents: documents.length,
|
|
3961
|
+
index_url: `https://adcli.jiangzhx.com/${platform}/index.md`,
|
|
3962
|
+
commands: [
|
|
3963
|
+
`adcli doc search <query> --platform ${platform}`
|
|
3964
|
+
]
|
|
3965
|
+
}
|
|
3966
|
+
]
|
|
3967
|
+
};
|
|
3968
|
+
});
|
|
3969
|
+
if (platformFilter && platforms.length === 0) {
|
|
3970
|
+
throw new Error(`unsupported platform: ${platformFilter}`);
|
|
3971
|
+
}
|
|
3972
|
+
if (args.json) {
|
|
3973
|
+
console.log(JSON.stringify({ platforms }, null, 2));
|
|
3974
|
+
return;
|
|
3975
|
+
}
|
|
3976
|
+
for (const item of platforms) {
|
|
3977
|
+
console.log(item.platform);
|
|
3978
|
+
for (const capability of item.capabilities) {
|
|
3979
|
+
console.log(` ${capability.name}`);
|
|
3980
|
+
for (const command of capability.commands) {
|
|
3981
|
+
console.log(` ${command}`);
|
|
3982
|
+
}
|
|
3983
|
+
console.log(` docs: ${capability.documents}`);
|
|
3984
|
+
console.log(` index: ${capability.index_url}`);
|
|
3985
|
+
}
|
|
3986
|
+
}
|
|
3987
|
+
}
|
|
3988
|
+
function printLlms(args) {
|
|
3989
|
+
const payload = {
|
|
3990
|
+
name: "AdCLI Docs Pack",
|
|
3991
|
+
base_url: "https://adcli.jiangzhx.com",
|
|
3992
|
+
llms_txt: "https://adcli.jiangzhx.com/llms.txt",
|
|
3993
|
+
llms_full_txt: "https://adcli.jiangzhx.com/llms-full.txt",
|
|
3994
|
+
search_index: "https://adcli.jiangzhx.com/search-index.json",
|
|
3995
|
+
platform_indexes: [
|
|
3996
|
+
"https://adcli.jiangzhx.com/kuaishou/index.md",
|
|
3997
|
+
"https://adcli.jiangzhx.com/oceanengine/index.md",
|
|
3998
|
+
"https://adcli.jiangzhx.com/tencent_ads/index.md"
|
|
3999
|
+
]
|
|
4000
|
+
};
|
|
4001
|
+
if (args.json) {
|
|
4002
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
4003
|
+
return;
|
|
4004
|
+
}
|
|
4005
|
+
if (args.command === "prompt") {
|
|
4006
|
+
console.log([
|
|
4007
|
+
"Use the AdCLI advertising API docs pack when answering advertising platform API questions.",
|
|
4008
|
+
"",
|
|
4009
|
+
`Start with: ${payload.llms_txt}`,
|
|
4010
|
+
`Use full index when needed: ${payload.llms_full_txt}`,
|
|
4011
|
+
`Use search index for local/tool search: ${payload.search_index}`,
|
|
4012
|
+
"",
|
|
4013
|
+
"Rules:",
|
|
4014
|
+
"- Prefer the Markdown docs from this docs pack over memory.",
|
|
4015
|
+
"- Cite the specific platform document URL or source URL used.",
|
|
4016
|
+
"- If a query names a platform, keep that platform as the primary context but do not ignore relevant cross-platform differences.",
|
|
4017
|
+
"- For API testing or implementation, identify method, path, auth requirement, parameters, response fields, and known limits.",
|
|
4018
|
+
"- If the docs are incomplete or ambiguous, say what is missing instead of guessing."
|
|
4019
|
+
].join(`
|
|
4020
|
+
`));
|
|
4021
|
+
return;
|
|
4022
|
+
}
|
|
4023
|
+
console.log([
|
|
4024
|
+
"AdCLI Docs Pack",
|
|
4025
|
+
"",
|
|
4026
|
+
`llms.txt: ${payload.llms_txt}`,
|
|
4027
|
+
`llms-full.txt: ${payload.llms_full_txt}`,
|
|
4028
|
+
`search index: ${payload.search_index}`,
|
|
4029
|
+
"",
|
|
4030
|
+
"Platform indexes:",
|
|
4031
|
+
...payload.platform_indexes.map((url) => `- ${url}`),
|
|
4032
|
+
"",
|
|
4033
|
+
"Prompt for AI/Agent:",
|
|
4034
|
+
" adcli llms prompt"
|
|
4035
|
+
].join(`
|
|
4036
|
+
`));
|
|
4037
|
+
}
|
|
1325
4038
|
function parseArgs(argv) {
|
|
1326
4039
|
const args = {
|
|
1327
4040
|
domain: argv[0],
|
|
1328
4041
|
command: argv[1],
|
|
1329
4042
|
query: [],
|
|
1330
|
-
index: process.env.ADCLI_SEARCH_INDEX
|
|
4043
|
+
index: process.env.ADCLI_SEARCH_INDEX,
|
|
1331
4044
|
limit: 10,
|
|
1332
|
-
json: false
|
|
4045
|
+
json: false,
|
|
4046
|
+
refresh: false
|
|
1333
4047
|
};
|
|
1334
4048
|
for (let index = 2;index < argv.length; index += 1) {
|
|
1335
4049
|
const value = argv[index];
|
|
@@ -1342,6 +4056,10 @@ function parseArgs(argv) {
|
|
|
1342
4056
|
index += 1;
|
|
1343
4057
|
continue;
|
|
1344
4058
|
}
|
|
4059
|
+
if (value === "--refresh") {
|
|
4060
|
+
args.refresh = true;
|
|
4061
|
+
continue;
|
|
4062
|
+
}
|
|
1345
4063
|
if (value === "--limit") {
|
|
1346
4064
|
args.limit = Number.parseInt(argv[index + 1] ?? "", 10);
|
|
1347
4065
|
index += 1;
|
|
@@ -1359,25 +4077,7 @@ function parseArgs(argv) {
|
|
|
1359
4077
|
}
|
|
1360
4078
|
return args;
|
|
1361
4079
|
}
|
|
1362
|
-
async function loadSearchIndex(index) {
|
|
1363
|
-
if (/^https?:\/\//i.test(index)) {
|
|
1364
|
-
const response = await fetch(index);
|
|
1365
|
-
if (!response.ok) {
|
|
1366
|
-
throw new Error(`failed to fetch search index: ${index} (${response.status})`);
|
|
1367
|
-
}
|
|
1368
|
-
return await response.json();
|
|
1369
|
-
}
|
|
1370
|
-
const indexPath = path.resolve(index);
|
|
1371
|
-
try {
|
|
1372
|
-
return JSON.parse(await readFile(indexPath, "utf8"));
|
|
1373
|
-
} catch (error) {
|
|
1374
|
-
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
1375
|
-
throw new Error(`missing search index: ${path.relative(process.cwd(), indexPath)}. Use --index ${defaultSearchIndexUrl} or run: bun run build:search-index`);
|
|
1376
|
-
}
|
|
1377
|
-
throw error;
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
4080
|
main().catch((error) => {
|
|
1381
|
-
console.error(error instanceof Error ? error.message : error);
|
|
4081
|
+
console.error(formatOceanEngineError(error) ?? (error instanceof Error ? error.message : error));
|
|
1382
4082
|
process.exit(1);
|
|
1383
4083
|
});
|