baja-lite 1.0.0
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/LICENSE +21 -0
- package/README.md +1 -0
- package/cjs/constant.d.ts +13 -0
- package/cjs/constant.js +19 -0
- package/cjs/error.d.ts +5 -0
- package/cjs/error.js +16 -0
- package/cjs/fn.d.ts +128 -0
- package/cjs/fn.js +169 -0
- package/cjs/index.d.ts +8 -0
- package/cjs/index.js +24 -0
- package/cjs/math.d.ts +69 -0
- package/cjs/math.js +435 -0
- package/cjs/now.d.ts +7 -0
- package/cjs/now.js +26 -0
- package/cjs/object.d.ts +77 -0
- package/cjs/object.js +212 -0
- package/cjs/set-ex.d.ts +171 -0
- package/cjs/set-ex.js +336 -0
- package/cjs/sql.d.ts +1216 -0
- package/cjs/sql.js +3380 -0
- package/cjs/string.d.ts +18 -0
- package/cjs/string.js +124 -0
- package/cjs/test-mysql.d.ts +1 -0
- package/cjs/test-mysql.js +108 -0
- package/cjs/test-sqlite.d.ts +1 -0
- package/cjs/test-sqlite.js +89 -0
- package/cjs/test.d.ts +1 -0
- package/cjs/test.js +4 -0
- package/es/constant.d.ts +13 -0
- package/es/constant.js +16 -0
- package/es/error.d.ts +5 -0
- package/es/error.js +13 -0
- package/es/fn.d.ts +128 -0
- package/es/fn.js +162 -0
- package/es/index.d.ts +8 -0
- package/es/index.js +8 -0
- package/es/math.d.ts +69 -0
- package/es/math.js +414 -0
- package/es/now.d.ts +7 -0
- package/es/now.js +16 -0
- package/es/object.d.ts +77 -0
- package/es/object.js +196 -0
- package/es/set-ex.d.ts +171 -0
- package/es/set-ex.js +332 -0
- package/es/sql.d.ts +1216 -0
- package/es/sql.js +3338 -0
- package/es/string.d.ts +18 -0
- package/es/string.js +109 -0
- package/es/test-mysql.d.ts +1 -0
- package/es/test-mysql.js +106 -0
- package/es/test-sqlite.d.ts +1 -0
- package/es/test-sqlite.js +87 -0
- package/es/test.d.ts +1 -0
- package/es/test.js +2 -0
- package/package.json +66 -0
package/cjs/math.js
ADDED
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getGeo = exports.calc = exports.Bus = exports.money = exports.merge = exports.round = exports.sub = exports.mul = exports.add = exports.divDef = exports.div = exports.min = exports.max = exports.num = exports.MoneyOption = void 0;
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
17
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
18
|
+
/** 金钱格式化可用样式 */
|
|
19
|
+
class MoneyOption {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.style = 'currency';
|
|
22
|
+
this.currency = 'CNY';
|
|
23
|
+
this.prefix = 2;
|
|
24
|
+
this.def = 0;
|
|
25
|
+
this.currencyDisplay = 'symbol';
|
|
26
|
+
this.useGrouping = true;
|
|
27
|
+
this.local = 'zh';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.MoneyOption = MoneyOption;
|
|
31
|
+
// const ONE = new Decimal(1);
|
|
32
|
+
const ZERO = new decimal_js_1.default(0);
|
|
33
|
+
function isNum(a) {
|
|
34
|
+
return a !== '' && a !== null && !isNaN(a);
|
|
35
|
+
}
|
|
36
|
+
const num = (val, def = 0) => {
|
|
37
|
+
if (val instanceof Bus) {
|
|
38
|
+
return val.over();
|
|
39
|
+
}
|
|
40
|
+
else if (!isNum(val)) {
|
|
41
|
+
return def;
|
|
42
|
+
}
|
|
43
|
+
return +val;
|
|
44
|
+
};
|
|
45
|
+
exports.num = num;
|
|
46
|
+
function filterNumber(array) {
|
|
47
|
+
const res = [];
|
|
48
|
+
array.forEach((element) => {
|
|
49
|
+
if (element instanceof Bus) {
|
|
50
|
+
res.push(element.over());
|
|
51
|
+
}
|
|
52
|
+
else if (isNum(element)) {
|
|
53
|
+
res.push(+element);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return res;
|
|
57
|
+
}
|
|
58
|
+
function filterNumber2(array, def) {
|
|
59
|
+
const res = [];
|
|
60
|
+
array.forEach((element) => {
|
|
61
|
+
if (element instanceof Bus) {
|
|
62
|
+
res.push(new decimal_js_1.default(element.over()));
|
|
63
|
+
}
|
|
64
|
+
else if (isNum(element)) {
|
|
65
|
+
res.push(new decimal_js_1.default(element));
|
|
66
|
+
}
|
|
67
|
+
else if (def !== undefined) {
|
|
68
|
+
res.push(new decimal_js_1.default(def));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return res;
|
|
72
|
+
}
|
|
73
|
+
const max = (...args) => {
|
|
74
|
+
const arr = filterNumber(args);
|
|
75
|
+
return Math.max.apply(null, arr);
|
|
76
|
+
};
|
|
77
|
+
exports.max = max;
|
|
78
|
+
const min = (...args) => {
|
|
79
|
+
const arr = filterNumber(args);
|
|
80
|
+
return Math.min.apply(null, arr);
|
|
81
|
+
};
|
|
82
|
+
exports.min = min;
|
|
83
|
+
const div = (...args) => {
|
|
84
|
+
const arr = filterNumber2(args);
|
|
85
|
+
if (arr.length > 1) {
|
|
86
|
+
return arr.reduce((a, b) => a.div(b)).toNumber();
|
|
87
|
+
}
|
|
88
|
+
else if (arr.length > 0) {
|
|
89
|
+
return arr[0].toNumber();
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
exports.div = div;
|
|
96
|
+
const divDef = (def, ...args) => {
|
|
97
|
+
const arr = filterNumber2(args);
|
|
98
|
+
if (arr.length > 1) {
|
|
99
|
+
const zeros = arr.slice(1).findIndex(i => i.equals(ZERO));
|
|
100
|
+
if (zeros > -1) {
|
|
101
|
+
return new decimal_js_1.default(def).toNumber();
|
|
102
|
+
}
|
|
103
|
+
return arr.reduce((a, b) => a.div(b)).toNumber();
|
|
104
|
+
}
|
|
105
|
+
else if (arr.length > 0) {
|
|
106
|
+
return arr[0].toNumber();
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
exports.divDef = divDef;
|
|
113
|
+
const add = (...args) => {
|
|
114
|
+
const arr = filterNumber2(args);
|
|
115
|
+
if (arr.length > 1) {
|
|
116
|
+
return arr.reduce((a, b) => a.add(b)).toNumber();
|
|
117
|
+
}
|
|
118
|
+
else if (arr.length > 0) {
|
|
119
|
+
return arr[0].toNumber();
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
exports.add = add;
|
|
126
|
+
const mul = (...args) => {
|
|
127
|
+
const arr = filterNumber2(args);
|
|
128
|
+
if (arr.length > 1) {
|
|
129
|
+
return arr.reduce((a, b) => a.mul(b)).toNumber();
|
|
130
|
+
}
|
|
131
|
+
else if (arr.length > 0) {
|
|
132
|
+
return arr[0].toNumber();
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
exports.mul = mul;
|
|
139
|
+
const sub = (...args) => {
|
|
140
|
+
const arr = filterNumber2(args, 0);
|
|
141
|
+
if (arr.length > 1) {
|
|
142
|
+
return arr.reduce((a, b) => a.sub(b)).toNumber();
|
|
143
|
+
}
|
|
144
|
+
else if (arr.length > 0) {
|
|
145
|
+
return arr[0].toNumber();
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
exports.sub = sub;
|
|
152
|
+
const roundMode = [decimal_js_1.default.ROUND_HALF_UP, decimal_js_1.default.ROUND_UP, decimal_js_1.default.ROUND_DOWN];
|
|
153
|
+
const round = (number, numDigits, upOrDown = 0) => {
|
|
154
|
+
if (isNum(number)) {
|
|
155
|
+
const nu = new decimal_js_1.default(number);
|
|
156
|
+
return nu.toDP(numDigits, roundMode[upOrDown]).toNumber();
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
exports.round = round;
|
|
163
|
+
/** =value.xx,其中xx=number,如number=99,表示修正数字为value.99 */
|
|
164
|
+
const merge = function (value, number) {
|
|
165
|
+
if (isNum(value) && isNum(number)) {
|
|
166
|
+
return new decimal_js_1.default(value).floor().add(`0.${number}`).toNumber();
|
|
167
|
+
}
|
|
168
|
+
else if (isNum(value)) {
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
exports.merge = merge;
|
|
176
|
+
const money = (value, option = {}) => {
|
|
177
|
+
// Intl.NumberFormat(option.local ?? 'zh', {
|
|
178
|
+
// style: option.style ?? 'currency',
|
|
179
|
+
// currency: option.currency ?? 'CNY',
|
|
180
|
+
// minimumFractionDigits: option.prefix ?? 2,
|
|
181
|
+
// currencyDisplay: option.currencyDisplay ?? 'symbol',
|
|
182
|
+
// useGrouping: option.useGrouping ?? true
|
|
183
|
+
// }).format(isNum(value) ? value : option.def).replace(/CN|\s/g, '');
|
|
184
|
+
return (isNum(value) ? value : option.def).toLocaleString(option.local ?? 'zh', {
|
|
185
|
+
style: option.style ?? 'currency',
|
|
186
|
+
currency: option.currency ?? 'CNY',
|
|
187
|
+
minimumFractionDigits: option.prefix ?? 2,
|
|
188
|
+
currencyDisplay: option.currencyDisplay ?? 'symbol',
|
|
189
|
+
useGrouping: option.useGrouping ?? true
|
|
190
|
+
}).replace(/CN|\s/g, '');
|
|
191
|
+
};
|
|
192
|
+
exports.money = money;
|
|
193
|
+
const IF = function () {
|
|
194
|
+
return function (_target, _propertyKey, descriptor) {
|
|
195
|
+
const fn = descriptor.value;
|
|
196
|
+
descriptor.value = function () {
|
|
197
|
+
if (this['ifit'] === true) {
|
|
198
|
+
// eslint-disable-next-line prefer-rest-params
|
|
199
|
+
const args = Array.from(arguments);
|
|
200
|
+
fn.call(this, ...args);
|
|
201
|
+
}
|
|
202
|
+
this['ifit'] = true;
|
|
203
|
+
return this;
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
class Bus {
|
|
208
|
+
constructor(result) {
|
|
209
|
+
this.ifit = true;
|
|
210
|
+
this.result = (0, exports.num)(result);
|
|
211
|
+
}
|
|
212
|
+
add(...args) {
|
|
213
|
+
this.result = (0, exports.add)(this.result, ...args);
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
sub(...args) {
|
|
217
|
+
this.result = (0, exports.sub)(this.result, ...args);
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
div(...args) {
|
|
221
|
+
this.result = (0, exports.div)(this.result, ...args);
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
divDef(def, ...args) {
|
|
225
|
+
this.result = (0, exports.divDef)(def, this.result, ...args);
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
mul(...args) {
|
|
229
|
+
this.result = (0, exports.mul)(this.result, ...args);
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
max(...args) {
|
|
233
|
+
this.result = (0, exports.max)(this.result, ...args);
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
min(...args) {
|
|
237
|
+
this.result = (0, exports.min)(this.result, ...args);
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
240
|
+
ac() {
|
|
241
|
+
this.result = (0, exports.sub)(0, this.result);
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
abs() {
|
|
245
|
+
this.result = Math.abs(this.result);
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
round(numDigits, upOrDown) {
|
|
249
|
+
this.result = (0, exports.round)(this.result, numDigits, upOrDown);
|
|
250
|
+
return this;
|
|
251
|
+
}
|
|
252
|
+
merge(number) {
|
|
253
|
+
this.result = (0, exports.merge)(this.result, number);
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
if(condition) {
|
|
257
|
+
this.ifit = condition;
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
260
|
+
over() {
|
|
261
|
+
return this.result;
|
|
262
|
+
}
|
|
263
|
+
money(option) {
|
|
264
|
+
return (0, exports.money)(this.result, option);
|
|
265
|
+
}
|
|
266
|
+
lt(data) {
|
|
267
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
268
|
+
return r.lessThan(d);
|
|
269
|
+
}
|
|
270
|
+
le(data) {
|
|
271
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
272
|
+
return r.lessThanOrEqualTo(d);
|
|
273
|
+
}
|
|
274
|
+
gt(data) {
|
|
275
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
276
|
+
return r.greaterThan(d);
|
|
277
|
+
}
|
|
278
|
+
ge(data) {
|
|
279
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
280
|
+
return r.greaterThanOrEqualTo(d);
|
|
281
|
+
}
|
|
282
|
+
nlt(data) {
|
|
283
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
284
|
+
return !r.lessThan(d);
|
|
285
|
+
}
|
|
286
|
+
nle(data) {
|
|
287
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
288
|
+
return !r.lessThanOrEqualTo(d);
|
|
289
|
+
}
|
|
290
|
+
ngt(data) {
|
|
291
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
292
|
+
return !r.greaterThan(d);
|
|
293
|
+
}
|
|
294
|
+
nge(data) {
|
|
295
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
296
|
+
return !r.greaterThanOrEqualTo(d);
|
|
297
|
+
}
|
|
298
|
+
eq(data) {
|
|
299
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
300
|
+
return r.equals(d);
|
|
301
|
+
}
|
|
302
|
+
ne(data) {
|
|
303
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
304
|
+
return !r.eq(d);
|
|
305
|
+
}
|
|
306
|
+
ifLt(data) {
|
|
307
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
308
|
+
this.ifit = r.lessThan(d);
|
|
309
|
+
return this;
|
|
310
|
+
}
|
|
311
|
+
ifLe(data) {
|
|
312
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
313
|
+
this.ifit = r.lessThanOrEqualTo(d);
|
|
314
|
+
return this;
|
|
315
|
+
}
|
|
316
|
+
ifGt(data) {
|
|
317
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
318
|
+
this.ifit = r.greaterThan(d);
|
|
319
|
+
return this;
|
|
320
|
+
}
|
|
321
|
+
ifGe(data) {
|
|
322
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
323
|
+
this.ifit = r.greaterThanOrEqualTo(d);
|
|
324
|
+
return this;
|
|
325
|
+
}
|
|
326
|
+
ifNlt(data) {
|
|
327
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
328
|
+
this.ifit = !r.lessThan(d);
|
|
329
|
+
return this;
|
|
330
|
+
}
|
|
331
|
+
ifNle(data) {
|
|
332
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
333
|
+
this.ifit = !r.lessThanOrEqualTo(d);
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
ifNgt(data) {
|
|
337
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
338
|
+
this.ifit = !r.greaterThan(d);
|
|
339
|
+
return this;
|
|
340
|
+
}
|
|
341
|
+
ifNge(data) {
|
|
342
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
343
|
+
this.ifit = !r.greaterThanOrEqualTo(d);
|
|
344
|
+
return this;
|
|
345
|
+
}
|
|
346
|
+
ifEq(data) {
|
|
347
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
348
|
+
this.ifit = r.equals(d);
|
|
349
|
+
return this;
|
|
350
|
+
}
|
|
351
|
+
ifNe(data) {
|
|
352
|
+
const [d, r] = filterNumber2([data, this.result]);
|
|
353
|
+
this.ifit = !r.eq(d);
|
|
354
|
+
return this;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
exports.Bus = Bus;
|
|
358
|
+
__decorate([
|
|
359
|
+
IF(),
|
|
360
|
+
__metadata("design:type", Function),
|
|
361
|
+
__metadata("design:paramtypes", [Object]),
|
|
362
|
+
__metadata("design:returntype", Object)
|
|
363
|
+
], Bus.prototype, "add", null);
|
|
364
|
+
__decorate([
|
|
365
|
+
IF(),
|
|
366
|
+
__metadata("design:type", Function),
|
|
367
|
+
__metadata("design:paramtypes", [Object]),
|
|
368
|
+
__metadata("design:returntype", Object)
|
|
369
|
+
], Bus.prototype, "sub", null);
|
|
370
|
+
__decorate([
|
|
371
|
+
IF(),
|
|
372
|
+
__metadata("design:type", Function),
|
|
373
|
+
__metadata("design:paramtypes", [Object]),
|
|
374
|
+
__metadata("design:returntype", Object)
|
|
375
|
+
], Bus.prototype, "div", null);
|
|
376
|
+
__decorate([
|
|
377
|
+
IF(),
|
|
378
|
+
__metadata("design:type", Function),
|
|
379
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
380
|
+
__metadata("design:returntype", Object)
|
|
381
|
+
], Bus.prototype, "divDef", null);
|
|
382
|
+
__decorate([
|
|
383
|
+
IF(),
|
|
384
|
+
__metadata("design:type", Function),
|
|
385
|
+
__metadata("design:paramtypes", [Object]),
|
|
386
|
+
__metadata("design:returntype", Object)
|
|
387
|
+
], Bus.prototype, "mul", null);
|
|
388
|
+
__decorate([
|
|
389
|
+
IF(),
|
|
390
|
+
__metadata("design:type", Function),
|
|
391
|
+
__metadata("design:paramtypes", [Object]),
|
|
392
|
+
__metadata("design:returntype", Object)
|
|
393
|
+
], Bus.prototype, "max", null);
|
|
394
|
+
__decorate([
|
|
395
|
+
IF(),
|
|
396
|
+
__metadata("design:type", Function),
|
|
397
|
+
__metadata("design:paramtypes", [Object]),
|
|
398
|
+
__metadata("design:returntype", Object)
|
|
399
|
+
], Bus.prototype, "min", null);
|
|
400
|
+
__decorate([
|
|
401
|
+
IF(),
|
|
402
|
+
__metadata("design:type", Function),
|
|
403
|
+
__metadata("design:paramtypes", []),
|
|
404
|
+
__metadata("design:returntype", Object)
|
|
405
|
+
], Bus.prototype, "ac", null);
|
|
406
|
+
__decorate([
|
|
407
|
+
IF(),
|
|
408
|
+
__metadata("design:type", Function),
|
|
409
|
+
__metadata("design:paramtypes", []),
|
|
410
|
+
__metadata("design:returntype", Object)
|
|
411
|
+
], Bus.prototype, "abs", null);
|
|
412
|
+
__decorate([
|
|
413
|
+
IF(),
|
|
414
|
+
__metadata("design:type", Function),
|
|
415
|
+
__metadata("design:paramtypes", [Number, Number]),
|
|
416
|
+
__metadata("design:returntype", Object)
|
|
417
|
+
], Bus.prototype, "round", null);
|
|
418
|
+
__decorate([
|
|
419
|
+
IF(),
|
|
420
|
+
__metadata("design:type", Function),
|
|
421
|
+
__metadata("design:paramtypes", [Object]),
|
|
422
|
+
__metadata("design:returntype", void 0)
|
|
423
|
+
], Bus.prototype, "merge", null);
|
|
424
|
+
const calc = (result) => {
|
|
425
|
+
return new Bus(result);
|
|
426
|
+
};
|
|
427
|
+
exports.calc = calc;
|
|
428
|
+
const getGeo = (p1, p2) => {
|
|
429
|
+
p1.lat = (0, exports.calc)(p1.latitude).mul(Math.PI).div(180).over();
|
|
430
|
+
p1.long = (0, exports.calc)(p1.longitude).mul(Math.PI).div(180).over();
|
|
431
|
+
p2.lat = (0, exports.calc)(p2.latitude).mul(Math.PI).div(180).over();
|
|
432
|
+
p2.long = (0, exports.calc)(p2.longitude).mul(Math.PI).div(180).over();
|
|
433
|
+
return (0, exports.calc)(Math.round((0, exports.mul)(Math.asin(Math.sqrt((0, exports.add)(Math.pow(Math.sin((0, exports.div)((0, exports.sub)(p1.lat, p2.lat), 2)), 2), (0, exports.mul)(Math.cos(p1.lat), Math.cos(p2.lat), Math.pow(Math.sin((0, exports.div)((0, exports.sub)(p1.long, p2.long), 2)), 2))))), 2, 6378.137, 10000))).div(10000).round(2).over();
|
|
434
|
+
};
|
|
435
|
+
exports.getGeo = getGeo;
|
package/cjs/now.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const dateTime = "YYYY-MM-DD HH:mm:ss";
|
|
2
|
+
export declare const dateXSDTime = "YYYY-MM-DDTHH:mm:ss";
|
|
3
|
+
export declare const date = "YYYY-MM-DD";
|
|
4
|
+
export declare const nowTime: () => string;
|
|
5
|
+
export declare const nowDate: () => string;
|
|
6
|
+
export declare const nowTimeXSD: () => string;
|
|
7
|
+
export declare const dateFormat: (str: any, format?: string) => any;
|
package/cjs/now.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.dateFormat = exports.nowTimeXSD = exports.nowDate = exports.nowTime = exports.date = exports.dateXSDTime = exports.dateTime = void 0;
|
|
7
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
+
exports.dateTime = 'YYYY-MM-DD HH:mm:ss';
|
|
9
|
+
exports.dateXSDTime = 'YYYY-MM-DDTHH:mm:ss';
|
|
10
|
+
exports.date = 'YYYY-MM-DD';
|
|
11
|
+
const nowTime = () => (0, dayjs_1.default)().format(exports.dateTime);
|
|
12
|
+
exports.nowTime = nowTime;
|
|
13
|
+
const nowDate = () => (0, dayjs_1.default)().format(exports.date);
|
|
14
|
+
exports.nowDate = nowDate;
|
|
15
|
+
const nowTimeXSD = () => (0, dayjs_1.default)().format(exports.dateXSDTime);
|
|
16
|
+
exports.nowTimeXSD = nowTimeXSD;
|
|
17
|
+
const dateFormat = (str, format) => {
|
|
18
|
+
if (str) {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
20
|
+
return (0, dayjs_1.default)(str).format(format || exports.dateTime);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return str;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.dateFormat = dateFormat;
|
package/cjs/object.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 对象对象(等同与convertBean)
|
|
3
|
+
* 仅会将classType有的属性进行转换
|
|
4
|
+
* 相当与一次属性过滤
|
|
5
|
+
* @param source
|
|
6
|
+
* @param classType
|
|
7
|
+
*/
|
|
8
|
+
export declare const copyBean: <T>(source: any, classType: any) => T;
|
|
9
|
+
/**
|
|
10
|
+
* 对象转换(等同与copyBean)
|
|
11
|
+
* 仅会将classType有的属性进行转换
|
|
12
|
+
* 相当与一次属性过滤
|
|
13
|
+
* @param source
|
|
14
|
+
* @param classType
|
|
15
|
+
*/
|
|
16
|
+
export declare const convertBean: <T>(source: any, classType: any) => T;
|
|
17
|
+
/**
|
|
18
|
+
* 批量对象转换(等同与copyBean)
|
|
19
|
+
* 仅会将classType有的属性进行转换
|
|
20
|
+
* 相当与一次属性过滤
|
|
21
|
+
* @param source
|
|
22
|
+
* @param classType
|
|
23
|
+
*/
|
|
24
|
+
export declare const convertBeans: <T>(source: any[], classType: any, cb?: (target: T, source: any) => void) => T[];
|
|
25
|
+
/**
|
|
26
|
+
* 创建一个空对象
|
|
27
|
+
* 其内各属性都是null
|
|
28
|
+
* @param classType
|
|
29
|
+
*/
|
|
30
|
+
export declare const emptyBean: <T>(classType: any) => T;
|
|
31
|
+
/**
|
|
32
|
+
* 将一个json数组提取为一个json对象
|
|
33
|
+
* @param source 源数组
|
|
34
|
+
* @param key 作为新对象的key的字段
|
|
35
|
+
* @param value 作为新对象value的字段,不传则将自身为value
|
|
36
|
+
*/
|
|
37
|
+
export declare const createBeanFromArray: <F, T = F>(source: F[], key: keyof F, value?: keyof F) => {
|
|
38
|
+
[name: string]: T;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* 转换复合对象为指定bean
|
|
42
|
+
* @param source
|
|
43
|
+
* @param classType
|
|
44
|
+
*/
|
|
45
|
+
export declare const coverComplexBean: <T>(source: any, classType: any) => {
|
|
46
|
+
data: T;
|
|
47
|
+
array: {
|
|
48
|
+
[key: string]: any[];
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* 将目标对象中为空的字段替换为source中对应key的值或者函数返回值
|
|
53
|
+
* @param target
|
|
54
|
+
* @param source
|
|
55
|
+
*/
|
|
56
|
+
export declare const fixEmptyPrototy: (target: any, source: {
|
|
57
|
+
[key: string]: any;
|
|
58
|
+
}) => Promise<void>;
|
|
59
|
+
export declare const mixArray: <T>(array: T[], key: keyof T, defKey?: string) => {
|
|
60
|
+
[key: string]: number;
|
|
61
|
+
};
|
|
62
|
+
export declare const mixList: <T, V = T>(array: T[], key: keyof T, value?: keyof T, defKey?: string) => {
|
|
63
|
+
[key: string]: V[];
|
|
64
|
+
};
|
|
65
|
+
export declare const array2map: <T = string | number>(array: string[], v: T) => {
|
|
66
|
+
[key: string]: T;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* 数组分割
|
|
70
|
+
* @param datas
|
|
71
|
+
* @param config(二选一) everyLength=每组个数(最后一组可能不足次数), groupCount=拆分几组
|
|
72
|
+
* @returns T[][]
|
|
73
|
+
*/
|
|
74
|
+
export declare const arraySplit: <T = any>(datas: T[], { everyLength, groupCount }?: {
|
|
75
|
+
everyLength?: number | undefined;
|
|
76
|
+
groupCount?: number | undefined;
|
|
77
|
+
}) => T[][];
|