@aitianyu.cn/types 0.0.1 → 0.0.3
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 +25 -1
- package/dist/lib/types/AreaCode.js +1 -0
- package/dist/lib/types/Exception.js +6 -0
- package/dist/lib/types/Logs.js +7 -0
- package/dist/lib/types/Object.js +3 -0
- package/dist/lib/types/PathBase.js +109 -0
- package/dist/lib/types/Security.js +1 -0
- package/dist/lib/types/TMap.js +138 -0
- package/dist/lib/types/index.js +17 -0
- package/dist/lib/utilities/coding/Error.js +44 -0
- package/dist/lib/utilities/coding/Path.js +198 -0
- package/dist/lib/utilities/coding/index.js +10 -0
- package/dist/lib/utilities/core/Errors.js +73 -1
- package/dist/lib/utilities/core/Language.js +13 -0
- package/dist/lib/utilities/core/Log.js +2 -0
- package/dist/lib/utilities/core/index.js +21 -0
- package/dist/lib/utilities/core/object/Calculater.js +230 -0
- package/dist/lib/utilities/core/object/Helper.js +201 -0
- package/dist/lib/utilities/security/Guid.js +1 -0
- package/dist/lib/utilities/security/Hash.js +1 -0
- package/dist/lib/utilities/security/index.js +8 -0
- package/dist/types/index.d.ts +9 -2
- package/dist/types/types/AreaCode.d.ts +1 -0
- package/dist/types/types/Exception.d.ts +6 -0
- package/dist/types/types/Logs.d.ts +43 -0
- package/dist/types/types/Object.d.ts +18 -0
- package/dist/types/types/PathBase.d.ts +76 -0
- package/dist/types/types/Security.d.ts +14 -0
- package/dist/types/types/TMap.d.ts +80 -0
- package/dist/types/types/Types.d.ts +13 -0
- package/dist/types/types/index.d.ts +9 -0
- package/dist/types/utilities/coding/Error.d.ts +27 -0
- package/dist/types/utilities/coding/Path.d.ts +61 -0
- package/dist/types/utilities/coding/index.d.ts +3 -0
- package/dist/types/utilities/core/Errors.d.ts +41 -0
- package/dist/types/utilities/core/Language.d.ts +13 -0
- package/dist/types/utilities/core/Log.d.ts +2 -0
- package/dist/types/utilities/core/index.d.ts +6 -0
- package/dist/types/utilities/core/object/Calculater.d.ts +22 -0
- package/dist/types/utilities/core/object/Helper.d.ts +39 -0
- package/dist/types/utilities/security/Guid.d.ts +1 -0
- package/dist/types/utilities/security/Hash.d.ts +1 -0
- package/dist/types/utilities/security/index.d.ts +3 -0
- package/package.json +11 -3
package/dist/lib/index.js
CHANGED
|
@@ -1,23 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**@format */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.hash = exports.guid = exports.Performance = exports.Log = exports.parseAreaString = exports.parseAreaCode = exports.ArgumentNullOrEmptyException = exports.EncryptOption = exports.LogLevel = exports.Exception = exports.AreaCode = void 0;
|
|
4
|
+
exports.hash = exports.guid = exports.ObjectHelper = exports.ObjectCalculater = 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
|
|
5
6
|
var AreaCode_1 = require("./types/AreaCode");
|
|
6
7
|
Object.defineProperty(exports, "AreaCode", { enumerable: true, get: function () { return AreaCode_1.AreaCode; } });
|
|
7
8
|
var Exception_1 = require("./types/Exception");
|
|
8
9
|
Object.defineProperty(exports, "Exception", { enumerable: true, get: function () { return Exception_1.Exception; } });
|
|
9
10
|
var Logs_1 = require("./types/Logs");
|
|
10
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; } });
|
|
11
14
|
var Security_1 = require("./types/Security");
|
|
12
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("./utilities/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("./utilities/coding/Path");
|
|
25
|
+
Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return Path_1.Path; } });
|
|
26
|
+
// core
|
|
13
27
|
var Errors_1 = require("./utilities/core/Errors");
|
|
14
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; } });
|
|
15
33
|
var Language_1 = require("./utilities/core/Language");
|
|
16
34
|
Object.defineProperty(exports, "parseAreaCode", { enumerable: true, get: function () { return Language_1.parseAreaCode; } });
|
|
17
35
|
Object.defineProperty(exports, "parseAreaString", { enumerable: true, get: function () { return Language_1.parseAreaString; } });
|
|
18
36
|
var Log_1 = require("./utilities/core/Log");
|
|
19
37
|
Object.defineProperty(exports, "Log", { enumerable: true, get: function () { return Log_1.Log; } });
|
|
20
38
|
Object.defineProperty(exports, "Performance", { enumerable: true, get: function () { return Log_1.Performance; } });
|
|
39
|
+
//// object
|
|
40
|
+
var Calculater_1 = require("./utilities/core/object/Calculater");
|
|
41
|
+
Object.defineProperty(exports, "ObjectCalculater", { enumerable: true, get: function () { return Calculater_1.ObjectCalculater; } });
|
|
42
|
+
var Helper_1 = require("./utilities/core/object/Helper");
|
|
43
|
+
Object.defineProperty(exports, "ObjectHelper", { enumerable: true, get: function () { return Helper_1.ObjectHelper; } });
|
|
44
|
+
// security
|
|
21
45
|
var Guid_1 = require("./utilities/security/Guid");
|
|
22
46
|
Object.defineProperty(exports, "guid", { enumerable: true, get: function () { return Guid_1.guid; } });
|
|
23
47
|
var Hash_1 = require("./utilities/security/Hash");
|
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
/**@format */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Exception = void 0;
|
|
5
|
+
/** Exception base class */
|
|
5
6
|
class Exception extends Error {
|
|
6
7
|
constructor(msg, options) {
|
|
7
8
|
super(msg, options);
|
|
8
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Get a string of the Exception object
|
|
12
|
+
*
|
|
13
|
+
* @returns return an error message
|
|
14
|
+
*/
|
|
9
15
|
toString() {
|
|
10
16
|
return this.message;
|
|
11
17
|
}
|
package/dist/lib/types/Logs.js
CHANGED
|
@@ -2,12 +2,19 @@
|
|
|
2
2
|
/**@format */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.LogLevel = void 0;
|
|
5
|
+
/** Tianyu Log Level */
|
|
5
6
|
var LogLevel;
|
|
6
7
|
(function (LogLevel) {
|
|
8
|
+
/** Debug mode log */
|
|
7
9
|
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
10
|
+
/** error msg */
|
|
8
11
|
LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
|
|
12
|
+
/** fatal error msg */
|
|
9
13
|
LogLevel[LogLevel["FATAL"] = 2] = "FATAL";
|
|
14
|
+
/** info log */
|
|
10
15
|
LogLevel[LogLevel["INFO"] = 3] = "INFO";
|
|
16
|
+
/** warning log */
|
|
11
17
|
LogLevel[LogLevel["WARNING"] = 4] = "WARNING";
|
|
18
|
+
/** default log */
|
|
12
19
|
LogLevel[LogLevel["LOG"] = 5] = "LOG";
|
|
13
20
|
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.PathBase = void 0;
|
|
5
|
+
/** Path base class */
|
|
6
|
+
class PathBase {
|
|
7
|
+
_dirs;
|
|
8
|
+
/**
|
|
9
|
+
* Create a Path instance by specified dirs
|
|
10
|
+
*
|
|
11
|
+
* @param dirs the specified directories
|
|
12
|
+
*/
|
|
13
|
+
constructor(dirs) {
|
|
14
|
+
this._dirs = (dirs && [...dirs]) || [];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Convert the path instance to string
|
|
18
|
+
*
|
|
19
|
+
* @returns return the fromatted string
|
|
20
|
+
*/
|
|
21
|
+
toString() {
|
|
22
|
+
if (0 === this._dirs.length) {
|
|
23
|
+
return "";
|
|
24
|
+
}
|
|
25
|
+
return this._dirs.join("/");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Iterator of path directories
|
|
29
|
+
*
|
|
30
|
+
* @returns return an iterator
|
|
31
|
+
*/
|
|
32
|
+
[Symbol.iterator]() {
|
|
33
|
+
let index = 0;
|
|
34
|
+
return {
|
|
35
|
+
next: () => {
|
|
36
|
+
if (index < this._dirs.length) {
|
|
37
|
+
return { done: false, value: this._dirs[index++] };
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return { done: true, value: "" };
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get a directories array deep copy
|
|
47
|
+
*
|
|
48
|
+
* @returns return directories
|
|
49
|
+
*/
|
|
50
|
+
getDirs() {
|
|
51
|
+
return this._dirs.concat();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get a number that indicates the directories count
|
|
55
|
+
*
|
|
56
|
+
* @returns return the directories count
|
|
57
|
+
*/
|
|
58
|
+
length() {
|
|
59
|
+
return this._dirs.length;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Append a new directory to the end of path
|
|
63
|
+
*
|
|
64
|
+
* @param dir the new directory name
|
|
65
|
+
* @returns return the new directories count
|
|
66
|
+
*/
|
|
67
|
+
append(dir) {
|
|
68
|
+
return this._dirs.push(dir);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Clean all the pathes
|
|
72
|
+
*/
|
|
73
|
+
clear() {
|
|
74
|
+
this._dirs = [];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Remove the end directory of the path instance and return it
|
|
78
|
+
*
|
|
79
|
+
* @returns return the end of directory
|
|
80
|
+
*/
|
|
81
|
+
pop() {
|
|
82
|
+
return this._dirs.pop();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Remove the first directory of the path instance and return it
|
|
86
|
+
*
|
|
87
|
+
* @returns return the first directory
|
|
88
|
+
*/
|
|
89
|
+
shift() {
|
|
90
|
+
return this._dirs.shift();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Convert the path instance to string for object comparing
|
|
94
|
+
*
|
|
95
|
+
* @returns return the comparable string
|
|
96
|
+
*/
|
|
97
|
+
getString() {
|
|
98
|
+
return this.toString();
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the hashcode of current path
|
|
102
|
+
*
|
|
103
|
+
* @returns always return 0
|
|
104
|
+
*/
|
|
105
|
+
getHashCode() {
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.PathBase = PathBase;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TMap = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Tianyu Map
|
|
7
|
+
* Support Customized Object type
|
|
8
|
+
*/
|
|
9
|
+
class TMap {
|
|
10
|
+
_map;
|
|
11
|
+
_kMap;
|
|
12
|
+
/**
|
|
13
|
+
* Create an empty Tianyu Map Instance
|
|
14
|
+
*/
|
|
15
|
+
constructor() {
|
|
16
|
+
this._map = new Map();
|
|
17
|
+
this._kMap = new Map();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Clean the Map instance
|
|
21
|
+
*/
|
|
22
|
+
clear() {
|
|
23
|
+
this._map.clear();
|
|
24
|
+
this._kMap.clear();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Delete a specified item from the instance
|
|
28
|
+
*
|
|
29
|
+
* @param key The key of the item
|
|
30
|
+
* @returns return true if deleted successful and return false if failed
|
|
31
|
+
*/
|
|
32
|
+
delete(key) {
|
|
33
|
+
const keyString = key.getString();
|
|
34
|
+
return this._map.delete(keyString) && this._kMap.delete(keyString);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Executes a provided function once per each key/value pair in the Map, in insertion order.
|
|
38
|
+
*
|
|
39
|
+
* @param callbackfn provided execution function
|
|
40
|
+
* @param thisArg additional args
|
|
41
|
+
*/
|
|
42
|
+
forEach(callbackfn, thisArg) {
|
|
43
|
+
const runMap = new Map();
|
|
44
|
+
this._map.forEach((value, key, map) => {
|
|
45
|
+
const keyObj = this._kMap.get(key);
|
|
46
|
+
if (!!!keyObj) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
runMap.set(keyObj, value);
|
|
50
|
+
callbackfn(value, keyObj, runMap);
|
|
51
|
+
}, thisArg);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns a specified element from the Map object. If the value that is associated to the provided key is an object,
|
|
55
|
+
* then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
|
|
56
|
+
*
|
|
57
|
+
* @param key The key of the value
|
|
58
|
+
* @returns Returns the element associated with the specified key.
|
|
59
|
+
* If no element is associated with the specified key, undefined is returned.
|
|
60
|
+
*/
|
|
61
|
+
get(key) {
|
|
62
|
+
const keyString = key.getString();
|
|
63
|
+
return this._map.get(keyString);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get a boolean value indicates whether an element with the specified key exists or not.
|
|
67
|
+
*
|
|
68
|
+
* @param key The key what wants to search
|
|
69
|
+
* @returns return true if the value is found
|
|
70
|
+
*/
|
|
71
|
+
has(key) {
|
|
72
|
+
const keyString = key.getString();
|
|
73
|
+
return this._kMap.has(keyString);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
|
|
77
|
+
*
|
|
78
|
+
* @param key The key of new element
|
|
79
|
+
* @param value The value of new element
|
|
80
|
+
* @returns return the instance that is current instance
|
|
81
|
+
*/
|
|
82
|
+
set(key, value) {
|
|
83
|
+
const keyString = key.getString();
|
|
84
|
+
this._map.set(keyString, value);
|
|
85
|
+
this._kMap.set(keyString, key);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get a number of elements in the Map
|
|
90
|
+
*
|
|
91
|
+
* @returns return the count of elements
|
|
92
|
+
*/
|
|
93
|
+
size() {
|
|
94
|
+
return this._kMap.size;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get all keys of the Map
|
|
98
|
+
*
|
|
99
|
+
* @returns return a keys iterator
|
|
100
|
+
*/
|
|
101
|
+
keys() {
|
|
102
|
+
return this._kMap.values();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get all values of the Map
|
|
106
|
+
*
|
|
107
|
+
* @returns return a values iterator
|
|
108
|
+
*/
|
|
109
|
+
values() {
|
|
110
|
+
return this._map.values();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get an Iterator of the Map
|
|
114
|
+
*
|
|
115
|
+
* @returns return an iterator object
|
|
116
|
+
*/
|
|
117
|
+
[Symbol.iterator]() {
|
|
118
|
+
const keys = this._map.entries();
|
|
119
|
+
const iteratorObj = {
|
|
120
|
+
next: () => {
|
|
121
|
+
const keyNext = keys.next();
|
|
122
|
+
if (keyNext.done) {
|
|
123
|
+
return {
|
|
124
|
+
done: true,
|
|
125
|
+
value: [undefined, undefined],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const value = [this._kMap.get(keyNext.value[0]), keyNext.value[1]];
|
|
129
|
+
return {
|
|
130
|
+
done: false,
|
|
131
|
+
value: value,
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
return iteratorObj;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.TMap = TMap;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TMap = exports.EncryptOption = exports.PathBase = exports.LogLevel = exports.Exception = exports.AreaCode = void 0;
|
|
5
|
+
// src
|
|
6
|
+
var AreaCode_1 = require("./AreaCode");
|
|
7
|
+
Object.defineProperty(exports, "AreaCode", { enumerable: true, get: function () { return AreaCode_1.AreaCode; } });
|
|
8
|
+
var Exception_1 = require("./Exception");
|
|
9
|
+
Object.defineProperty(exports, "Exception", { enumerable: true, get: function () { return Exception_1.Exception; } });
|
|
10
|
+
var Logs_1 = require("./Logs");
|
|
11
|
+
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return Logs_1.LogLevel; } });
|
|
12
|
+
var PathBase_1 = require("./PathBase");
|
|
13
|
+
Object.defineProperty(exports, "PathBase", { enumerable: true, get: function () { return PathBase_1.PathBase; } });
|
|
14
|
+
var Security_1 = require("./Security");
|
|
15
|
+
Object.defineProperty(exports, "EncryptOption", { enumerable: true, get: function () { return Security_1.EncryptOption; } });
|
|
16
|
+
var TMap_1 = require("./TMap");
|
|
17
|
+
Object.defineProperty(exports, "TMap", { enumerable: true, get: function () { return TMap_1.TMap; } });
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.PathDirAndFileConvertInvaild = exports.PathDirectoryValidationFailException = exports.PathProcessorSourceLostException = void 0;
|
|
5
|
+
const Exception_1 = require("../../types/Exception");
|
|
6
|
+
/**
|
|
7
|
+
* Source lost exception of Path Processor.
|
|
8
|
+
* Exception will be thrown if the path is file but the file field is not specified
|
|
9
|
+
*/
|
|
10
|
+
class PathProcessorSourceLostException extends Exception_1.Exception {
|
|
11
|
+
constructor(msg) {
|
|
12
|
+
super(msg);
|
|
13
|
+
}
|
|
14
|
+
toString() {
|
|
15
|
+
return `路径处理器 - 指定的参数 ( path.file ) 为空`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.PathProcessorSourceLostException = PathProcessorSourceLostException;
|
|
19
|
+
/**
|
|
20
|
+
* Path directory name is not valid.
|
|
21
|
+
* Exception will be thrown if the path name has the invalid char
|
|
22
|
+
*/
|
|
23
|
+
class PathDirectoryValidationFailException extends Exception_1.Exception {
|
|
24
|
+
constructor(msg) {
|
|
25
|
+
super(msg);
|
|
26
|
+
}
|
|
27
|
+
toString() {
|
|
28
|
+
return `路径处理器 - 指定的路径目录 ( ${this.message} ) 无效`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.PathDirectoryValidationFailException = PathDirectoryValidationFailException;
|
|
32
|
+
/**
|
|
33
|
+
* Path is file or directory but target type is not.
|
|
34
|
+
* Exception will be thrown if the path is file(directory) but try to convert to directory(file)
|
|
35
|
+
*/
|
|
36
|
+
class PathDirAndFileConvertInvaild extends Exception_1.Exception {
|
|
37
|
+
constructor(path, type) {
|
|
38
|
+
super(`${path} 为 ${type === "directory" ? "目录" : "文件"}`);
|
|
39
|
+
}
|
|
40
|
+
toString() {
|
|
41
|
+
return `路径处理器 - 不能将文件与目录相互转换 ( ${this.message} ) `;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.PathDirAndFileConvertInvaild = PathDirAndFileConvertInvaild;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Path = void 0;
|
|
5
|
+
const PathBase_1 = require("../../types/PathBase");
|
|
6
|
+
const Error_1 = require("./Error");
|
|
7
|
+
const __charInDirValidation = {
|
|
8
|
+
"/": { file: false, dir: false },
|
|
9
|
+
".": { file: true, dir: false },
|
|
10
|
+
};
|
|
11
|
+
function _dirNameChecker(dir) {
|
|
12
|
+
if (!dir)
|
|
13
|
+
return "drop";
|
|
14
|
+
for (const ch of dir) {
|
|
15
|
+
const validation = __charInDirValidation[ch];
|
|
16
|
+
if (validation && !validation.dir) {
|
|
17
|
+
return "invalid";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return "valid";
|
|
21
|
+
}
|
|
22
|
+
function _dirFileTypeChecker(src) {
|
|
23
|
+
if (!src)
|
|
24
|
+
return "drop";
|
|
25
|
+
let dirType = false;
|
|
26
|
+
let fileType = false;
|
|
27
|
+
for (const char of src) {
|
|
28
|
+
const validation = __charInDirValidation[char];
|
|
29
|
+
if (dirType) {
|
|
30
|
+
if (validation && !validation.dir)
|
|
31
|
+
return "invalid";
|
|
32
|
+
}
|
|
33
|
+
else if (fileType) {
|
|
34
|
+
if (validation && !validation.file)
|
|
35
|
+
return "invalid";
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (validation) {
|
|
39
|
+
if (validation.dir && !validation.file)
|
|
40
|
+
dirType = true;
|
|
41
|
+
else if (!validation.dir && validation.file)
|
|
42
|
+
fileType = true;
|
|
43
|
+
else if (!validation.dir && !validation.file)
|
|
44
|
+
return "invalid";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if ((!dirType && !fileType) || dirType)
|
|
49
|
+
return "directory";
|
|
50
|
+
else
|
|
51
|
+
return "file";
|
|
52
|
+
}
|
|
53
|
+
function _parsePathFromString(src) {
|
|
54
|
+
const path = {
|
|
55
|
+
dirs: [],
|
|
56
|
+
file: undefined,
|
|
57
|
+
type: "directory",
|
|
58
|
+
};
|
|
59
|
+
if (!src) {
|
|
60
|
+
return path;
|
|
61
|
+
}
|
|
62
|
+
const prsedSrc = src.trim();
|
|
63
|
+
const srcSplit = prsedSrc.split("/");
|
|
64
|
+
if (srcSplit.length === 0) {
|
|
65
|
+
return path;
|
|
66
|
+
}
|
|
67
|
+
for (let i = 0; i < srcSplit.length - 1; ++i) {
|
|
68
|
+
const dir = srcSplit[i];
|
|
69
|
+
const validation = _dirNameChecker(dir);
|
|
70
|
+
if (validation === "invalid") {
|
|
71
|
+
throw new Error_1.PathDirectoryValidationFailException(dir);
|
|
72
|
+
}
|
|
73
|
+
if (validation === "valid") {
|
|
74
|
+
path.dirs.push(dir);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const lastDir = srcSplit[srcSplit.length - 1];
|
|
78
|
+
const dirType = _dirFileTypeChecker(lastDir);
|
|
79
|
+
if (dirType === "directory") {
|
|
80
|
+
path.dirs.push(lastDir);
|
|
81
|
+
}
|
|
82
|
+
else if (dirType === "file") {
|
|
83
|
+
path.file = lastDir;
|
|
84
|
+
path.type = "file";
|
|
85
|
+
}
|
|
86
|
+
return path;
|
|
87
|
+
}
|
|
88
|
+
/** Path */
|
|
89
|
+
class Path extends PathBase_1.PathBase {
|
|
90
|
+
_type;
|
|
91
|
+
_file;
|
|
92
|
+
/**
|
|
93
|
+
* Create a new Path instance
|
|
94
|
+
*
|
|
95
|
+
* @param dirs the directory names
|
|
96
|
+
* @param type indicate which type the Path is
|
|
97
|
+
* @param file the file name if the type is file
|
|
98
|
+
*/
|
|
99
|
+
constructor(dirs, type, file) {
|
|
100
|
+
super();
|
|
101
|
+
if (typeof dirs === "string") {
|
|
102
|
+
const parsePath = _parsePathFromString(dirs);
|
|
103
|
+
if (type && type != parsePath.type) {
|
|
104
|
+
throw new Error_1.PathDirAndFileConvertInvaild(dirs, parsePath.type);
|
|
105
|
+
}
|
|
106
|
+
this._dirs = parsePath.dirs;
|
|
107
|
+
type = parsePath.type;
|
|
108
|
+
file = parsePath.file;
|
|
109
|
+
}
|
|
110
|
+
else if (Array.isArray(dirs)) {
|
|
111
|
+
this._dirs = dirs;
|
|
112
|
+
}
|
|
113
|
+
this._type = type || (file && "file") || "directory";
|
|
114
|
+
this._file = file;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Convert the path to a string
|
|
118
|
+
*
|
|
119
|
+
* @returns return the string
|
|
120
|
+
*/
|
|
121
|
+
toString() {
|
|
122
|
+
if (this.getType() === "file" && !!!this.getFile()) {
|
|
123
|
+
throw new Error_1.PathProcessorSourceLostException();
|
|
124
|
+
}
|
|
125
|
+
if (this.length() === 0 && !!!this.getFile()) {
|
|
126
|
+
return "";
|
|
127
|
+
}
|
|
128
|
+
const dirs = [];
|
|
129
|
+
for (const dirItem of this._dirs) {
|
|
130
|
+
const validation = _dirNameChecker(dirItem);
|
|
131
|
+
if (validation === "invalid") {
|
|
132
|
+
throw new Error_1.PathDirectoryValidationFailException(dirItem);
|
|
133
|
+
}
|
|
134
|
+
if (validation === "valid") {
|
|
135
|
+
dirs.push(dirItem);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const file = this.getFile();
|
|
139
|
+
if (!!file)
|
|
140
|
+
dirs.push(file);
|
|
141
|
+
if (dirs.length === 0) {
|
|
142
|
+
return "";
|
|
143
|
+
}
|
|
144
|
+
return dirs.join("/");
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Set the target type
|
|
148
|
+
*
|
|
149
|
+
* @param type new type
|
|
150
|
+
*/
|
|
151
|
+
setType(type) {
|
|
152
|
+
this._type = type;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get the path type of current instance
|
|
156
|
+
*
|
|
157
|
+
* @returns return the path type
|
|
158
|
+
*/
|
|
159
|
+
getType() {
|
|
160
|
+
return this._type;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Set the path file name
|
|
164
|
+
*
|
|
165
|
+
* @param file the new file name
|
|
166
|
+
* @returns return the old file name
|
|
167
|
+
*/
|
|
168
|
+
setFile(file) {
|
|
169
|
+
const oldFile = this._file;
|
|
170
|
+
this._file = file;
|
|
171
|
+
return oldFile;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get the file name of current instance
|
|
175
|
+
*
|
|
176
|
+
* @returns return the file name
|
|
177
|
+
*/
|
|
178
|
+
getFile() {
|
|
179
|
+
return this._file;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* IComparable impl to get a string what equals to current instance
|
|
183
|
+
*
|
|
184
|
+
* @returns return the string
|
|
185
|
+
*/
|
|
186
|
+
getString() {
|
|
187
|
+
return this.toString();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get a hash code of current instance
|
|
191
|
+
*
|
|
192
|
+
* @returns always return 0
|
|
193
|
+
*/
|
|
194
|
+
getHashCode() {
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
exports.Path = Path;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**@format */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Path = exports.PathDirAndFileConvertInvaild = exports.PathDirectoryValidationFailException = exports.PathProcessorSourceLostException = void 0;
|
|
5
|
+
var Error_1 = require("./Error");
|
|
6
|
+
Object.defineProperty(exports, "PathProcessorSourceLostException", { enumerable: true, get: function () { return Error_1.PathProcessorSourceLostException; } });
|
|
7
|
+
Object.defineProperty(exports, "PathDirectoryValidationFailException", { enumerable: true, get: function () { return Error_1.PathDirectoryValidationFailException; } });
|
|
8
|
+
Object.defineProperty(exports, "PathDirAndFileConvertInvaild", { enumerable: true, get: function () { return Error_1.PathDirAndFileConvertInvaild; } });
|
|
9
|
+
var Path_1 = require("./Path");
|
|
10
|
+
Object.defineProperty(exports, "Path", { enumerable: true, get: function () { return Path_1.Path; } });
|