Skip to content

Commit d29b6af

Browse files
committed
chore: update
1 parent 3ca4803 commit d29b6af

27 files changed

+753
-49
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
README.md

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
},
55
"editor.formatOnSave": false,
66
"unocss.root": "./packages/site",
7+
"i18n-ally.localesPaths": [
8+
"packages/site/locales"
9+
],
710
}

README.md

Lines changed: 136 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,140 @@
1-
# PNPM MonoRepo Starter
1+
<p align="center">
2+
<img src="https://raw.githubusercontent.com/imageList/imglist/master/logo.png" style="width:200px" />
3+
<h1 align="center">JSON-TSC</h1>
4+
<p align="center">A plugin that makes it easier to convert JSON to Typescript types.</p>
5+
</p>
6+
<p align="center">
7+
<a href="https://www.npmjs.com/package/json-tsc"><img src="https://img.shields.io/npm/v/json-tsc?color=c95f8b&amp;label=" alt="NPM version"></a></p>
8+
<p align="center">
9+
<a href="https://onu.zyob.top/">🤹‍♂️ Preview</a>
10+
</p>
11+
12+
## Features
13+
14+
- 🌈 Simple - Provides the easiest API to convert JSON into Typescript interaface.
15+
- 🎉 Ts Supported - Support TypeScript & type checked & type inference.
216

317
## Usage
418

5-
## Credits
6-
19+
```bash
20+
npm i json-tsc -D
21+
```
22+
23+
Import `JSON_TSC` into the file you want to convert.
24+
25+
```ts
26+
import { JSON_TSC } from "json-tsc";
27+
28+
const JSON_TEST = {
29+
"a": 0,
30+
"b": {
31+
"c": "string",
32+
"d": [1, 2, 3],
33+
"e": {
34+
"f": true,
35+
"g": null,
36+
},
37+
},
38+
};
39+
40+
const json_tsc = new JSON_TSC({
41+
prependWithO: true,
42+
sortAlphabetically: false,
43+
prependExport: true,
44+
useArrayGeneric: false,
45+
optionalFields: false,
46+
prefix: "",
47+
});
48+
49+
const result = json_tsc.transform(JSON_TEST);
50+
51+
// result
52+
type JSON_TSC = ORootObject;
53+
export interface ORootObject {
54+
a: number;
55+
b: OB;
56+
}
57+
export interface OB {
58+
c: string;
59+
d: number[];
60+
e: OE;
61+
}
62+
export interface OE {
63+
f: boolean;
64+
g: any;
65+
}
66+
```
67+
68+
## Config
69+
70+
```ts
71+
export interface JSON_TSC_CONFIG {
72+
/**
73+
* zh-CN: 是否在生成的类型前面加上 O
74+
* en: Whether to add O in front of the generated type
75+
*/
76+
prependWithO: boolean
77+
/**
78+
* zh-CN: 是否按照字母顺序排序
79+
* en: Whether to sort in alphabetical order
80+
*/
81+
sortAlphabetically: boolean
82+
/**
83+
* zh-CN: 是否在生成的类型前面加上 export
84+
* en: Whether to add export in front of the generated type
85+
*/
86+
prependExport: boolean
87+
/**
88+
* zh-CN: 是否使用 ''Array<T>'' 代替 ''T[]'
89+
* en: Whether to use ''Array<T>'' instead of ''T[]''
90+
*/
91+
useArrayGeneric: boolean
92+
/**
93+
* zh-CN: 是否将所有字段设置为可选
94+
* en: Whether to set all fields to optional
95+
*/
96+
optionalFields: boolean
97+
/**
98+
* zh-CN: 生成的类型前面的前缀
99+
* en: Prefix in front of generated type
100+
*/
101+
prefix: string
102+
/**
103+
* zh-CN: 生成的类型后面的后缀
104+
* en: Suffix behind generated type
105+
*/
106+
rootObjectName: string
107+
}
108+
109+
```
110+
111+
## [Use it Now]()
112+
113+
![image](https://raw.githubusercontent.com/imageList/imglist/master/20221027234023.png)
114+
115+
116+
## Development
117+
118+
You can see the preview of the following commands:
119+
120+
```bash
121+
npm run build
122+
```
123+
124+
Then you can run playground to see the result.
125+
126+
```bash
127+
npm run play
128+
```
129+
130+
If you want start the dev server, you can run:
131+
132+
```bash
133+
npm run dev
134+
```
135+
136+
137+
7138
## License
139+
140+
[MIT](./LICENSE) License © 2022 [yzh990918](https://github.com/yzh990918)

netlify.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[build.environment]
2+
NPM_FLAGS = "--version"
3+
NODE_VERSION = "16"
4+
5+
[build]
6+
publish = "packages/site/dist"
7+
command = "npx [email protected] i --frozen-lockfile false && npx [email protected] build && npx [email protected] run deploy"
8+
ignore = "git diff --quiet HEAD^ HEAD . ../packages"
9+
10+
[functions]
11+
node_bundler = "esbuild"

packages/.DS_Store

6 KB
Binary file not shown.

packages/site/.DS_Store

6 KB
Binary file not shown.

packages/site/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ declare module '@vue/runtime-core' {
99
export interface GlobalComponents {
1010
Bg: typeof import('./src/components/layout/bg.vue')['default']
1111
Counter: typeof import('./src/components/Counter.vue')['default']
12+
ElButton: typeof import('element-plus/es')['ElButton']
1213
ElCard: typeof import('element-plus/es')['ElCard']
1314
ElDivider: typeof import('element-plus/es')['ElDivider']
1415
ElInput: typeof import('element-plus/es')['ElInput']

packages/site/locales/en.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ config:
99
rootObjectName: Please input the root object name
1010
btn:
1111
transform: Transform
12+
reset: Reset
1213
copied: Copied
13-
Copy: Copy Result
14+
copy: Copy Result
1415
import_first: 'Example 1: JSON fragment'
1516
import_second: 'Example 2: JSON fragment'
17+
toggle_langs: Change languages
1618
textarea:
1719
inputCode: Please input the json
1820
outputCode: Show the transformed interface code

packages/site/locales/zh-CN.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
config:
22
title: JSON-TSC 配置选项
3-
prependWithO: 'Interface 以 ''O'' 为开头'
4-
sortAlphabetically: 按字母顺序排序
5-
prependExport: '添加 ''export'' 关键字声明'
6-
useArrayGeneric: '使用 ''Array<T>'' 代替 ''T[]'''
7-
optionalFields: 将所有字段变为可选字段
3+
prependWithO: 'Interface 以 ''O'' 为开头:'
4+
sortAlphabetically: '按字母顺序排序:'
5+
prependExport: '添加 ''export'' 关键字声明:'
6+
useArrayGeneric: '使用 ''Array<T>'' 代替 ''T[]'':'
7+
optionalFields: '将所有字段变为可选字段:'
88
prefix: 请填写前缀
99
rootObjectName: 请填写根元素名称
1010
btn:
1111
transform: 转换
12+
reset: 重置
1213
copied: 已拷贝
13-
Copy: 拷贝结果
14+
copy: 拷贝结果
1415
import_first: '示例1: JSON片段'
1516
import_second: '示例2: JSON片段'
17+
toggle_langs: 切换语言
1618
textarea:
1719
inputCode: 请输入 JSON 代码
1820
outputCode: 查看您的 interface 代码

packages/site/public/.DS_Store

6 KB
Binary file not shown.
9.58 KB
Loading
33.2 KB
Loading
8.65 KB
Loading
345 Bytes
Loading
889 Bytes
Loading

packages/site/public/favicon.ico

15 KB
Binary file not shown.

packages/site/public/favicon.svg

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/site/public/logo.png

203 KB
Loading

packages/site/src/components/layout/TheHeader.vue

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<script setup lang="ts">
2+
const { t, availableLocales, locale } = useI18n()
3+
4+
const toggleLocales = () => {
5+
// change to some real logic
6+
const locales = availableLocales
7+
locale.value = locales[(locales.indexOf(locale.value) + 1) % locales.length]
8+
}
9+
</script>
10+
111
<template>
212
<header h-16 flex justify-between items-center px-8>
313
<div flex justify-start items-center gap-4>
@@ -6,15 +16,26 @@
616
JSON-TSC
717
</h1>
818
</div>
9-
<a
10-
class="icon-btn"
11-
text-lg
12-
i-carbon-logo-github
13-
rel="noreferrer"
14-
href="https://github.com/251205668/vitest-vue-starter"
15-
target="_blank"
16-
title="GitHub"
17-
/>
19+
20+
<div flex space-x-4>
21+
<a
22+
class="icon-btn mx-2"
23+
:class="locale === 'en' ? '' : '-rotate-y-180'"
24+
:title="t('btn.toggle_langs')"
25+
@click="toggleLocales()"
26+
>
27+
<div i-carbon:translate />
28+
</a>
29+
<a
30+
class="icon-btn"
31+
text-lg
32+
i-carbon-logo-github
33+
rel="noreferrer"
34+
href="https://github.com/251205668/vitest-vue-starter"
35+
target="_blank"
36+
title="GitHub"
37+
/>
38+
</div>
1839
</header>
1940
</template>
2041

0 commit comments

Comments
 (0)