Compare commits
No commits in common. "a13262a2730bab14e8b7f293e5512645e3d7a7fb" and "53a8ec680a3965a71b50ccbc7786fdf426c5fcdc" have entirely different histories.
a13262a273
...
53a8ec680a
4 changed files with 2735 additions and 2880 deletions
File diff suppressed because it is too large
Load diff
|
@ -133,13 +133,12 @@ impl From<ParsedDate> for OffsetDateTime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prepare the datestring for parsing: lowercase and filter out unnecessary punctuation
|
fn filter_str(string: &str) -> String {
|
||||||
fn filter_datestr(string: &str) -> String {
|
|
||||||
string
|
string
|
||||||
.to_lowercase()
|
.to_lowercase()
|
||||||
.chars()
|
.chars()
|
||||||
.filter_map(|c| {
|
.filter_map(|c| {
|
||||||
if matches!(c, '\u{200b}' | '.') || c.is_ascii_digit() {
|
if c == '\u{200b}' || c.is_ascii_digit() {
|
||||||
None
|
None
|
||||||
} else if c == '-' {
|
} else if c == '-' {
|
||||||
Some(' ')
|
Some(' ')
|
||||||
|
@ -198,7 +197,7 @@ fn parse_textual_month(entry: &dictionary::Entry, filtered_str: &str) -> Option<
|
||||||
/// Returns [`None`] if the date could not be parsed.
|
/// Returns [`None`] if the date could not be parsed.
|
||||||
pub fn parse_timeago(lang: Language, textual_date: &str) -> Option<TimeAgo> {
|
pub fn parse_timeago(lang: Language, textual_date: &str) -> Option<TimeAgo> {
|
||||||
let entry = dictionary::entry(lang);
|
let entry = dictionary::entry(lang);
|
||||||
let filtered_str = filter_datestr(textual_date);
|
let filtered_str = filter_str(textual_date);
|
||||||
|
|
||||||
let qu: u8 = util::parse_numeric_prod(textual_date).unwrap_or(1);
|
let qu: u8 = util::parse_numeric_prod(textual_date).unwrap_or(1);
|
||||||
|
|
||||||
|
@ -245,7 +244,7 @@ pub fn parse_timeago_dt_or_warn(
|
||||||
pub fn parse_textual_date(lang: Language, textual_date: &str) -> Option<ParsedDate> {
|
pub fn parse_textual_date(lang: Language, textual_date: &str) -> Option<ParsedDate> {
|
||||||
let entry = dictionary::entry(lang);
|
let entry = dictionary::entry(lang);
|
||||||
let by_char = util::lang_by_char(lang);
|
let by_char = util::lang_by_char(lang);
|
||||||
let filtered_str = filter_datestr(textual_date);
|
let filtered_str = filter_str(textual_date);
|
||||||
|
|
||||||
let nums = util::parse_numeric_vec::<u16>(textual_date);
|
let nums = util::parse_numeric_vec::<u16>(textual_date);
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,60 +0,0 @@
|
||||||
const fs = require("fs");
|
|
||||||
const DICT_PATH = "dictionary.json";
|
|
||||||
|
|
||||||
const dict = JSON.parse(fs.readFileSync(DICT_PATH));
|
|
||||||
|
|
||||||
const TA_TOKENS = { s: 1, m: 2, h: 3, D: 4, W: 5, M: 6, Y: 7 };
|
|
||||||
|
|
||||||
// Sort a dictionary by value
|
|
||||||
function sortDict(dict) {
|
|
||||||
// Create items array
|
|
||||||
const items = Object.keys(dict).map(function (key) {
|
|
||||||
return [key, dict[key]];
|
|
||||||
});
|
|
||||||
// Sort the array based on the second element
|
|
||||||
items.sort(function (first, second) {
|
|
||||||
let d1;
|
|
||||||
if (typeof first[1] === "string") {
|
|
||||||
// Check for timeago token
|
|
||||||
const tokenPat = /^(\d*)([smhDWMY])$/;
|
|
||||||
const m1 = first[1].match(tokenPat);
|
|
||||||
const m2 = second[1].match(tokenPat);
|
|
||||||
if (m1 !== null && m2 !== null) {
|
|
||||||
const tok1 = TA_TOKENS[m1[2]];
|
|
||||||
const tok2 = TA_TOKENS[m2[2]];
|
|
||||||
if (tok1 === tok2) {
|
|
||||||
const n1 = parseInt(m1[1]) || 0;
|
|
||||||
const n2 = parseInt(m2[1]) || 0;
|
|
||||||
d1 = n1 - n2;
|
|
||||||
} else {
|
|
||||||
d1 = tok1 - tok2;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
d1 = first[1].localeCompare(second[1]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
d1 = first[1] - second[1];
|
|
||||||
}
|
|
||||||
if (d1 === 0) {
|
|
||||||
return first[0].localeCompare(second[0]);
|
|
||||||
}
|
|
||||||
return d1;
|
|
||||||
});
|
|
||||||
|
|
||||||
const newDict = {};
|
|
||||||
items.forEach((item) => {
|
|
||||||
newDict[item[0]] = item[1];
|
|
||||||
});
|
|
||||||
return newDict;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [mainLang, entry] of Object.entries(dict)) {
|
|
||||||
for (key of Object.keys(entry)) {
|
|
||||||
const val = entry[key];
|
|
||||||
if (typeof val === "object" && !Array.isArray(val)) {
|
|
||||||
dict[mainLang][key] = sortDict(val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync(DICT_PATH, JSON.stringify(dict, null, 2) + "\n");
|
|
Loading…
Reference in a new issue