Skip to content

Commit 065a370

Browse files
author
ZHY
committed
Clean code
1 parent aeaaecf commit 065a370

File tree

12 files changed

+29
-35
lines changed

12 files changed

+29
-35
lines changed

src/app/components/limit/add-dialog/form/url.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ const protocolSelect = (protocolRef: Ref<string>) => h(ElSelect, {
3737

3838
const url2PathItems = (url: string) => {
3939
const querySign = url.indexOf('?')
40-
querySign > -1 && (url = url.substr(0, querySign))
40+
querySign > -1 && (url = url.substring(0, querySign))
4141
const hashSign = url.indexOf('#')
42-
hashSign > -1 && (url = url.substr(0, hashSign))
42+
hashSign > -1 && (url = url.substring(0, hashSign))
4343
return url.split('/').filter(path => path).map(path => UrlPathItem.of(path))
4444
}
4545

@@ -58,10 +58,10 @@ const handlePaste = async (protocolRef: Ref<string>, pathItemsRef: Ref<UrlPathIt
5858
url = decodeURI(url)
5959
if (url.startsWith(Protocol.HTTP)) {
6060
protocol = Protocol.HTTP
61-
url = url.substr(Protocol.HTTP.length)
61+
url = url.substring(Protocol.HTTP.length)
6262
} else if (url.startsWith(Protocol.HTTPS)) {
6363
protocol = Protocol.HTTPS
64-
url = url.substr(Protocol.HTTPS.length)
64+
url = url.substring(Protocol.HTTPS.length)
6565
}
6666
protocolRef.value = protocol
6767
pathItemsRef.value = url2PathItems(url)

src/app/components/trend/host-option-info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class HostOptionInfo {
3232
static from(key: string) {
3333
if (!key || !key.length) return this.empty()
3434
const merged = key.charAt(0) === '1'
35-
return new HostOptionInfo(key.substr(1), merged)
35+
return new HostOptionInfo(key.substring(1), merged)
3636
}
3737

3838
key(): string {

src/database/archived-database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ArchivedDatabase extends BaseDatabase {
2222
const result = {}
2323
Object.entries(items)
2424
.filter(([key]) => key.startsWith(ARCHIVED_PREFIX))
25-
.map(([key, val]) => [key.substr(ARCHIVED_PREFIX.length), val])
25+
.map(([key, val]) => [key.substring(ARCHIVED_PREFIX.length), val])
2626
.forEach(([key, val]) => result[key] = val)
2727
log('All archived', result)
2828
return Promise.resolve(result)

src/database/host-alias-database.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ const ABBR_MAP = {
2424
const generateKey = (host: string) => DB_KEY_PREFIX + host
2525
const hostOf = (key: string) => key.substring(DB_KEY_PREFIX_LENGTH)
2626
function valueOf(host: string, value: string): HostAlias {
27-
const abbr = value.substr(0, 1)
27+
const abbr = value.substring(0, 1)
2828

2929
return {
3030
host,
3131
source: ABBR_MAP[abbr],
32-
name: value.substr(1)
32+
name: value.substring(1)
3333
}
3434
}
3535

src/database/period-database.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ function merge(exists: { [dateKey: string]: FocusPerDay }, toMerge: PeriodInfo[]
2828
function db2PeriodInfos(data: { [dateKey: string]: FocusPerDay }): PeriodInfo[] {
2929
const result: PeriodInfo[] = []
3030
Object.entries(data).forEach((([dateKey, val]) => {
31-
const dateStr = dateKey.substr(KEY_PREFIX_LENGTH)
31+
const dateStr = dateKey.substring(KEY_PREFIX_LENGTH)
3232
const date = new Date(
33-
Number.parseInt(dateStr.substr(0, 4)),
34-
Number.parseInt(dateStr.substr(4, 2)) - 1,
35-
Number.parseInt(dateStr.substr(6, 2))
33+
Number.parseInt(dateStr.substring(0, 4)),
34+
Number.parseInt(dateStr.substring(4, 6)) - 1,
35+
Number.parseInt(dateStr.substring(6, 8))
3636
)
3737
Object
3838
.entries(val)

src/database/timer-database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class TimerDatabase extends BaseDatabase {
199199
let result: DataItem[] = []
200200

201201
for (let key in items) {
202-
const date = key.substr(0, 8)
202+
const date = key.substring(0, 8)
203203
const host = key.substring(8)
204204
const val: WastePerDay = items[key]
205205
if (this.filterBefore(date, host, val, _cond)) {

src/popup/components/chart/option.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function calcPositionOfTooltip(container: HTMLDivElement, point: (number | strin
9898
tooltipWidth = tooltip.offsetWidth
9999
if (!tooltipWidth) {
100100
const styleWidth = tooltip.style.width
101-
tooltipWidth = Number.parseFloat(styleWidth.endsWith('px') ? styleWidth.substr(0, styleWidth.length) : styleWidth)
101+
tooltipWidth = Number.parseFloat(styleWidth.endsWith('px') ? styleWidth.substring(0, styleWidth.length) : styleWidth)
102102
}
103103
tooltipWidth = tooltipWidth || 0
104104
}
@@ -121,9 +121,9 @@ function calculateSubTitleText(date: Date | Date[]) {
121121
if (startStr === endStr) {
122122
return startStr
123123
} else {
124-
if (startStr.substr(0, 4) === endStr.substr(0, 4)) {
124+
if (startStr.substring(0, 4) === endStr.substring(0, 4)) {
125125
// the same year
126-
endStr = endStr.substr(5)
126+
endStr = endStr.substring(5)
127127
}
128128
return `${startStr}-${endStr}`
129129
}

src/service/components/host-merge-ruler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface IHostMergeRuler {
1616
}
1717

1818
/**
19-
* @param host host
20-
* @param dotCount the count of dots to remain
19+
* @param origin origin host
20+
* @param dotCount the count of dots to remain
2121
*/
2222
const getTheSuffix = (origin: string, dotCount: number) => {
2323
if (isIpAndPort(origin)) return origin
@@ -33,7 +33,7 @@ const getTheSuffix = (origin: string, dotCount: number) => {
3333
}
3434

3535
const index = origin.lastIndexOf('.')
36-
result.push(origin.substr(index + 1))
36+
result.push(origin.substring(index + 1))
3737
origin = origin.substring(0, index)
3838
}
3939
return result.reverse().join('.')
@@ -68,7 +68,7 @@ export default class CustomizedHostMergeRuler implements IHostMergeRuler {
6868
}
6969

7070
/**
71-
* @param host origin host
71+
* @param origin origin host
7272
* @returns merged host
7373
*/
7474
merge(origin: string): string {

src/service/components/period-calculator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function calculate(timestamp: number, milliseconds: number): PeriodInfo[]
4040
/**
4141
* Found the max divisible period
4242
*
43-
* @param date date
43+
* @param period key
4444
* @param periodWindowSize divisor
4545
*/
4646
export function getMaxDivisiblePeriod(period: PeriodKey, periodWindowSize: number): PeriodKey {

src/util/i18n/i18n-vue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export type NodeTranslateProps<MessageType> = {
3434
/**
3535
* Translate with slots for vue
3636
*
37-
* @param key key path
38-
* @param param param, slot vnodes
37+
* @param messages messages
38+
* @param props param, slot vnodes
3939
* @returns The array of vnodes or strings
4040
*/
4141
export function tN<MessageType>(messages: MessageType, props: NodeTranslateProps<MessageType>): I18nResultItem[] {

0 commit comments

Comments
 (0)