@aitianyu.cn/types 0.0.11 → 0.0.13
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/dist/lib/index.js +54 -54
- package/dist/lib/types/AreaCode.js +269 -269
- package/dist/lib/types/Exception.js +19 -19
- package/dist/lib/types/Logs.js +20 -20
- package/dist/lib/types/Object.js +3 -3
- package/dist/lib/types/PathBase.js +109 -109
- package/dist/lib/types/Security.js +10 -10
- package/dist/lib/types/TMap.js +138 -138
- package/dist/lib/types/Types.js +3 -3
- package/dist/lib/types/index.js +17 -17
- package/dist/lib/utilities/coding/Error.js +44 -44
- package/dist/lib/utilities/coding/Path.js +198 -198
- package/dist/lib/utilities/coding/index.js +10 -10
- package/dist/lib/utilities/core/Errors.js +86 -86
- package/dist/lib/utilities/core/Language.js +559 -559
- package/dist/lib/utilities/core/Log.js +108 -108
- package/dist/lib/utilities/core/TypeConvertion.js +25 -25
- package/dist/lib/utilities/core/index.js +21 -21
- package/dist/lib/utilities/core/interface/ITJSON.js +3 -0
- package/dist/lib/utilities/core/interface/ITianyuType.js +3 -0
- package/dist/lib/utilities/core/object/ArrayHelper.js +35 -35
- package/dist/lib/utilities/core/object/Calculater.js +230 -230
- package/dist/lib/utilities/core/object/Helper.js +201 -201
- package/dist/lib/utilities/core/object/StringHelper.js +22 -22
- package/dist/lib/utilities/core/type/TArray.js +7 -0
- package/dist/lib/utilities/core/type/TBoolean.js +7 -0
- package/dist/lib/utilities/core/type/TJSON.js +7 -0
- package/dist/lib/utilities/core/type/TNumber.js +7 -0
- package/dist/lib/utilities/core/type/TObject.js +7 -0
- package/dist/lib/utilities/core/type/TString.js +7 -0
- package/dist/lib/utilities/security/Guid.js +20 -20
- package/dist/lib/utilities/security/Hash.js +15 -15
- package/dist/lib/utilities/security/index.js +8 -8
- package/dist/types/index.d.ts +21 -21
- package/dist/types/types/AreaCode.d.ts +135 -135
- package/dist/types/types/Exception.d.ts +11 -11
- package/dist/types/types/Logs.d.ts +64 -64
- package/dist/types/types/Object.d.ts +18 -18
- package/dist/types/types/PathBase.d.ts +76 -76
- package/dist/types/types/Security.d.ts +23 -23
- package/dist/types/types/TMap.d.ts +80 -80
- package/dist/types/types/Types.d.ts +25 -20
- package/dist/types/types/index.d.ts +9 -9
- package/dist/types/utilities/coding/Error.d.ts +27 -27
- package/dist/types/utilities/coding/Path.d.ts +61 -61
- package/dist/types/utilities/coding/index.d.ts +3 -3
- package/dist/types/utilities/core/Errors.d.ts +47 -47
- package/dist/types/utilities/core/Language.d.ts +17 -17
- package/dist/types/utilities/core/Log.d.ts +12 -12
- package/dist/types/utilities/core/TypeConvertion.d.ts +2 -2
- package/dist/types/utilities/core/index.d.ts +6 -6
- package/dist/types/utilities/core/interface/ITJSON.d.ts +5 -0
- package/dist/types/utilities/core/interface/ITianyuType.d.ts +5 -0
- package/dist/types/utilities/core/object/ArrayHelper.d.ts +11 -11
- package/dist/types/utilities/core/object/Calculater.d.ts +22 -22
- package/dist/types/utilities/core/object/Helper.d.ts +39 -39
- package/dist/types/utilities/core/object/StringHelper.d.ts +4 -4
- package/dist/types/utilities/core/type/TArray.d.ts +3 -0
- package/dist/types/utilities/core/type/TBoolean.d.ts +3 -0
- package/dist/types/utilities/core/type/TJSON.d.ts +3 -0
- package/dist/types/utilities/core/type/TNumber.d.ts +3 -0
- package/dist/types/utilities/core/type/TObject.d.ts +3 -0
- package/dist/types/utilities/core/type/TString.d.ts +3 -0
- package/dist/types/utilities/security/Guid.d.ts +3 -3
- package/dist/types/utilities/security/Hash.d.ts +3 -3
- package/dist/types/utilities/security/index.d.ts +3 -3
- package/package.json +51 -51
|
@@ -1,201 +1,201 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**@format */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.ObjectHelper = void 0;
|
|
5
|
-
const Errors_1 = require("../Errors");
|
|
6
|
-
/** Object Helper of Tianyu to provide data type checking, objects comparing, validation, data clone and other functions */
|
|
7
|
-
class ObjectHelper {
|
|
8
|
-
/**
|
|
9
|
-
* check whether the specified value does extend from nodejs native type
|
|
10
|
-
*
|
|
11
|
-
* @param {any} value supported value type of tianyu store
|
|
12
|
-
* @returns {boolean} return true if the value is based on type number, string, boolean, function, otherwise false
|
|
13
|
-
*/
|
|
14
|
-
static isSimpleDataType(value) {
|
|
15
|
-
if (!!!value)
|
|
16
|
-
return true;
|
|
17
|
-
const typeofValue = typeof value;
|
|
18
|
-
return typeofValue === "boolean" || typeofValue === "string" || typeofValue === "number" || typeofValue === "symbol";
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* get a deep copy from source
|
|
22
|
-
*
|
|
23
|
-
* @param {any} sources the specified source value
|
|
24
|
-
* @returns {any} return a new value that is independent from sources
|
|
25
|
-
*/
|
|
26
|
-
static clone(source) {
|
|
27
|
-
return ObjectHelper._clone(source);
|
|
28
|
-
}
|
|
29
|
-
static _clone(source) {
|
|
30
|
-
if (typeof source === "function") {
|
|
31
|
-
throw new Errors_1.ObjectCloneFunctionNotSupportException();
|
|
32
|
-
}
|
|
33
|
-
// check if source is simple data type, return directly
|
|
34
|
-
if (ObjectHelper.isSimpleDataType(source)) {
|
|
35
|
-
return source;
|
|
36
|
-
}
|
|
37
|
-
if (Array.isArray(source)) {
|
|
38
|
-
// if is array type
|
|
39
|
-
return ObjectHelper._cloneArray(source);
|
|
40
|
-
}
|
|
41
|
-
// otherwise, source value is a record type
|
|
42
|
-
return ObjectHelper._cloneRecordType(source);
|
|
43
|
-
}
|
|
44
|
-
static _cloneArray(source) {
|
|
45
|
-
// create a new array to save result
|
|
46
|
-
const result = [];
|
|
47
|
-
if (0 === source.length) {
|
|
48
|
-
// if source value is empty array, return directly
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
// loop all the item in the source value and to clone the item
|
|
52
|
-
for (const item of source) {
|
|
53
|
-
result.push(ObjectHelper._clone(item));
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
static _cloneRecordType(source) {
|
|
58
|
-
// get all the record key from source object
|
|
59
|
-
const keys = Object.keys(source);
|
|
60
|
-
if (0 === keys.length) {
|
|
61
|
-
// if the object is empty, return an empty object
|
|
62
|
-
return {};
|
|
63
|
-
}
|
|
64
|
-
const result = {};
|
|
65
|
-
// loop all the items in the source object by the key name
|
|
66
|
-
for (const keyName of keys) {
|
|
67
|
-
const sourceItem = source[keyName];
|
|
68
|
-
result[keyName] = ObjectHelper._clone(sourceItem);
|
|
69
|
-
}
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Check the object whether can be stringified
|
|
74
|
-
*
|
|
75
|
-
* @param obj be checked object
|
|
76
|
-
* @returns return true is valid, otherwise false
|
|
77
|
-
*/
|
|
78
|
-
static validateSerializable(obj) {
|
|
79
|
-
// if type is function, is not invaliable to be string
|
|
80
|
-
if (typeof obj === "function") {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
// if is simple data type, is valiable
|
|
84
|
-
if (ObjectHelper.isSimpleDataType(obj)) {
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
// if is array, check member
|
|
88
|
-
if (Array.isArray(obj)) {
|
|
89
|
-
for (const item of obj) {
|
|
90
|
-
// contains invalid member, return false
|
|
91
|
-
if (!ObjectHelper.validateSerializable(item)) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
// if is object, check member
|
|
99
|
-
const keys = Object.keys(obj);
|
|
100
|
-
for (const keyName of keys) {
|
|
101
|
-
const item = obj[keyName];
|
|
102
|
-
// contains invalid member, return false
|
|
103
|
-
if (!ObjectHelper.validateSerializable(item)) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
// if the object is not an object type, return false
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Compare two or more objects are the same or different
|
|
116
|
-
*
|
|
117
|
-
* @param objs the objects which need to be compared
|
|
118
|
-
* @returns same - if all the objects are same, different - if at least one object is not same to other objects
|
|
119
|
-
* @description if there are only one parameter or no parameter is provided, same result will be returned
|
|
120
|
-
*/
|
|
121
|
-
static compareObjects(...objs) {
|
|
122
|
-
// if objs less than 2, is not comparable
|
|
123
|
-
if (objs.length < 2) {
|
|
124
|
-
return "same";
|
|
125
|
-
}
|
|
126
|
-
// if the first obj is simple data type, return different if other objects is not simple obj
|
|
127
|
-
// or the type is not totally same.
|
|
128
|
-
if (ObjectHelper.isSimpleDataType(objs[0])) {
|
|
129
|
-
return ObjectHelper._compareSimpleType(...objs);
|
|
130
|
-
}
|
|
131
|
-
// if the first obj is array type, check all the objects are array and to do the detail checking
|
|
132
|
-
if (Array.isArray(objs[0])) {
|
|
133
|
-
return ObjectHelper._compareArrayType(...objs);
|
|
134
|
-
}
|
|
135
|
-
return ObjectHelper._compareObjectType(...objs);
|
|
136
|
-
}
|
|
137
|
-
static _compareSimpleType(...objs) {
|
|
138
|
-
const firstObjType = typeof objs[0];
|
|
139
|
-
for (let i = 1; i < objs.length; ++i) {
|
|
140
|
-
if (firstObjType !== typeof objs[i] || objs[0] !== objs[i]) {
|
|
141
|
-
return "different";
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return "same";
|
|
145
|
-
}
|
|
146
|
-
static _compareArrayType(...objs) {
|
|
147
|
-
for (let i = 1; i < objs.length; ++i) {
|
|
148
|
-
// check the type and array length if the obj is array type
|
|
149
|
-
if (!Array.isArray(objs[i]) || objs[i].length !== objs[0].length) {
|
|
150
|
-
return "different";
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
// loop each item of the array to have a detail checking
|
|
154
|
-
for (let j = 0; j < objs[0].length; ++j) {
|
|
155
|
-
// create a checking array
|
|
156
|
-
const items = [objs[0][j]];
|
|
157
|
-
for (let i = 1; i < objs.length; ++i) {
|
|
158
|
-
// add all the items of the each object which have the same index
|
|
159
|
-
items.push(objs[i][j]);
|
|
160
|
-
}
|
|
161
|
-
const cmpRes = ObjectHelper.compareObjects(...items);
|
|
162
|
-
if (cmpRes !== "same") {
|
|
163
|
-
return cmpRes;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return "same";
|
|
167
|
-
}
|
|
168
|
-
static _compareObjectType(...objs) {
|
|
169
|
-
try {
|
|
170
|
-
// other cases, the first obj is not simple obj and array, take checking as object
|
|
171
|
-
// start add all the objects keys
|
|
172
|
-
const keysOfObjs = [];
|
|
173
|
-
keysOfObjs.push(Object.keys(objs[0]));
|
|
174
|
-
// firstly, check the types of other objects
|
|
175
|
-
for (let i = 1; i < objs.length; ++i) {
|
|
176
|
-
keysOfObjs.push(Object.keys(objs[i]));
|
|
177
|
-
}
|
|
178
|
-
// check the keys are same or different
|
|
179
|
-
if (ObjectHelper.compareObjects(...keysOfObjs) !== "same") {
|
|
180
|
-
return "different";
|
|
181
|
-
}
|
|
182
|
-
// compare all the items
|
|
183
|
-
for (const key of keysOfObjs[0]) {
|
|
184
|
-
const items = [];
|
|
185
|
-
for (const obj of objs) {
|
|
186
|
-
items.push(obj[key]);
|
|
187
|
-
}
|
|
188
|
-
// get the items compare result
|
|
189
|
-
const cmpRes = ObjectHelper.compareObjects(...items);
|
|
190
|
-
if (cmpRes !== "same") {
|
|
191
|
-
return cmpRes;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return "same";
|
|
195
|
-
}
|
|
196
|
-
catch {
|
|
197
|
-
return "different";
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
exports.ObjectHelper = ObjectHelper;
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ObjectHelper = void 0;
|
|
5
|
+
const Errors_1 = require("../Errors");
|
|
6
|
+
/** Object Helper of Tianyu to provide data type checking, objects comparing, validation, data clone and other functions */
|
|
7
|
+
class ObjectHelper {
|
|
8
|
+
/**
|
|
9
|
+
* check whether the specified value does extend from nodejs native type
|
|
10
|
+
*
|
|
11
|
+
* @param {any} value supported value type of tianyu store
|
|
12
|
+
* @returns {boolean} return true if the value is based on type number, string, boolean, function, otherwise false
|
|
13
|
+
*/
|
|
14
|
+
static isSimpleDataType(value) {
|
|
15
|
+
if (!!!value)
|
|
16
|
+
return true;
|
|
17
|
+
const typeofValue = typeof value;
|
|
18
|
+
return typeofValue === "boolean" || typeofValue === "string" || typeofValue === "number" || typeofValue === "symbol";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* get a deep copy from source
|
|
22
|
+
*
|
|
23
|
+
* @param {any} sources the specified source value
|
|
24
|
+
* @returns {any} return a new value that is independent from sources
|
|
25
|
+
*/
|
|
26
|
+
static clone(source) {
|
|
27
|
+
return ObjectHelper._clone(source);
|
|
28
|
+
}
|
|
29
|
+
static _clone(source) {
|
|
30
|
+
if (typeof source === "function") {
|
|
31
|
+
throw new Errors_1.ObjectCloneFunctionNotSupportException();
|
|
32
|
+
}
|
|
33
|
+
// check if source is simple data type, return directly
|
|
34
|
+
if (ObjectHelper.isSimpleDataType(source)) {
|
|
35
|
+
return source;
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(source)) {
|
|
38
|
+
// if is array type
|
|
39
|
+
return ObjectHelper._cloneArray(source);
|
|
40
|
+
}
|
|
41
|
+
// otherwise, source value is a record type
|
|
42
|
+
return ObjectHelper._cloneRecordType(source);
|
|
43
|
+
}
|
|
44
|
+
static _cloneArray(source) {
|
|
45
|
+
// create a new array to save result
|
|
46
|
+
const result = [];
|
|
47
|
+
if (0 === source.length) {
|
|
48
|
+
// if source value is empty array, return directly
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
// loop all the item in the source value and to clone the item
|
|
52
|
+
for (const item of source) {
|
|
53
|
+
result.push(ObjectHelper._clone(item));
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
static _cloneRecordType(source) {
|
|
58
|
+
// get all the record key from source object
|
|
59
|
+
const keys = Object.keys(source);
|
|
60
|
+
if (0 === keys.length) {
|
|
61
|
+
// if the object is empty, return an empty object
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
const result = {};
|
|
65
|
+
// loop all the items in the source object by the key name
|
|
66
|
+
for (const keyName of keys) {
|
|
67
|
+
const sourceItem = source[keyName];
|
|
68
|
+
result[keyName] = ObjectHelper._clone(sourceItem);
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Check the object whether can be stringified
|
|
74
|
+
*
|
|
75
|
+
* @param obj be checked object
|
|
76
|
+
* @returns return true is valid, otherwise false
|
|
77
|
+
*/
|
|
78
|
+
static validateSerializable(obj) {
|
|
79
|
+
// if type is function, is not invaliable to be string
|
|
80
|
+
if (typeof obj === "function") {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
// if is simple data type, is valiable
|
|
84
|
+
if (ObjectHelper.isSimpleDataType(obj)) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
// if is array, check member
|
|
88
|
+
if (Array.isArray(obj)) {
|
|
89
|
+
for (const item of obj) {
|
|
90
|
+
// contains invalid member, return false
|
|
91
|
+
if (!ObjectHelper.validateSerializable(item)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
// if is object, check member
|
|
99
|
+
const keys = Object.keys(obj);
|
|
100
|
+
for (const keyName of keys) {
|
|
101
|
+
const item = obj[keyName];
|
|
102
|
+
// contains invalid member, return false
|
|
103
|
+
if (!ObjectHelper.validateSerializable(item)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// if the object is not an object type, return false
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Compare two or more objects are the same or different
|
|
116
|
+
*
|
|
117
|
+
* @param objs the objects which need to be compared
|
|
118
|
+
* @returns same - if all the objects are same, different - if at least one object is not same to other objects
|
|
119
|
+
* @description if there are only one parameter or no parameter is provided, same result will be returned
|
|
120
|
+
*/
|
|
121
|
+
static compareObjects(...objs) {
|
|
122
|
+
// if objs less than 2, is not comparable
|
|
123
|
+
if (objs.length < 2) {
|
|
124
|
+
return "same";
|
|
125
|
+
}
|
|
126
|
+
// if the first obj is simple data type, return different if other objects is not simple obj
|
|
127
|
+
// or the type is not totally same.
|
|
128
|
+
if (ObjectHelper.isSimpleDataType(objs[0])) {
|
|
129
|
+
return ObjectHelper._compareSimpleType(...objs);
|
|
130
|
+
}
|
|
131
|
+
// if the first obj is array type, check all the objects are array and to do the detail checking
|
|
132
|
+
if (Array.isArray(objs[0])) {
|
|
133
|
+
return ObjectHelper._compareArrayType(...objs);
|
|
134
|
+
}
|
|
135
|
+
return ObjectHelper._compareObjectType(...objs);
|
|
136
|
+
}
|
|
137
|
+
static _compareSimpleType(...objs) {
|
|
138
|
+
const firstObjType = typeof objs[0];
|
|
139
|
+
for (let i = 1; i < objs.length; ++i) {
|
|
140
|
+
if (firstObjType !== typeof objs[i] || objs[0] !== objs[i]) {
|
|
141
|
+
return "different";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return "same";
|
|
145
|
+
}
|
|
146
|
+
static _compareArrayType(...objs) {
|
|
147
|
+
for (let i = 1; i < objs.length; ++i) {
|
|
148
|
+
// check the type and array length if the obj is array type
|
|
149
|
+
if (!Array.isArray(objs[i]) || objs[i].length !== objs[0].length) {
|
|
150
|
+
return "different";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// loop each item of the array to have a detail checking
|
|
154
|
+
for (let j = 0; j < objs[0].length; ++j) {
|
|
155
|
+
// create a checking array
|
|
156
|
+
const items = [objs[0][j]];
|
|
157
|
+
for (let i = 1; i < objs.length; ++i) {
|
|
158
|
+
// add all the items of the each object which have the same index
|
|
159
|
+
items.push(objs[i][j]);
|
|
160
|
+
}
|
|
161
|
+
const cmpRes = ObjectHelper.compareObjects(...items);
|
|
162
|
+
if (cmpRes !== "same") {
|
|
163
|
+
return cmpRes;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return "same";
|
|
167
|
+
}
|
|
168
|
+
static _compareObjectType(...objs) {
|
|
169
|
+
try {
|
|
170
|
+
// other cases, the first obj is not simple obj and array, take checking as object
|
|
171
|
+
// start add all the objects keys
|
|
172
|
+
const keysOfObjs = [];
|
|
173
|
+
keysOfObjs.push(Object.keys(objs[0]));
|
|
174
|
+
// firstly, check the types of other objects
|
|
175
|
+
for (let i = 1; i < objs.length; ++i) {
|
|
176
|
+
keysOfObjs.push(Object.keys(objs[i]));
|
|
177
|
+
}
|
|
178
|
+
// check the keys are same or different
|
|
179
|
+
if (ObjectHelper.compareObjects(...keysOfObjs) !== "same") {
|
|
180
|
+
return "different";
|
|
181
|
+
}
|
|
182
|
+
// compare all the items
|
|
183
|
+
for (const key of keysOfObjs[0]) {
|
|
184
|
+
const items = [];
|
|
185
|
+
for (const obj of objs) {
|
|
186
|
+
items.push(obj[key]);
|
|
187
|
+
}
|
|
188
|
+
// get the items compare result
|
|
189
|
+
const cmpRes = ObjectHelper.compareObjects(...items);
|
|
190
|
+
if (cmpRes !== "same") {
|
|
191
|
+
return cmpRes;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return "same";
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return "different";
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.ObjectHelper = ObjectHelper;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**@format */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.StringHelper = void 0;
|
|
5
|
-
class StringHelper {
|
|
6
|
-
static format(source, args) {
|
|
7
|
-
if (!args) {
|
|
8
|
-
return source;
|
|
9
|
-
}
|
|
10
|
-
const argument = Array.isArray(args) ? args : [args];
|
|
11
|
-
return source.replace(/('')|\{([0-9]+(?:\s*,[^{}]*)?)\}|[{}]/g, (_match, $1, $2, _$3) => {
|
|
12
|
-
if ($1) {
|
|
13
|
-
return "'";
|
|
14
|
-
}
|
|
15
|
-
else if ($2) {
|
|
16
|
-
return String(argument[parseInt($2, 10)]);
|
|
17
|
-
}
|
|
18
|
-
return "";
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.StringHelper = StringHelper;
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.StringHelper = void 0;
|
|
5
|
+
class StringHelper {
|
|
6
|
+
static format(source, args) {
|
|
7
|
+
if (!args) {
|
|
8
|
+
return source;
|
|
9
|
+
}
|
|
10
|
+
const argument = Array.isArray(args) ? args : [args];
|
|
11
|
+
return source.replace(/('')|\{([0-9]+(?:\s*,[^{}]*)?)\}|[{}]/g, (_match, $1, $2, _$3) => {
|
|
12
|
+
if ($1) {
|
|
13
|
+
return "'";
|
|
14
|
+
}
|
|
15
|
+
else if ($2) {
|
|
16
|
+
return String(argument[parseInt($2, 10)]);
|
|
17
|
+
}
|
|
18
|
+
return "";
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.StringHelper = StringHelper;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**@format */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.guid = void 0;
|
|
5
|
-
/** Generate a Guid value string */
|
|
6
|
-
function guid() {
|
|
7
|
-
let d = new Date().getTime();
|
|
8
|
-
if (typeof performance === "undefined") {
|
|
9
|
-
// global.performance = require("perf_hooks").performance;
|
|
10
|
-
global.performance = eval("require")("perf_hooks").performance;
|
|
11
|
-
}
|
|
12
|
-
d += performance.now(); //use high-precision timer if available
|
|
13
|
-
const uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
14
|
-
const r = (d + Math.random() * 16) % 16 | 0; // d是随机种子
|
|
15
|
-
d = Math.floor(d / 16);
|
|
16
|
-
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
|
|
17
|
-
});
|
|
18
|
-
return uuid;
|
|
19
|
-
}
|
|
20
|
-
exports.guid = guid;
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.guid = void 0;
|
|
5
|
+
/** Generate a Guid value string */
|
|
6
|
+
function guid() {
|
|
7
|
+
let d = new Date().getTime();
|
|
8
|
+
if (typeof performance === "undefined") {
|
|
9
|
+
// global.performance = require("perf_hooks").performance;
|
|
10
|
+
global.performance = eval("require")("perf_hooks").performance;
|
|
11
|
+
}
|
|
12
|
+
d += performance.now(); //use high-precision timer if available
|
|
13
|
+
const uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
14
|
+
const r = (d + Math.random() * 16) % 16 | 0; // d是随机种子
|
|
15
|
+
d = Math.floor(d / 16);
|
|
16
|
+
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
|
|
17
|
+
});
|
|
18
|
+
return uuid;
|
|
19
|
+
}
|
|
20
|
+
exports.guid = guid;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**@format */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.hash = void 0;
|
|
5
|
-
/** Generate a hash code number of the string */
|
|
6
|
-
function hash(source) {
|
|
7
|
-
let length = source.length;
|
|
8
|
-
let hashCode = 0;
|
|
9
|
-
while (length--) {
|
|
10
|
-
hashCode = (hashCode << 5) - hashCode + source.charCodeAt(length);
|
|
11
|
-
hashCode = hashCode & hashCode; // convert to 32 bit
|
|
12
|
-
}
|
|
13
|
-
return hashCode;
|
|
14
|
-
}
|
|
15
|
-
exports.hash = hash;
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.hash = void 0;
|
|
5
|
+
/** Generate a hash code number of the string */
|
|
6
|
+
function hash(source) {
|
|
7
|
+
let length = source.length;
|
|
8
|
+
let hashCode = 0;
|
|
9
|
+
while (length--) {
|
|
10
|
+
hashCode = (hashCode << 5) - hashCode + source.charCodeAt(length);
|
|
11
|
+
hashCode = hashCode & hashCode; // convert to 32 bit
|
|
12
|
+
}
|
|
13
|
+
return hashCode;
|
|
14
|
+
}
|
|
15
|
+
exports.hash = hash;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**@format */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.hash = exports.guid = void 0;
|
|
5
|
-
var Guid_1 = require("./Guid");
|
|
6
|
-
Object.defineProperty(exports, "guid", { enumerable: true, get: function () { return Guid_1.guid; } });
|
|
7
|
-
var Hash_1 = require("./Hash");
|
|
8
|
-
Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return Hash_1.hash; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.hash = exports.guid = void 0;
|
|
5
|
+
var Guid_1 = require("./Guid");
|
|
6
|
+
Object.defineProperty(exports, "guid", { enumerable: true, get: function () { return Guid_1.guid; } });
|
|
7
|
+
var Hash_1 = require("./Hash");
|
|
8
|
+
Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return Hash_1.hash; } });
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
/**@format */
|
|
2
|
-
export { AreaCode } from "./types/AreaCode";
|
|
3
|
-
export { Exception } from "./types/Exception";
|
|
4
|
-
export { LogLevel, type ILog, type IPerfRecorder } from "./types/Logs";
|
|
5
|
-
export { type IObjectDiffInfo, type ObjectDiffMap } from "./types/Object";
|
|
6
|
-
export { PathBase } from "./types/PathBase";
|
|
7
|
-
export { EncryptOption, type ICipher } from "./types/Security";
|
|
8
|
-
export { TMap } from "./types/TMap";
|
|
9
|
-
export { type MapOfBoolean, type MapOfStrings, type MapOfString, type MapOfType, type CallbackAction, type CallbackActionT, type IComparable, } from "./types/Types";
|
|
10
|
-
export { PathProcessorSourceLostException, PathDirectoryValidationFailException, PathDirAndFileConvertInvaild, } from "./utilities/coding/Error";
|
|
11
|
-
export { type PathTargetType, Path } from "./utilities/coding/Path";
|
|
12
|
-
export { ArgumentNullOrEmptyException, ObjectCloneFunctionNotSupportException, ObjectMergeStatusCheckFailedException, ObjectDiffApplyInvalidStatusException, ObjectDiffMergeFailedException, } from "./utilities/core/Errors";
|
|
13
|
-
export { parseAreaCode, parseAreaString } from "./utilities/core/Language";
|
|
14
|
-
export { Log, Performance } from "./utilities/core/Log";
|
|
15
|
-
export { getBoolean } from "./utilities/core/TypeConvertion";
|
|
16
|
-
export { ObjectCalculater } from "./utilities/core/object/Calculater";
|
|
17
|
-
export { ObjectHelper } from "./utilities/core/object/Helper";
|
|
18
|
-
export { ArrayHelper } from "./utilities/core/object/ArrayHelper";
|
|
19
|
-
export { StringHelper } from "./utilities/core/object/StringHelper";
|
|
20
|
-
export { guid } from "./utilities/security/Guid";
|
|
21
|
-
export { hash } from "./utilities/security/Hash";
|
|
1
|
+
/**@format */
|
|
2
|
+
export { AreaCode } from "./types/AreaCode";
|
|
3
|
+
export { Exception } from "./types/Exception";
|
|
4
|
+
export { LogLevel, type ILog, type IPerfRecorder } from "./types/Logs";
|
|
5
|
+
export { type IObjectDiffInfo, type ObjectDiffMap } from "./types/Object";
|
|
6
|
+
export { PathBase } from "./types/PathBase";
|
|
7
|
+
export { EncryptOption, type ICipher } from "./types/Security";
|
|
8
|
+
export { TMap } from "./types/TMap";
|
|
9
|
+
export { type MapOfBoolean, type MapOfStrings, type MapOfString, type MapOfType, type CallbackAction, type CallbackActionT, type IComparable, type KeyValuePair, } from "./types/Types";
|
|
10
|
+
export { PathProcessorSourceLostException, PathDirectoryValidationFailException, PathDirAndFileConvertInvaild, } from "./utilities/coding/Error";
|
|
11
|
+
export { type PathTargetType, Path } from "./utilities/coding/Path";
|
|
12
|
+
export { ArgumentNullOrEmptyException, ObjectCloneFunctionNotSupportException, ObjectMergeStatusCheckFailedException, ObjectDiffApplyInvalidStatusException, ObjectDiffMergeFailedException, } from "./utilities/core/Errors";
|
|
13
|
+
export { parseAreaCode, parseAreaString } from "./utilities/core/Language";
|
|
14
|
+
export { Log, Performance } from "./utilities/core/Log";
|
|
15
|
+
export { getBoolean } from "./utilities/core/TypeConvertion";
|
|
16
|
+
export { ObjectCalculater } from "./utilities/core/object/Calculater";
|
|
17
|
+
export { ObjectHelper } from "./utilities/core/object/Helper";
|
|
18
|
+
export { ArrayHelper } from "./utilities/core/object/ArrayHelper";
|
|
19
|
+
export { StringHelper } from "./utilities/core/object/StringHelper";
|
|
20
|
+
export { guid } from "./utilities/security/Guid";
|
|
21
|
+
export { hash } from "./utilities/security/Hash";
|