ts-run-test 1.0.5
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/.idea/dictionaries/project.xml +7 -0
- package/.idea/inspectionProfiles/Project_Default.xml +22 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/misc.xml +10 -0
- package/.idea/modules.xml +8 -0
- package/.idea/ts-run-test.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.release-it.json +23 -0
- package/CHANGELOG.md +6 -0
- package/_test_/EventBus.ts +33 -0
- package/_test_/EventLoop.js +60 -0
- package/_test_/EventLoop.ts +85 -0
- package/_test_/IO.ts +62 -0
- package/_test_/ShengBei.html +84 -0
- package/_test_/__dirname.ts +17 -0
- package/_test_/aaaa.cjs +4 -0
- package/_test_/array.ts +26 -0
- package/_test_/async.ts +58 -0
- package/_test_/bfc.html +28 -0
- package/_test_/bin.ts +26 -0
- package/_test_/buffer.ts +21 -0
- package/_test_/build-icons/icon.ico +0 -0
- package/_test_/build-icons/icon_1024x1024.png +0 -0
- package/_test_/build-icons/icon_128x128.png +0 -0
- package/_test_/build-icons/icon_16x16.png +0 -0
- package/_test_/build-icons/icon_256x256.png +0 -0
- package/_test_/build-icons/icon_32x32.png +0 -0
- package/_test_/build-icons/icon_48x48.png +0 -0
- package/_test_/build-icons/icon_512x512.png +0 -0
- package/_test_/build-icons/icon_64x64.png +0 -0
- package/_test_/build-icons/splash/splash_100.png +0 -0
- package/_test_/build-icons/splash/splash_200.png +0 -0
- package/_test_/build-icons/tray/tray_black.png +0 -0
- package/_test_/build-icons/tray/tray_white.png +0 -0
- package/_test_/check.ts +65 -0
- package/_test_/closures.ts +12 -0
- package/_test_/copy.ts +25 -0
- package/_test_/debounce.ts +71 -0
- package/_test_/decorator.ts +37 -0
- package/_test_/deepCopy.ts +35 -0
- package/_test_/dom.ts +19 -0
- package/_test_/fetch.ts +45 -0
- package/_test_/get-template-version.ts +48 -0
- package/_test_/get.ts +52 -0
- package/_test_/gh.ts +19 -0
- package/_test_/gh_test.ts +93 -0
- package/_test_/icon.ico +0 -0
- package/_test_/icon.png +0 -0
- package/_test_/icon.ts +120 -0
- package/_test_/iconsize.ts +30 -0
- package/_test_/iterator.ts +112 -0
- package/_test_/link.ts +10 -0
- package/_test_/my/instanceof.ts +35 -0
- package/_test_/my/new.ts +22 -0
- package/_test_/new.ts +6 -0
- package/_test_/object.ts +2 -0
- package/_test_/observer.html +40 -0
- package/_test_/package.json +49 -0
- package/_test_/prototype.ts +27 -0
- package/_test_/proxy.ts +6 -0
- package/_test_/random.ts +29 -0
- package/_test_/react.ts +0 -0
- package/_test_/reg.ts +1 -0
- package/_test_/register.ts +61 -0
- package/_test_/release.config.cts +11 -0
- package/_test_/result.ts +37 -0
- package/_test_/task.ts +196 -0
- package/_test_/temp.md +8 -0
- package/_test_/tesp.ts +23 -0
- package/_test_/test.ts +59 -0
- package/_test_/typed.ts +55 -0
- package/_test_/worker.html +23 -0
- package/_test_/worker.js +4 -0
- package/_test_/worker.ts +5 -0
- package/_test_/xhr.ts +27 -0
- package/_test_//347/210/254/350/231/253.html +93 -0
- package/cache/00a25bc33880251d135060b213749534.jpg +0 -0
- package/cache/10_1730106978_t_NW.jpg +0 -0
- package/cache/11_1730104692_t_NW.jpg +0 -0
- package/cache/15_1730601804_t_NW.jpg +0 -0
- package/cache/17_1730434147_t_NW.jpg +0 -0
- package/cache/19ca581d7f9bf915d3cfb64299a9d5e0.jpg +0 -0
- package/cache/1ccf0b78ab293de8b2aa984773cf315b.jpg +0 -0
- package/cache/21a7518978f91278e75600b75390654e.jpg +0 -0
- package/cache/26ec1ad41910fa9f6236a98c8165a4f3.jpg +0 -0
- package/cache/2_1730114275_t_NW.jpg +0 -0
- package/cache/2a8542fbba235dda9d40c417a94083b5.jpg +0 -0
- package/cache/38_1730084632_t_NW.jpg +0 -0
- package/cache/45205cfc98b45aba7284124f730d37a4.jpg +0 -0
- package/cache/4_1730111766_t_NW.jpg +0 -0
- package/cache/544139e9bbc38597242c2a3d2ba9ede3.jpg +0 -0
- package/cache/60_1729079556_t_NW.jpg +0 -0
- package/cache/61_1729079251_t_NW.jpg +0 -0
- package/cache/65_1729078235_t_NW.jpg +0 -0
- package/cache/6b553b33cb2bc5423ca0a825a9596d7e.jpg +0 -0
- package/cache/74f7bbcd04af36cd224ebed548ba9f96.jpg +0 -0
- package/cache/762fa502959439d4ab1cc2f124c5fe31.jpg +0 -0
- package/cache/7_1730108771_t_NW.jpg +0 -0
- package/cache/82_1730202406_t_NW.jpg +0 -0
- package/cache/861641b72e0aa40abd4ad87c473100f6.jpg +0 -0
- package/cache/91_1730201579_t_NW.jpg +0 -0
- package/cache/95c1eceb38272ac57be2d1f14af3baa5.jpg +0 -0
- package/cache/99cae3416ed7d4ebce46003c291d5cc2.jpg +0 -0
- package/cache/9cf9878a0e979c6b9965ef415cfb43f1.jpg +0 -0
- package/cache/9e9db2fd267dc561244225efc1a872b3.jpg +0 -0
- package/cache/bc7bde2766d07dadd7fafd80854d6c5c.jpg +0 -0
- package/cache/c18d359f69c6b975604549f56237bfa8.jpg +0 -0
- package/cache/cf8143cd193619f57fc1ae06aed1ffec.jpg +0 -0
- package/cache/f3a5f2b40033da74d857c8dc0244948a.jpg +0 -0
- package/cache/f5d0336a68ec2b35eeb76706b02576bd.jpg +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +2 -0
- package/dist/ip2region.cjs +11 -0
- package/dist/ip2region.d.cts +1 -0
- package/dist/ip2region.d.ts +1 -0
- package/dist/ip2region.js +20 -0
- package/dist/npm.d.ts +1 -0
- package/dist/npm.js +3 -0
- package/dist/pkg-filed.d.ts +1 -0
- package/dist/pkg-filed.js +18 -0
- package/dist/restore-wechat-images.d.ts +1 -0
- package/dist/restore-wechat-images.js +39 -0
- package/package.json +43 -0
- package/record.md +59 -0
- package/src/copyDir.ts +21 -0
- package/src/example.png +0 -0
- package/src/formatText.ts +83 -0
- package/src/index.ts +1 -0
- package/src/ip2region.cts +13 -0
- package/src/npm.ts +5 -0
- package/src/pkg-filed.ts +30 -0
- package/src/puppeteer.ts +51 -0
- package/src/restore-wechat-images.ts +50 -0
- package/src/try.ts +9 -0
- package/src/useCrawler.ts +31 -0
- package/tsconfig.json +20 -0
- package/tsdown.config.ts +15 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { readFileSync } from 'fs'
|
|
2
|
+
import { writeFile } from 'fs/promises'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
interface TextFormatOptions {
|
|
6
|
+
convertEnglishPunctuationToChinese?: boolean;
|
|
7
|
+
convertFullWidthToHalfWidth?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function formatText(text: string, options: TextFormatOptions = {}): string {
|
|
11
|
+
const {
|
|
12
|
+
convertEnglishPunctuationToChinese = false,
|
|
13
|
+
convertFullWidthToHalfWidth = true,
|
|
14
|
+
} = options;
|
|
15
|
+
|
|
16
|
+
// 全角转半角
|
|
17
|
+
if (convertFullWidthToHalfWidth) {
|
|
18
|
+
text = text.replace(/[\uFF01-\uFF5E]/g, ch =>
|
|
19
|
+
String.fromCharCode(ch.charCodeAt(0) - 0xFEE0)
|
|
20
|
+
).replace(/\u3000/g, ' '); // 全角空格转半角
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 英文标点转中文标点
|
|
24
|
+
if (convertEnglishPunctuationToChinese) {
|
|
25
|
+
const punctuationMap: Record<string, string> = {
|
|
26
|
+
',': ',',
|
|
27
|
+
'.': '。',
|
|
28
|
+
':': ':',
|
|
29
|
+
';': ';',
|
|
30
|
+
'?': '?',
|
|
31
|
+
'!': '!',
|
|
32
|
+
'(': '(',
|
|
33
|
+
')': ')',
|
|
34
|
+
'[': '【',
|
|
35
|
+
']': '】',
|
|
36
|
+
'"': '“',
|
|
37
|
+
"'": '‘'
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
text = text.replace(/[.,:;?!()\[\]"']/g, m => punctuationMap[m] || m);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 插入中英文之间的空格,排除中英文标点之间
|
|
44
|
+
// 汉字与英文/数字
|
|
45
|
+
text = text
|
|
46
|
+
.replace(/([\u4e00-\u9fa5])([a-zA-Z0-9@#&\-_])/g, '$1 $2') // 中文后面是英文/数字
|
|
47
|
+
.replace(/([a-zA-Z0-9@#&\-_])([\u4e00-\u9fa5])/g, '$1 $2'); // 英文/数字后面是中文
|
|
48
|
+
|
|
49
|
+
// 删除标点符号周围的多余空格(中文标点)
|
|
50
|
+
text = text.replace(/([\u3002\uff0c\uff01\uff1f\uff1a\uff1b\uff08\uff09\u3001\u201c\u201d\u2018\u2019])\s+/g, '$1');
|
|
51
|
+
text = text.replace(/\s+([\u3002\uff0c\uff01\uff1f\uff1a\uff1b\uff08\uff09\u3001\u201c\u201d\u2018\u2019])/g, '$1');
|
|
52
|
+
|
|
53
|
+
// 多空格合并为1个空格
|
|
54
|
+
// text = text.replace(/\s{2,}/g, ' ');
|
|
55
|
+
|
|
56
|
+
return text.trim();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function insertSpaceBetweenChineseAndEnglish(text: string): string {
|
|
60
|
+
return text
|
|
61
|
+
// 中文与英文/数字之间插入空格(中文在前)
|
|
62
|
+
.replace(/([\u4e00-\u9fa5])([a-zA-Z0-9])/g, '$1 $2')
|
|
63
|
+
// 英文/数字与中文之间插入空格(中文在后)
|
|
64
|
+
.replace(/([a-zA-Z0-9])([\u4e00-\u9fa5])/g, '$1 $2')
|
|
65
|
+
// 去除重复空格(如已有空格再插入避免变成两个)
|
|
66
|
+
.replace(/ {2,}/g, ' ')
|
|
67
|
+
.trim()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
const raw = '你好world!这是a测试,数字123和符号@#要处理。';
|
|
72
|
+
const result = insertSpaceBetweenChineseAndEnglish(raw);
|
|
73
|
+
|
|
74
|
+
console.log(result);
|
|
75
|
+
// 输出:你好 world!这是 a 测试,数字 123 和符号 @# 要处理。
|
|
76
|
+
|
|
77
|
+
const txt = readFileSync('./vue_interview_21_50.md', 'utf-8')
|
|
78
|
+
|
|
79
|
+
const res = insertSpaceBetweenChineseAndEnglish(txt);
|
|
80
|
+
|
|
81
|
+
console.log(res.replace(/第 (\d+) 题:/g, '$1. '))
|
|
82
|
+
|
|
83
|
+
await writeFile('./vue_i.md', res.replace(/第 (\d+) 题:/g, '$1. '));
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log('Happy developing ✨')
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import IP2Region from 'ip2region'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const ip = '127.0.0.1'
|
|
5
|
+
|
|
6
|
+
const query = new IP2Region()
|
|
7
|
+
const ipAddress = query.search(ip)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
console.log('>>> ipAddress:', ipAddress)
|
|
11
|
+
// >>> ipAddress: { country: '', province: '', city: '内网IP', isp: '内网IP' }
|
|
12
|
+
|
|
13
|
+
|
package/src/npm.ts
ADDED
package/src/pkg-filed.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { readFileSync } from 'fs'
|
|
2
|
+
import { exec } from 'node:child_process'
|
|
3
|
+
import { join } from 'path'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export const getFiledValue = (pkg: string, filed: string = 'version'): Promise<[ string, string ]> => {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
exec(
|
|
9
|
+
`pnpm view ${ pkg } ${ filed } --json`, { encoding: 'utf8' },
|
|
10
|
+
(err, stdout) => resolve([ pkg, err ? '' : JSON.parse(stdout) ]),
|
|
11
|
+
)
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const pkg = JSON.parse(readFileSync(join(process.cwd(), '..', 'package.json'), 'utf8'))
|
|
17
|
+
const deps = Object.keys({ ...pkg.dependencies, ...pkg.devDependencies })
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const getLicense = (pkg: string) => getFiledValue(pkg, 'license')
|
|
21
|
+
const licenses = await Promise.all(deps.map(getLicense))
|
|
22
|
+
|
|
23
|
+
console.log('已安装依赖许可证:', licenses)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const getVersion = (pkg: string) => getFiledValue(pkg, 'version')
|
|
27
|
+
const versions = await Promise.all(deps.map(getVersion))
|
|
28
|
+
|
|
29
|
+
console.log('已安装依赖版本:', versions)
|
|
30
|
+
|
package/src/puppeteer.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline'
|
|
2
|
+
import puppeteer from 'puppeteer'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const rl = createInterface({
|
|
6
|
+
input: process.stdin,
|
|
7
|
+
output: process.stdout,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
rl.on('line', async (str) => {
|
|
11
|
+
console.log('str >>> :', str)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const browser = await puppeteer.launch({
|
|
16
|
+
headless: false,
|
|
17
|
+
defaultViewport: {
|
|
18
|
+
width: 0,
|
|
19
|
+
height: 0,
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const page = await browser.newPage()
|
|
24
|
+
await page.goto('http://localhost:5173/vite-press/')
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
await page.screenshot({ path: 'example.png' });
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
await page.type('h1', '被劫持了')
|
|
31
|
+
|
|
32
|
+
const title = await page.$eval('h1', el => el.textContent);
|
|
33
|
+
console.log('页面标题:', title);
|
|
34
|
+
|
|
35
|
+
// await browser.close();
|
|
36
|
+
|
|
37
|
+
// await page.waitForSelector('#username');
|
|
38
|
+
//
|
|
39
|
+
//
|
|
40
|
+
// const $username = await page.$('#username');
|
|
41
|
+
// await $username?.type('1111111', {
|
|
42
|
+
// delay: 100
|
|
43
|
+
// });
|
|
44
|
+
//
|
|
45
|
+
// const $password = await page.$('#password');
|
|
46
|
+
// await $password?.type('testtest', {
|
|
47
|
+
// delay: 100
|
|
48
|
+
// });
|
|
49
|
+
//
|
|
50
|
+
// const $button = await page.$('button[type="submit"]');
|
|
51
|
+
// await $button?.click();
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readFileSync } from 'fs'
|
|
2
|
+
import { writeFile } from 'fs/promises'
|
|
3
|
+
import { basename, join } from 'path'
|
|
4
|
+
import { globSync } from 'tinyglobby'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const getFileType = (buffer: Buffer) => {
|
|
8
|
+
const jpg = Buffer.from([ 0xff, 0xd8, 0xff ])
|
|
9
|
+
const png = Buffer.from([ 0x89, 0x50, 0x4e, 0x47 ])
|
|
10
|
+
|
|
11
|
+
const sub = (s: number, e: number) => buffer.subarray(s, e)
|
|
12
|
+
|
|
13
|
+
if (sub(0, 3).equals(jpg)) {
|
|
14
|
+
return 'jpg'
|
|
15
|
+
}
|
|
16
|
+
if (sub(0, 4).equals(png)) {
|
|
17
|
+
return 'png'
|
|
18
|
+
}
|
|
19
|
+
if ([ 'GIF87a', 'GIF89a' ].includes(sub(0, 6).toString())) {
|
|
20
|
+
return 'gif'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const readDatFiles = (dir: string) => {
|
|
25
|
+
return globSync([ '**/*.dat' ], { cwd: dir })
|
|
26
|
+
.map((file: string) => join(dir, file))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const restoreDatImages = (files: string[], output: string) => {
|
|
30
|
+
files.forEach(async (filepath: string) => {
|
|
31
|
+
const buffer = readFileSync(filepath)
|
|
32
|
+
const ext = getFileType(buffer)
|
|
33
|
+
|
|
34
|
+
if (ext) {
|
|
35
|
+
const filename = basename(filepath).replace(/\.dat$/, `.${ ext }`)
|
|
36
|
+
const newFilepath = join(output, filename)
|
|
37
|
+
|
|
38
|
+
await writeFile(newFilepath, buffer)
|
|
39
|
+
|
|
40
|
+
console.log(`✔ Restored: ${ filepath } -> ${ filename }`)
|
|
41
|
+
} else {
|
|
42
|
+
console.warn(`✖ Unknown type file: ${ filepath }`)
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
const root = 'C:\\Users\\ASUS\\Documents'
|
|
49
|
+
restoreDatImages(readDatFiles(root), 'E:\\ts-run-test\\cache')
|
|
50
|
+
|
package/src/try.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function isBrowserProcess() {
|
|
2
|
+
return typeof window === 'object' && typeof window.navigator === 'object'
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function isElectronAppFrontend() {
|
|
6
|
+
return typeof navigator === 'object' && navigator.userAgent.toLowerCase().indexOf('electron') >= 0
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
console.log(isElectronAppFrontend(), isBrowserProcess())
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Crawler, { CrawlerRequestOptions, CrawlerRequestResponse, CreateCrawlerOptions } from 'crawler'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
type UrisOrOptions =
|
|
5
|
+
| string
|
|
6
|
+
| readonly string[]
|
|
7
|
+
| CrawlerRequestOptions
|
|
8
|
+
| readonly CrawlerRequestOptions[]
|
|
9
|
+
|
|
10
|
+
export const useCrawler = (urisOrOptions: UrisOrOptions, options?: CreateCrawlerOptions) => {
|
|
11
|
+
return new Promise<CrawlerRequestResponse>((resolve, reject) => {
|
|
12
|
+
new Crawler({
|
|
13
|
+
maxConnections: 10,
|
|
14
|
+
callback: (error, res, done) => {
|
|
15
|
+
if (error) {
|
|
16
|
+
reject(error)
|
|
17
|
+
} else {
|
|
18
|
+
resolve(res)
|
|
19
|
+
}
|
|
20
|
+
done()
|
|
21
|
+
},
|
|
22
|
+
...options,
|
|
23
|
+
})
|
|
24
|
+
.queue(urisOrOptions)
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
console.log(await useCrawler('https://peiyanlu.github.io/vite-press/'))
|
|
30
|
+
|
|
31
|
+
console.log(this)
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"forceConsistentCasingInFileNames": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"moduleResolution": "node",
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"isolatedDeclarations": false,
|
|
13
|
+
"extendedDiagnostics": true,
|
|
14
|
+
"experimentalDecorators": true,
|
|
15
|
+
},
|
|
16
|
+
"include": [
|
|
17
|
+
"src",
|
|
18
|
+
"_test_"
|
|
19
|
+
]
|
|
20
|
+
}
|
package/tsdown.config.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineConfig } from 'tsdown'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
type Config = ReturnType<typeof defineConfig>
|
|
5
|
+
|
|
6
|
+
const esmConfig: Config = defineConfig({
|
|
7
|
+
entry: [ './src' ],
|
|
8
|
+
dts: true,
|
|
9
|
+
treeshake: false,
|
|
10
|
+
format: 'esm',
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const config: Config[] = [ esmConfig ]
|
|
14
|
+
|
|
15
|
+
export default config
|