@shaxpir/duiduidui-models 1.6.2 → 1.6.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/models/Profile.d.ts +10 -0
- package/dist/models/Profile.js +50 -0
- package/package.json +1 -1
package/dist/models/Profile.d.ts
CHANGED
|
@@ -36,4 +36,14 @@ export declare class Profile extends Content {
|
|
|
36
36
|
reason?: string;
|
|
37
37
|
message?: string;
|
|
38
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Validate full name format
|
|
41
|
+
* @param fullName The full name to validate
|
|
42
|
+
* @returns Object with isValid boolean and optional error message
|
|
43
|
+
*/
|
|
44
|
+
static validateFullName(fullName: string): {
|
|
45
|
+
isValid: boolean;
|
|
46
|
+
reason?: string;
|
|
47
|
+
message?: string;
|
|
48
|
+
};
|
|
39
49
|
}
|
package/dist/models/Profile.js
CHANGED
|
@@ -129,5 +129,55 @@ class Profile extends Content_1.Content {
|
|
|
129
129
|
}
|
|
130
130
|
return { isValid: true };
|
|
131
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Validate full name format
|
|
134
|
+
* @param fullName The full name to validate
|
|
135
|
+
* @returns Object with isValid boolean and optional error message
|
|
136
|
+
*/
|
|
137
|
+
static validateFullName(fullName) {
|
|
138
|
+
// Full name is optional, so empty string is valid
|
|
139
|
+
if (!fullName || fullName.length === 0) {
|
|
140
|
+
return { isValid: true };
|
|
141
|
+
}
|
|
142
|
+
if (fullName.length > 100) {
|
|
143
|
+
return {
|
|
144
|
+
isValid: false,
|
|
145
|
+
reason: 'too_long',
|
|
146
|
+
message: 'Full name must be 100 characters or less'
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
// Allow a wide range of characters for international names
|
|
150
|
+
// - Letters from any language (Unicode letters)
|
|
151
|
+
// - Spaces, hyphens, apostrophes, periods (common in names)
|
|
152
|
+
// - Chinese characters (CJK Unified Ideographs)
|
|
153
|
+
// Reject control characters, emojis, and other special characters
|
|
154
|
+
const validPattern = /^[\p{L}\p{M}\s'\-\.]+$/u;
|
|
155
|
+
if (!validPattern.test(fullName)) {
|
|
156
|
+
return {
|
|
157
|
+
isValid: false,
|
|
158
|
+
reason: 'invalid_characters',
|
|
159
|
+
message: 'Full name contains invalid characters. Only letters, spaces, hyphens, apostrophes, and periods are allowed'
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
// Check for reasonable structure (not just whitespace/punctuation)
|
|
163
|
+
const hasLetter = /\p{L}/u.test(fullName);
|
|
164
|
+
if (!hasLetter) {
|
|
165
|
+
return {
|
|
166
|
+
isValid: false,
|
|
167
|
+
reason: 'no_letters',
|
|
168
|
+
message: 'Full name must contain at least one letter'
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
// Prevent excessive repeated characters (likely spam/invalid)
|
|
172
|
+
const hasExcessiveRepeats = /(.)\1{9,}/.test(fullName);
|
|
173
|
+
if (hasExcessiveRepeats) {
|
|
174
|
+
return {
|
|
175
|
+
isValid: false,
|
|
176
|
+
reason: 'excessive_repeats',
|
|
177
|
+
message: 'Full name contains too many repeated characters'
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return { isValid: true };
|
|
181
|
+
}
|
|
132
182
|
}
|
|
133
183
|
exports.Profile = Profile;
|