oak-domain 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/lib/OakError.d.ts +7 -0
- package/lib/OakError.js +29 -0
- package/lib/actions/action.d.ts +6 -0
- package/lib/actions/action.js +12 -0
- package/lib/actions/relation.d.ts +1 -0
- package/lib/actions/relation.js +2 -0
- package/lib/compiler/env.d.ts +10 -0
- package/lib/compiler/env.js +26 -0
- package/lib/compiler/schemalBuilder.d.ts +2 -0
- package/lib/compiler/schemalBuilder.js +2738 -0
- package/lib/compiler/uiBuilder.d.ts +1 -0
- package/lib/compiler/uiBuilder.js +3 -0
- package/lib/compiler/utils.d.ts +2 -0
- package/lib/compiler/utils.js +11 -0
- package/lib/store/CascadeStore.d.ts +38 -0
- package/lib/store/CascadeStore.js +681 -0
- package/lib/store/TriggerExecutor.d.ts +30 -0
- package/lib/store/TriggerExecutor.js +549 -0
- package/lib/store/UniversalContext.d.ts +26 -0
- package/lib/store/UniversalContext.js +208 -0
- package/lib/store/actionDef.d.ts +8 -0
- package/lib/store/actionDef.js +241 -0
- package/lib/store/filter.d.ts +36 -0
- package/lib/store/filter.js +121 -0
- package/lib/store/relation.d.ts +13 -0
- package/lib/store/relation.js +64 -0
- package/lib/store/watchers.d.ts +2 -0
- package/lib/store/watchers.js +32 -0
- package/lib/types/Action.d.ts +14 -0
- package/lib/types/Action.js +2 -0
- package/lib/types/AppLoader.d.ts +11 -0
- package/lib/types/AppLoader.js +10 -0
- package/lib/types/Aspect.d.ts +12 -0
- package/lib/types/Aspect.js +4 -0
- package/lib/types/Auth.d.ts +28 -0
- package/lib/types/Auth.js +2 -0
- package/lib/types/Connector.d.ts +26 -0
- package/lib/types/Connector.js +9 -0
- package/lib/types/Context.d.ts +14 -0
- package/lib/types/Context.js +3 -0
- package/lib/types/DataType.d.ts +17 -0
- package/lib/types/DataType.js +5 -0
- package/lib/types/Demand.d.ts +77 -0
- package/lib/types/Demand.js +9 -0
- package/lib/types/Entity.d.ts +138 -0
- package/lib/types/Entity.js +8 -0
- package/lib/types/Exception.d.ts +48 -0
- package/lib/types/Exception.js +178 -0
- package/lib/types/Expression.d.ts +132 -0
- package/lib/types/Expression.js +378 -0
- package/lib/types/Geo.d.ts +18 -0
- package/lib/types/Geo.js +2 -0
- package/lib/types/Locale.d.ts +24 -0
- package/lib/types/Locale.js +2 -0
- package/lib/types/Logger.d.ts +5 -0
- package/lib/types/Logger.js +3 -0
- package/lib/types/Polyfill.d.ts +23 -0
- package/lib/types/Polyfill.js +2 -0
- package/lib/types/RowStore.d.ts +22 -0
- package/lib/types/RowStore.js +33 -0
- package/lib/types/Storage.d.ts +48 -0
- package/lib/types/Storage.js +2 -0
- package/lib/types/Trigger.d.ts +105 -0
- package/lib/types/Trigger.js +24 -0
- package/lib/types/Txn.d.ts +2 -0
- package/lib/types/Txn.js +3 -0
- package/lib/types/Watcher.d.ts +19 -0
- package/lib/types/Watcher.js +4 -0
- package/lib/types/index.d.ts +18 -0
- package/lib/types/index.js +30 -0
- package/lib/types/schema/DataTypes.d.ts +32 -0
- package/lib/types/schema/DataTypes.js +3 -0
- package/lib/utils/SimpleConnector.d.ts +29 -0
- package/lib/utils/SimpleConnector.js +145 -0
- package/lib/utils/assert.d.ts +5 -0
- package/lib/utils/assert.js +11 -0
- package/lib/utils/concurrent.d.ts +15 -0
- package/lib/utils/concurrent.js +138 -0
- package/lib/utils/geo.d.ts +4 -0
- package/lib/utils/geo.js +24 -0
- package/lib/utils/lodash.d.ts +16 -0
- package/lib/utils/lodash.js +32 -0
- package/lib/utils/string.d.ts +2 -0
- package/lib/utils/string.js +11 -0
- package/lib/utils/uuid.d.ts +2 -0
- package/lib/utils/uuid.js +11 -0
- package/lib/utils/validator.d.ts +23 -0
- package/lib/utils/validator.js +123 -0
- package/package.json +38 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare type Mode = 'S' | 'X';
|
|
2
|
+
/**
|
|
3
|
+
* 模拟一个读写锁,用于同步。
|
|
4
|
+
* 注意,千万不要发生自己等自己
|
|
5
|
+
*/
|
|
6
|
+
export declare class RWLock {
|
|
7
|
+
private readNumber;
|
|
8
|
+
private writeNumber;
|
|
9
|
+
private readWaiter;
|
|
10
|
+
private writeWaiter;
|
|
11
|
+
constructor();
|
|
12
|
+
acquire(mode: Mode): Promise<void>;
|
|
13
|
+
release(): void;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.RWLock = void 0;
|
|
54
|
+
var assert_1 = __importDefault(require("assert"));
|
|
55
|
+
/**
|
|
56
|
+
* 模拟一个读写锁,用于同步。
|
|
57
|
+
* 注意,千万不要发生自己等自己
|
|
58
|
+
*/
|
|
59
|
+
var RWLock = /** @class */ (function () {
|
|
60
|
+
function RWLock() {
|
|
61
|
+
this.readNumber = 0;
|
|
62
|
+
this.writeNumber = 0;
|
|
63
|
+
this.readWaiter = [];
|
|
64
|
+
this.writeWaiter = [];
|
|
65
|
+
}
|
|
66
|
+
RWLock.prototype.acquire = function (mode) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
+
var p, p;
|
|
69
|
+
var _this = this;
|
|
70
|
+
return __generator(this, function (_a) {
|
|
71
|
+
switch (_a.label) {
|
|
72
|
+
case 0:
|
|
73
|
+
if (!(mode === 'S')) return [3 /*break*/, 4];
|
|
74
|
+
_a.label = 1;
|
|
75
|
+
case 1:
|
|
76
|
+
if (!(this.writeNumber > 0)) return [3 /*break*/, 3];
|
|
77
|
+
p = new Promise(function (resolve) { return _this.readWaiter.push(resolve); });
|
|
78
|
+
return [4 /*yield*/, p];
|
|
79
|
+
case 2:
|
|
80
|
+
_a.sent();
|
|
81
|
+
return [3 /*break*/, 1];
|
|
82
|
+
case 3:
|
|
83
|
+
this.readNumber++;
|
|
84
|
+
return [3 /*break*/, 7];
|
|
85
|
+
case 4:
|
|
86
|
+
if (!(this.writeNumber || this.readNumber)) return [3 /*break*/, 6];
|
|
87
|
+
p = new Promise(function (resolve) { return _this.writeWaiter.push(resolve); });
|
|
88
|
+
return [4 /*yield*/, p];
|
|
89
|
+
case 5:
|
|
90
|
+
_a.sent();
|
|
91
|
+
return [3 /*break*/, 4];
|
|
92
|
+
case 6:
|
|
93
|
+
this.writeNumber++;
|
|
94
|
+
_a.label = 7;
|
|
95
|
+
case 7: return [2 /*return*/];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
RWLock.prototype.release = function () {
|
|
101
|
+
var e_1, _a;
|
|
102
|
+
if (this.writeNumber) {
|
|
103
|
+
(0, assert_1.default)(this.writeNumber === 1);
|
|
104
|
+
this.writeNumber = 0;
|
|
105
|
+
if (this.readWaiter.length > 0) {
|
|
106
|
+
try {
|
|
107
|
+
for (var _b = __values(this.readWaiter), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
108
|
+
var f = _c.value;
|
|
109
|
+
f(undefined);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
113
|
+
finally {
|
|
114
|
+
try {
|
|
115
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
116
|
+
}
|
|
117
|
+
finally { if (e_1) throw e_1.error; }
|
|
118
|
+
}
|
|
119
|
+
this.readWaiter = [];
|
|
120
|
+
}
|
|
121
|
+
else if (this.writeWaiter.length > 0) {
|
|
122
|
+
var f = this.writeWaiter.pop();
|
|
123
|
+
f(undefined);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
(0, assert_1.default)(this.readNumber > 0);
|
|
128
|
+
(0, assert_1.default)(this.readWaiter.length === 0);
|
|
129
|
+
this.readNumber--;
|
|
130
|
+
if (this.readNumber === 0) {
|
|
131
|
+
var f = this.writeWaiter.pop();
|
|
132
|
+
f && f(undefined);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
return RWLock;
|
|
137
|
+
}());
|
|
138
|
+
exports.RWLock = RWLock;
|
package/lib/utils/geo.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDistanceBetweenPoints = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 计算地球上两点之间的球面距离
|
|
6
|
+
*/
|
|
7
|
+
function getDistanceBetweenPoints(lat1, lon1, lat2, lon2) {
|
|
8
|
+
// 转为弧度
|
|
9
|
+
function toRadians(d) {
|
|
10
|
+
return d * Math.PI / 180;
|
|
11
|
+
}
|
|
12
|
+
var R = 6378137; // 地球长半径
|
|
13
|
+
var φ1 = toRadians(lat1);
|
|
14
|
+
var φ2 = toRadians(lat2);
|
|
15
|
+
var Δφ = toRadians(lat2 - lat1);
|
|
16
|
+
var Δλ = toRadians(lon2 - lon1);
|
|
17
|
+
var a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
|
|
18
|
+
Math.cos(φ1) * Math.cos(φ2) *
|
|
19
|
+
Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
|
|
20
|
+
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
21
|
+
var d = R * c;
|
|
22
|
+
return d * 1000;
|
|
23
|
+
}
|
|
24
|
+
exports.getDistanceBetweenPoints = getDistanceBetweenPoints;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 避免lodash打包体积过大
|
|
3
|
+
* 像assign, keys尽量使用Object的函数
|
|
4
|
+
*/
|
|
5
|
+
import unset from 'lodash/unset';
|
|
6
|
+
import pull from 'lodash/pull';
|
|
7
|
+
import uniq from 'lodash/uniq';
|
|
8
|
+
import get from 'lodash/get';
|
|
9
|
+
import set from 'lodash/set';
|
|
10
|
+
import intersection from 'lodash/intersection';
|
|
11
|
+
import omit from 'lodash/omit';
|
|
12
|
+
import merge from 'lodash/merge';
|
|
13
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
14
|
+
import pick from 'lodash/pick';
|
|
15
|
+
import isEqual from 'lodash/isEqual';
|
|
16
|
+
export { unset, pull, uniq, get, set, intersection, omit, merge, cloneDeep, pick, isEqual, };
|
|
@@ -0,0 +1,32 @@
|
|
|
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.isEqual = exports.pick = exports.cloneDeep = exports.merge = exports.omit = exports.intersection = exports.set = exports.get = exports.uniq = exports.pull = exports.unset = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* 避免lodash打包体积过大
|
|
9
|
+
* 像assign, keys尽量使用Object的函数
|
|
10
|
+
*/
|
|
11
|
+
var unset_1 = __importDefault(require("lodash/unset"));
|
|
12
|
+
exports.unset = unset_1.default;
|
|
13
|
+
var pull_1 = __importDefault(require("lodash/pull"));
|
|
14
|
+
exports.pull = pull_1.default;
|
|
15
|
+
var uniq_1 = __importDefault(require("lodash/uniq"));
|
|
16
|
+
exports.uniq = uniq_1.default;
|
|
17
|
+
var get_1 = __importDefault(require("lodash/get"));
|
|
18
|
+
exports.get = get_1.default;
|
|
19
|
+
var set_1 = __importDefault(require("lodash/set"));
|
|
20
|
+
exports.set = set_1.default;
|
|
21
|
+
var intersection_1 = __importDefault(require("lodash/intersection"));
|
|
22
|
+
exports.intersection = intersection_1.default;
|
|
23
|
+
var omit_1 = __importDefault(require("lodash/omit"));
|
|
24
|
+
exports.omit = omit_1.default;
|
|
25
|
+
var merge_1 = __importDefault(require("lodash/merge"));
|
|
26
|
+
exports.merge = merge_1.default;
|
|
27
|
+
var cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
28
|
+
exports.cloneDeep = cloneDeep_1.default;
|
|
29
|
+
var pick_1 = __importDefault(require("lodash/pick"));
|
|
30
|
+
exports.pick = pick_1.default;
|
|
31
|
+
var isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
32
|
+
exports.isEqual = isEqual_1.default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.firstLetterUpperCase = exports.firstLetterLowerCase = void 0;
|
|
4
|
+
function firstLetterLowerCase(s) {
|
|
5
|
+
return s.slice(0, 1).toLowerCase().concat(s.slice(1));
|
|
6
|
+
}
|
|
7
|
+
exports.firstLetterLowerCase = firstLetterLowerCase;
|
|
8
|
+
function firstLetterUpperCase(s) {
|
|
9
|
+
return s.slice(0, 1).toUpperCase().concat(s.slice(1));
|
|
10
|
+
}
|
|
11
|
+
exports.firstLetterUpperCase = firstLetterUpperCase;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expandUuidTo36Bytes = exports.shrinkUuidTo32Bytes = void 0;
|
|
4
|
+
function shrinkUuidTo32Bytes(uuid) {
|
|
5
|
+
return uuid.replaceAll('-', '');
|
|
6
|
+
}
|
|
7
|
+
exports.shrinkUuidTo32Bytes = shrinkUuidTo32Bytes;
|
|
8
|
+
function expandUuidTo36Bytes(uuidShrinked) {
|
|
9
|
+
return "".concat(uuidShrinked.slice(0, 8), "-").concat(uuidShrinked.slice(8, 12), "-").concat(uuidShrinked.slice(12, 16), "-").concat(uuidShrinked.slice(16, 20), "-").concat(uuidShrinked.slice(20));
|
|
10
|
+
}
|
|
11
|
+
exports.expandUuidTo36Bytes = expandUuidTo36Bytes;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare type ValidatorFunction = (text: string, size?: number) => string | boolean;
|
|
2
|
+
declare type ValidatorMoneyFunction = (text: string, zero?: boolean) => string | boolean;
|
|
3
|
+
export declare const isMobile: ValidatorFunction;
|
|
4
|
+
export declare const isPassword: ValidatorFunction;
|
|
5
|
+
export declare const isCaptcha: ValidatorFunction;
|
|
6
|
+
export declare const isIdCardNumber: ValidatorFunction;
|
|
7
|
+
export declare const isPassportNumber: ValidatorFunction;
|
|
8
|
+
export declare const isHkCardNumber: ValidatorFunction;
|
|
9
|
+
export declare const isAmCardNumber: ValidatorFunction;
|
|
10
|
+
export declare const isTwCardNumber: ValidatorFunction;
|
|
11
|
+
export declare const isBirthNumber: ValidatorFunction;
|
|
12
|
+
export declare const isSoldierNumber: ValidatorFunction;
|
|
13
|
+
export declare const isUrl: ValidatorFunction;
|
|
14
|
+
export declare const isNickname: ValidatorFunction;
|
|
15
|
+
export declare const isSizedCaptcha: ValidatorFunction;
|
|
16
|
+
export declare const isDigital: ValidatorFunction;
|
|
17
|
+
export declare const isPhone: ValidatorFunction;
|
|
18
|
+
export declare const isNumber: ValidatorFunction;
|
|
19
|
+
export declare const isMoney: ValidatorMoneyFunction;
|
|
20
|
+
export declare const isVehicleNumber: ValidatorFunction;
|
|
21
|
+
export declare function checkAttributesNotNull<T extends Record<string, any>>(data: T, attributes: Array<keyof T>, allowEmpty?: true): void;
|
|
22
|
+
export declare function checkAttributesScope<T extends Record<string, any>>(data: T, attributes: Array<keyof T>): void;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Xc on 2018/12/23.
|
|
3
|
+
*/
|
|
4
|
+
'use strict';
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.checkAttributesScope = exports.checkAttributesNotNull = exports.isVehicleNumber = exports.isMoney = exports.isNumber = exports.isPhone = exports.isDigital = exports.isSizedCaptcha = exports.isNickname = exports.isUrl = exports.isSoldierNumber = exports.isBirthNumber = exports.isTwCardNumber = exports.isAmCardNumber = exports.isHkCardNumber = exports.isPassportNumber = exports.isIdCardNumber = exports.isCaptcha = exports.isPassword = exports.isMobile = void 0;
|
|
7
|
+
var types_1 = require("../types");
|
|
8
|
+
var isMobile = function (text) {
|
|
9
|
+
return ((text) && (typeof text === "string") && ((/^1[3|4|5|6|7|8|9]\d{9}$/.test(text))));
|
|
10
|
+
};
|
|
11
|
+
exports.isMobile = isMobile;
|
|
12
|
+
var isPassword = function (text) {
|
|
13
|
+
return ((text) && (typeof text === "string") && (/^[a-zA-Z0-9!.@]{8,16}$/.test(text)));
|
|
14
|
+
};
|
|
15
|
+
exports.isPassword = isPassword;
|
|
16
|
+
var isCaptcha = function (text) {
|
|
17
|
+
return ((text) && (typeof text === "string") && (/^\d{4}$/.test(text)));
|
|
18
|
+
};
|
|
19
|
+
exports.isCaptcha = isCaptcha;
|
|
20
|
+
var isIdCardNumber = function (text) {
|
|
21
|
+
return ((typeof text === "string") && text.length === 18 && (/^\d{6}(18|19|20)\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(text)));
|
|
22
|
+
};
|
|
23
|
+
exports.isIdCardNumber = isIdCardNumber;
|
|
24
|
+
var isPassportNumber = function (text) {
|
|
25
|
+
// 护照
|
|
26
|
+
// 规则: 14/15开头 + 7位数字, G + 8位数字, P + 7位数字, S/D + 7或8位数字,等
|
|
27
|
+
// 样本: 141234567, G12345678, P1234567
|
|
28
|
+
return typeof text === 'string' && /^([a-zA-z]|[0-9]){5,17}$/.test(text);
|
|
29
|
+
};
|
|
30
|
+
exports.isPassportNumber = isPassportNumber;
|
|
31
|
+
var isHkCardNumber = function (text) {
|
|
32
|
+
// 港澳居民来往内地通行证
|
|
33
|
+
// 规则: H/M + 10位或6位数字
|
|
34
|
+
// 样本: H1234567890
|
|
35
|
+
return typeof text === 'string' && /^([A-Z]\d{6,10}(\(\w{1}\))?)$/.test(text);
|
|
36
|
+
};
|
|
37
|
+
exports.isHkCardNumber = isHkCardNumber;
|
|
38
|
+
var isAmCardNumber = function (text) {
|
|
39
|
+
return typeof text === 'string' && /^([A-Z]\d{6,10}(\(\w{1}\))?)$/.test(text);
|
|
40
|
+
};
|
|
41
|
+
exports.isAmCardNumber = isAmCardNumber;
|
|
42
|
+
var isTwCardNumber = function (text) {
|
|
43
|
+
// 台湾居民来往大陆通行证
|
|
44
|
+
// 规则: 新版8位或18位数字, 旧版10位数字 + 英文字母
|
|
45
|
+
// 样本: 12345678 或 1234567890B
|
|
46
|
+
return typeof text === 'string' && /^\d{8}|^[a-zA-Z0-9]{10}|^\d{18}$/.test(text);
|
|
47
|
+
};
|
|
48
|
+
exports.isTwCardNumber = isTwCardNumber;
|
|
49
|
+
var isBirthNumber = function (text) {
|
|
50
|
+
return typeof text === 'string' && /^[a-zA-Z0-9]{5,21}$/.test(text);
|
|
51
|
+
};
|
|
52
|
+
exports.isBirthNumber = isBirthNumber;
|
|
53
|
+
var isSoldierNumber = function (text) {
|
|
54
|
+
// 军官证
|
|
55
|
+
// 规则: 军/兵/士/文/职/广/(其他中文) + "字第" + 4到8位字母或数字 + "号"
|
|
56
|
+
// 样本: 军字第2001988号, 士字第P011816X号
|
|
57
|
+
return typeof text === 'string' && /^[\u4E00-\u9FA5](字第)([0-9a-zA-Z]{4,8})(号?)$/.test(text);
|
|
58
|
+
};
|
|
59
|
+
exports.isSoldierNumber = isSoldierNumber;
|
|
60
|
+
var isUrl = function (str) {
|
|
61
|
+
var regex = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/;
|
|
62
|
+
return typeof str === "string" && regex.test(str);
|
|
63
|
+
};
|
|
64
|
+
exports.isUrl = isUrl;
|
|
65
|
+
var isNickname = function (str) {
|
|
66
|
+
return str && typeof str === "string" && str.trim().length > 0 && str.length < 16;
|
|
67
|
+
};
|
|
68
|
+
exports.isNickname = isNickname;
|
|
69
|
+
var isSizedCaptcha = function (text, size) {
|
|
70
|
+
return typeof text === 'string' && text.length === size && !isNaN(parseInt(text, 10));
|
|
71
|
+
};
|
|
72
|
+
exports.isSizedCaptcha = isSizedCaptcha;
|
|
73
|
+
var isDigital = function (digital) {
|
|
74
|
+
return /^\d{6,12}$/.test(digital);
|
|
75
|
+
};
|
|
76
|
+
exports.isDigital = isDigital;
|
|
77
|
+
var isPhone = function (phone) {
|
|
78
|
+
// return /^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/.test(phone);
|
|
79
|
+
return /^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/.test(phone);
|
|
80
|
+
};
|
|
81
|
+
exports.isPhone = isPhone;
|
|
82
|
+
var isNumber = function (str) {
|
|
83
|
+
return /^[0-9]*$/.test(str);
|
|
84
|
+
};
|
|
85
|
+
exports.isNumber = isNumber;
|
|
86
|
+
var isMoney = function (str, zero) {
|
|
87
|
+
// zero为true包含零
|
|
88
|
+
if (zero) {
|
|
89
|
+
// 金额,最多可以有两位小数
|
|
90
|
+
return /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(str);
|
|
91
|
+
}
|
|
92
|
+
return /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/.test(str);
|
|
93
|
+
};
|
|
94
|
+
exports.isMoney = isMoney;
|
|
95
|
+
var isVehicleNumber = function (str) {
|
|
96
|
+
// const xreg=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DF]$)|([DF][A-HJ-NP-Z0-9][0-9]{4}$))/;
|
|
97
|
+
// const creg=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
|
|
98
|
+
var reg = /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/;
|
|
99
|
+
return reg.test(str);
|
|
100
|
+
};
|
|
101
|
+
exports.isVehicleNumber = isVehicleNumber;
|
|
102
|
+
function checkAttributesNotNull(data, attributes, allowEmpty) {
|
|
103
|
+
var attrs = attributes.filter(function (attr) {
|
|
104
|
+
if (data[attr] === null || data[attr] === '') {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
if (!allowEmpty && !data.hasOwnProperty(attr)) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
if (attrs.length > 0) {
|
|
112
|
+
throw new types_1.OakInputIllegalException(attrs, '属性不能为空');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.checkAttributesNotNull = checkAttributesNotNull;
|
|
116
|
+
;
|
|
117
|
+
function checkAttributesScope(data, attributes) {
|
|
118
|
+
var attrs = attributes.filter(function (attr) { return !data.hasOwnProperty(attr); });
|
|
119
|
+
if (attrs.length > 0) {
|
|
120
|
+
throw new types_1.OakInputIllegalException(attrs, '多余的属性');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.checkAttributesScope = checkAttributesScope;
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "oak-domain",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "XuChang"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"lib/**/*"
|
|
12
|
+
],
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@babel/cli": "^7.12.13",
|
|
15
|
+
"@babel/core": "^7.12.13",
|
|
16
|
+
"@babel/plugin-proposal-class-properties": "^7.12.13",
|
|
17
|
+
"@babel/preset-env": "^7.12.13",
|
|
18
|
+
"@babel/preset-typescript": "^7.12.13",
|
|
19
|
+
"@types/assert": "^1.5.6",
|
|
20
|
+
"@types/fs-extra": "^9.0.13",
|
|
21
|
+
"@types/lodash": "^4.14.182",
|
|
22
|
+
"@types/luxon": "^2.0.9",
|
|
23
|
+
"@types/mocha": "^8.2.0",
|
|
24
|
+
"@types/node": "^14.14.25",
|
|
25
|
+
"@types/react": "^17.0.2",
|
|
26
|
+
"@types/uuid": "^8.3.0",
|
|
27
|
+
"assert": "^2.0.0",
|
|
28
|
+
"cross-env": "^7.0.2",
|
|
29
|
+
"fs-extra": "^10.0.0",
|
|
30
|
+
"mocha": "^8.2.1",
|
|
31
|
+
"ts-node": "^9.1.1",
|
|
32
|
+
"typescript": "4.5.5"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"dayjs": "^1.11.4",
|
|
36
|
+
"lodash": "^4.17.21"
|
|
37
|
+
}
|
|
38
|
+
}
|