baja-lite 1.6.4 → 1.6.6
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/boot-remote.d.ts +2 -0
- package/{src/boot-remote.ts → boot-remote.js} +66 -64
- package/boot.d.ts +2 -0
- package/{src/boot.ts → boot.js} +166 -170
- package/code.d.ts +2 -0
- package/{src/code.ts → code.js} +405 -414
- package/convert-xml.d.ts +10 -0
- package/{src/convert-xml.ts → convert-xml.js} +410 -460
- package/error.d.ts +5 -0
- package/error.js +13 -0
- package/event.d.ts +10 -0
- package/event.js +38 -0
- package/fn.d.ts +128 -0
- package/fn.js +172 -0
- package/{src/index.ts → index.d.ts} +10 -11
- package/index.js +10 -0
- package/math.d.ts +83 -0
- package/math.js +451 -0
- package/object.d.ts +126 -0
- package/object.js +321 -0
- package/package.json +13 -13
- package/snowflake.d.ts +12 -0
- package/{src/snowflake.ts → snowflake.js} +108 -127
- package/sql.d.ts +2151 -0
- package/sql.js +5371 -0
- package/sqlite.d.ts +32 -0
- package/{src/sqlite.ts → sqlite.js} +156 -157
- package/string.d.ts +17 -0
- package/string.js +105 -0
- package/test-mysql.d.ts +2 -0
- package/test-mysql.js +114 -0
- package/test-postgresql.d.ts +2 -0
- package/{src/test-postgresql.ts → test-postgresql.js} +91 -80
- package/test-sqlite.d.ts +1 -0
- package/{src/test-sqlite.ts → test-sqlite.js} +90 -80
- package/test-xml.d.ts +1 -0
- package/{src/test-xml.ts → test-xml.js} +2 -2
- package/test.d.ts +1 -0
- package/{src/test.ts → test.js} +2 -3
- package/wx/base.d.ts +11 -0
- package/wx/base.js +78 -0
- package/wx/mini.d.ts +52 -0
- package/wx/mini.js +112 -0
- package/wx/organ.d.ts +65 -0
- package/wx/organ.js +171 -0
- package/{src/wx/types.ts → wx/types.d.ts} +560 -549
- package/wx/types.js +1 -0
- package/{src/wx.ts → wx.d.ts} +3 -3
- package/wx.js +3 -0
- package/.eslintignore +0 -7
- package/.eslintrc.cjs +0 -89
- package/.prettierrc +0 -7
- package/.vscode/settings.json +0 -9
- package/ci.js +0 -33
- package/package-cjs.json +0 -17
- package/pnpm-lock.yaml +0 -2840
- package/pnpm-workspace.yaml +0 -2
- package/src/error.ts +0 -11
- package/src/event.ts +0 -34
- package/src/fn.ts +0 -295
- package/src/math.ts +0 -405
- package/src/object.ts +0 -342
- package/src/sql.ts +0 -5529
- package/src/string.ts +0 -111
- package/src/test-mysql.ts +0 -148
- package/src/wx/base.ts +0 -77
- package/src/wx/mini.ts +0 -147
- package/src/wx/organ.ts +0 -290
- package/tsconfig.cjs.json +0 -42
- package/tsconfig.json +0 -44
- package/xml/event-report.xml +0 -13
- package/yarn.lock +0 -1977
- /package/{Readme.md → README.md} +0 -0
package/src/math.ts
DELETED
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
import Decimal from 'decimal.js';
|
|
3
|
-
/** 金钱格式化可用样式 */
|
|
4
|
-
export class MoneyOption {
|
|
5
|
-
style?: 'currency' | 'decimal' | 'percent' = 'currency';
|
|
6
|
-
currency?: string = 'CNY';
|
|
7
|
-
prefix?: number = 2;
|
|
8
|
-
def?: number = 0;
|
|
9
|
-
currencyDisplay?: 'symbol' | 'name' | 'code' = 'symbol';
|
|
10
|
-
useGrouping?: boolean = true;
|
|
11
|
-
local?: string = 'zh';
|
|
12
|
-
}
|
|
13
|
-
export interface Point {
|
|
14
|
-
latitude: string;
|
|
15
|
-
longitude: string;
|
|
16
|
-
lat: number;
|
|
17
|
-
long: number;
|
|
18
|
-
}
|
|
19
|
-
// const ONE = new Decimal(1);
|
|
20
|
-
const ZERO = new Decimal(0);
|
|
21
|
-
function isNum(a: any): boolean {
|
|
22
|
-
return a !== '' && a !== null && !isNaN(a);
|
|
23
|
-
}
|
|
24
|
-
export const num = (val: any, def = 0): number => {
|
|
25
|
-
if (val instanceof Bus) {
|
|
26
|
-
return val.over();
|
|
27
|
-
} else if (!isNum(val)) {
|
|
28
|
-
return def;
|
|
29
|
-
}
|
|
30
|
-
return +val;
|
|
31
|
-
};
|
|
32
|
-
function filterNumber(array: any[]): number[] {
|
|
33
|
-
const res: number[] = [];
|
|
34
|
-
array.forEach((element) => {
|
|
35
|
-
if (element instanceof Bus) {
|
|
36
|
-
res.push(element.over());
|
|
37
|
-
} else if (isNum(element)) {
|
|
38
|
-
res.push(+element);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
return res;
|
|
42
|
-
}
|
|
43
|
-
function filterNumber2(array: any[], def?: number): Decimal[] {
|
|
44
|
-
const res: Decimal[] = [];
|
|
45
|
-
array.forEach((element) => {
|
|
46
|
-
if (element instanceof Bus) {
|
|
47
|
-
res.push(new Decimal(element.over()));
|
|
48
|
-
} else if (isNum(element)) {
|
|
49
|
-
res.push(new Decimal(element));
|
|
50
|
-
} else if (def !== undefined) {
|
|
51
|
-
res.push(new Decimal(def));
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
return res;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export const max = (...args: any[]): number => {
|
|
58
|
-
const arr = filterNumber(args);
|
|
59
|
-
return Math.max.apply(null, arr);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const min = (...args: any[]): number => {
|
|
63
|
-
const arr = filterNumber(args);
|
|
64
|
-
return Math.min.apply(null, arr);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export const div = (...args: any[]): number => {
|
|
68
|
-
const arr: Decimal[] = filterNumber2(args);
|
|
69
|
-
if (arr!.length > 1) {
|
|
70
|
-
return arr!.reduce((a, b) => a.div(b)).toNumber();
|
|
71
|
-
} else if (arr!.length > 0) {
|
|
72
|
-
return arr[0]!.toNumber();
|
|
73
|
-
} else {
|
|
74
|
-
return 0;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
export const divDef = (def: any, ...args: any[]): number => {
|
|
78
|
-
const arr: Decimal[] = filterNumber2(args);
|
|
79
|
-
if (arr!.length > 1) {
|
|
80
|
-
const zeros = arr!.slice(1).findIndex(i => i.equals(ZERO));
|
|
81
|
-
if (zeros > -1) {
|
|
82
|
-
return new Decimal(def).toNumber();
|
|
83
|
-
}
|
|
84
|
-
return arr!.reduce((a, b) => a.div(b)).toNumber();
|
|
85
|
-
} else if (arr!.length > 0) {
|
|
86
|
-
return arr[0]!.toNumber();
|
|
87
|
-
} else {
|
|
88
|
-
return 0;
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export const add = (...args: any[]): number => {
|
|
93
|
-
const arr = filterNumber2(args);
|
|
94
|
-
if (arr!.length > 1) {
|
|
95
|
-
return arr!.reduce((a, b) => a.add(b)).toNumber();
|
|
96
|
-
} else if (arr!.length > 0) {
|
|
97
|
-
return arr[0]!.toNumber();
|
|
98
|
-
} else {
|
|
99
|
-
return 0;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export const mul = (...args: any[]): number => {
|
|
104
|
-
const arr = filterNumber2(args);
|
|
105
|
-
if (arr!.length > 1) {
|
|
106
|
-
return arr!.reduce((a, b) => a.mul(b)).toNumber();
|
|
107
|
-
} else if (arr!.length > 0) {
|
|
108
|
-
return arr[0]!.toNumber();
|
|
109
|
-
} else {
|
|
110
|
-
return 0;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export const sub = (...args: any[]): number => {
|
|
115
|
-
const arr = filterNumber2(args, 0);
|
|
116
|
-
if (arr!.length > 1) {
|
|
117
|
-
return arr!.reduce((a, b) => a.sub(b)).toNumber();
|
|
118
|
-
} else if (arr!.length > 0) {
|
|
119
|
-
return arr[0]!.toNumber();
|
|
120
|
-
} else {
|
|
121
|
-
return 0;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const roundMode = [Decimal.ROUND_HALF_UP, Decimal.ROUND_UP, Decimal.ROUND_DOWN];
|
|
126
|
-
export const round = (number: any, numDigits: number, upOrDown = 0): number => {
|
|
127
|
-
if (isNum(number)) {
|
|
128
|
-
const nu = new Decimal(number);
|
|
129
|
-
return nu.toDP(numDigits, roundMode[upOrDown]!).toNumber();
|
|
130
|
-
} else {
|
|
131
|
-
return 0;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
/** =value.xx,其中xx=number,如number=99,表示修正数字为value.99 */
|
|
135
|
-
export const merge = function (value: any, number: any) {
|
|
136
|
-
if (isNum(value) && isNum(number)) {
|
|
137
|
-
return new Decimal(value).floor().add(`0.${number}`).toNumber();
|
|
138
|
-
} else if (isNum(value)) {
|
|
139
|
-
return value;
|
|
140
|
-
} else {
|
|
141
|
-
return 0;
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
export const money = (
|
|
147
|
-
value: any,
|
|
148
|
-
option: MoneyOption = {}
|
|
149
|
-
): string => {
|
|
150
|
-
// Intl.NumberFormat(option.local ?? 'zh', {
|
|
151
|
-
// style: option.style ?? 'currency',
|
|
152
|
-
// currency: option.currency ?? 'CNY',
|
|
153
|
-
// minimumFractionDigits: option.prefix ?? 2,
|
|
154
|
-
// currencyDisplay: option.currencyDisplay ?? 'symbol',
|
|
155
|
-
// useGrouping: option.useGrouping ?? true
|
|
156
|
-
// }).format(isNum(value) ? value : option.def).replace(/CN|\s/g, '');
|
|
157
|
-
return (isNum(value) ? value : option.def).toLocaleString(option.local ?? 'zh', {
|
|
158
|
-
style: option.style ?? 'currency',
|
|
159
|
-
currency: option.currency ?? 'CNY',
|
|
160
|
-
minimumFractionDigits: option.prefix ?? 2,
|
|
161
|
-
currencyDisplay: option.currencyDisplay ?? 'symbol',
|
|
162
|
-
useGrouping: option.useGrouping ?? true
|
|
163
|
-
}).replace(/CN|\s/g, '');
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const IF = function () {
|
|
167
|
-
return function (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) {
|
|
168
|
-
const fn = descriptor!.value;
|
|
169
|
-
descriptor!.value = function (this: Bus) {
|
|
170
|
-
if (this['ifit'] === true) {
|
|
171
|
-
// eslint-disable-next-line prefer-rest-params
|
|
172
|
-
const args = Array.from(arguments);
|
|
173
|
-
fn.call(this, ...args);
|
|
174
|
-
}
|
|
175
|
-
this['ifit'] = true;
|
|
176
|
-
return this;
|
|
177
|
-
};
|
|
178
|
-
};
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
export class Bus {
|
|
182
|
-
private result: number;
|
|
183
|
-
private ifit = true;
|
|
184
|
-
constructor(result: any) {
|
|
185
|
-
this.result = num(result);
|
|
186
|
-
}
|
|
187
|
-
@IF()
|
|
188
|
-
add(...args: any[]): this {
|
|
189
|
-
this.result = add(this.result, ...args);
|
|
190
|
-
return this;
|
|
191
|
-
}
|
|
192
|
-
@IF()
|
|
193
|
-
sub(...args: any[]): this {
|
|
194
|
-
this.result = sub(this.result, ...args);
|
|
195
|
-
return this;
|
|
196
|
-
}
|
|
197
|
-
@IF()
|
|
198
|
-
div(...args: any[]): this {
|
|
199
|
-
this.result = div(this.result, ...args);
|
|
200
|
-
return this;
|
|
201
|
-
}
|
|
202
|
-
@IF()
|
|
203
|
-
divDef(def: any, ...args: any[]): this {
|
|
204
|
-
this.result = divDef(def, this.result, ...args);
|
|
205
|
-
return this;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
@IF()
|
|
209
|
-
mul(...args: any[]): this {
|
|
210
|
-
this.result = mul(this.result, ...args);
|
|
211
|
-
return this;
|
|
212
|
-
}
|
|
213
|
-
@IF()
|
|
214
|
-
max(...args: any[]): this {
|
|
215
|
-
this.result = max(this.result, ...args);
|
|
216
|
-
return this;
|
|
217
|
-
}
|
|
218
|
-
@IF()
|
|
219
|
-
min(...args: any[]): this {
|
|
220
|
-
this.result = min(this.result, ...args);
|
|
221
|
-
return this;
|
|
222
|
-
}
|
|
223
|
-
@IF()
|
|
224
|
-
ac(): this {
|
|
225
|
-
this.result = sub(0, this.result);
|
|
226
|
-
return this;
|
|
227
|
-
}
|
|
228
|
-
@IF()
|
|
229
|
-
abs(): this {
|
|
230
|
-
this.result = Math.abs(this.result);
|
|
231
|
-
return this;
|
|
232
|
-
}
|
|
233
|
-
@IF()
|
|
234
|
-
round(numDigits: number, upOrDown?: number): this {
|
|
235
|
-
this.result = round(this.result, numDigits, upOrDown);
|
|
236
|
-
return this;
|
|
237
|
-
}
|
|
238
|
-
@IF()
|
|
239
|
-
merge(number: any) {
|
|
240
|
-
this.result = merge(this.result, number);
|
|
241
|
-
return this;
|
|
242
|
-
}
|
|
243
|
-
if(condition: boolean) {
|
|
244
|
-
this.ifit = condition;
|
|
245
|
-
return this;
|
|
246
|
-
}
|
|
247
|
-
over(): number {
|
|
248
|
-
return this.result;
|
|
249
|
-
}
|
|
250
|
-
money(
|
|
251
|
-
option?: MoneyOption
|
|
252
|
-
): string {
|
|
253
|
-
return money(this.result, option);
|
|
254
|
-
}
|
|
255
|
-
lt(data: any): boolean {
|
|
256
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
257
|
-
return r!.lessThan(d!);
|
|
258
|
-
}
|
|
259
|
-
le(data: any): boolean {
|
|
260
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
261
|
-
return r!.lessThanOrEqualTo(d!);
|
|
262
|
-
}
|
|
263
|
-
gt(data: any): boolean {
|
|
264
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
265
|
-
return r!.greaterThan(d!);
|
|
266
|
-
}
|
|
267
|
-
ge(data: any): boolean {
|
|
268
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
269
|
-
return r!.greaterThanOrEqualTo(d!);
|
|
270
|
-
}
|
|
271
|
-
nlt(data: any): boolean {
|
|
272
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
273
|
-
return !r!.lessThan(d!);
|
|
274
|
-
}
|
|
275
|
-
nle(data: any): boolean {
|
|
276
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
277
|
-
return !r!.lessThanOrEqualTo(d!);
|
|
278
|
-
}
|
|
279
|
-
ngt(data: any): boolean {
|
|
280
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
281
|
-
return !r!.greaterThan(d!);
|
|
282
|
-
}
|
|
283
|
-
nge(data: any): boolean {
|
|
284
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
285
|
-
return !r!.greaterThanOrEqualTo(d!);
|
|
286
|
-
}
|
|
287
|
-
eq(data: any): boolean {
|
|
288
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
289
|
-
return r!.equals(d!);
|
|
290
|
-
}
|
|
291
|
-
ne(data: any): boolean {
|
|
292
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
293
|
-
return !r!.eq(d!);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
ifLt(data: any): this {
|
|
297
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
298
|
-
this.ifit = r!.lessThan(d!);
|
|
299
|
-
return this;
|
|
300
|
-
}
|
|
301
|
-
ifLe(data: any): this {
|
|
302
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
303
|
-
this.ifit = r!.lessThanOrEqualTo(d!);
|
|
304
|
-
return this;
|
|
305
|
-
}
|
|
306
|
-
ifGt(data: any): this {
|
|
307
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
308
|
-
this.ifit = r!.greaterThan(d!);
|
|
309
|
-
return this;
|
|
310
|
-
}
|
|
311
|
-
ifGe(data: any): this {
|
|
312
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
313
|
-
this.ifit = r!.greaterThanOrEqualTo(d!);
|
|
314
|
-
return this;
|
|
315
|
-
}
|
|
316
|
-
ifNlt(data: any): this {
|
|
317
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
318
|
-
this.ifit = !r!.lessThan(d!);
|
|
319
|
-
return this;
|
|
320
|
-
}
|
|
321
|
-
ifNle(data: any): this {
|
|
322
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
323
|
-
this.ifit = !r!.lessThanOrEqualTo(d!);
|
|
324
|
-
return this;
|
|
325
|
-
}
|
|
326
|
-
ifNgt(data: any): this {
|
|
327
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
328
|
-
this.ifit = !r!.greaterThan(d!);
|
|
329
|
-
return this;
|
|
330
|
-
}
|
|
331
|
-
ifNge(data: any): this {
|
|
332
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
333
|
-
this.ifit = !r!.greaterThanOrEqualTo(d!);
|
|
334
|
-
return this;
|
|
335
|
-
}
|
|
336
|
-
ifEq(data: any): this {
|
|
337
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
338
|
-
this.ifit = r!.equals(d!);
|
|
339
|
-
return this;
|
|
340
|
-
}
|
|
341
|
-
ifNe(data: any): this {
|
|
342
|
-
const [d, r] = filterNumber2([data, this.result]);
|
|
343
|
-
this.ifit = !r!.eq(d!);
|
|
344
|
-
return this;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
export const calc = (result: any) => {
|
|
349
|
-
return new Bus(result);
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
export const getGeo = (p1: Point, p2: Point) => {
|
|
353
|
-
p1.lat = calc(p1.latitude).mul(Math.PI).div(180).over();
|
|
354
|
-
p1.long = calc(p1.longitude).mul(Math.PI).div(180).over();
|
|
355
|
-
p2.lat = calc(p2.latitude).mul(Math.PI).div(180).over();
|
|
356
|
-
p2.long = calc(p2.longitude).mul(Math.PI).div(180).over();
|
|
357
|
-
return calc(
|
|
358
|
-
Math.round(
|
|
359
|
-
mul(
|
|
360
|
-
Math.asin(
|
|
361
|
-
Math.sqrt(
|
|
362
|
-
add(Math.pow(Math.sin(div(sub(p1.lat, p2.lat), 2)), 2),
|
|
363
|
-
mul(
|
|
364
|
-
Math.cos(p1.lat), Math.cos(p2.lat), Math.pow(Math.sin(div(sub(p1.long, p2.long), 2)), 2)
|
|
365
|
-
))
|
|
366
|
-
)), 2, 6378.137, 10000))).div(10000).round(2).over();
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
const ZM = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
370
|
-
/**
|
|
371
|
-
* 十进制转换自定义进制
|
|
372
|
-
* @param from 数字
|
|
373
|
-
* @param to 自定义进制的字符
|
|
374
|
-
* @returns
|
|
375
|
-
*/
|
|
376
|
-
export function ten2Any(from: number, to = ZM) {
|
|
377
|
-
let result = '';
|
|
378
|
-
const length = to.length;
|
|
379
|
-
while (from > 0) {
|
|
380
|
-
from--;
|
|
381
|
-
let remainder = from % length;
|
|
382
|
-
result = to.charAt(remainder) + result;
|
|
383
|
-
from = Math.floor(from / length);
|
|
384
|
-
}
|
|
385
|
-
return result;
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* 自定义进制转换十进制
|
|
389
|
-
* @param from
|
|
390
|
-
* @param to
|
|
391
|
-
* @returns
|
|
392
|
-
*/
|
|
393
|
-
export function any2Ten(from: string, to = ZM) {
|
|
394
|
-
let decimal = 0;
|
|
395
|
-
from = from.toUpperCase();
|
|
396
|
-
for (let i = 0; i < from.length; i++) {
|
|
397
|
-
const char = from[from.length - 1 - i]!.toUpperCase();
|
|
398
|
-
const index = to.indexOf(char);
|
|
399
|
-
if (index > -1) {
|
|
400
|
-
const value = to.indexOf(char) + 1;
|
|
401
|
-
decimal += value * Math.pow(26, i);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return decimal;
|
|
405
|
-
}
|