@fctc/widget-logic 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +83 -0
- package/dist/index.mjs +54 -0
- package/dist/require.d.mts +6 -0
- package/dist/require.d.ts +6 -0
- package/dist/require.js +41 -0
- package/dist/require.mjs +14 -0
- package/dist/validate.d.mts +11 -0
- package/dist/validate.d.ts +11 -0
- package/dist/validate.js +83 -0
- package/dist/validate.mjs +54 -0
- package/package.json +37 -0
package/README.md
ADDED
|
File without changes
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { handleGeneratePasswordMessage, handleValidateInput, handleValidateInputByType } from './validate.mjs';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { handleGeneratePasswordMessage, handleValidateInput, handleValidateInputByType } from './validate.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
handleGeneratePasswordMessage: () => handleGeneratePasswordMessage,
|
|
24
|
+
handleValidateInput: () => handleValidateInput,
|
|
25
|
+
handleValidateInputByType: () => handleValidateInputByType
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/utils/validate.ts
|
|
30
|
+
function handleValidateInputByType(value, type) {
|
|
31
|
+
if (type === "text") {
|
|
32
|
+
return /^[\p{L}\s]+$/u.test(value);
|
|
33
|
+
}
|
|
34
|
+
if (type === "number") {
|
|
35
|
+
return /^[0-9]+$/.test(value);
|
|
36
|
+
}
|
|
37
|
+
if (type === "email") {
|
|
38
|
+
return /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
|
|
39
|
+
}
|
|
40
|
+
if (type === "phone") {
|
|
41
|
+
return /^(0|\+?84)[0-9]{9}$/.test(value);
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
function handleGeneratePasswordMessage({ min, max, upcase, digit, special }) {
|
|
46
|
+
let message = `M\u1EADt kh\u1EA9u ph\u1EA3i c\xF3 t\u1EEB ${min} \u0111\u1EBFn ${max} k\xFD t\u1EF1`;
|
|
47
|
+
if (upcase || upcase === "0") {
|
|
48
|
+
message += `, ${upcase} ch\u1EEF in hoa`;
|
|
49
|
+
}
|
|
50
|
+
if (digit || digit === "0") {
|
|
51
|
+
message += `, ${digit} s\u1ED1`;
|
|
52
|
+
}
|
|
53
|
+
if (special || special === "0") {
|
|
54
|
+
message += `, ${special} k\xFD t\u1EF1 \u0111\u1EB7c bi\u1EC7t`;
|
|
55
|
+
}
|
|
56
|
+
return message;
|
|
57
|
+
}
|
|
58
|
+
function handleValidateInput(props) {
|
|
59
|
+
const { value, widget, regex, min, max, upcase, digit, special, textValidate } = props;
|
|
60
|
+
if (!value) return true;
|
|
61
|
+
if (widget === "custom_passord") {
|
|
62
|
+
if (regex && !new RegExp(regex)?.test(value)) {
|
|
63
|
+
return handleGeneratePasswordMessage({
|
|
64
|
+
min,
|
|
65
|
+
max,
|
|
66
|
+
upcase,
|
|
67
|
+
digit,
|
|
68
|
+
special
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
if (!widget) return;
|
|
74
|
+
const inputType = widget === "email" ? "email" : widget === "phone" ? "phone" : widget === "text-only" ? "text" : widget === "number" ? "number" : null;
|
|
75
|
+
if (!inputType) return;
|
|
76
|
+
return handleValidateInputByType(value, inputType) || textValidate;
|
|
77
|
+
}
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
handleGeneratePasswordMessage,
|
|
81
|
+
handleValidateInput,
|
|
82
|
+
handleValidateInputByType
|
|
83
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/utils/validate.ts
|
|
2
|
+
function handleValidateInputByType(value, type) {
|
|
3
|
+
if (type === "text") {
|
|
4
|
+
return /^[\p{L}\s]+$/u.test(value);
|
|
5
|
+
}
|
|
6
|
+
if (type === "number") {
|
|
7
|
+
return /^[0-9]+$/.test(value);
|
|
8
|
+
}
|
|
9
|
+
if (type === "email") {
|
|
10
|
+
return /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
|
|
11
|
+
}
|
|
12
|
+
if (type === "phone") {
|
|
13
|
+
return /^(0|\+?84)[0-9]{9}$/.test(value);
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
function handleGeneratePasswordMessage({ min, max, upcase, digit, special }) {
|
|
18
|
+
let message = `M\u1EADt kh\u1EA9u ph\u1EA3i c\xF3 t\u1EEB ${min} \u0111\u1EBFn ${max} k\xFD t\u1EF1`;
|
|
19
|
+
if (upcase || upcase === "0") {
|
|
20
|
+
message += `, ${upcase} ch\u1EEF in hoa`;
|
|
21
|
+
}
|
|
22
|
+
if (digit || digit === "0") {
|
|
23
|
+
message += `, ${digit} s\u1ED1`;
|
|
24
|
+
}
|
|
25
|
+
if (special || special === "0") {
|
|
26
|
+
message += `, ${special} k\xFD t\u1EF1 \u0111\u1EB7c bi\u1EC7t`;
|
|
27
|
+
}
|
|
28
|
+
return message;
|
|
29
|
+
}
|
|
30
|
+
function handleValidateInput(props) {
|
|
31
|
+
const { value, widget, regex, min, max, upcase, digit, special, textValidate } = props;
|
|
32
|
+
if (!value) return true;
|
|
33
|
+
if (widget === "custom_passord") {
|
|
34
|
+
if (regex && !new RegExp(regex)?.test(value)) {
|
|
35
|
+
return handleGeneratePasswordMessage({
|
|
36
|
+
min,
|
|
37
|
+
max,
|
|
38
|
+
upcase,
|
|
39
|
+
digit,
|
|
40
|
+
special
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (!widget) return;
|
|
46
|
+
const inputType = widget === "email" ? "email" : widget === "phone" ? "phone" : widget === "text-only" ? "text" : widget === "number" ? "number" : null;
|
|
47
|
+
if (!inputType) return;
|
|
48
|
+
return handleValidateInputByType(value, inputType) || textValidate;
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
handleGeneratePasswordMessage,
|
|
52
|
+
handleValidateInput,
|
|
53
|
+
handleValidateInputByType
|
|
54
|
+
};
|
package/dist/require.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/require.ts
|
|
21
|
+
var require_exports = {};
|
|
22
|
+
__export(require_exports, {
|
|
23
|
+
handleRequire: () => handleRequire
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(require_exports);
|
|
26
|
+
|
|
27
|
+
// src/utils/require.ts
|
|
28
|
+
function handleRequire(props) {
|
|
29
|
+
const { required, invisible, string, textRequired } = props;
|
|
30
|
+
if (required && !invisible) {
|
|
31
|
+
return {
|
|
32
|
+
value: true,
|
|
33
|
+
message: `${string} ${textRequired}`
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
handleRequire
|
|
41
|
+
});
|
package/dist/require.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/utils/require.ts
|
|
2
|
+
function handleRequire(props) {
|
|
3
|
+
const { required, invisible, string, textRequired } = props;
|
|
4
|
+
if (required && !invisible) {
|
|
5
|
+
return {
|
|
6
|
+
value: true,
|
|
7
|
+
message: `${string} ${textRequired}`
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
handleRequire
|
|
14
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function handleValidateInputByType(value: string, type: 'text' | 'number' | 'phone' | 'email'): boolean;
|
|
2
|
+
declare function handleGeneratePasswordMessage({ min, max, upcase, digit, special }: {
|
|
3
|
+
min?: string;
|
|
4
|
+
max?: string;
|
|
5
|
+
upcase?: string;
|
|
6
|
+
digit?: string;
|
|
7
|
+
special?: string;
|
|
8
|
+
}): string;
|
|
9
|
+
declare function handleValidateInput(props: any): any;
|
|
10
|
+
|
|
11
|
+
export { handleGeneratePasswordMessage, handleValidateInput, handleValidateInputByType };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function handleValidateInputByType(value: string, type: 'text' | 'number' | 'phone' | 'email'): boolean;
|
|
2
|
+
declare function handleGeneratePasswordMessage({ min, max, upcase, digit, special }: {
|
|
3
|
+
min?: string;
|
|
4
|
+
max?: string;
|
|
5
|
+
upcase?: string;
|
|
6
|
+
digit?: string;
|
|
7
|
+
special?: string;
|
|
8
|
+
}): string;
|
|
9
|
+
declare function handleValidateInput(props: any): any;
|
|
10
|
+
|
|
11
|
+
export { handleGeneratePasswordMessage, handleValidateInput, handleValidateInputByType };
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/validate.ts
|
|
21
|
+
var validate_exports = {};
|
|
22
|
+
__export(validate_exports, {
|
|
23
|
+
handleGeneratePasswordMessage: () => handleGeneratePasswordMessage,
|
|
24
|
+
handleValidateInput: () => handleValidateInput,
|
|
25
|
+
handleValidateInputByType: () => handleValidateInputByType
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(validate_exports);
|
|
28
|
+
|
|
29
|
+
// src/utils/validate.ts
|
|
30
|
+
function handleValidateInputByType(value, type) {
|
|
31
|
+
if (type === "text") {
|
|
32
|
+
return /^[\p{L}\s]+$/u.test(value);
|
|
33
|
+
}
|
|
34
|
+
if (type === "number") {
|
|
35
|
+
return /^[0-9]+$/.test(value);
|
|
36
|
+
}
|
|
37
|
+
if (type === "email") {
|
|
38
|
+
return /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
|
|
39
|
+
}
|
|
40
|
+
if (type === "phone") {
|
|
41
|
+
return /^(0|\+?84)[0-9]{9}$/.test(value);
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
function handleGeneratePasswordMessage({ min, max, upcase, digit, special }) {
|
|
46
|
+
let message = `M\u1EADt kh\u1EA9u ph\u1EA3i c\xF3 t\u1EEB ${min} \u0111\u1EBFn ${max} k\xFD t\u1EF1`;
|
|
47
|
+
if (upcase || upcase === "0") {
|
|
48
|
+
message += `, ${upcase} ch\u1EEF in hoa`;
|
|
49
|
+
}
|
|
50
|
+
if (digit || digit === "0") {
|
|
51
|
+
message += `, ${digit} s\u1ED1`;
|
|
52
|
+
}
|
|
53
|
+
if (special || special === "0") {
|
|
54
|
+
message += `, ${special} k\xFD t\u1EF1 \u0111\u1EB7c bi\u1EC7t`;
|
|
55
|
+
}
|
|
56
|
+
return message;
|
|
57
|
+
}
|
|
58
|
+
function handleValidateInput(props) {
|
|
59
|
+
const { value, widget, regex, min, max, upcase, digit, special, textValidate } = props;
|
|
60
|
+
if (!value) return true;
|
|
61
|
+
if (widget === "custom_passord") {
|
|
62
|
+
if (regex && !new RegExp(regex)?.test(value)) {
|
|
63
|
+
return handleGeneratePasswordMessage({
|
|
64
|
+
min,
|
|
65
|
+
max,
|
|
66
|
+
upcase,
|
|
67
|
+
digit,
|
|
68
|
+
special
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
if (!widget) return;
|
|
74
|
+
const inputType = widget === "email" ? "email" : widget === "phone" ? "phone" : widget === "text-only" ? "text" : widget === "number" ? "number" : null;
|
|
75
|
+
if (!inputType) return;
|
|
76
|
+
return handleValidateInputByType(value, inputType) || textValidate;
|
|
77
|
+
}
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
handleGeneratePasswordMessage,
|
|
81
|
+
handleValidateInput,
|
|
82
|
+
handleValidateInputByType
|
|
83
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/utils/validate.ts
|
|
2
|
+
function handleValidateInputByType(value, type) {
|
|
3
|
+
if (type === "text") {
|
|
4
|
+
return /^[\p{L}\s]+$/u.test(value);
|
|
5
|
+
}
|
|
6
|
+
if (type === "number") {
|
|
7
|
+
return /^[0-9]+$/.test(value);
|
|
8
|
+
}
|
|
9
|
+
if (type === "email") {
|
|
10
|
+
return /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(value);
|
|
11
|
+
}
|
|
12
|
+
if (type === "phone") {
|
|
13
|
+
return /^(0|\+?84)[0-9]{9}$/.test(value);
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
function handleGeneratePasswordMessage({ min, max, upcase, digit, special }) {
|
|
18
|
+
let message = `M\u1EADt kh\u1EA9u ph\u1EA3i c\xF3 t\u1EEB ${min} \u0111\u1EBFn ${max} k\xFD t\u1EF1`;
|
|
19
|
+
if (upcase || upcase === "0") {
|
|
20
|
+
message += `, ${upcase} ch\u1EEF in hoa`;
|
|
21
|
+
}
|
|
22
|
+
if (digit || digit === "0") {
|
|
23
|
+
message += `, ${digit} s\u1ED1`;
|
|
24
|
+
}
|
|
25
|
+
if (special || special === "0") {
|
|
26
|
+
message += `, ${special} k\xFD t\u1EF1 \u0111\u1EB7c bi\u1EC7t`;
|
|
27
|
+
}
|
|
28
|
+
return message;
|
|
29
|
+
}
|
|
30
|
+
function handleValidateInput(props) {
|
|
31
|
+
const { value, widget, regex, min, max, upcase, digit, special, textValidate } = props;
|
|
32
|
+
if (!value) return true;
|
|
33
|
+
if (widget === "custom_passord") {
|
|
34
|
+
if (regex && !new RegExp(regex)?.test(value)) {
|
|
35
|
+
return handleGeneratePasswordMessage({
|
|
36
|
+
min,
|
|
37
|
+
max,
|
|
38
|
+
upcase,
|
|
39
|
+
digit,
|
|
40
|
+
special
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (!widget) return;
|
|
46
|
+
const inputType = widget === "email" ? "email" : widget === "phone" ? "phone" : widget === "text-only" ? "text" : widget === "number" ? "number" : null;
|
|
47
|
+
if (!inputType) return;
|
|
48
|
+
return handleValidateInputByType(value, inputType) || textValidate;
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
handleGeneratePasswordMessage,
|
|
52
|
+
handleValidateInput,
|
|
53
|
+
handleValidateInputByType
|
|
54
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fctc/widget-logic",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.cjs",
|
|
5
|
+
"module": "dist/index.mjs",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"require": "./dist/index.cjs"
|
|
11
|
+
},
|
|
12
|
+
"./require": {
|
|
13
|
+
"import": "./dist/require.mjs",
|
|
14
|
+
"require": "./dist/require.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./validate": {
|
|
17
|
+
"import": "./dist/validate.mjs",
|
|
18
|
+
"require": "./dist/validate.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"test": "jest"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"tslib": "^2.8.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"jest": "^29.7.0",
|
|
33
|
+
"tsup": "^8.0.0",
|
|
34
|
+
"typescript": "^5.8.2"
|
|
35
|
+
},
|
|
36
|
+
"packageManager": "yarn@1.22.0"
|
|
37
|
+
}
|