2023-11-28 14:24:41 +00:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
const FALSE_VALUES = [
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
'0',
|
|
|
|
'f',
|
|
|
|
'F',
|
|
|
|
'false',
|
|
|
|
'FALSE',
|
|
|
|
'off',
|
|
|
|
'OFF',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {any} value
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2024-02-27 14:59:20 +00:00
|
|
|
export function isTruthy(value) {
|
|
|
|
return value && !FALSE_VALUES.includes(value);
|
|
|
|
}
|
2024-01-22 10:02:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* See app/lib/ascii_folder.rb for the canon definitions
|
|
|
|
* of these constants
|
|
|
|
*/
|
|
|
|
const NON_ASCII_CHARS = 'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž';
|
|
|
|
const EQUIVALENT_ASCII_CHARS = 'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} str
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2024-02-27 14:59:20 +00:00
|
|
|
export function foldToASCII(str) {
|
2024-01-22 10:02:26 +00:00
|
|
|
const regex = new RegExp(NON_ASCII_CHARS.split('').join('|'), 'g');
|
|
|
|
|
|
|
|
return str.replace(regex, function(match) {
|
|
|
|
const index = NON_ASCII_CHARS.indexOf(match);
|
|
|
|
return EQUIVALENT_ASCII_CHARS[index];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} str
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2024-02-27 14:59:20 +00:00
|
|
|
export function normalizeHashtag(str) {
|
2024-01-22 10:02:26 +00:00
|
|
|
return foldToASCII(str.normalize('NFKC').toLowerCase()).replace(/[^\p{L}\p{N}_\u00b7\u200c]/gu, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string|string[]} arrayOrString
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2024-02-27 14:59:20 +00:00
|
|
|
export function firstParam(arrayOrString) {
|
2024-01-22 10:02:26 +00:00
|
|
|
if (Array.isArray(arrayOrString)) {
|
|
|
|
return arrayOrString[0];
|
|
|
|
} else {
|
|
|
|
return arrayOrString;
|
|
|
|
}
|
|
|
|
}
|