@codady/utils 0.0.1
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/CHANGELOG.md +20 -0
- package/LICENSE +24 -0
- package/README.md +24 -0
- package/dist/utils.cjs.js +113 -0
- package/dist/utils.cjs.min.js +15 -0
- package/dist/utils.esm.js +111 -0
- package/dist/utils.esm.min.js +15 -0
- package/dist/utils.umd.js +119 -0
- package/dist/utils.umd.min.js +15 -0
- package/dist.zip +0 -0
- package/package.json +73 -0
- package/rollup.config.js +68 -0
- package/script-mini.js +41 -0
- package/script-note.js +34 -0
- package/src/deepClone.js +53 -0
- package/src/deepClone.ts +59 -0
- package/src/escapeHTML - /345/211/257/346/234/254.js" +29 -0
- package/src/escapeHTML.js +29 -0
- package/src/escapeHTML.ts +30 -0
- package/src/execluteStr.js +29 -0
- package/src/executeStr.js +36 -0
- package/src/executeStr.ts +42 -0
- package/src/getDataType.js +38 -0
- package/src/getDataType.ts +37 -0
- package/src/parseStr.js +46 -0
- package/src/parseStr.ts +47 -0
- package/src/renderTpl.js +70 -0
- package/src/renderTpl.ts +86 -0
- package/src/requireTypes.js +48 -0
- package/src/requireTypes.ts +54 -0
- package/tsconfig.json +108 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All changes to Utils including new features, updates, and removals are documented here.
|
|
4
|
+
|
|
5
|
+
## [v0.0.1] - 2025-12-15
|
|
6
|
+
|
|
7
|
+
### Distribution Files
|
|
8
|
+
- **JS**: https://unpkg.com/@codady/utils@0.0.1/dist/js/utils.js
|
|
9
|
+
- **Zip**: https://unpkg.com/@codady/utils@0.0.1/dist.zip
|
|
10
|
+
|
|
11
|
+
### Changes
|
|
12
|
+
|
|
13
|
+
#### Fixed
|
|
14
|
+
- Null
|
|
15
|
+
|
|
16
|
+
#### Added
|
|
17
|
+
- Publish the first version.
|
|
18
|
+
|
|
19
|
+
#### Removed
|
|
20
|
+
- Null
|
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 AXUI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
Please keep our copyright information. If you have any questions,
|
|
24
|
+
please contact us: 3217728223@qq.com.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
# Utils for web front-end
|
|
3
|
+
|
|
4
|
+
This is a set of general-purpose JavaScript utility functions developed by the AXUI team. All functions are pure and do not involve CSS or other third-party libraries. They are suitable for any web front-end environment.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# Related Resources
|
|
8
|
+
|
|
9
|
+
Website:https://www.axui.cn
|
|
10
|
+
|
|
11
|
+
Examples:https://www.axui.cn
|
|
12
|
+
|
|
13
|
+
NPM:https://www.npmjs.com/package/@codady/utils
|
|
14
|
+
|
|
15
|
+
Github:https://github.com/codady/utils
|
|
16
|
+
|
|
17
|
+
Gitee:https://gitee.com/codady/utils
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Contact Us
|
|
21
|
+
|
|
22
|
+
QQ Group:952502085
|
|
23
|
+
|
|
24
|
+
QQ Online:3217728223
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
|
|
2
|
+
/*!
|
|
3
|
+
* @since Last modified: 2025-12-16 9:8:6
|
|
4
|
+
* @name Utils for web front-end.
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @author AXUI development team <3217728223@qq.com>
|
|
7
|
+
* @description This is a set of general-purpose JavaScript utility functions developed by the AXUI team. All functions are pure and do not involve CSS or other third-party libraries. They are suitable for any web front-end environment.
|
|
8
|
+
* @see {@link https://www.axui.cn|Official website}
|
|
9
|
+
* @see {@link https://github.com/codady/utils/issues|github issues}
|
|
10
|
+
* @see {@link https://gitee.com/codady/utils/issues|Gitee issues}
|
|
11
|
+
* @see {@link https://www.npmjs.com/package/@codady/utils|NPM}
|
|
12
|
+
* @issue QQ Group No.1:952502085
|
|
13
|
+
* @copyright This software supports the MIT License, allowing free learning and commercial use, but please retain the terms 'ax,' 'axui,' 'AX,' and 'AXUI' within the software.
|
|
14
|
+
* @license MIT license
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
'use strict';
|
|
18
|
+
|
|
19
|
+
const getDataType = (obj) => {
|
|
20
|
+
let tmp = Object.prototype.toString.call(obj).slice(8, -1), result;
|
|
21
|
+
if (tmp === 'Function' && /^\s*class\s+/.test(obj.toString())) {
|
|
22
|
+
result = 'Class';
|
|
23
|
+
}
|
|
24
|
+
else if (tmp === 'Object' && Object.getPrototypeOf(obj) !== Object.prototype) {
|
|
25
|
+
result = 'Instance';
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
result = tmp;
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
//document.createElement -> HTMLxxxElement
|
|
32
|
+
//document.createDocumentFragment() -> DocumentFragment
|
|
33
|
+
//document.createComment() -> Comment
|
|
34
|
+
//document.createTextNode -> Text
|
|
35
|
+
//document.createCDATASection() -> XMLDocument
|
|
36
|
+
//document.createProcessingInstruction() -> ProcessingInstruction
|
|
37
|
+
//document.createRange() -> Range
|
|
38
|
+
//document.createTreeWalker() -> TreeWalker
|
|
39
|
+
//document.createNodeIterator() -> NodeIterator
|
|
40
|
+
//document.createElementNS('http://www.w3.org/2000/svg', 'svg'); -> SVGSVGElement
|
|
41
|
+
//document.createElementNS('http://www.w3.org/1998/Math/MathML', 'math'); -> MathMLElement
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const deepClone = (data) => {
|
|
45
|
+
const dataType = getDataType(data);
|
|
46
|
+
if (dataType === 'Object') {
|
|
47
|
+
const newObj = {};
|
|
48
|
+
const symbols = Object.getOwnPropertySymbols(data);
|
|
49
|
+
// Clone regular properties
|
|
50
|
+
for (const key in data) {
|
|
51
|
+
newObj[key] = deepClone(data[key]);
|
|
52
|
+
}
|
|
53
|
+
// Clone Symbol properties
|
|
54
|
+
if (symbols.length > 0) {
|
|
55
|
+
for (const symbol of symbols) {
|
|
56
|
+
newObj[symbol] = deepClone(data[symbol]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return newObj;
|
|
60
|
+
}
|
|
61
|
+
else if (dataType === 'Array') {
|
|
62
|
+
return data.map(item => deepClone(item));
|
|
63
|
+
}
|
|
64
|
+
else if (dataType === 'Date') {
|
|
65
|
+
return new Date(data.getTime());
|
|
66
|
+
}
|
|
67
|
+
else if (dataType === 'RegExp') {
|
|
68
|
+
const regex = data;
|
|
69
|
+
return new RegExp(regex.source, regex.flags);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Number, String, Boolean, Symbol,Text,Comment,Set,Map, HTML*Element, Function,Error,Promise,ArrayBuffer,Blob,File, return directly
|
|
73
|
+
return data;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const requireTypes = (data, require, cb) => {
|
|
78
|
+
// Normalize the input types (convert to array if it's a single type)
|
|
79
|
+
let requiredTypes = Array.isArray(require) ? require : [require], dataType = getDataType(data), typeLower = dataType.toLowerCase(),
|
|
80
|
+
// Normalize the type names (to lower case)
|
|
81
|
+
normalizedTypes = requiredTypes.map((type) => type.toLowerCase()),
|
|
82
|
+
// Check if the type is an HTML element (more specific than just 'html')
|
|
83
|
+
normalizedDataType = typeLower.includes('html') ? 'element' : typeLower;
|
|
84
|
+
// If callback exists, handle error through callback
|
|
85
|
+
if (cb) {
|
|
86
|
+
try {
|
|
87
|
+
if (!normalizedTypes.includes(normalizedDataType)) {
|
|
88
|
+
throw new TypeError(`Expected data type(s): [${normalizedTypes.join(', ')}], but got: ${normalizedDataType}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
cb(error, dataType);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// If no callback is provided, throw an error directly
|
|
97
|
+
if (!normalizedTypes.includes(normalizedDataType)) {
|
|
98
|
+
throw new TypeError(`Expected data type(s): [${normalizedTypes.join(', ')}], but got: ${normalizedDataType}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return dataType;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const utils = {
|
|
105
|
+
//executeStr,
|
|
106
|
+
getDataType,
|
|
107
|
+
requireTypes,
|
|
108
|
+
//renderTpl,
|
|
109
|
+
//parseStr,
|
|
110
|
+
deepClone,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
module.exports = utils;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @since Last modified: 2025-11-15 11:0:34
|
|
3
|
+
* @name Utils for web front-end.
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
* @author AXUI development team <3217728223@qq.com>
|
|
6
|
+
* @description This is a set of general-purpose JavaScript utility functions developed by the AXUI team. All functions are pure and do not involve CSS or other third-party libraries. They are suitable for any web front-end environment.
|
|
7
|
+
* @see {@link https://www.axui.cn|Official website}
|
|
8
|
+
* @see {@link https://github.com/codady/utils/issues|github issues}
|
|
9
|
+
* @see {@link https://gitee.com/codady/utils/issues|Gitee issues}
|
|
10
|
+
* @see {@link https://www.npmjs.com/package/@codady/utils|NPM}
|
|
11
|
+
* @issue QQ Group No.1:952502085
|
|
12
|
+
* @copyright This software supports the MIT License, allowing free learning and commercial use, but please retain the terms 'ax,' 'axui,' 'AX,' and 'AXUI' within the software.
|
|
13
|
+
* @license MIT license
|
|
14
|
+
*/
|
|
15
|
+
"use strict";const getDataType=e=>{let t,r=Object.prototype.toString.call(e).slice(8,-1);return t="Function"===r&&/^\s*class\s+/.test(e.toString())?"Class":"Object"===r&&Object.getPrototypeOf(e)!==Object.prototype?"Instance":r,t},requireTypes=(e,t,r)=>{let s=getDataType(e).toLowerCase(),o="string"==typeof t?[t]:t;if(s.includes("html")&&(s="element"),o=o.map(e=>e.toLowerCase()),r)try{if(!o.includes(s))throw new Error(`Wrong data type,Require types: "${""+o}"!`)}catch(e){r(e)}else if(!o.includes(s))throw new Error(`Wrong data type,Require types: "${""+o}"!`)};exports.getDataType=getDataType,exports.requireTypes=requireTypes;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
|
|
2
|
+
/*!
|
|
3
|
+
* @since Last modified: 2025-12-16 9:8:6
|
|
4
|
+
* @name Utils for web front-end.
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @author AXUI development team <3217728223@qq.com>
|
|
7
|
+
* @description This is a set of general-purpose JavaScript utility functions developed by the AXUI team. All functions are pure and do not involve CSS or other third-party libraries. They are suitable for any web front-end environment.
|
|
8
|
+
* @see {@link https://www.axui.cn|Official website}
|
|
9
|
+
* @see {@link https://github.com/codady/utils/issues|github issues}
|
|
10
|
+
* @see {@link https://gitee.com/codady/utils/issues|Gitee issues}
|
|
11
|
+
* @see {@link https://www.npmjs.com/package/@codady/utils|NPM}
|
|
12
|
+
* @issue QQ Group No.1:952502085
|
|
13
|
+
* @copyright This software supports the MIT License, allowing free learning and commercial use, but please retain the terms 'ax,' 'axui,' 'AX,' and 'AXUI' within the software.
|
|
14
|
+
* @license MIT license
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const getDataType = (obj) => {
|
|
18
|
+
let tmp = Object.prototype.toString.call(obj).slice(8, -1), result;
|
|
19
|
+
if (tmp === 'Function' && /^\s*class\s+/.test(obj.toString())) {
|
|
20
|
+
result = 'Class';
|
|
21
|
+
}
|
|
22
|
+
else if (tmp === 'Object' && Object.getPrototypeOf(obj) !== Object.prototype) {
|
|
23
|
+
result = 'Instance';
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
result = tmp;
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
//document.createElement -> HTMLxxxElement
|
|
30
|
+
//document.createDocumentFragment() -> DocumentFragment
|
|
31
|
+
//document.createComment() -> Comment
|
|
32
|
+
//document.createTextNode -> Text
|
|
33
|
+
//document.createCDATASection() -> XMLDocument
|
|
34
|
+
//document.createProcessingInstruction() -> ProcessingInstruction
|
|
35
|
+
//document.createRange() -> Range
|
|
36
|
+
//document.createTreeWalker() -> TreeWalker
|
|
37
|
+
//document.createNodeIterator() -> NodeIterator
|
|
38
|
+
//document.createElementNS('http://www.w3.org/2000/svg', 'svg'); -> SVGSVGElement
|
|
39
|
+
//document.createElementNS('http://www.w3.org/1998/Math/MathML', 'math'); -> MathMLElement
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const deepClone = (data) => {
|
|
43
|
+
const dataType = getDataType(data);
|
|
44
|
+
if (dataType === 'Object') {
|
|
45
|
+
const newObj = {};
|
|
46
|
+
const symbols = Object.getOwnPropertySymbols(data);
|
|
47
|
+
// Clone regular properties
|
|
48
|
+
for (const key in data) {
|
|
49
|
+
newObj[key] = deepClone(data[key]);
|
|
50
|
+
}
|
|
51
|
+
// Clone Symbol properties
|
|
52
|
+
if (symbols.length > 0) {
|
|
53
|
+
for (const symbol of symbols) {
|
|
54
|
+
newObj[symbol] = deepClone(data[symbol]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return newObj;
|
|
58
|
+
}
|
|
59
|
+
else if (dataType === 'Array') {
|
|
60
|
+
return data.map(item => deepClone(item));
|
|
61
|
+
}
|
|
62
|
+
else if (dataType === 'Date') {
|
|
63
|
+
return new Date(data.getTime());
|
|
64
|
+
}
|
|
65
|
+
else if (dataType === 'RegExp') {
|
|
66
|
+
const regex = data;
|
|
67
|
+
return new RegExp(regex.source, regex.flags);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Number, String, Boolean, Symbol,Text,Comment,Set,Map, HTML*Element, Function,Error,Promise,ArrayBuffer,Blob,File, return directly
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const requireTypes = (data, require, cb) => {
|
|
76
|
+
// Normalize the input types (convert to array if it's a single type)
|
|
77
|
+
let requiredTypes = Array.isArray(require) ? require : [require], dataType = getDataType(data), typeLower = dataType.toLowerCase(),
|
|
78
|
+
// Normalize the type names (to lower case)
|
|
79
|
+
normalizedTypes = requiredTypes.map((type) => type.toLowerCase()),
|
|
80
|
+
// Check if the type is an HTML element (more specific than just 'html')
|
|
81
|
+
normalizedDataType = typeLower.includes('html') ? 'element' : typeLower;
|
|
82
|
+
// If callback exists, handle error through callback
|
|
83
|
+
if (cb) {
|
|
84
|
+
try {
|
|
85
|
+
if (!normalizedTypes.includes(normalizedDataType)) {
|
|
86
|
+
throw new TypeError(`Expected data type(s): [${normalizedTypes.join(', ')}], but got: ${normalizedDataType}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
cb(error, dataType);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// If no callback is provided, throw an error directly
|
|
95
|
+
if (!normalizedTypes.includes(normalizedDataType)) {
|
|
96
|
+
throw new TypeError(`Expected data type(s): [${normalizedTypes.join(', ')}], but got: ${normalizedDataType}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return dataType;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const utils = {
|
|
103
|
+
//executeStr,
|
|
104
|
+
getDataType,
|
|
105
|
+
requireTypes,
|
|
106
|
+
//renderTpl,
|
|
107
|
+
//parseStr,
|
|
108
|
+
deepClone,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export { utils as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @since Last modified: 2025-11-15 11:0:34
|
|
3
|
+
* @name Utils for web front-end.
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
* @author AXUI development team <3217728223@qq.com>
|
|
6
|
+
* @description This is a set of general-purpose JavaScript utility functions developed by the AXUI team. All functions are pure and do not involve CSS or other third-party libraries. They are suitable for any web front-end environment.
|
|
7
|
+
* @see {@link https://www.axui.cn|Official website}
|
|
8
|
+
* @see {@link https://github.com/codady/utils/issues|github issues}
|
|
9
|
+
* @see {@link https://gitee.com/codady/utils/issues|Gitee issues}
|
|
10
|
+
* @see {@link https://www.npmjs.com/package/@codady/utils|NPM}
|
|
11
|
+
* @issue QQ Group No.1:952502085
|
|
12
|
+
* @copyright This software supports the MIT License, allowing free learning and commercial use, but please retain the terms 'ax,' 'axui,' 'AX,' and 'AXUI' within the software.
|
|
13
|
+
* @license MIT license
|
|
14
|
+
*/
|
|
15
|
+
const getDataType=e=>{let t,r=Object.prototype.toString.call(e).slice(8,-1);return t="Function"===r&&/^\s*class\s+/.test(e.toString())?"Class":"Object"===r&&Object.getPrototypeOf(e)!==Object.prototype?"Instance":r,t},requireTypes=(e,t,r)=>{let o=getDataType(e).toLowerCase(),s="string"==typeof t?[t]:t;if(o.includes("html")&&(o="element"),s=s.map(e=>e.toLowerCase()),r)try{if(!s.includes(o))throw new Error(`Wrong data type,Require types: "${""+s}"!`)}catch(e){r(e)}else if(!s.includes(o))throw new Error(`Wrong data type,Require types: "${""+s}"!`)};export{getDataType,requireTypes};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
|
|
2
|
+
/*!
|
|
3
|
+
* @since Last modified: 2025-12-16 9:8:6
|
|
4
|
+
* @name Utils for web front-end.
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @author AXUI development team <3217728223@qq.com>
|
|
7
|
+
* @description This is a set of general-purpose JavaScript utility functions developed by the AXUI team. All functions are pure and do not involve CSS or other third-party libraries. They are suitable for any web front-end environment.
|
|
8
|
+
* @see {@link https://www.axui.cn|Official website}
|
|
9
|
+
* @see {@link https://github.com/codady/utils/issues|github issues}
|
|
10
|
+
* @see {@link https://gitee.com/codady/utils/issues|Gitee issues}
|
|
11
|
+
* @see {@link https://www.npmjs.com/package/@codady/utils|NPM}
|
|
12
|
+
* @issue QQ Group No.1:952502085
|
|
13
|
+
* @copyright This software supports the MIT License, allowing free learning and commercial use, but please retain the terms 'ax,' 'axui,' 'AX,' and 'AXUI' within the software.
|
|
14
|
+
* @license MIT license
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
(function (global, factory) {
|
|
18
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
19
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
20
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.utils = factory());
|
|
21
|
+
})(this, (function () { 'use strict';
|
|
22
|
+
|
|
23
|
+
const getDataType = (obj) => {
|
|
24
|
+
let tmp = Object.prototype.toString.call(obj).slice(8, -1), result;
|
|
25
|
+
if (tmp === 'Function' && /^\s*class\s+/.test(obj.toString())) {
|
|
26
|
+
result = 'Class';
|
|
27
|
+
}
|
|
28
|
+
else if (tmp === 'Object' && Object.getPrototypeOf(obj) !== Object.prototype) {
|
|
29
|
+
result = 'Instance';
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
result = tmp;
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
//document.createElement -> HTMLxxxElement
|
|
36
|
+
//document.createDocumentFragment() -> DocumentFragment
|
|
37
|
+
//document.createComment() -> Comment
|
|
38
|
+
//document.createTextNode -> Text
|
|
39
|
+
//document.createCDATASection() -> XMLDocument
|
|
40
|
+
//document.createProcessingInstruction() -> ProcessingInstruction
|
|
41
|
+
//document.createRange() -> Range
|
|
42
|
+
//document.createTreeWalker() -> TreeWalker
|
|
43
|
+
//document.createNodeIterator() -> NodeIterator
|
|
44
|
+
//document.createElementNS('http://www.w3.org/2000/svg', 'svg'); -> SVGSVGElement
|
|
45
|
+
//document.createElementNS('http://www.w3.org/1998/Math/MathML', 'math'); -> MathMLElement
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const deepClone = (data) => {
|
|
49
|
+
const dataType = getDataType(data);
|
|
50
|
+
if (dataType === 'Object') {
|
|
51
|
+
const newObj = {};
|
|
52
|
+
const symbols = Object.getOwnPropertySymbols(data);
|
|
53
|
+
// Clone regular properties
|
|
54
|
+
for (const key in data) {
|
|
55
|
+
newObj[key] = deepClone(data[key]);
|
|
56
|
+
}
|
|
57
|
+
// Clone Symbol properties
|
|
58
|
+
if (symbols.length > 0) {
|
|
59
|
+
for (const symbol of symbols) {
|
|
60
|
+
newObj[symbol] = deepClone(data[symbol]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return newObj;
|
|
64
|
+
}
|
|
65
|
+
else if (dataType === 'Array') {
|
|
66
|
+
return data.map(item => deepClone(item));
|
|
67
|
+
}
|
|
68
|
+
else if (dataType === 'Date') {
|
|
69
|
+
return new Date(data.getTime());
|
|
70
|
+
}
|
|
71
|
+
else if (dataType === 'RegExp') {
|
|
72
|
+
const regex = data;
|
|
73
|
+
return new RegExp(regex.source, regex.flags);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Number, String, Boolean, Symbol,Text,Comment,Set,Map, HTML*Element, Function,Error,Promise,ArrayBuffer,Blob,File, return directly
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const requireTypes = (data, require, cb) => {
|
|
82
|
+
// Normalize the input types (convert to array if it's a single type)
|
|
83
|
+
let requiredTypes = Array.isArray(require) ? require : [require], dataType = getDataType(data), typeLower = dataType.toLowerCase(),
|
|
84
|
+
// Normalize the type names (to lower case)
|
|
85
|
+
normalizedTypes = requiredTypes.map((type) => type.toLowerCase()),
|
|
86
|
+
// Check if the type is an HTML element (more specific than just 'html')
|
|
87
|
+
normalizedDataType = typeLower.includes('html') ? 'element' : typeLower;
|
|
88
|
+
// If callback exists, handle error through callback
|
|
89
|
+
if (cb) {
|
|
90
|
+
try {
|
|
91
|
+
if (!normalizedTypes.includes(normalizedDataType)) {
|
|
92
|
+
throw new TypeError(`Expected data type(s): [${normalizedTypes.join(', ')}], but got: ${normalizedDataType}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
cb(error, dataType);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// If no callback is provided, throw an error directly
|
|
101
|
+
if (!normalizedTypes.includes(normalizedDataType)) {
|
|
102
|
+
throw new TypeError(`Expected data type(s): [${normalizedTypes.join(', ')}], but got: ${normalizedDataType}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return dataType;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const utils = {
|
|
109
|
+
//executeStr,
|
|
110
|
+
getDataType,
|
|
111
|
+
requireTypes,
|
|
112
|
+
//renderTpl,
|
|
113
|
+
//parseStr,
|
|
114
|
+
deepClone,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return utils;
|
|
118
|
+
|
|
119
|
+
}));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @since Last modified: 2025-11-15 11:0:34
|
|
3
|
+
* @name Utils for web front-end.
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
* @author AXUI development team <3217728223@qq.com>
|
|
6
|
+
* @description This is a set of general-purpose JavaScript utility functions developed by the AXUI team. All functions are pure and do not involve CSS or other third-party libraries. They are suitable for any web front-end environment.
|
|
7
|
+
* @see {@link https://www.axui.cn|Official website}
|
|
8
|
+
* @see {@link https://github.com/codady/utils/issues|github issues}
|
|
9
|
+
* @see {@link https://gitee.com/codady/utils/issues|Gitee issues}
|
|
10
|
+
* @see {@link https://www.npmjs.com/package/@codady/utils|NPM}
|
|
11
|
+
* @issue QQ Group No.1:952502085
|
|
12
|
+
* @copyright This software supports the MIT License, allowing free learning and commercial use, but please retain the terms 'ax,' 'axui,' 'AX,' and 'AXUI' within the software.
|
|
13
|
+
* @license MIT license
|
|
14
|
+
*/
|
|
15
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).utils={})}(this,function(e){"use strict";const getDataType=e=>{let t,o=Object.prototype.toString.call(e).slice(8,-1);return t="Function"===o&&/^\s*class\s+/.test(e.toString())?"Class":"Object"===o&&Object.getPrototypeOf(e)!==Object.prototype?"Instance":o,t};e.getDataType=getDataType,e.requireTypes=(e,t,o)=>{let n=getDataType(e).toLowerCase(),s="string"==typeof t?[t]:t;if(n.includes("html")&&(n="element"),s=s.map(e=>e.toLowerCase()),o)try{if(!s.includes(n))throw new Error(`Wrong data type,Require types: "${""+s}"!`)}catch(e){o(e)}else if(!s.includes(n))throw new Error(`Wrong data type,Require types: "${""+s}"!`)}});
|
package/dist.zip
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codady/utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"author": "AXUI Development Team",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "This is a set of general-purpose JavaScript utility functions developed by the AXUI team. All functions are pure and do not involve CSS or other third-party libraries. They are suitable for any web front-end environment.",
|
|
7
|
+
"main": "./modules.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"types": "./types/utils.d.ts",
|
|
10
|
+
"directories": {
|
|
11
|
+
"doc": "docs"
|
|
12
|
+
},
|
|
13
|
+
"private": false,
|
|
14
|
+
"workspaces": [],
|
|
15
|
+
"files": [
|
|
16
|
+
"examples",
|
|
17
|
+
"docs",
|
|
18
|
+
"dist",
|
|
19
|
+
"src",
|
|
20
|
+
"dist.zip",
|
|
21
|
+
"package.json",
|
|
22
|
+
"rollup.config.js",
|
|
23
|
+
"tsconfig.json",
|
|
24
|
+
"script-mini.js",
|
|
25
|
+
"script-note.js",
|
|
26
|
+
"CHANGELOG.md",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
32
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
33
|
+
"@types/node": "^22.19.1",
|
|
34
|
+
"archiver": "^7.0.1",
|
|
35
|
+
"cross-env": "^7.0.3",
|
|
36
|
+
"rollup": "^4.18.1",
|
|
37
|
+
"rollup-plugin-replace": "^2.2.0",
|
|
38
|
+
"terser": "^5.27.2"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "rollup --config",
|
|
42
|
+
"mini": "node script-mini.js",
|
|
43
|
+
"zip": "node script-zip.js",
|
|
44
|
+
"push": "node script-push.js",
|
|
45
|
+
"all": "cross-env REPLACE=true npm run build && npm run css && npm run mini && (npm run zip || true) && npm publish && (npm run push || true)"
|
|
46
|
+
},
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "https://github.com/codady/utils"
|
|
50
|
+
},
|
|
51
|
+
"extraRepositories": [
|
|
52
|
+
{
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "https://gitee.com/codady/utils"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"keywords": [
|
|
58
|
+
"javascript",
|
|
59
|
+
"es6",
|
|
60
|
+
"components",
|
|
61
|
+
"vnode",
|
|
62
|
+
"mvvm",
|
|
63
|
+
"html5",
|
|
64
|
+
"css3"
|
|
65
|
+
],
|
|
66
|
+
"bugs": {
|
|
67
|
+
"url": "https://github.com/codady/utils/issues"
|
|
68
|
+
},
|
|
69
|
+
"homepage": "https://www.axui.cn",
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"simple-git": "^3.27.0"
|
|
72
|
+
}
|
|
73
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Last modified: 2025/11/15 11:10:09
|
|
3
|
+
*/
|
|
4
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
5
|
+
import replace from 'rollup-plugin-replace';
|
|
6
|
+
import note from './script-note.js';
|
|
7
|
+
import json from '@rollup/plugin-json';
|
|
8
|
+
|
|
9
|
+
const sharePlugins = [
|
|
10
|
+
{
|
|
11
|
+
name: "remove-comments",
|
|
12
|
+
transform(code) {
|
|
13
|
+
const cleanedCode = code.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
14
|
+
return {
|
|
15
|
+
code: cleanedCode,
|
|
16
|
+
map: null,
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
process.env.REPLACE === 'true' && replace({
|
|
21
|
+
preventAssignment: true,
|
|
22
|
+
'console.log': '',
|
|
23
|
+
}),
|
|
24
|
+
resolve(),
|
|
25
|
+
json(),
|
|
26
|
+
].filter(Boolean);
|
|
27
|
+
export default [
|
|
28
|
+
{
|
|
29
|
+
input: './modules.js',
|
|
30
|
+
output:
|
|
31
|
+
{
|
|
32
|
+
dir: './dist/',
|
|
33
|
+
format: 'umd',
|
|
34
|
+
name: 'utils',
|
|
35
|
+
entryFileNames: 'utils.umd.js',
|
|
36
|
+
banner: note,
|
|
37
|
+
},
|
|
38
|
+
plugins: [
|
|
39
|
+
...sharePlugins,
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
input: './modules.js',
|
|
44
|
+
output:
|
|
45
|
+
{
|
|
46
|
+
dir: './dist/',
|
|
47
|
+
format: 'es',
|
|
48
|
+
entryFileNames: 'utils.esm.js',
|
|
49
|
+
banner: note,
|
|
50
|
+
},
|
|
51
|
+
plugins: [
|
|
52
|
+
...sharePlugins
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
input: './modules.js',
|
|
57
|
+
output:
|
|
58
|
+
{
|
|
59
|
+
dir: './dist/',
|
|
60
|
+
format: 'cjs',
|
|
61
|
+
entryFileNames: 'utils.cjs.js',
|
|
62
|
+
banner: note,
|
|
63
|
+
},
|
|
64
|
+
plugins: [
|
|
65
|
+
...sharePlugins
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
]
|
package/script-mini.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Last modified: 2025/11/15 11:10:03
|
|
4
|
+
*/
|
|
5
|
+
import { exec } from 'child_process';
|
|
6
|
+
|
|
7
|
+
const runCommand = (command) => {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
exec(command, (error, stdout, stderr) => {
|
|
10
|
+
if (error) {
|
|
11
|
+
reject(`exec error: ${error}`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (stderr) {
|
|
15
|
+
reject(`stderr: ${stderr}`);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
resolve(stdout);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const minifyJsFile = (input, output) => {
|
|
24
|
+
const command = `npx terser ${input} -o ${output} -c arguments,dead_code,directives,arrows,drop_console -m keep_classnames=true,keep_fnames=true`;
|
|
25
|
+
return runCommand(command);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const minifyJs = async () => {
|
|
30
|
+
try {
|
|
31
|
+
await minifyJsFile('./dist/utils.umd.js', './dist/utils.umd.min.js');
|
|
32
|
+
await minifyJsFile('./dist/utils.esm.js', './dist/utils.esm.min.js');
|
|
33
|
+
await minifyJsFile('./dist/utils.cjs.js', './dist/utils.cjs.min.js');
|
|
34
|
+
|
|
35
|
+
console.log('Minification complete.');
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error(`Error during minification: ${error}`);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
minifyJs();
|