@aitianyu.cn/types 0.0.12 → 0.1.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/dist/lib/{utilities/coding → coding}/Error.js +44 -44
- package/dist/lib/{utilities/coding → coding}/Path.js +210 -198
- package/dist/lib/{utilities/core → core}/Errors.js +86 -86
- package/dist/lib/{utilities/core → core}/Language.js +561 -559
- package/dist/lib/{utilities/core → core}/Log.js +112 -108
- package/dist/lib/{utilities/core → core}/TypeConvertion.js +25 -25
- package/dist/lib/{utilities/core → core}/interface/ITJSON.js +3 -3
- package/dist/lib/{utilities/core → core}/interface/ITianyuType.js +3 -3
- package/dist/lib/{utilities/core → core}/object/ArrayHelper.js +35 -35
- package/dist/lib/core/object/Bytes.js +21 -0
- package/dist/lib/{utilities/core → core}/object/Calculater.js +240 -230
- package/dist/lib/core/object/DataView.js +23 -0
- package/dist/lib/core/object/Integer.js +117 -0
- package/dist/lib/core/object/Json.js +35 -0
- package/dist/lib/{utilities/core/object/Helper.js → core/object/ObjectHelper.js} +202 -201
- package/dist/lib/core/object/StringHelper.js +61 -0
- package/dist/lib/{utilities/core → core}/type/TArray.js +8 -7
- package/dist/lib/{utilities/core → core}/type/TBoolean.js +7 -7
- package/dist/lib/{utilities/core → core}/type/TJSON.js +7 -7
- package/dist/lib/{utilities/core → core}/type/TNumber.js +7 -7
- package/dist/lib/{utilities/core → core}/type/TObject.js +7 -7
- package/dist/lib/{utilities/core → core}/type/TString.js +7 -7
- package/dist/lib/index.js +70 -54
- package/dist/lib/security/Base32.js +104 -0
- package/dist/lib/security/Guid.js +26 -0
- package/dist/lib/{utilities/security → security}/Hash.js +16 -15
- package/dist/lib/security/QRCode.js +46 -0
- package/dist/lib/security/RSA.js +62 -0
- package/dist/lib/security/SHA.js +67 -0
- 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 +139 -138
- package/dist/lib/types/Types.js +3 -3
- package/dist/lib/types/index.js +17 -17
- package/dist/types/{utilities/coding → coding}/Error.d.ts +27 -27
- package/dist/types/{utilities/coding → coding}/Path.d.ts +61 -61
- package/dist/types/{utilities/core → core}/Errors.d.ts +47 -47
- package/dist/types/{utilities/core → core}/Language.d.ts +17 -17
- package/dist/types/{utilities/core → core}/Log.d.ts +12 -12
- package/dist/types/{utilities/core → core}/TypeConvertion.d.ts +2 -2
- package/dist/types/{utilities/core → core}/interface/ITJSON.d.ts +5 -5
- package/dist/types/{utilities/core → core}/interface/ITianyuType.d.ts +5 -5
- package/dist/types/{utilities/core → core}/object/ArrayHelper.d.ts +11 -11
- package/dist/types/core/object/Bytes.d.ts +13 -0
- package/dist/types/{utilities/core → core}/object/Calculater.d.ts +22 -22
- package/dist/types/core/object/DataView.d.ts +11 -0
- package/dist/types/core/object/Integer.d.ts +71 -0
- package/dist/types/core/object/Json.d.ts +22 -0
- package/dist/types/{utilities/core/object/Helper.d.ts → core/object/ObjectHelper.d.ts} +39 -39
- package/dist/types/core/object/StringHelper.d.ts +21 -0
- package/dist/types/{utilities/core → core}/type/TArray.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TBoolean.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TJSON.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TNumber.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TObject.d.ts +3 -3
- package/dist/types/{utilities/core → core}/type/TString.d.ts +3 -3
- package/dist/types/index.d.ts +29 -21
- package/dist/types/security/Base32.d.ts +42 -0
- package/dist/types/security/Guid.d.ts +4 -0
- package/dist/types/{utilities/security → security}/Hash.d.ts +3 -3
- package/dist/types/security/QRCode.d.ts +11 -0
- package/dist/types/security/RSA.d.ts +68 -0
- package/dist/types/security/SHA.d.ts +40 -0
- 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 -25
- package/dist/types/types/index.d.ts +9 -9
- package/package.json +57 -51
- package/dist/lib/utilities/coding/index.js +0 -10
- package/dist/lib/utilities/core/index.js +0 -21
- package/dist/lib/utilities/core/object/StringHelper.js +0 -22
- package/dist/lib/utilities/security/Guid.js +0 -20
- package/dist/lib/utilities/security/index.js +0 -8
- package/dist/types/utilities/coding/index.d.ts +0 -3
- package/dist/types/utilities/core/index.d.ts +0 -6
- package/dist/types/utilities/core/object/StringHelper.d.ts +0 -4
- package/dist/types/utilities/security/Guid.d.ts +0 -3
- package/dist/types/utilities/security/index.d.ts +0 -3
package/dist/lib/index.js
CHANGED
|
@@ -1,54 +1,70 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**@format */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.hash = exports.guid = exports.StringHelper = exports.ArrayHelper = exports.ObjectHelper = exports.ObjectCalculater = exports.getBoolean = exports.Performance = exports.Log = exports.parseAreaString = exports.parseAreaCode = exports.ObjectDiffMergeFailedException = exports.ObjectDiffApplyInvalidStatusException = exports.ObjectMergeStatusCheckFailedException = exports.ObjectCloneFunctionNotSupportException = exports.ArgumentNullOrEmptyException = exports.Path = exports.PathDirAndFileConvertInvaild = exports.PathDirectoryValidationFailException = exports.PathProcessorSourceLostException = exports.TMap = exports.EncryptOption = exports.PathBase = exports.LogLevel = exports.Exception = exports.AreaCode = void 0;
|
|
5
|
-
// src/types
|
|
6
|
-
var AreaCode_1 = require("./types/AreaCode");
|
|
7
|
-
Object.defineProperty(exports, "AreaCode", { enumerable: true, get: function () { return AreaCode_1.AreaCode; } });
|
|
8
|
-
var Exception_1 = require("./types/Exception");
|
|
9
|
-
Object.defineProperty(exports, "Exception", { enumerable: true, get: function () { return Exception_1.Exception; } });
|
|
10
|
-
var Logs_1 = require("./types/Logs");
|
|
11
|
-
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return Logs_1.LogLevel; } });
|
|
12
|
-
var PathBase_1 = require("./types/PathBase");
|
|
13
|
-
Object.defineProperty(exports, "PathBase", { enumerable: true, get: function () { return PathBase_1.PathBase; } });
|
|
14
|
-
var Security_1 = require("./types/Security");
|
|
15
|
-
Object.defineProperty(exports, "EncryptOption", { enumerable: true, get: function () { return Security_1.EncryptOption; } });
|
|
16
|
-
var TMap_1 = require("./types/TMap");
|
|
17
|
-
Object.defineProperty(exports, "TMap", { enumerable: true, get: function () { return TMap_1.TMap; } });
|
|
18
|
-
// utilities
|
|
19
|
-
// coding
|
|
20
|
-
var Error_1 = require("./
|
|
21
|
-
Object.defineProperty(exports, "PathProcessorSourceLostException", { enumerable: true, get: function () { return Error_1.PathProcessorSourceLostException; } });
|
|
22
|
-
Object.defineProperty(exports, "PathDirectoryValidationFailException", { enumerable: true, get: function () { return Error_1.PathDirectoryValidationFailException; } });
|
|
23
|
-
Object.defineProperty(exports, "PathDirAndFileConvertInvaild", { enumerable: true, get: function () { return Error_1.PathDirAndFileConvertInvaild; } });
|
|
24
|
-
var Path_1 = require("./
|
|
25
|
-
Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return Path_1.Path; } });
|
|
26
|
-
// core
|
|
27
|
-
var Errors_1 = require("./
|
|
28
|
-
Object.defineProperty(exports, "ArgumentNullOrEmptyException", { enumerable: true, get: function () { return Errors_1.ArgumentNullOrEmptyException; } });
|
|
29
|
-
Object.defineProperty(exports, "ObjectCloneFunctionNotSupportException", { enumerable: true, get: function () { return Errors_1.ObjectCloneFunctionNotSupportException; } });
|
|
30
|
-
Object.defineProperty(exports, "ObjectMergeStatusCheckFailedException", { enumerable: true, get: function () { return Errors_1.ObjectMergeStatusCheckFailedException; } });
|
|
31
|
-
Object.defineProperty(exports, "ObjectDiffApplyInvalidStatusException", { enumerable: true, get: function () { return Errors_1.ObjectDiffApplyInvalidStatusException; } });
|
|
32
|
-
Object.defineProperty(exports, "ObjectDiffMergeFailedException", { enumerable: true, get: function () { return Errors_1.ObjectDiffMergeFailedException; } });
|
|
33
|
-
var Language_1 = require("./
|
|
34
|
-
Object.defineProperty(exports, "parseAreaCode", { enumerable: true, get: function () { return Language_1.parseAreaCode; } });
|
|
35
|
-
Object.defineProperty(exports, "parseAreaString", { enumerable: true, get: function () { return Language_1.parseAreaString; } });
|
|
36
|
-
var Log_1 = require("./
|
|
37
|
-
Object.defineProperty(exports, "Log", { enumerable: true, get: function () { return Log_1.Log; } });
|
|
38
|
-
Object.defineProperty(exports, "Performance", { enumerable: true, get: function () { return Log_1.Performance; } });
|
|
39
|
-
var TypeConvertion_1 = require("./
|
|
40
|
-
Object.defineProperty(exports, "getBoolean", { enumerable: true, get: function () { return TypeConvertion_1.getBoolean; } });
|
|
41
|
-
//// object
|
|
42
|
-
var Calculater_1 = require("./
|
|
43
|
-
Object.defineProperty(exports, "ObjectCalculater", { enumerable: true, get: function () { return Calculater_1.ObjectCalculater; } });
|
|
44
|
-
var
|
|
45
|
-
Object.defineProperty(exports, "ObjectHelper", { enumerable: true, get: function () { return
|
|
46
|
-
var ArrayHelper_1 = require("./
|
|
47
|
-
Object.defineProperty(exports, "ArrayHelper", { enumerable: true, get: function () { return ArrayHelper_1.ArrayHelper; } });
|
|
48
|
-
var StringHelper_1 = require("./
|
|
49
|
-
Object.defineProperty(exports, "StringHelper", { enumerable: true, get: function () { return StringHelper_1.StringHelper; } });
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SHA = exports.RSA = exports.QRCode = exports.hash = exports.guid = exports.Base32 = exports.Json = exports.Integer = exports.DataView = exports.Bytes = exports.StringHelper = exports.ArrayHelper = exports.ObjectHelper = exports.ObjectCalculater = exports.getBoolean = exports.Performance = exports.Log = exports.parseAreaString = exports.parseAreaCode = exports.ObjectDiffMergeFailedException = exports.ObjectDiffApplyInvalidStatusException = exports.ObjectMergeStatusCheckFailedException = exports.ObjectCloneFunctionNotSupportException = exports.ArgumentNullOrEmptyException = exports.Path = exports.PathDirAndFileConvertInvaild = exports.PathDirectoryValidationFailException = exports.PathProcessorSourceLostException = exports.TMap = exports.EncryptOption = exports.PathBase = exports.LogLevel = exports.Exception = exports.AreaCode = void 0;
|
|
5
|
+
// src/types
|
|
6
|
+
var AreaCode_1 = require("./types/AreaCode");
|
|
7
|
+
Object.defineProperty(exports, "AreaCode", { enumerable: true, get: function () { return AreaCode_1.AreaCode; } });
|
|
8
|
+
var Exception_1 = require("./types/Exception");
|
|
9
|
+
Object.defineProperty(exports, "Exception", { enumerable: true, get: function () { return Exception_1.Exception; } });
|
|
10
|
+
var Logs_1 = require("./types/Logs");
|
|
11
|
+
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return Logs_1.LogLevel; } });
|
|
12
|
+
var PathBase_1 = require("./types/PathBase");
|
|
13
|
+
Object.defineProperty(exports, "PathBase", { enumerable: true, get: function () { return PathBase_1.PathBase; } });
|
|
14
|
+
var Security_1 = require("./types/Security");
|
|
15
|
+
Object.defineProperty(exports, "EncryptOption", { enumerable: true, get: function () { return Security_1.EncryptOption; } });
|
|
16
|
+
var TMap_1 = require("./types/TMap");
|
|
17
|
+
Object.defineProperty(exports, "TMap", { enumerable: true, get: function () { return TMap_1.TMap; } });
|
|
18
|
+
// utilities
|
|
19
|
+
// coding
|
|
20
|
+
var Error_1 = require("./coding/Error");
|
|
21
|
+
Object.defineProperty(exports, "PathProcessorSourceLostException", { enumerable: true, get: function () { return Error_1.PathProcessorSourceLostException; } });
|
|
22
|
+
Object.defineProperty(exports, "PathDirectoryValidationFailException", { enumerable: true, get: function () { return Error_1.PathDirectoryValidationFailException; } });
|
|
23
|
+
Object.defineProperty(exports, "PathDirAndFileConvertInvaild", { enumerable: true, get: function () { return Error_1.PathDirAndFileConvertInvaild; } });
|
|
24
|
+
var Path_1 = require("./coding/Path");
|
|
25
|
+
Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return Path_1.Path; } });
|
|
26
|
+
// core
|
|
27
|
+
var Errors_1 = require("./core/Errors");
|
|
28
|
+
Object.defineProperty(exports, "ArgumentNullOrEmptyException", { enumerable: true, get: function () { return Errors_1.ArgumentNullOrEmptyException; } });
|
|
29
|
+
Object.defineProperty(exports, "ObjectCloneFunctionNotSupportException", { enumerable: true, get: function () { return Errors_1.ObjectCloneFunctionNotSupportException; } });
|
|
30
|
+
Object.defineProperty(exports, "ObjectMergeStatusCheckFailedException", { enumerable: true, get: function () { return Errors_1.ObjectMergeStatusCheckFailedException; } });
|
|
31
|
+
Object.defineProperty(exports, "ObjectDiffApplyInvalidStatusException", { enumerable: true, get: function () { return Errors_1.ObjectDiffApplyInvalidStatusException; } });
|
|
32
|
+
Object.defineProperty(exports, "ObjectDiffMergeFailedException", { enumerable: true, get: function () { return Errors_1.ObjectDiffMergeFailedException; } });
|
|
33
|
+
var Language_1 = require("./core/Language");
|
|
34
|
+
Object.defineProperty(exports, "parseAreaCode", { enumerable: true, get: function () { return Language_1.parseAreaCode; } });
|
|
35
|
+
Object.defineProperty(exports, "parseAreaString", { enumerable: true, get: function () { return Language_1.parseAreaString; } });
|
|
36
|
+
var Log_1 = require("./core/Log");
|
|
37
|
+
Object.defineProperty(exports, "Log", { enumerable: true, get: function () { return Log_1.Log; } });
|
|
38
|
+
Object.defineProperty(exports, "Performance", { enumerable: true, get: function () { return Log_1.Performance; } });
|
|
39
|
+
var TypeConvertion_1 = require("./core/TypeConvertion");
|
|
40
|
+
Object.defineProperty(exports, "getBoolean", { enumerable: true, get: function () { return TypeConvertion_1.getBoolean; } });
|
|
41
|
+
//// object
|
|
42
|
+
var Calculater_1 = require("./core/object/Calculater");
|
|
43
|
+
Object.defineProperty(exports, "ObjectCalculater", { enumerable: true, get: function () { return Calculater_1.ObjectCalculater; } });
|
|
44
|
+
var ObjectHelper_1 = require("./core/object/ObjectHelper");
|
|
45
|
+
Object.defineProperty(exports, "ObjectHelper", { enumerable: true, get: function () { return ObjectHelper_1.ObjectHelper; } });
|
|
46
|
+
var ArrayHelper_1 = require("./core/object/ArrayHelper");
|
|
47
|
+
Object.defineProperty(exports, "ArrayHelper", { enumerable: true, get: function () { return ArrayHelper_1.ArrayHelper; } });
|
|
48
|
+
var StringHelper_1 = require("./core/object/StringHelper");
|
|
49
|
+
Object.defineProperty(exports, "StringHelper", { enumerable: true, get: function () { return StringHelper_1.StringHelper; } });
|
|
50
|
+
var Bytes_1 = require("./core/object/Bytes");
|
|
51
|
+
Object.defineProperty(exports, "Bytes", { enumerable: true, get: function () { return Bytes_1.Bytes; } });
|
|
52
|
+
var DataView_1 = require("./core/object/DataView");
|
|
53
|
+
Object.defineProperty(exports, "DataView", { enumerable: true, get: function () { return DataView_1.DataView; } });
|
|
54
|
+
var Integer_1 = require("./core/object/Integer");
|
|
55
|
+
Object.defineProperty(exports, "Integer", { enumerable: true, get: function () { return Integer_1.Integer; } });
|
|
56
|
+
var Json_1 = require("./core/object/Json");
|
|
57
|
+
Object.defineProperty(exports, "Json", { enumerable: true, get: function () { return Json_1.Json; } });
|
|
58
|
+
// security
|
|
59
|
+
var Base32_1 = require("./security/Base32");
|
|
60
|
+
Object.defineProperty(exports, "Base32", { enumerable: true, get: function () { return Base32_1.Base32; } });
|
|
61
|
+
var Guid_1 = require("./security/Guid");
|
|
62
|
+
Object.defineProperty(exports, "guid", { enumerable: true, get: function () { return Guid_1.guid; } });
|
|
63
|
+
var Hash_1 = require("./security/Hash");
|
|
64
|
+
Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return Hash_1.hash; } });
|
|
65
|
+
var QRCode_1 = require("./security/QRCode");
|
|
66
|
+
Object.defineProperty(exports, "QRCode", { enumerable: true, get: function () { return QRCode_1.QRCode; } });
|
|
67
|
+
var RSA_1 = require("./security/RSA");
|
|
68
|
+
Object.defineProperty(exports, "RSA", { enumerable: true, get: function () { return RSA_1.RSA; } });
|
|
69
|
+
var SHA_1 = require("./security/SHA");
|
|
70
|
+
Object.defineProperty(exports, "SHA", { enumerable: true, get: function () { return SHA_1.SHA; } });
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Base32 = void 0;
|
|
5
|
+
const Bytes_1 = require("../core/object/Bytes");
|
|
6
|
+
const DataView_1 = require("../core/object/DataView");
|
|
7
|
+
const Integer_1 = require("../core/object/Integer");
|
|
8
|
+
const StringHelper_1 = require("../core/object/StringHelper");
|
|
9
|
+
/** Base32 Encoding Lib */
|
|
10
|
+
class Base32 {
|
|
11
|
+
static RFC4648_CHS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
12
|
+
static RFC4648_HEX_CHS = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
|
13
|
+
static CROCKFORD_CHS = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
14
|
+
/**
|
|
15
|
+
* To encode the buffer to be a Base32 encoded string
|
|
16
|
+
*
|
|
17
|
+
* @param data input source buffer
|
|
18
|
+
* @param encoding encoding type
|
|
19
|
+
* @returns return the encoded string
|
|
20
|
+
*/
|
|
21
|
+
static encode(data, encoding) {
|
|
22
|
+
const alphabet = Base32.getAlphabet(encoding);
|
|
23
|
+
const view = DataView_1.DataView.parse(data);
|
|
24
|
+
let bits = 0;
|
|
25
|
+
let value = 0;
|
|
26
|
+
let output = "";
|
|
27
|
+
for (let i = 0; i < view.byteLength; i++) {
|
|
28
|
+
value = Integer_1.Integer.or(Integer_1.Integer.left(value, 8), view.getUint8(i));
|
|
29
|
+
bits += 8;
|
|
30
|
+
while (bits >= 5) {
|
|
31
|
+
const index = Integer_1.Integer.and(Integer_1.Integer.rightUnsigned(value, bits - 5), 31);
|
|
32
|
+
const char = alphabet[index];
|
|
33
|
+
if (char === undefined) {
|
|
34
|
+
throw new Error(StringHelper_1.StringHelper.format('Invalid index: {0} in alphabet "{1}"', [index, alphabet]));
|
|
35
|
+
}
|
|
36
|
+
output += char;
|
|
37
|
+
bits -= 5;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (bits > 0) {
|
|
41
|
+
output += alphabet[Integer_1.Integer.and(Integer_1.Integer.left(value, 5 - bits), 31)];
|
|
42
|
+
}
|
|
43
|
+
if (encoding !== "Crockford") {
|
|
44
|
+
while (output.length % 8 !== 0) {
|
|
45
|
+
output += "=";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return output;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Decode the input string to be an array buffer
|
|
52
|
+
*
|
|
53
|
+
* @param input source string
|
|
54
|
+
* @param encoding encoding type
|
|
55
|
+
* @returns return the target array buffer
|
|
56
|
+
*/
|
|
57
|
+
static decode(input, encoding) {
|
|
58
|
+
const alphabet = Base32.getAlphabet(encoding);
|
|
59
|
+
const data = encoding !== "Crockford" ? input.replace(/=+$/, "") : input.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1");
|
|
60
|
+
const length = data.length;
|
|
61
|
+
let bits = 0;
|
|
62
|
+
let value = 0;
|
|
63
|
+
let index = 0;
|
|
64
|
+
const output = new Uint8Array(Integer_1.Integer.or((length * 5) / 8, 0));
|
|
65
|
+
for (let i = 0; i < length; i++) {
|
|
66
|
+
value = Integer_1.Integer.or(Integer_1.Integer.left(value, 5), Base32.readChar(alphabet, data[i]));
|
|
67
|
+
bits += 5;
|
|
68
|
+
if (bits >= 8) {
|
|
69
|
+
output[index++] = Integer_1.Integer.and(Integer_1.Integer.rightUnsigned(value, bits - 8), 255);
|
|
70
|
+
bits -= 8;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return output.buffer;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get a random string which is encoded by given encoding type
|
|
77
|
+
*
|
|
78
|
+
* @param size random bytes size
|
|
79
|
+
* @param encoding encoding type
|
|
80
|
+
* @returns return encoded random string
|
|
81
|
+
*/
|
|
82
|
+
static random(size, encoding = "RFC4648") {
|
|
83
|
+
const bytes = Bytes_1.Bytes.random(size);
|
|
84
|
+
return Base32.encode(bytes, encoding);
|
|
85
|
+
}
|
|
86
|
+
static getAlphabet(encoding) {
|
|
87
|
+
const alphabet = encoding === "RFC4648" || encoding === "RFC3548"
|
|
88
|
+
? Base32.RFC4648_CHS
|
|
89
|
+
: encoding === "RFC4648-HEX"
|
|
90
|
+
? Base32.RFC4648_HEX_CHS
|
|
91
|
+
: encoding === "Crockford"
|
|
92
|
+
? Base32.CROCKFORD_CHS
|
|
93
|
+
: "";
|
|
94
|
+
return alphabet;
|
|
95
|
+
}
|
|
96
|
+
static readChar(alphabet, char) {
|
|
97
|
+
const idx = alphabet.indexOf(char);
|
|
98
|
+
if (idx === -1) {
|
|
99
|
+
throw new Error(StringHelper_1.StringHelper.format("Invalid character found: {0}", char));
|
|
100
|
+
}
|
|
101
|
+
return idx;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.Base32 = Base32;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.guid = void 0;
|
|
5
|
+
const Integer_1 = require("../core/object/Integer");
|
|
6
|
+
const UUID_TEMPLATE = {
|
|
7
|
+
none: "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx",
|
|
8
|
+
default: "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",
|
|
9
|
+
};
|
|
10
|
+
/** Generate a Guid value string */
|
|
11
|
+
function guid(type = "default") {
|
|
12
|
+
let d = new Date().getTime();
|
|
13
|
+
if (typeof performance === "undefined") {
|
|
14
|
+
// global.performance = require("perf_hooks").performance;
|
|
15
|
+
// eslint-disable-next-line no-eval
|
|
16
|
+
global.performance = eval("require")("perf_hooks").performance;
|
|
17
|
+
}
|
|
18
|
+
d += performance.now(); //use high-precision timer if available
|
|
19
|
+
const uuid = UUID_TEMPLATE[type].replace(/[xy]/g, (c) => {
|
|
20
|
+
const r = Integer_1.Integer.or((d + Math.random() * 16) % 16, 0); // d是随机种子
|
|
21
|
+
d = Math.floor(d / 16);
|
|
22
|
+
return (c === "x" ? r : Integer_1.Integer.or(Integer_1.Integer.and(r, 0x3), 0x8)).toString(16);
|
|
23
|
+
});
|
|
24
|
+
return uuid;
|
|
25
|
+
}
|
|
26
|
+
exports.guid = guid;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**@format */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.hash = void 0;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
hashCode = hashCode
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.hash = void 0;
|
|
5
|
+
const Integer_1 = require("../core/object/Integer");
|
|
6
|
+
/** Generate a hash code number of the string */
|
|
7
|
+
function hash(source) {
|
|
8
|
+
let length = source.length;
|
|
9
|
+
let hashCode = 0;
|
|
10
|
+
while (length--) {
|
|
11
|
+
hashCode = Integer_1.Integer.left(hashCode, 5) - hashCode + source.charCodeAt(length);
|
|
12
|
+
hashCode = Integer_1.Integer.and(hashCode, hashCode); // convert to 32 bit
|
|
13
|
+
}
|
|
14
|
+
return hashCode;
|
|
15
|
+
}
|
|
16
|
+
exports.hash = hash;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @format */
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.QRCode = void 0;
|
|
28
|
+
const qrcode = __importStar(require("qrcode"));
|
|
29
|
+
/** QR code Lib */
|
|
30
|
+
class QRCode {
|
|
31
|
+
/**
|
|
32
|
+
* Async getting a base64 URL of given text
|
|
33
|
+
*
|
|
34
|
+
* @param text source text
|
|
35
|
+
* @returns return base64 URL string
|
|
36
|
+
*/
|
|
37
|
+
static async getURL(text) {
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
qrcode.toDataURL(text, (error, url) => {
|
|
40
|
+
const textURL = error ? "" : url;
|
|
41
|
+
resolve(textURL);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.QRCode = QRCode;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.RSA = void 0;
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
/** RSA Lib */
|
|
7
|
+
class RSA {
|
|
8
|
+
/**
|
|
9
|
+
* To get a new RSA public key and private key
|
|
10
|
+
*
|
|
11
|
+
* @param options RSA key generation option
|
|
12
|
+
* @returns return new RSA key
|
|
13
|
+
*/
|
|
14
|
+
static new(options) {
|
|
15
|
+
const { publicKey, privateKey } = (0, crypto_1.generateKeyPairSync)("rsa", options);
|
|
16
|
+
return {
|
|
17
|
+
privateKey: privateKey,
|
|
18
|
+
publicKey: publicKey,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* To encode a value with public key, the encoded data can be decoded by private key
|
|
23
|
+
*
|
|
24
|
+
* @param data input data
|
|
25
|
+
* @param publicKey encoding public key
|
|
26
|
+
* @returns return encoded buffer
|
|
27
|
+
*/
|
|
28
|
+
static encodepub(data, publicKey) {
|
|
29
|
+
return (0, crypto_1.publicEncrypt)(publicKey, data);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* To encode a value with private key, the encoded data can be decoded by public key
|
|
33
|
+
*
|
|
34
|
+
* @param data input data
|
|
35
|
+
* @param publicKey encoding private key
|
|
36
|
+
* @returns return encoded buffer
|
|
37
|
+
*/
|
|
38
|
+
static encodepri(data, privateKey) {
|
|
39
|
+
return (0, crypto_1.privateEncrypt)(privateKey, data);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* To decode a value with public key, the value is encoded by private key
|
|
43
|
+
*
|
|
44
|
+
* @param data input data
|
|
45
|
+
* @param publicKey decoding public key
|
|
46
|
+
* @returns return decoded buffer
|
|
47
|
+
*/
|
|
48
|
+
static decodepub(data, publicKey) {
|
|
49
|
+
return (0, crypto_1.publicDecrypt)(publicKey, data);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* To decode a value with private key, the value is encoded by public key
|
|
53
|
+
*
|
|
54
|
+
* @param data input data
|
|
55
|
+
* @param privateKey decoding private key
|
|
56
|
+
* @returns return decoded buffer
|
|
57
|
+
*/
|
|
58
|
+
static decodepri(data, privateKey) {
|
|
59
|
+
return (0, crypto_1.privateDecrypt)(privateKey, data);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.RSA = RSA;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @format */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SHA = void 0;
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
/** SHA Lib */
|
|
10
|
+
class SHA {
|
|
11
|
+
/**
|
|
12
|
+
* Calculate SHA256 code of data based on specified string encoding.
|
|
13
|
+
*
|
|
14
|
+
* @param data source data
|
|
15
|
+
* @param encoding string encoding type, default encoding type is 'utf-8', only used when data type is string
|
|
16
|
+
* @returns return the SHA256 code buffer
|
|
17
|
+
*/
|
|
18
|
+
static sha256(data, encoding = "utf-8") {
|
|
19
|
+
return SHA.sha("sha256", data, encoding);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Calculate SHA512 code of data based on specified string encoding.
|
|
23
|
+
*
|
|
24
|
+
* @param data source data
|
|
25
|
+
* @param encoding string encoding type, default encoding type is 'utf-8', only used when data type is string
|
|
26
|
+
* @returns return the SHA256 code buffer
|
|
27
|
+
*/
|
|
28
|
+
static sha512(data, encoding = "utf-8") {
|
|
29
|
+
return SHA.sha("sha512", data, encoding);
|
|
30
|
+
}
|
|
31
|
+
static sha(algorithm, data, encoding) {
|
|
32
|
+
const buffer = typeof data === "string" ? Buffer.from(data, encoding) : data;
|
|
33
|
+
const hash = crypto_1.default.createHash(algorithm);
|
|
34
|
+
hash.update(buffer);
|
|
35
|
+
return hash.digest();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Calculate SHA256 code of data based on a stream
|
|
39
|
+
*
|
|
40
|
+
* @param stream data stream
|
|
41
|
+
* @returns return the encoded buffer
|
|
42
|
+
*/
|
|
43
|
+
static async stream256(stream) {
|
|
44
|
+
return SHA.streamSHA("sha256", stream);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Calculate SHA512 code of data based on a stream
|
|
48
|
+
*
|
|
49
|
+
* @param stream data stream
|
|
50
|
+
* @returns return the encoded buffer
|
|
51
|
+
*/
|
|
52
|
+
static async stream512(stream) {
|
|
53
|
+
return SHA.streamSHA("sha512", stream);
|
|
54
|
+
}
|
|
55
|
+
static async streamSHA(algorithm, stream) {
|
|
56
|
+
const hash = crypto_1.default.createHash(algorithm);
|
|
57
|
+
return new Promise((resolve) => {
|
|
58
|
+
stream.on("data", (data) => {
|
|
59
|
+
hash.update(data);
|
|
60
|
+
});
|
|
61
|
+
stream.on("end", () => {
|
|
62
|
+
resolve(hash.digest());
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.SHA = SHA;
|