@shaxpir/duiduidui-models 1.6.0 → 1.6.2

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.
@@ -26,4 +26,14 @@ export declare class Profile extends Content {
26
26
  get avatarCropping(): ImageCropping;
27
27
  setAvatarCropping(value: ImageCropping): void;
28
28
  static findByUsername(username: string): Promise<Profile[]>;
29
+ /**
30
+ * Validate username format
31
+ * @param username The username to validate
32
+ * @returns Object with isValid boolean and optional error message
33
+ */
34
+ static validateUsername(username: string): {
35
+ isValid: boolean;
36
+ reason?: string;
37
+ message?: string;
38
+ };
29
39
  }
@@ -89,5 +89,45 @@ class Profile extends Content_1.Content {
89
89
  const shareSync = repo_1.ShareSyncFactory.get();
90
90
  return shareSync.findAndAcquire(ContentKind_1.ContentKind.PROFILE, { "payload.username": username });
91
91
  }
92
+ /**
93
+ * Validate username format
94
+ * @param username The username to validate
95
+ * @returns Object with isValid boolean and optional error message
96
+ */
97
+ static validateUsername(username) {
98
+ if (!username || username.length < 2) {
99
+ return {
100
+ isValid: false,
101
+ reason: 'too_short',
102
+ message: 'Username must be at least 2 characters long'
103
+ };
104
+ }
105
+ if (username.length > 20) {
106
+ return {
107
+ isValid: false,
108
+ reason: 'too_long',
109
+ message: 'Username must be 20 characters or less'
110
+ };
111
+ }
112
+ // Alphanumeric, Chinese characters (CJK Unified Ideographs), underscores, hyphens
113
+ // CJK Unified Ideographs range: U+4E00-U+9FFF
114
+ const validPattern = /^[a-zA-Z0-9\u4E00-\u9FFF_-]+$/;
115
+ if (!validPattern.test(username)) {
116
+ return {
117
+ isValid: false,
118
+ reason: 'invalid_characters',
119
+ message: 'Username can only contain letters, numbers, Chinese characters, underscores, and hyphens'
120
+ };
121
+ }
122
+ // Cannot start or end with underscore/hyphen
123
+ if (/^[_-]|[_-]$/.test(username)) {
124
+ return {
125
+ isValid: false,
126
+ reason: 'invalid_format',
127
+ message: 'Username cannot start or end with underscore or hyphen'
128
+ };
129
+ }
130
+ return { isValid: true };
131
+ }
92
132
  }
93
133
  exports.Profile = Profile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"