Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc624fe9

Browse files
Add types for common directory (anuraghazra#2153)
* Add types for common directory* Reflect the code reviews* style: improve syntax* style: improve typescript syntaxCo-authored-by: rickstaa <rick.staa@outlook.com>
1 parentbcda6ce commitc624fe9

File tree

13 files changed

+309
-88
lines changed

13 files changed

+309
-88
lines changed

‎src/cards/wakatime-card.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,7 @@ import {
1111
import{getStyles}from"../getStyles";
1212
import{wakatimeCardLocales}from"../translations";
1313

14-
/** Import language colors.
15-
*
16-
*@description Here we use the workaround found in
17-
* https://stackoverflow.com/questions/66726365/how-should-i-import-json-in-node
18-
* since vercel is using v16.14.0 which does not yet support json imports without the
19-
* --experimental-json-modules flag.
20-
*/
21-
import{createRequire}from"module";
22-
constrequire=createRequire(import.meta.url);
23-
constlanguageColors=require("../common/languageColorson");// now works
14+
importlanguageColorsfrom"../common/languageColors.json";
2415

2516
/**
2617
*@param {{color: string, text: string}} param0

‎src/common/Card.ts

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,78 @@
11
import{getAnimations}from"../getStyles";
22
import{encodeHTML,flexLayout}from"./utils";
33

4-
classCard{
4+
/** Card colors. */
5+
exportinterfaceCardColors{
6+
/** Title color. */
7+
titleColor:string;
8+
/** Text color. */
9+
textColor:string;
10+
/** Icon color. */
11+
iconColor:string;
12+
/** Background color. */
13+
bgColor:string;
14+
/** Border color. */
15+
borderColor:string;
16+
}
17+
18+
/** Accessibility label. */
19+
interfaceAccessibilityLabel{
20+
/** The label to display. */
21+
title:string;
22+
/** The value to display. */
23+
desc:string;
24+
}
25+
26+
/** Card properties. */
27+
interfaceCardProps{
28+
/** Card width. */
29+
width:number;
30+
/** Card height. */
31+
height:number;
32+
/** Card border radius. */
33+
border_radius:number;
34+
/** Card colors. */
35+
colors:CardColors|{};
36+
/** Card title. */
37+
customTitle?:string;
38+
/** Card default title. */
39+
defaultTitle?:string;
40+
/** Card title prefix icon. */
41+
titlePrefixIcon?:string;
42+
}
43+
44+
/**
45+
* Card class.
46+
*/
47+
exportclassCard{
48+
/** Card width. */
49+
width:number;
50+
/** Card height. */
51+
height:number;
52+
/** Whether the card border is hidden. */
53+
hideBorder:boolean;
54+
/** Whether the card title is hidden. */
55+
hideTitle:boolean;
56+
/** Border radius. */
57+
border_radius:number;
58+
/** Card colors. */
59+
colors:CardColors|{};
60+
/** Card title. */
61+
title:string;
62+
/** Card css. */
63+
css:string;
64+
/** Card x padding. */
65+
paddingX:number;
66+
/** Card y padding. */
67+
paddingY:number;
68+
/** Card title prefix icon. */
69+
titlePrefixIcon?:string;
70+
/** Whether the card is animated. */
71+
animations:boolean;
72+
/** Accessibility label title. */
73+
a11yTitle:string;
74+
/** Accessibility label description. */
75+
a11yDesc:string;
576
/**
677
*@param {object} args
778
*@param {number?=} args.width
@@ -20,7 +91,7 @@ class Card {
2091
customTitle,
2192
defaultTitle="",
2293
titlePrefixIcon,
23-
}){
94+
}:CardProps){
2495
this.width=width;
2596
this.height=height;
2697

@@ -53,29 +124,29 @@ class Card {
53124
/**
54125
*@param {{title: string, desc: string}} prop
55126
*/
56-
setAccessibilityLabel({ title, desc}){
127+
setAccessibilityLabel({ title, desc}:AccessibilityLabel){
57128
this.a11yTitle=title;
58129
this.a11yDesc=desc;
59130
}
60131

61132
/**
62133
*@param {string} value
63134
*/
64-
setCSS(value){
135+
setCSS(value:string){
65136
this.css=value;
66137
}
67138

68139
/**
69140
*@param {boolean} value
70141
*/
71-
setHideBorder(value){
142+
setHideBorder(value:boolean){
72143
this.hideBorder=value;
73144
}
74145

75146
/**
76147
*@param {boolean} value
77148
*/
78-
setHideTitle(value){
149+
setHideTitle(value:boolean){
79150
this.hideTitle=value;
80151
if(value){
81152
this.height-=30;
@@ -85,7 +156,7 @@ class Card {
85156
/**
86157
*@param {string} text
87158
*/
88-
setTitle(text){
159+
setTitle(text:string){
89160
this.title=text;
90161
}
91162

@@ -137,7 +208,7 @@ class Card {
137208
gradientTransform="rotate(${this.colors.bgColor[0]})"
138209
gradientUnits="userSpaceOnUse"
139210
>
140-
${gradients.map((grad,index)=>{
211+
${gradients.map((grad:string,index:number)=>{
141212
letoffset=(index*100)/(gradients.length-1);
142213
return`<stop offset="${offset}%" stop-color="#${grad}" />`;
143214
})}
@@ -150,7 +221,7 @@ class Card {
150221
/**
151222
*@param {string} body
152223
*/
153-
render(body){
224+
render(body:string){
154225
return`
155226
<svg
156227
width="${this.width}"
@@ -215,6 +286,3 @@ class Card {
215286
`;
216287
}
217288
}
218-
219-
export{Card};
220-
exportdefaultCard;

‎src/common/I18n.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1-
classI18n{
2-
constructor({ locale, translations}){
1+
typeTranslations=Record<string,Record<string,string>>;
2+
3+
/**
4+
* I18n translation class.
5+
*/
6+
exportclassI18n{
7+
/** The language locale. */
8+
locale?:string;
9+
/** The translations object. */
10+
translations:Translations;
11+
/** The fallback language locale. */
12+
fallbackLocale:string;
13+
14+
constructor({
15+
locale,
16+
translations,
17+
}:{
18+
locale?:string;
19+
translations:Translations;
20+
}){
321
this.locale=locale;
422
this.translations=translations;
523
this.fallbackLocale="en";
624
}
725

8-
t(str){
26+
t(str:string){
927
if(!this.translations[str]){
1028
thrownewError(`${str} Translation string not found`);
1129
}
@@ -17,6 +35,3 @@ class I18n {
1735
returnthis.translations[str][this.locale||this.fallbackLocale];
1836
}
1937
}
20-
21-
export{I18n};
22-
exportdefaultI18n;

‎src/common/blacklist.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
constblacklist=["renovate-bot","technote-space","sw-yx"];
2-
3-
export{blacklist};
4-
exportdefaultblacklist;
1+
/** User blacklist. */
2+
exportconstblacklist=["renovate-bot","technote-space","sw-yx"];

‎src/common/createProgressNode.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import{clampValue}from"./utils";
22

3-
interfaceIcreateProgressNode{
3+
4+
/** CreateProgressNode properties. */
5+
interfaceCreateProgressNodeProps{
6+
/** Progress bar item x position. */
47
x:number;
8+
/** Progress bar item y position.. */
59
y:number;
10+
/** Progress bar item width. */
611
width:number;
12+
/** Progress bar item color. */
713
color:string;
14+
/** Progress value. */
815
progress:number;
16+
/** Progress bar item background color. */
917
progressBarBackgroundColor:string;
1018
}
1119

@@ -16,7 +24,7 @@ const createProgressNode = ({
1624
color,
1725
progress,
1826
progressBarBackgroundColor,
19-
}:IcreateProgressNode)=>{
27+
}:CreateProgressNodeProps)=>{
2028
constprogressPercentage=clampValue(progress,2,100);
2129

2230
return`

‎src/common/icons.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
consticons={
1+
2+
exporttypeIcons={[key:string]:string};
3+
4+
consticons:Icons={
25
star:`<path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"/>`,
36
commits:`<path fill-rule="evenodd" d="M1.643 3.143L.427 1.927A.25.25 0 000 2.104V5.75c0 .138.112.25.25.25h3.646a.25.25 0 00.177-.427L2.715 4.215a6.5 6.5 0 11-1.18 4.458.75.75 0 10-1.493.154 8.001 8.001 0 101.6-5.684zM7.75 4a.75.75 0 01.75.75v2.992l2.028.812a.75.75 0 01-.557 1.392l-2.5-1A.75.75 0 017 8.25v-3.5A.75.75 0 017.75 4z"/>`,
47
prs:`<path fill-rule="evenodd" d="M7.177 3.073L9.573.677A.25.25 0 0110 .854v4.792a.25.25 0 01-.427.177L7.177 3.427a.25.25 0 010-.354zM3.75 2.5a.75.75 0 100 1.5.75.75 0 000-1.5zm-2.25.75a2.25 2.25 0 113 2.122v5.256a2.251 2.251 0 11-1.5 0V5.372A2.25 2.25 0 011.5 3.25zM11 2.5h-1V4h1a1 1 0 011 1v5.628a2.251 2.251 0 101.5 0V5A2.5 2.5 0 0011 2.5zm1 10.25a.75.75 0 111.5 0 .75.75 0 01-1.5 0zM3.75 12a.75.75 0 100 1.5.75.75 0 000-1.5z"/>`,

‎src/common/retryer.ts

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1+
importaxios,{
2+
AxiosError,
3+
AxiosPromise,
4+
AxiosRequestHeaders,
5+
AxiosResponse,
6+
}from"axios";
17
import{CustomError,logger}from"./utils";
28

9+
10+
/** Data fetcher. */
11+
typeFetcher=(
12+
/** Fetcher variables. */
13+
variables:AxiosRequestHeaders,
14+
/** Authentication token. */
15+
token:string,
16+
/** The number of retries. */
17+
retries?:number,
18+
)=>AxiosPromise<any>
19+
320
/**
421
* Try to execute the fetcher function until it succeeds or the max number of retries is reached.
522
*
@@ -9,15 +26,19 @@ import { CustomError, logger } from "./utils";
926
*@param {number} retryerParams.retries How many times to retry.
1027
*@returns Promise<retryer>
1128
*/
12-
constretryer=async(fetcher,variables,retries=0)=>{
29+
exportconstretryer=async(
30+
fetcher:Fetcher,
31+
variables:AxiosRequestHeaders,
32+
retries=0,
33+
):Promise<any>=>{
1334
if(retries>7){
1435
thrownewCustomError("Maximum retries exceeded",CustomError.MAX_RETRY);
1536
}
1637
try{
1738
// try to fetch with the first token since RETRIES is 0 index i'm adding +1
1839
letresponse=awaitfetcher(
1940
variables,
20-
process.env[`PAT_${retries+1}`],
41+
process.env[`PAT_${retries+1}`]asstring,
2142
retries,
2243
);
2344

@@ -36,18 +57,17 @@ const retryer = async (fetcher, variables, retries = 0) => {
3657
// finally return the response
3758
returnresponse;
3859
}catch(err){
39-
// prettier-ignore
40-
// also checking for bad credentials if any tokens gets invalidated
41-
constisBadCredential=err.response.data&&err.response.data.message==="Bad credentials";
60+
if(axios.isAxiosError(err)){
61+
// prettier-ignore
62+
// also checking for bad credentials if any tokens gets invalidated
63+
constisBadCredential=err?.response?.data&&err.response.data.message==="Bad credentials";
4264

43-
if(isBadCredential){
44-
logger.log(`PAT_${retries+1} Failed`);
45-
retries++;
46-
// directly return from the function
47-
returnretryer(fetcher,variables,retries);
65+
if(isBadCredential){
66+
logger.log(`PAT_${retries+1} Failed`);
67+
retries++;
68+
// directly return from the function
69+
returnretryer(fetcher,variables,retries);
70+
}
4871
}
4972
}
5073
};
51-
52-
export{retryer};
53-
exportdefaultretryer;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp