baja-lite 1.3.27 → 1.3.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/boot-remote.d.ts +2 -0
  2. package/{src/boot-remote.ts → boot-remote.js} +6 -7
  3. package/boot.d.ts +2 -0
  4. package/{src/boot.ts → boot.js} +31 -38
  5. package/code.d.ts +2 -0
  6. package/{src/code.ts → code.js} +71 -66
  7. package/convert-xml.d.ts +10 -0
  8. package/{src/convert-xml.ts → convert-xml.js} +105 -155
  9. package/enum.d.ts +2 -0
  10. package/enum.js +31 -0
  11. package/error.d.ts +5 -0
  12. package/error.js +13 -0
  13. package/fn.d.ts +128 -0
  14. package/fn.js +172 -0
  15. package/{src/index.ts → index.d.ts} +11 -12
  16. package/index.js +11 -0
  17. package/list.d.ts +10 -0
  18. package/{src/list.ts → list.js} +8 -9
  19. package/math.d.ts +83 -0
  20. package/math.js +451 -0
  21. package/object.d.ts +83 -0
  22. package/object.js +221 -0
  23. package/package.json +2 -2
  24. package/snowflake.d.ts +12 -0
  25. package/{src/snowflake.ts → snowflake.js} +33 -52
  26. package/sql.d.ts +1797 -0
  27. package/sql.js +4802 -0
  28. package/sqlite.d.ts +32 -0
  29. package/{src/sqlite.ts → sqlite.js} +53 -52
  30. package/string.d.ts +17 -0
  31. package/string.js +105 -0
  32. package/test-mysql.d.ts +2 -0
  33. package/test-mysql.js +109 -0
  34. package/test-postgresql.d.ts +2 -0
  35. package/{src/test-postgresql.ts → test-postgresql.js} +91 -80
  36. package/test-sqlite.d.ts +1 -0
  37. package/{src/test-sqlite.ts → test-sqlite.js} +90 -80
  38. package/test-xml.d.ts +1 -0
  39. package/{src/test-xml.ts → test-xml.js} +1 -1
  40. package/test.d.ts +1 -0
  41. package/{src/test.ts → test.js} +2 -3
  42. package/wx/base.d.ts +11 -0
  43. package/wx/base.js +78 -0
  44. package/wx/mini.d.ts +52 -0
  45. package/wx/mini.js +112 -0
  46. package/wx/organ.d.ts +65 -0
  47. package/wx/organ.js +171 -0
  48. package/{src/wx/types.ts → wx/types.d.ts} +21 -10
  49. package/wx/types.js +1 -0
  50. package/wx.js +3 -0
  51. package/.eslintignore +0 -7
  52. package/.eslintrc.cjs +0 -89
  53. package/.prettierrc +0 -4
  54. package/.vscode/settings.json +0 -8
  55. package/ci.js +0 -29
  56. package/package-cjs.json +0 -17
  57. package/src/enum.ts +0 -71
  58. package/src/error.ts +0 -11
  59. package/src/fn.ts +0 -295
  60. package/src/math.ts +0 -405
  61. package/src/object.ts +0 -247
  62. package/src/sql.ts +0 -5023
  63. package/src/string.ts +0 -111
  64. package/src/test-mysql.ts +0 -144
  65. package/src/wx/base.ts +0 -76
  66. package/src/wx/mini.ts +0 -147
  67. package/src/wx/organ.ts +0 -290
  68. package/tsconfig.cjs.json +0 -42
  69. package/tsconfig.json +0 -44
  70. package/tsconfig.tsbuildinfo +0 -1
  71. package/xml/event-report.xml +0 -13
  72. package/yarn.lock +0 -1757
  73. /package/{Readme.md → README.md} +0 -0
  74. /package/{src/wx.ts → wx.d.ts} +0 -0
package/src/fn.ts DELETED
@@ -1,295 +0,0 @@
1
- import { arraySplit } from './object.js';
2
- import { Throw } from './error.js';
3
- /**
4
- * 回调函数promise化
5
- * 调用示例
6
- * soap.excute(arg1, arg2, function(error, data){});
7
- * 可使用为:
8
- * const soap_excute = promise({
9
- * fn: soap.excute,
10
- * target: soap
11
- * });
12
- * const data = await soap_excute(arg1, arg2);
13
- * @param this
14
- * @param param1
15
- */
16
- export const promise = function <T>(
17
- this: any,
18
- { fn, target, last = true }: { fn: (...args: any[]) => any; target?: any; last?: boolean }
19
- ): (...args: any[]) => Promise<T> {
20
- return (...args: any[]): Promise<T> => {
21
- return new Promise((resolve, reject) => {
22
- args[last === true ? 'push' : 'unshift'](
23
- (
24
- err: {
25
- message: string;
26
- [key: string]: any;
27
- } | null,
28
- data: T
29
- ) => {
30
- if (err === null || err === undefined) {
31
- return resolve.call(this, data);
32
- }
33
- return reject(err);
34
- }
35
- );
36
- if (target) {
37
- fn.apply(target, args);
38
- } else {
39
- fn.apply({}, args);
40
- }
41
- });
42
- };
43
- };
44
-
45
- export const sleep = (time: number = parseInt(`${Math.random()}`) + 200,) =>
46
- new Promise((resolve) => setTimeout(resolve, time));
47
-
48
- /**
49
- * 执行器
50
- * @param fn
51
- * @param {
52
- ifFinish?: (result?: T) => boolean; // 是否结束,默认是建议判断 !!result
53
- maxTryTimes?: number; //最多尝试几次,默认是20
54
- onFail?: () => Promise<boolean | undefined> | boolean | undefined; // 失败时的回调,返回false表示停止执行
55
- name?: string; // 执行器名称,用于打印日志
56
- exitIfFail?: boolean; // 失败时是否退出,默认是false. 这里设置true后,onFail返回true,也会停止执行
57
- defVal?: T; // 失败时的默认值
58
- sleepAppend?: number; // 等待延迟MS,默认是1000内随机+200
59
- * }
60
- * @returns
61
- */
62
- export async function dieTrying<T = any>(
63
- fn: (...args: any[]) => Promise<T | undefined> | T | undefined,
64
- {
65
- ifFinish = (result?: T) => !!result,
66
- maxTryTimes = 20,
67
- onFail,
68
- name = 'dieTrying',
69
- exitIfFail = true,
70
- defVal,
71
- sleepAppend = 0
72
- }: {
73
- ifFinish?: (result?: T) => boolean;
74
- maxTryTimes?: number;
75
- onFail?: () => Promise<boolean | undefined> | boolean | undefined;
76
- name?: string;
77
- exitIfFail?: boolean;
78
- defVal?: T;
79
- sleepAppend?: number;
80
- } = {}): Promise<T | undefined> {
81
- let count = 0;
82
- let result = defVal;
83
- while (result = await fn(), !ifFinish(result)) {
84
- await sleep(parseInt(`${Math.random() * 1000}`) + sleepAppend);
85
- count++;
86
- console.debug(`${name} try ${count} times`);
87
- if (count > maxTryTimes) {
88
- if (onFail) {
89
- const remuseExcute = await onFail();
90
- console.error(`${name} timeout`);
91
- count = 0;
92
- if (remuseExcute === false) {
93
- break;
94
- }
95
- }
96
- if (exitIfFail) {
97
- break;
98
- }
99
- }
100
- }
101
- return result;
102
- }
103
- export enum ExcuteSplitMode {
104
- SyncTrust,
105
- SyncNoTrust,
106
- AsyncTrust,
107
- AsyncNoTrust,
108
- }
109
- /**
110
- * 数组分割执行
111
- * @param datas 数组
112
- * @param fn 执行的函数, 参数1:分割数组;参数2:第几个分割数组;参数3:分割数组的数量;参数4:从第几个下标(相对于总数组)元素开始;参数5:到第几个下标(相对于总数组)元素结束
113
- * @param config 配置(三选一):everyLength=每组个数(最后一组可能不足次数), groupCount=拆分几组, extendParams=依附拆分数组;
114
- * @param 额外选项 settled=是否并行?
115
- * T: datas类型
116
- * E: extendParams类型
117
- * R: 返回值类型
118
- */
119
- /**
120
- * 数组分割执行
121
- *
122
- * # 参数说明
123
- * @param sync 同步异步开关
124
- * @param datas 数组
125
- * @param fn 执行的函数
126
- ```
127
- ** `args`: 分割后的小数组
128
- ** `index`: 第几个小数组
129
- ** `length`: 总共多少个小数组
130
- ** `extendParam`?: `参见下面Option中的extendParams`
131
- ** `startIndex`?: 本次小数组的第一个元素是从总数组的第几个元素
132
- ** `endIndex`?: 本次小数组的最后一个元素是从总数组的第几个元素
133
- fn: (args: T[], index: number, length: number, extendParam?: E, startIndex?: number, endIndex?: number):R => {
134
-
135
- }
136
- ```
137
- * @param option 选项
138
-
139
- ## 分割数组方式:2种,选择一种即可
140
- 1. everyLength=每组个数(最后一组可能不足次数)
141
- 2. groupCount=拆分几组
142
- ## settled 异步执行是否并行执行? 默认false
143
- ## `extendParams`:扩展参数
144
- ** 数组
145
- ** 结合分组方式:groupCount使用。例如:
146
- ```
147
- `groupCount`=5,那么可以传入5个`extendParams`,在执行分组时,会为每个数组传入对应下标的`extendParam`
148
- ```
149
- ## `trust` 是否信任方法体,默认false
150
- * true时,执行时捕获不异常, 返回值变为 R[]
151
- * false时,执行时捕获异常,并返回 { result: R[]; error: string[]; };
152
- # 泛型说明:全部可选
153
- 1. T = 数组类型
154
- 2. R = 返回结果类型
155
- 3. E = 扩展参数类型
156
-
157
- * @returns
158
- */
159
- export function excuteSplit<T = any, R = any, E = any>(
160
- sync: ExcuteSplitMode.SyncTrust,
161
- datas: T[],
162
- fn: (args: T[], index: number, length: number, extendParam?: E, startIndex?: number, endIndex?: number) => R,
163
- option: {
164
- everyLength?: number;
165
- groupCount?: number;
166
- settled?: boolean;
167
- extendParams?: E[];
168
- }
169
- ): R[];
170
- export function excuteSplit<T = any, R = any, E = any>(
171
- sync: ExcuteSplitMode.SyncNoTrust,
172
- datas: T[],
173
- fn: (args: T[], index: number, length: number, extendParam?: E, startIndex?: number, endIndex?: number) => R,
174
- option: {
175
- everyLength?: number;
176
- groupCount?: number;
177
- settled?: boolean;
178
- extendParams?: E[];
179
- }
180
- ): { result: R[]; error: string[]; };
181
- export function excuteSplit<T = any, R = any, E = any>(
182
- sync: ExcuteSplitMode.AsyncTrust,
183
- datas: T[],
184
- fn: (args: T[], index: number, length: number, extendParam?: E, startIndex?: number, endIndex?: number) => Promise<R>,
185
- option: {
186
- everyLength?: number;
187
- groupCount?: number;
188
- settled?: boolean;
189
- extendParams?: E[];
190
- }
191
- ): Promise<R[]>;
192
- export function excuteSplit<T = any, R = any, E = any>(
193
- sync: ExcuteSplitMode.AsyncNoTrust,
194
- datas: T[],
195
- fn: (args: T[], index: number, length: number, extendParam?: E, startIndex?: number, endIndex?: number) => Promise<R>,
196
- option: {
197
- everyLength?: number;
198
- groupCount?: number;
199
- settled?: boolean;
200
- extendParams?: E[];
201
- }
202
- ): Promise<{ result: R[]; error: string[]; }>;
203
- export function excuteSplit<T = any, R = any, E = any>(
204
- sync: ExcuteSplitMode,
205
- datas: T[],
206
- fn: (args: T[], index: number, length: number, extendParam?: E, startIndex?: number, endIndex?: number) => R | Promise<R>,
207
- { everyLength = 0, groupCount = 0, settled = false, extendParams = new Array<E>() }: {
208
- everyLength?: number;
209
- groupCount?: number;
210
- settled?: boolean;
211
- extendParams?: E[];
212
- }
213
- ): Promise<{ result: R[]; error: string[]; }> | Promise<R[]> | { result: R[]; error: string[]; } | R[] {
214
- if (extendParams.length > 0) {
215
- groupCount = extendParams.length;
216
- }
217
- Throw.if(everyLength === 0 && groupCount === 0, '参数错误!');
218
- const ps = { everyLength, groupCount };
219
- const list = arraySplit(datas, ps);
220
- if (sync === ExcuteSplitMode.AsyncTrust) {
221
- return new Promise<R[]>(async (resolve, reject) => {
222
- try {
223
- const reasons: R[] = [];
224
- if (settled) {
225
- const result = await Promise.allSettled(list.map((list, i) => fn(list, i, list.length, extendParams[i])));
226
- for (const item of result) {
227
- if (item.status === 'rejected') {
228
- reject(item.reason);
229
- } else {
230
- reasons.push(item.value);
231
- }
232
- }
233
- } else {
234
- for (let i = 0; i < list.length; i++) {
235
- const startIndex = (i - 1) * ps.everyLength;
236
- const endIndex = startIndex + list[i]!.length - 1;
237
- reasons.push(await fn(list[i]!, i, list.length, extendParams[i], startIndex, endIndex));
238
- }
239
- }
240
- resolve(reasons);
241
- } catch (error) {
242
- reject(error);
243
- }
244
- });
245
- } else if (sync === ExcuteSplitMode.AsyncNoTrust) {
246
- return new Promise<{ result: R[]; error: string[]; }>(async (resolve, reject) => {
247
- try {
248
- const reasons: { result: R[]; error: string[]; } = { result: [], error: [] };
249
- if (settled) {
250
- const result = await Promise.allSettled(list.map((list, i) => fn(list, i, list.length, extendParams[i])));
251
- for (const item of result) {
252
- if (item.status === 'rejected') {
253
- reasons.error.push(item.reason);
254
- } else {
255
- reasons.result.push(item.value);
256
- }
257
- }
258
- } else {
259
- for (let i = 0; i < list.length; i++) {
260
- const startIndex = (i - 1) * ps.everyLength;
261
- const endIndex = startIndex + list[i]!.length - 1;
262
- try {
263
- reasons.result.push(await fn(list[i]!, i, list.length, extendParams[i], startIndex, endIndex));
264
- } catch (error) {
265
- reasons.error.push(error as string);
266
- }
267
- }
268
- }
269
- resolve(reasons);
270
- } catch (error) {
271
- reject(error);
272
- }
273
- });
274
- } else if (sync === ExcuteSplitMode.SyncTrust) {
275
- const reasons: R[] = [];
276
- for (let i = 0; i < list.length; i++) {
277
- const startIndex = (i - 1) * ps.everyLength;
278
- const endIndex = startIndex + list[i]!.length - 1;
279
- reasons.push(fn(list[i]!, i, list.length, extendParams[i], startIndex, endIndex) as R);
280
- }
281
- return reasons;
282
- } else {
283
- const reasons: { result: R[]; error: string[]; } = { result: [], error: [] };
284
- for (let i = 0; i < list.length; i++) {
285
- try {
286
- const startIndex = (i - 1) * ps.everyLength;
287
- const endIndex = startIndex + list[i]!.length - 1;
288
- reasons.result.push(fn(list[i]!, i, list.length, extendParams[i], startIndex, endIndex) as R);
289
- } catch (error) {
290
- reasons.error.push(error as string);
291
- }
292
- }
293
- return reasons;
294
- }
295
- }
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
- }