Skip to content

Commit 67e1c02

Browse files
committed
🛠 convert to typescript
1 parent a637597 commit 67e1c02

16 files changed

+655
-106
lines changed

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
preset: '@vue/cli-plugin-unit-jest'
2+
preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel'
33
}

package-lock.json

+566-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@
2525
"vue": "^3.0.0-beta.1"
2626
},
2727
"devDependencies": {
28+
"@types/jest": "^24.0.19",
29+
"@typescript-eslint/eslint-plugin": "^2.33.0",
30+
"@typescript-eslint/parser": "^2.33.0",
2831
"@vue/cli-plugin-babel": "^4.1.0",
2932
"@vue/cli-plugin-eslint": "^4.2.2",
33+
"@vue/cli-plugin-typescript": "^4.5.11",
3034
"@vue/cli-plugin-unit-jest": "^4.2.2",
3135
"@vue/cli-service": "^4.2.3",
3236
"@vue/compiler-sfc": "^3.0.0-beta.1",
3337
"@vue/eslint-config-prettier": "^6.0.0",
3438
"@vue/eslint-config-standard": "^5.1.0",
39+
"@vue/eslint-config-typescript": "^5.0.2",
3540
"@vue/test-utils": "^2.0.0-alpha.1",
3641
"babel-eslint": "^10.0.3",
3742
"core-js": "^3.4.4",
@@ -43,6 +48,7 @@
4348
"eslint-plugin-standard": "^4.0.0",
4449
"eslint-plugin-vue": "^7.0.0-alpha.0",
4550
"jest": "^25.1.0",
51+
"typescript": "~3.9.3",
4652
"vue": "^2.6.10",
4753
"vue-cli-plugin-vue-next": "~0.1.4"
4854
},
@@ -55,13 +61,14 @@
5561
"plugin:vue/vue3-essential",
5662
"eslint:recommended",
5763
"@vue/standard",
58-
"prettier"
64+
"prettier",
65+
"@vue/typescript"
5966
],
6067
"rules": {
6168
"quotes": "error"
6269
},
6370
"parserOptions": {
64-
"parser": "babel-eslint"
71+
"parser": "@typescript-eslint/parser"
6572
},
6673
"overrides": [
6774
{

src/App.vue

+11-84
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,25 @@
11
<template>
22
<div id="app">
3-
<div class="wrap">
4-
<h1>Vue Simple Password Meter</h1>
5-
<p>
6-
<b>Vue Simple Passwod Meter</b> is a simple password checker written in
7-
vanilla js and extremly lightweight
8-
</p>
9-
10-
<form>
11-
<label for="password">Password</label>
12-
<input id="password" type="password" v-model="value" />
13-
<small v-if="score === 0">use better password</small>
14-
<password-meter :password="value" @score="onScore" />
15-
</form>
16-
</div>
3+
<input type="password" v-model="pass">
4+
<password-meter :password="pass" />
175
</div>
186
</template>
197

20-
<script>
21-
import passwordMeter from './password-meter.vue'
22-
23-
export default {
24-
name: 'app',
8+
<script lang="ts">
9+
import { defineComponent } from 'vue';
10+
import PasswordMeter from './password-meter.vue'
11+
export default defineComponent({
12+
name: 'App',
2513
components: {
26-
passwordMeter
14+
PasswordMeter
2715
},
28-
data () {
16+
data() {
2917
return {
30-
value: null,
31-
score: null
32-
}
33-
},
34-
methods: {
35-
onScore ({ score, strength }) {
36-
// eslint-disable-next-line no-console
37-
console.log(score, strength)
38-
39-
this.score = score
18+
pass: ''
4019
}
4120
}
42-
}
21+
});
4322
</script>
4423

4524
<style>
46-
#app {
47-
font-family: "Avenir", Helvetica, Arial, sans-serif;
48-
-webkit-font-smoothing: antialiased;
49-
-moz-osx-font-smoothing: grayscale;
50-
text-align: center;
51-
color: #2c3e50;
52-
display: flex;
53-
align-items: center;
54-
justify-content: center;
55-
height: 100vh;
56-
margin: 0;
57-
padding: 0;
58-
}
59-
60-
* {
61-
padding: 0;
62-
margin: 0;
63-
}
64-
65-
#app .wrap {
66-
max-width: 450px;
67-
margin: auto;
68-
}
69-
70-
#app .wrap input {
71-
border: 1px solid #ccc;
72-
padding: 5px 10px;
73-
border-radius: 3px;
74-
width: 100%;
75-
box-sizing: border-box;
76-
}
77-
78-
#app p {
79-
margin: 16px 0;
80-
color: #777;
81-
line-height: 1.5;
82-
}
83-
84-
#app p b {
85-
color: #333333;
86-
}
87-
88-
#app form {
89-
margin: 0 25px;
90-
}
91-
92-
#app form label {
93-
display: block;
94-
font-size: 12px;
95-
text-align: left;
96-
margin-bottom: 6px;
97-
}
9825
</style>

src/logic/checkStrength.js renamed to src/logic/checkStrength.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scorePassword from './scorePassword'
22
import nameScore from './nameScore'
33

4-
const checkStrength = pass => {
4+
const checkStrength = (pass: string) => {
55
const score = scorePassword(pass)
66
return nameScore(score)
77
}
File renamed without changes.

src/logic/nameScore.js renamed to src/logic/nameScore.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const nameScore = score => {
1+
const nameScore = (score: number): string => {
22
switch (score) {
33
case 0:
44
return 'risky'
@@ -11,7 +11,7 @@ const nameScore = score => {
1111
case 4:
1212
return 'secure'
1313
default:
14-
return null
14+
return ''
1515
}
1616
}
1717

src/logic/scorePassword.js renamed to src/logic/scorePassword.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const scorePassword = pass => {
1+
const scorePassword = (pass : string): number => {
22
let score = 0
33
let length = 0
44
let specialChar = 0

src/main.js renamed to src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { createApp } from 'vue';
22
import App from './App.vue'
33

4-
createApp(App).mount('#app')
4+
createApp( App ).mount('#app')

src/password-meter.vue

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
<div class="po-password-strength-bar" :class="passwordClass"></div>
33
</template>
44

5-
<script>
5+
<script lang="ts">
6+
import {defineComponent} from 'vue'
67
import { checkStrength, scorePassword } from './logic'
78
8-
export default {
9+
export default defineComponent({
910
name: 'password-meter',
1011
props: {
1112
password: String
1213
},
1314
computed: {
14-
passwordClass() {
15+
passwordClass(): object | null {
1516
if (!this.password) {
1617
return null
1718
}
@@ -24,7 +25,7 @@ export default {
2425
}
2526
}
2627
}
27-
}
28+
})
2829
</script>
2930

3031
<style>

src/shims-tsx.d.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Vue, { VNode } from 'vue'
2+
3+
declare global {
4+
namespace JSX {
5+
// tslint:disable no-empty-interface
6+
interface Element extends VNode {}
7+
// tslint:disable no-empty-interface
8+
// @ts-ignore
9+
interface ElementClass extends Vue {}
10+
interface IntrinsicElements {
11+
[elem: string]: any
12+
}
13+
}
14+
}

src/shims-vue.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.vue' {
2+
import Vue from 'vue'
3+
export default Vue
4+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

tsconfig.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"strict": true,
6+
"jsx": "preserve",
7+
"importHelpers": true,
8+
"moduleResolution": "node",
9+
"allowJs": true,
10+
"esModuleInterop": true,
11+
"allowSyntheticDefaultImports": true,
12+
"sourceMap": true,
13+
"baseUrl": ".",
14+
"types": [
15+
"webpack-env",
16+
"jest"
17+
],
18+
"paths": {
19+
"@/*": [
20+
"src/*"
21+
]
22+
},
23+
"lib": [
24+
"esnext",
25+
"dom",
26+
"dom.iterable",
27+
"scripthost"
28+
]
29+
},
30+
"include": [
31+
"src/**/*.ts",
32+
"src/**/*.tsx",
33+
"src/**/*.vue",
34+
"tests/**/*.ts",
35+
"tests/**/*.tsx"
36+
],
37+
"exclude": [
38+
"node_modules"
39+
]
40+
}

0 commit comments

Comments
 (0)