@@ -42,64 +42,64 @@ const renderError = (message, secondaryMessage = "") => {
42
42
* @param {string } str String to encode.
43
43
* @returns {string } Encoded string.
44
44
*/
45
- function encodeHTML ( str ) {
45
+ const encodeHTML = ( str ) => {
46
46
return str
47
47
. replace ( / [ \u00A0 - \u9999 < > & ] (? ! # ) / gim, ( i ) => {
48
48
return "&#" + i . charCodeAt ( 0 ) + ";" ;
49
49
} )
50
50
. replace ( / \u0008 / gim, "" ) ;
51
- }
51
+ } ;
52
52
53
53
/**
54
54
* Retrieves num with suffix k(thousands) precise to 1 decimal if greater than 999.
55
55
*
56
56
* @param {number } num The number to format.
57
57
* @returns {string|number } The formatted number.
58
58
*/
59
- function kFormatter ( num ) {
59
+ const kFormatter = ( num ) => {
60
60
return Math . abs ( num ) > 999
61
61
? Math . sign ( num ) * parseFloat ( ( Math . abs ( num ) / 1000 ) . toFixed ( 1 ) ) + "k"
62
62
: Math . sign ( num ) * Math . abs ( num ) ;
63
- }
63
+ } ;
64
64
65
65
/**
66
66
* Checks if a string is a valid hex color.
67
67
*
68
68
* @param {string } hexColor String to check.
69
69
* @returns {boolean } True if the given string is a valid hex color.
70
70
*/
71
- function isValidHexColor ( hexColor ) {
71
+ const isValidHexColor = ( hexColor ) => {
72
72
return new RegExp (
73
73
/ ^ ( [ A - F a - f 0 - 9 ] { 8 } | [ A - F a - f 0 - 9 ] { 6 } | [ A - F a - f 0 - 9 ] { 3 } | [ A - F a - f 0 - 9 ] { 4 } ) $ / ,
74
74
) . test ( hexColor ) ;
75
- }
75
+ } ;
76
76
77
77
/**
78
78
* Returns boolean if value is either "true" or "false" else the value as it is.
79
79
*
80
80
* @param {string } value The value to parse.
81
81
* @returns {boolean | string } The parsed value.
82
82
*/
83
- function parseBoolean ( value ) {
83
+ const parseBoolean = ( value ) => {
84
84
if ( value === "true" ) {
85
85
return true ;
86
86
} else if ( value === "false" ) {
87
87
return false ;
88
88
} else {
89
89
return value ;
90
90
}
91
- }
91
+ } ;
92
92
93
93
/**
94
94
* Parse string to array of strings.
95
95
*
96
96
* @param {string } str The string to parse.
97
97
* @returns {string[] } The array of strings.
98
98
*/
99
- function parseArray ( str ) {
99
+ const parseArray = ( str ) => {
100
100
if ( ! str ) return [ ] ;
101
101
return str . split ( "," ) ;
102
- }
102
+ } ;
103
103
104
104
/**
105
105
* Clamp the given number between the given range.
@@ -109,21 +109,21 @@ function parseArray(str) {
109
109
* @param {number } max The maximum value.
110
110
* returns {number} The clamped number.
111
111
*/
112
- function clampValue ( number , min , max ) {
112
+ const clampValue = ( number , min , max ) => {
113
113
// @ts -ignore
114
114
if ( Number . isNaN ( parseInt ( number ) ) ) return min ;
115
115
return Math . max ( min , Math . min ( number , max ) ) ;
116
- }
116
+ } ;
117
117
118
118
/**
119
119
* Check if the given string is a valid gradient.
120
120
*
121
121
* @param {string[] } colors Array of colors.
122
122
* @returns {boolean } True if the given string is a valid gradient.
123
123
*/
124
- function isValidGradient ( colors ) {
124
+ const isValidGradient = ( colors ) => {
125
125
return isValidHexColor ( colors [ 1 ] ) && isValidHexColor ( colors [ 2 ] ) ;
126
- }
126
+ } ;
127
127
128
128
/**
129
129
* Retrieves a gradient if color has more than one valid hex codes else a single color.
@@ -132,7 +132,7 @@ function isValidGradient(colors) {
132
132
* @param {string } fallbackColor The fallback color.
133
133
* @returns {string | string[] } The gradient or color.
134
134
*/
135
- function fallbackColor ( color , fallbackColor ) {
135
+ const fallbackColor = ( color , fallbackColor ) => {
136
136
let gradient = null ;
137
137
138
138
let colors = color ? color . split ( "," ) : [ ] ;
@@ -144,7 +144,7 @@ function fallbackColor(color, fallbackColor) {
144
144
( gradient ? gradient : isValidHexColor ( color ) && `#${ color } ` ) ||
145
145
fallbackColor
146
146
) ;
147
- }
147
+ } ;
148
148
149
149
/**
150
150
* Send GraphQL request to GitHub API.
@@ -153,15 +153,15 @@ function fallbackColor(color, fallbackColor) {
153
153
* @param {import('axios').AxiosRequestConfig['headers'] } headers Request headers.
154
154
* @returns {Promise<any> } Request response.
155
155
*/
156
- function request ( data , headers ) {
156
+ const request = ( data , headers ) => {
157
157
// @ts -ignore
158
158
return axios ( {
159
159
url : "https://api.github.com/graphql" ,
160
160
method : "post" ,
161
161
headers,
162
162
data,
163
163
} ) ;
164
- }
164
+ } ;
165
165
166
166
/**
167
167
* Auto layout utility, allows us to layout things vertically or horizontally with
@@ -174,7 +174,7 @@ function request(data, headers) {
174
174
* @param {"column" | "row"?= } props.direction Direction to layout items.
175
175
* @returns {string[] } Array of items with proper layout.
176
176
*/
177
- function flexLayout ( { items, gap, direction, sizes = [ ] } ) {
177
+ const flexLayout = ( { items, gap, direction, sizes = [ ] } ) => {
178
178
let lastSize = 0 ;
179
179
// filter() for filtering out empty strings
180
180
return items . filter ( Boolean ) . map ( ( item , i ) => {
@@ -186,7 +186,7 @@ function flexLayout({ items, gap, direction, sizes = [] }) {
186
186
lastSize += size + gap ;
187
187
return `<g transform="${ transform } ">${ item } </g>` ;
188
188
} ) ;
189
- }
189
+ } ;
190
190
191
191
/**
192
192
* Returns theme based colors with proper overrides and defaults.
@@ -201,7 +201,7 @@ function flexLayout({ items, gap, direction, sizes = [] }) {
201
201
* @param {string } args.fallbackTheme Fallback theme.
202
202
*
203
203
*/
204
- function getCardColors ( {
204
+ const getCardColors = ( {
205
205
title_color,
206
206
text_color,
207
207
icon_color,
@@ -210,7 +210,7 @@ function getCardColors({
210
210
ring_color,
211
211
theme,
212
212
fallbackTheme = "default" ,
213
- } ) {
213
+ } ) => {
214
214
const defaultTheme = themes [ fallbackTheme ] ;
215
215
const selectedTheme = themes [ theme ] || defaultTheme ;
216
216
const defaultBorderColor =
@@ -248,7 +248,7 @@ function getCardColors({
248
248
) ;
249
249
250
250
return { titleColor, iconColor, textColor, bgColor, borderColor, ringColor } ;
251
- }
251
+ } ;
252
252
253
253
/**
254
254
* Split text over multiple lines based on the card width.
@@ -258,7 +258,7 @@ function getCardColors({
258
258
* @param {number } maxLines Maximum number of lines.
259
259
* @returns {string[] } Array of lines.
260
260
*/
261
- function wrapTextMultiline ( text , width = 59 , maxLines = 3 ) {
261
+ const wrapTextMultiline = ( text , width = 59 , maxLines = 3 ) => {
262
262
const fullWidthComma = "," ;
263
263
const encoded = encodeHTML ( text ) ;
264
264
const isChinese = encoded . includes ( fullWidthComma ) ;
@@ -283,7 +283,7 @@ function wrapTextMultiline(text, width = 59, maxLines = 3) {
283
283
// Remove empty lines if text fits in less than maxLines lines
284
284
const multiLineText = lines . filter ( Boolean ) ;
285
285
return multiLineText ;
286
- }
286
+ } ;
287
287
288
288
const noop = ( ) => { } ;
289
289
// return console instance based on the environment
@@ -349,7 +349,7 @@ class MissingParamError extends Error {
349
349
* @param {number } fontSize Font size.
350
350
* @returns {number } Text length.
351
351
*/
352
- function measureText ( str , fontSize = 10 ) {
352
+ const measureText = ( str , fontSize = 10 ) => {
353
353
// prettier-ignore
354
354
const widths = [
355
355
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -381,7 +381,7 @@ function measureText(str, fontSize = 10) {
381
381
)
382
382
. reduce ( ( cur , acc ) => acc + cur ) * fontSize
383
383
) ;
384
- }
384
+ } ;
385
385
386
386
/** @param {string } name */
387
387
const lowercaseTrim = ( name ) => name . toLowerCase ( ) . trim ( ) ;
@@ -394,7 +394,7 @@ const lowercaseTrim = (name) => name.toLowerCase().trim();
394
394
* @param {number } perChunk Number of languages per column.
395
395
* @returns {Array<T> } Array of languages split in two columns.
396
396
*/
397
- function chunkArray ( arr , perChunk ) {
397
+ const chunkArray = ( arr , perChunk ) => {
398
398
return arr . reduce ( ( resultArray , item , index ) => {
399
399
const chunkIndex = Math . floor ( index / perChunk ) ;
400
400
@@ -406,20 +406,20 @@ function chunkArray(arr, perChunk) {
406
406
407
407
return resultArray ;
408
408
} , [ ] ) ;
409
- }
409
+ } ;
410
410
411
411
/**
412
412
* Parse emoji from string.
413
413
*
414
414
* @param {string } str String to parse emoji from.
415
415
* @returns {string } String with emoji parsed.
416
416
*/
417
- function parseEmojis ( str ) {
417
+ const parseEmojis = ( str ) => {
418
418
if ( ! str ) throw new Error ( "[parseEmoji]: str argument not provided" ) ;
419
419
return str . replace ( / : \w + : / gm, ( emoji ) => {
420
420
return toEmoji . get ( emoji ) || "" ;
421
421
} ) ;
422
- }
422
+ } ;
423
423
424
424
export {
425
425
ERROR_CARD_LENGTH ,
0 commit comments