xw-devtool-cli 1.0.0 → 1.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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2025 npmxw
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any purpose
6
+ with or without fee is hereby granted, provided that the above copyright notice
7
+ and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
13
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
14
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
15
+ THIS SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xw-devtool-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "description": "基于node的开发者助手cli",
6
6
  "main": "index.js",
@@ -1,5 +1,6 @@
1
1
  import inquirer from 'inquirer';
2
2
  import { LoremIpsum } from 'lorem-ipsum';
3
+ import dayjs from 'dayjs';
3
4
  import { copy } from '../utils/clipboard.js';
4
5
  import { selectFromMenu } from '../utils/menu.js';
5
6
 
@@ -15,7 +16,6 @@ const lorem = new LoremIpsum({
15
16
  });
16
17
 
17
18
  function generateChinese(length) {
18
- // Common Chinese characters (simplified)
19
19
  const commonChars = "的一是在不了有和人这中大为上个国我以要他时来用们生到作地于出就分对成会可主发年动同工也能下过子说产种面而方后多定行学法所民得经十三之进着等部度家电力里如水化高自二理起小物现实加量都两体制机当使点从业本去把性好应开它合还因由其些然前外天政四日那社义事平形相全表间样与关各重新线内数角路最题验打果指气流接南情场变由规德问展七九几欲问无程和气光料村员真眼体别";
20
20
  let result = '';
21
21
  for (let i = 0; i < length; i++) {
@@ -25,10 +25,115 @@ function generateChinese(length) {
25
25
  return result;
26
26
  }
27
27
 
28
+ function randomInt(min, max) {
29
+ return Math.floor(Math.random() * (max - min + 1)) + min;
30
+ }
31
+
32
+ function padNumber(num, len) {
33
+ return String(num).padStart(len, '0');
34
+ }
35
+
36
+ export function generateChineseID() {
37
+ const areas = ['110101', '110102', '120101', '310101', '440104', '440305', '320102', '330106', '500101', '210102'];
38
+ const area = areas[randomInt(0, areas.length - 1)];
39
+ const start = new Date(1960, 0, 1).getTime();
40
+ const end = new Date(2010, 11, 31).getTime();
41
+ const ts = start + Math.floor(Math.random() * (end - start));
42
+ const date = dayjs(ts).format('YYYYMMDD');
43
+ const seq = padNumber(randomInt(0, 999), 3);
44
+ const base = area + date + seq;
45
+ const weights = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
46
+ const map = ['1','0','X','9','8','7','6','5','4','3','2'];
47
+ let sum = 0;
48
+ for (let i = 0; i < 17; i++) {
49
+ sum += parseInt(base[i], 10) * weights[i];
50
+ }
51
+ const check = map[sum % 11];
52
+ return base + check;
53
+ }
54
+
55
+ export function generateEmail() {
56
+ const letters = 'abcdefghijklmnopqrstuvwxyz';
57
+ const lettersDigits = letters + '0123456789';
58
+ let user = letters[randomInt(0, letters.length - 1)];
59
+ const userLen = randomInt(5, 12);
60
+ for (let i = 0; i < userLen; i++) {
61
+ const pool = Math.random() < 0.1 ? '._' : lettersDigits;
62
+ user += pool[randomInt(0, pool.length - 1)];
63
+ }
64
+ const domains = ['gmail.com', 'outlook.com', 'yahoo.com', 'qq.com', '163.com', 'icloud.com', 'example.com'];
65
+ const domain = domains[randomInt(0, domains.length - 1)];
66
+ return `${user}@${domain}`;
67
+ }
68
+
69
+ export function generateURL() {
70
+ const proto = Math.random() < 0.8 ? 'https' : 'http';
71
+ const letters = 'abcdefghijklmnopqrstuvwxyz';
72
+ const tlds = ['com', 'net', 'org', 'cn', 'io', 'dev'];
73
+ const labelLen = randomInt(5, 10);
74
+ let label = '';
75
+ for (let i = 0; i < labelLen; i++) {
76
+ label += letters[randomInt(0, letters.length - 1)];
77
+ }
78
+ const tld = tlds[randomInt(0, tlds.length - 1)];
79
+ const pathSegCount = randomInt(0, 3);
80
+ let path = '';
81
+ for (let i = 0; i < pathSegCount; i++) {
82
+ let seg = '';
83
+ const segLen = randomInt(3, 8);
84
+ for (let j = 0; j < segLen; j++) {
85
+ seg += letters[randomInt(0, letters.length - 1)];
86
+ }
87
+ path += `/${seg}`;
88
+ }
89
+ const withQuery = Math.random() < 0.4;
90
+ let query = '';
91
+ if (withQuery) {
92
+ const k = letters.substring(0, randomInt(3, 6));
93
+ const v = letters.substring(0, randomInt(3, 6));
94
+ query = `?${k}=${v}`;
95
+ }
96
+ const host = Math.random() < 0.7 ? `www.${label}.${tld}` : `${label}.${tld}`;
97
+ return `${proto}://${host}${path}${query}`;
98
+ }
99
+
100
+ export function generateOrderNo() {
101
+ const ts = dayjs().format('YYYYMMDDHHmmss');
102
+ const rand = padNumber(randomInt(0, 999999), 6);
103
+ return `ORD${ts}${rand}`;
104
+ }
105
+
106
+ export function generateMobile() {
107
+ const prefixes = ['130','131','132','133','134','135','136','137','138','139','150','151','152','153','155','156','157','158','159','170','171','172','173','175','176','177','178','180','181','182','183','185','186','187','188','189','198','199','166'];
108
+ const p = prefixes[randomInt(0, prefixes.length - 1)];
109
+ let rest = '';
110
+ for (let i = 0; i < 8; i++) {
111
+ rest += String(randomInt(0, 9));
112
+ }
113
+ return `${p}${rest}`;
114
+ }
115
+
116
+ export function generateLandline() {
117
+ const areas = ['010','020','021','022','023','024','025','027','028','029','0311','0371','0531','0755','0571'];
118
+ const area = areas[randomInt(0, areas.length - 1)];
119
+ const len = randomInt(7, 8);
120
+ let num = '';
121
+ for (let i = 0; i < len; i++) {
122
+ num += String(randomInt(0, 9));
123
+ }
124
+ return `${area}-${num}`;
125
+ }
126
+
28
127
  export async function mockHandler() {
29
- const type = await selectFromMenu('Mock Text', [
30
- { name: 'English', value: 'en' },
31
- { name: 'Chinese', value: 'cn' }
128
+ const type = await selectFromMenu('Mock Data', [
129
+ { name: '英文段落', value: 'en' },
130
+ { name: '中文字符', value: 'cn' },
131
+ { name: '身份证号', value: 'id' },
132
+ { name: '邮箱', value: 'email' },
133
+ { name: 'URL', value: 'url' },
134
+ { name: '订单号', value: 'order' },
135
+ { name: '手机号', value: 'mobile' },
136
+ { name: '座机号', value: 'landline' }
32
137
  ]);
33
138
 
34
139
  let result = '';
@@ -43,7 +148,7 @@ export async function mockHandler() {
43
148
  }
44
149
  ]);
45
150
  result = lorem.generateParagraphs(count);
46
- } else {
151
+ } else if (type === 'cn') {
47
152
  const { count } = await inquirer.prompt([
48
153
  {
49
154
  type: 'number',
@@ -53,6 +158,48 @@ export async function mockHandler() {
53
158
  }
54
159
  ]);
55
160
  result = generateChinese(count);
161
+ } else if (type === 'id') {
162
+ const { count } = await inquirer.prompt([
163
+ { type: 'number', name: 'count', message: 'Generate how many?', default: 1 }
164
+ ]);
165
+ const arr = [];
166
+ for (let i = 0; i < count; i++) arr.push(generateChineseID());
167
+ result = arr.join('\n');
168
+ } else if (type === 'email') {
169
+ const { count } = await inquirer.prompt([
170
+ { type: 'number', name: 'count', message: 'Generate how many?', default: 1 }
171
+ ]);
172
+ const arr = [];
173
+ for (let i = 0; i < count; i++) arr.push(generateEmail());
174
+ result = arr.join('\n');
175
+ } else if (type === 'url') {
176
+ const { count } = await inquirer.prompt([
177
+ { type: 'number', name: 'count', message: 'Generate how many?', default: 1 }
178
+ ]);
179
+ const arr = [];
180
+ for (let i = 0; i < count; i++) arr.push(generateURL());
181
+ result = arr.join('\n');
182
+ } else if (type === 'order') {
183
+ const { count } = await inquirer.prompt([
184
+ { type: 'number', name: 'count', message: 'Generate how many?', default: 1 }
185
+ ]);
186
+ const arr = [];
187
+ for (let i = 0; i < count; i++) arr.push(generateOrderNo());
188
+ result = arr.join('\n');
189
+ } else if (type === 'mobile') {
190
+ const { count } = await inquirer.prompt([
191
+ { type: 'number', name: 'count', message: 'Generate how many?', default: 1 }
192
+ ]);
193
+ const arr = [];
194
+ for (let i = 0; i < count; i++) arr.push(generateMobile());
195
+ result = arr.join('\n');
196
+ } else if (type === 'landline') {
197
+ const { count } = await inquirer.prompt([
198
+ { type: 'number', name: 'count', message: 'Generate how many?', default: 1 }
199
+ ]);
200
+ const arr = [];
201
+ for (let i = 0; i < count; i++) arr.push(generateLandline());
202
+ result = arr.join('\n');
56
203
  }
57
204
 
58
205
  console.log(`\nResult:\n${result}\n`);