Skip to content

Commit 75ae56b

Browse files
committed
refactor: use typescript
1 parent d581aa7 commit 75ae56b

File tree

13 files changed

+4162
-2667
lines changed

13 files changed

+4162
-2667
lines changed

.githooks/pre-commit

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
22

3-
pnpm run lint:staged
3+
pnpm run lint:staged || exit 1
4+
pnpm run lint:type || exit 1
45
pnpm test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,5 @@ $RECYCLE.BIN/
168168
*.lnk
169169

170170
# End of https://gitignore.io/api/node,windows
171+
index.js
172+
index.d.ts

.npmrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
registry = https://mirrors.tencent.com/npm/
2+
3+
shamefully-hoist = true

eslint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import base from '@nice-move/all-in-base/eslint';
2+
3+
export default [...base];

index.js renamed to index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
const regexp =
2-
/((?<k1>(?!=)\S+)=((?<v1>(["'`])(.*?)\5)|(?<v2>\S+)))|(?<k2>\S+)/g;
2+
/((?<k1>[^=\s]+)=((?<v1>(["'`])(.*?)\5)|(?<v2>\S+)))|(?<k2>\S+)/g;
33

4-
export function parse(string) {
4+
export function parse(string: string) {
55
const io = (string ?? '').matchAll(regexp);
66

77
return new Map(
88
[...io]
9-
.map((item) => item?.groups)
9+
.map((item) => item?.groups || {})
1010
.map(({ k1, k2, v1, v2 }) => [k1 ?? k2, v1 ?? v2]),
1111
);
1212
}
1313

14-
export function stringify(object) {
14+
export function stringify(object: object | Map<string, unknown>) {
1515
return (
1616
object instanceof Map ? [...object.entries()] : Object.entries(object)
1717
)
1818
.map(([k, v]) => [k, v].filter((i) => i !== undefined).join('='))
1919
.join(' ');
2020
}
2121

22-
export function getValue(string) {
22+
export function getValue(string: string): string {
2323
return string?.match?.(/(["'`])(?<value>.*?)\1/)?.groups?.value ?? string;
2424
}

package.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
22
"name": "markdown-code-block-meta",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "A library to parse/stringify metadata of markdown code block",
55
"license": "MIT",
66
"author": {
7-
"name": "Eric Chen",
8-
"email": "[email protected]"
7+
"name": "Eric Chen"
98
},
109
"keywords": [
1110
"code-block",
@@ -19,45 +18,46 @@
1918
"homepage": "https://github.com/nice-move/markdown-code-block-meta",
2019
"repository": {
2120
"type": "git",
22-
"url": "https://github.com/nice-move/markdown-code-block-meta.git"
21+
"url": "git+https://github.com/nice-move/markdown-code-block-meta.git"
2322
},
2423
"bugs": {
2524
"url": "https://github.com/nice-move/markdown-code-block-meta/issues"
2625
},
2726
"main": "index.js",
28-
"files": [],
27+
"files": [
28+
"index.d.ts"
29+
],
2930
"type": "module",
3031
"scripts": {
32+
"build": "tsc -p tsconfig.build.json",
3133
"lint:staged": "nice-move lint staged",
34+
"lint:type": "tsc -p tsconfig.json",
3235
"prepare": "nice-move git hooks",
33-
"prepublishOnly": "pnpm run lint:staged && pnpm test",
36+
"prepublishOnly": "pnpm run lint:staged && pnpm test && pnpm run build",
3437
"snapshot": "ava --fail-fast -u",
3538
"test": "ava --fail-fast"
3639
},
3740
"devDependencies": {
38-
"@bring-it/npm": "^0.3.5",
39-
"@nice-move/cli": "^0.10.13",
40-
"@nice-move/eslint-config-base": "^0.9.22",
41-
"@nice-move/prettier-config": "^0.9.6",
42-
"ava": "^5.3.1",
43-
"eslint": "^8.51.0",
44-
"eslint-plugin-ava": "^14.0.0",
45-
"garou": "^0.6.17",
46-
"prettier": "^3.0.3"
47-
},
41+
"@bring-it/npm": "^0.9.0",
42+
"@nice-move/all-in-base": "^0.6.18",
43+
"ava": "^6.4.1",
44+
"eslint": "^9.37.0",
45+
"garou": "^0.9.15",
46+
"prettier": "^3.6.2",
47+
"typescript": "^5.9.3"
48+
},
49+
"packageManager": "[email protected]",
4850
"engines": {
49-
"node": "^16.15.0 || ^18.12.0"
51+
"node": ">=18.12.0 || ^16.15.0"
5052
},
5153
"publishConfig": {
5254
"access": "public",
5355
"registry": "https://registry.npmjs.org/"
5456
},
55-
"packageManager": "[email protected]",
56-
"eslintConfig": {
57-
"extends": "@nice-move/eslint-config-base"
58-
},
59-
"nice-move": {
60-
"import-groups": "nice-move-preset"
57+
"ava": {
58+
"extensions": [
59+
"mts"
60+
]
6161
},
6262
"prettier": "@nice-move/prettier-config"
6363
}

0 commit comments

Comments
 (0)