-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcommon.rs
More file actions
313 lines (284 loc) · 8.7 KB
/
Copy pathcommon.rs
File metadata and controls
313 lines (284 loc) · 8.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
use hashbrown::HashMap;
use serde::{Deserialize, Serialize};
use tsify::Tsify;
use crate::{
commit::{Commit, StringCommit},
date::Date,
version::Version,
};
pub const LOC_EXCLUDED: &[&str] = &[
"JSON",
"SVG",
"XML",
"YAML",
"AsciiDoc",
"Astro",
"Autoconf",
"Automake",
"BASH",
"Bazel",
"Batch",
"CMake",
"CSS",
"Dockerfile",
"Edn",
"Fish",
"Forge Config",
"Gherkin (Cucumber)",
"GraphQL",
"Handlebars",
"HCL",
"HTML",
"INI",
"Jupyter Notebooks",
"Just",
"Jsonnet",
"LESS",
"Makefile",
"Markdown",
"MSBuild",
"Nix",
"Org",
"Plain Text",
"PlantUML",
"PowerShell",
"PostCSS",
"Protocol Buffers",
"Pug",
"ReStructuredText",
"Rakefile",
"Sass",
"Shell",
"SRecode Template",
"Stylus",
"TOML",
"TeX",
"Typst",
];
pub const FILE_EXT_INCLUDED: &[&str] = &[
"ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs", "css", "svelte", "vue", "scss", "sass",
"py", "rs", "java", "kt", "rb", "c", "cpp", "h", "hpp",
];
// list of i18n adjacent libraries, thanks chatgpt
pub const I18N_DEPENDENCIES: &[&str] = &[
"i18next",
"i18n",
"node-polyglot",
"formatjs",
"intl-messageformat",
"intl-relativeformat",
"messageformat",
"react-intl",
"react-i18next",
"next-i18next",
"next-intl",
"@lingui/core",
"@lingui/react",
"vue-i18n",
"vue-i18next",
"@ngx-translate/core",
"@angular/localize",
"react-native-localize",
"expo-localization",
"svelte-i18n",
"intl",
"globalize",
];
pub const I18N_LOCALE_CODES: &[&str] = &[
"Cy-az-AZ", "Cy-sr-SP", "Cy-uz-UZ", "Lt-az-AZ", "Lt-sr-SP", "Lt-uz-UZ", "aa", "ab", "ae", "af",
"af-ZA", "ak", "am", "an", "ar", "ar-AE", "ar-BH", "ar-DZ", "ar-EG", "ar-IQ", "ar-JO", "ar-KW",
"ar-LB", "ar-LY", "ar-MA", "ar-OM", "ar-QA", "ar-SA", "ar-SY", "ar-TN", "ar-YE", "as", "av",
"ay", "az", "ba", "be", "be-BY", "bg", "bg-BG", "bh", "bi", "bm", "bn", "bo", "br", "bs", "ca",
"ca-ES", "ce", "ch", "co", "cr", "cs", "cs-CZ", "cu", "cv", "cy", "da", "da-DK", "de", "de-AT",
"de-CH", "de-DE", "de-LI", "de-LU", "div-MV", "dv", "dz", "ee", "el", "el-GR", "en", "en-AU",
"en-BZ", "en-CA", "en-CB", "en-GB", "en-IE", "en-JM", "en-NZ", "en-PH", "en-TT", "en-US",
"en-ZA", "en-ZW", "eo", "es", "es-AR", "es-BO", "es-CL", "es-CO", "es-CR", "es-DO", "es-EC",
"es-ES", "es-GT", "es-HN", "es-MX", "es-NI", "es-PA", "es-PE", "es-PR", "es-PY", "es-SV",
"es-UY", "es-VE", "et", "et-EE", "eu", "eu-ES", "fa", "fa-IR", "ff", "fi", "fi-FI", "fj", "fo",
"fo-FO", "fr", "fr-BE", "fr-CA", "fr-CH", "fr-FR", "fr-LU", "fr-MC", "fy", "ga", "gd", "gl",
"gl-ES", "gn", "gu", "gu-IN", "gv", "ha", "he", "he-IL", "hi", "hi-IN", "ho", "hr", "hr-HR",
"ht", "hu", "hu-HU", "hy", "hy-AM", "hz", "ia", "id", "id-ID", "ie", "ig", "ii", "ik", "io",
"is", "is-IS", "it", "it-CH", "it-IT", "iu", "ja", "ja-JP", "jv", "ka", "ka-GE", "kg", "ki",
"kj", "kk", "kk-KZ", "kl", "km", "kn", "kn-IN", "ko", "ko-KR", "kr", "ks", "ku", "kv", "kw",
"ky", "ky-KZ", "la", "lb", "lg", "li", "ln", "lo", "lt", "lt-LT", "lu", "lv", "lv-LV", "mg",
"mh", "mi", "mk", "mk-MK", "ml", "mn", "mn-MN", "mr", "mr-IN", "ms", "ms-BN", "ms-MY", "mt",
"my", "na", "nb", "nb-NO", "nd", "ne", "ng", "nl", "nl-BE", "nl-NL", "nn", "nn-NO", "no", "nr",
"nv", "ny", "oc", "oj", "om", "or", "os", "pa", "pa-IN", "pi", "pl", "pl-PL", "ps", "pt",
"pt-BR", "pt-PT", "qu", "rm", "rn", "ro", "ro-RO", "ru", "ru-RU", "rw", "sa", "sa-IN", "sc",
"sd", "se", "sg", "si", "sk", "sk-SK", "sl", "sl-SI", "sm", "sn", "so", "sq", "sq-AL", "sr",
"ss", "st", "su", "sv", "sv-FI", "sv-SE", "sw", "sw-KE", "ta", "ta-IN", "te", "te-IN", "tg",
"th", "th-TH", "ti", "tk", "tl", "tn", "to", "tr", "tr-TR", "ts", "tt", "tt-RU", "tw", "ty",
"ug", "uk", "uk-UA", "ur", "ur-PK", "uz", "ve", "vi", "vi-VN", "vo", "wa", "wo", "xh", "yi",
"yo", "za", "zh", "zh-CHS", "zh-CHT", "zh-CN", "zh-HK", "zh-MO", "zh-SG", "zh-TW", "zu",
];
pub const I18N_FILE_ENDINGS: &[&str] = &[".json", ".yaml", ".yml", ".js", ".ts"];
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct EntryChange {
pub property: String,
pub commit: Commit,
pub old_value: String,
pub new_value: String,
}
impl EntryChange {
pub fn to_data_point(&self) -> EntryChangeDataPoint {
EntryChangeDataPoint {
property: self.property.clone(),
commit: self.commit.to_string_commit(),
old_value: self.old_value.clone(),
new_value: self.new_value.clone(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct DownloadHistory(pub HashMap<String, u32>);
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VersionHistory {
pub version: String,
#[serde(skip)]
pub version_object: Option<Version>,
pub initial_release_date: Date,
#[serde(default, skip_serializing_if = "is_false")]
pub prerelease: bool,
#[serde(default = "default_true", skip_serializing_if = "is_true")]
pub released_while_listed: bool,
}
fn is_false(value: &bool) -> bool {
!*value
}
fn is_true(value: &bool) -> bool {
*value
}
fn default_true() -> bool {
true
}
#[derive(Tsify, Debug, Clone, Serialize)]
#[tsify(into_wasm_abi)]
pub struct OverviewDataPoint {
pub id: String,
pub name: String,
pub author: String,
pub repo: String,
pub repo_url: String,
pub added_commit: StringCommit,
pub removed_commit: Option<StringCommit>,
}
#[derive(Tsify, Debug, Clone, Serialize, Deserialize)]
#[tsify(into_wasm_abi)]
pub struct DownloadDataPoint {
pub date: String,
pub downloads: Option<u32>,
pub delta: Option<u32>,
}
#[derive(Tsify, Debug, Clone, Serialize, Deserialize)]
#[tsify(into_wasm_abi)]
pub struct MultiDownloadDataPoint {
pub date: String,
pub category: String,
pub downloads: Option<u32>,
pub delta: Option<u32>,
}
#[derive(Tsify, Debug, Clone, Serialize, Deserialize)]
#[tsify(into_wasm_abi)]
pub struct VersionDataPoint {
pub version: String,
pub date: String,
pub deprecated: bool,
pub prerelease: bool,
pub released_while_listed: bool,
}
#[derive(Tsify, Debug, Clone, Serialize)]
#[tsify(into_wasm_abi)]
pub struct EntryChangeDataPoint {
pub property: String,
pub commit: StringCommit,
pub old_value: String,
pub new_value: String,
}
#[derive(Tsify, Debug, Clone, Serialize)]
#[tsify(into_wasm_abi)]
pub struct IndividualDownloadDataPoint {
pub id: String,
pub name: String,
pub date: String,
pub downloads: u32,
pub version_count: u32,
pub total_loc: u32,
}
#[derive(Tsify, Debug, Clone, Serialize)]
#[tsify(into_wasm_abi)]
pub struct HallOfFameDataPoint {
pub id: String,
pub name: String,
pub downloads_new: u32,
pub downloads_start: u32,
pub data: Vec<DownloadDataPoint>,
}
#[derive(Tsify, Debug, Clone, Serialize)]
#[tsify(into_wasm_abi)]
pub struct CountMonthlyDataPoint {
pub date: String,
pub total: u32,
pub total_with_removed: u32,
pub new: u32,
pub new_removed: u32,
}
#[derive(Tsify, Debug, Clone, Serialize)]
#[tsify(into_wasm_abi)]
pub struct RemovedByReleaseDataPoint {
pub date: String,
pub percentage: f64,
}
#[derive(Tsify, Debug, Clone, Serialize)]
#[tsify(into_wasm_abi)]
pub struct InactivityByReleaseDataPoint {
pub date: String,
pub inactive_one_year: f64,
pub inactive_two_years: f64,
pub inactive_three_years: f64,
pub inactive_four_years: f64,
pub inactive_five_years: f64,
}
#[derive(Tsify, Debug, Clone, Serialize)]
#[tsify(into_wasm_abi)]
pub struct NamedDataPoint {
pub name: String,
pub value: f64,
}
pub fn increment_named_data_points(points: &mut Vec<NamedDataPoint>, name: &str, value: f64) {
if let Some(point) = points.iter_mut().find(|p| p.name == name) {
point.value += value;
} else {
points.push(NamedDataPoint {
name: name.to_string(),
value,
});
}
}
pub fn to_percentage(value: &mut f64, total: f64) {
if total == 0.0 {
*value = 0.0;
} else {
*value = (*value / total) * 100.0;
}
}
#[derive(Tsify, Debug, Clone, Serialize)]
#[tsify(into_wasm_abi)]
pub struct StackedNamedDataPoint {
pub name: String,
pub layer: String,
pub value: f64,
}
#[derive(Tsify, Debug, Clone, Serialize)]
#[tsify(into_wasm_abi)]
pub struct MilestoneMonthGroup {
pub month: String,
pub milestones: Vec<MilestoneDataPoint>,
}
#[derive(Tsify, Debug, Clone, Serialize)]
#[tsify(into_wasm_abi)]
pub struct MilestoneDataPoint {
pub milestone_type: String,
pub milestone_value: u32,
pub date: String,
pub plugin_id: Option<String>,
}