Work on general clean up. Better export and email of sponsor data
This commit is contained in:
@@ -610,6 +610,234 @@ function count_words(text: string) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Adapted from: To Title Case © 2018 David Gouch | https://github.com/gouch/to-title-case */
|
||||
|
||||
// eslint-disable-next-line no-extend-native
|
||||
function to_title_case (text_string) {
|
||||
// console.log('*** to_title_case() ***');
|
||||
|
||||
let smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|v.?|vs.?|via)$/i
|
||||
let alphanumericPattern = /([A-Za-z0-9\u00C0-\u00FF])/
|
||||
let wordSeparators = /([ :–—-])/
|
||||
|
||||
return text_string.split(wordSeparators)
|
||||
.map(function (current, index, array) {
|
||||
if (
|
||||
/* Check for small words */
|
||||
current.search(smallWords) > -1 &&
|
||||
/* Skip first and last word */
|
||||
index !== 0 &&
|
||||
index !== array.length - 1 &&
|
||||
/* Ignore title end and subtitle start */
|
||||
array[index - 3] !== ':' &&
|
||||
array[index + 1] !== ':' &&
|
||||
/* Ignore small words that start a hyphenated phrase */
|
||||
(array[index + 1] !== '-' ||
|
||||
(array[index - 1] === '-' && array[index + 1] === '-'))
|
||||
) {
|
||||
return current.toLowerCase()
|
||||
}
|
||||
|
||||
/* Ignore intentional capitalization */
|
||||
if (current.substr(1).search(/[A-Z]|\../) > -1) {
|
||||
return current
|
||||
}
|
||||
|
||||
/* Ignore URLs */
|
||||
if (array[index + 1] === ':' && array[index + 2] !== '') {
|
||||
return current
|
||||
}
|
||||
|
||||
/* Capitalize the first letter */
|
||||
return current.replace(alphanumericPattern, function (match) {
|
||||
return match.toUpperCase()
|
||||
})
|
||||
})
|
||||
.join('')
|
||||
}
|
||||
|
||||
|
||||
// Updated 2023-08-18
|
||||
function set_obj_prop_display_name({prop_name, obj_type=null, prefix_w_obj_type=true, prefix_all_w_obj_type=false, replace_underscores=true, title_case=true, override=null}) {
|
||||
console.log('*** set_obj_prop_display_name() ***');
|
||||
|
||||
if (override) {
|
||||
return override;
|
||||
}
|
||||
|
||||
let known_obj_type_li = ['account', 'address', 'contact', 'event_badge', 'event_exhibit', 'event_file', 'event_location', 'event_person', 'event_presentation', 'event_presenter', 'event_registration', 'event_session', 'event', 'hosted_file', 'order_line', 'order', 'person', 'user'];
|
||||
|
||||
|
||||
let known_obj_type_li_dict = [
|
||||
{name: 'account', display: 'Account'},
|
||||
{name: 'address', display: 'Address'},
|
||||
{name: 'contact', display: 'Contact'},
|
||||
{name: 'event_badge', display: 'Event Badge'},
|
||||
{name: 'event_exhibit', display: 'Event Exhibit'},
|
||||
{name: 'event_file', display: 'Event File'},
|
||||
{name: 'event_location', display: 'Event Location'},
|
||||
{name: 'event_person', display: 'Event Person'},
|
||||
{name: 'event_presentation', display: 'Event Presentation'},
|
||||
{name: 'event_presenter', display: 'Event Presenter'},
|
||||
{name: 'event_registration', display: 'Event Registration'},
|
||||
{name: 'event_session', display: 'Event Session'},
|
||||
{name: 'event', display: 'Event'},
|
||||
{name: 'hosted_file', display: 'Hosted File'},
|
||||
{name: 'order_line', display: 'Order Line'},
|
||||
{name: 'order', display: 'Order'},
|
||||
{name: 'person', display: 'Person'},
|
||||
{name: 'user', display: 'User'},
|
||||
];
|
||||
|
||||
let prop_display_name = prop_name;
|
||||
|
||||
if (!prefix_w_obj_type) {
|
||||
if (obj_type) {
|
||||
prop_display_name = prop_name.replace(obj_type, '');
|
||||
} else {
|
||||
for (let i = 0; i < known_obj_type_li_dict.length; i++) {
|
||||
// console.log(known_obj_type_li_dict[i]);
|
||||
|
||||
if (prop_name.startsWith(known_obj_type_li_dict[i].name)) {
|
||||
// console.log(`Found ${known_obj_type_li_dict[i].name}`);
|
||||
prop_display_name = prop_name.replace(known_obj_type_li_dict[i].name, '');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// for (let i = 0; i < known_obj_type_li.length; i++) {
|
||||
// // console.log(known_obj_type_li[i]);
|
||||
|
||||
// if (prop_name.startsWith(known_obj_type_li[i])) {
|
||||
// console.log(`Found ${known_obj_type_li[i]}`);
|
||||
// prop_display_name = prop_name.replace(known_obj_type_li[i], '');
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
if (!prefix_all_w_obj_type) {
|
||||
for (let i = 0; i < known_obj_type_li.length; i++) {
|
||||
// console.log(known_obj_type_li[i]);
|
||||
|
||||
let found_obj_type = null;
|
||||
|
||||
if (prop_name.startsWith(known_obj_type_li_dict[i].name)) {
|
||||
// if (prop_name.startsWith(known_obj_type_li[i])) {
|
||||
// console.log(`Found ${known_obj_type_li_dict[i].name}`);
|
||||
found_obj_type = known_obj_type_li_dict[i].name;
|
||||
if (found_obj_type == obj_type) {
|
||||
prop_display_name = prop_name.replace(known_obj_type_li_dict[i].name, '');
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if (obj_type) {
|
||||
// prop_display_name = prop_name.replace(obj_type, '');
|
||||
// } else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(prop_display_name);
|
||||
|
||||
if (prop_display_name.search('ID')) {
|
||||
|
||||
}
|
||||
prop_display_name = prop_display_name.replace('id_random', 'ID');
|
||||
|
||||
if (replace_underscores) {
|
||||
prop_display_name = prop_display_name.replaceAll('_', ' ');
|
||||
}
|
||||
|
||||
if (title_case) {
|
||||
prop_display_name = to_title_case(prop_display_name);
|
||||
}
|
||||
|
||||
// console.log(prop_display_name);
|
||||
|
||||
return prop_display_name;
|
||||
}
|
||||
|
||||
|
||||
function return_obj_type_path({obj_type=null, obj_type_prop_name=null}) {
|
||||
console.log('*** set_obj_prop_display_name() ***');
|
||||
|
||||
let obj_type_path = null;
|
||||
|
||||
let known_obj_type_li = ['account', 'address', 'archive', 'archive_content', 'contact', 'event_badge', 'event_exhibit', 'event_file', 'event_location', 'event_person', 'event_presentation', 'event_presenter', 'event_registration', 'event_session', 'event', 'hosted_file', 'order_line', 'order', 'person', 'post', 'post_comment', 'user'];
|
||||
|
||||
let known_obj_type_li_dict = [
|
||||
{name: 'account', display: 'Account', path: 'account'},
|
||||
{name: 'archive', display: 'Archive', path: 'archive'},
|
||||
{name: 'address', display: 'Address', path: 'address'},
|
||||
{name: 'archive', display: 'Archive', path: 'archive'},
|
||||
{name: 'archive_content', display: 'Archive Content', path: 'archive/content'},
|
||||
{name: 'contact', display: 'Contact', path: 'contact'},
|
||||
{name: 'data_store', display: 'Data Store', path: 'data_store'},
|
||||
{name: 'event_abstract', display: 'Event Abstract', path: 'event/abstract'},
|
||||
{name: 'event_badge', display: 'Event Badge', path: 'event/badge'},
|
||||
{name: 'event_device', display: 'Event Device', path: 'event/device'},
|
||||
{name: 'event_exhibit', display: 'Event Exhibit', path: 'event/exhibit'},
|
||||
{name: 'event_file', display: 'Event File', path: 'event/file'},
|
||||
{name: 'event_location', display: 'Event Location', path: 'event/location'},
|
||||
{name: 'event_person', display: 'Event Person', path: 'event/person'},
|
||||
{name: 'event_presentation', display: 'Event Presentation', path: 'event/'},
|
||||
{name: 'event_presenter', display: 'Event Presenter', path: 'event/presenter'},
|
||||
{name: 'event_registration', display: 'Event Registration', path: 'event/registration'},
|
||||
{name: 'event_session', display: 'Event Session', path: 'event/session'},
|
||||
{name: 'event', display: 'Event', path: 'event'},
|
||||
{name: 'hosted_file', display: 'Hosted File', path: 'hosted_file'},
|
||||
{name: 'journal', display: 'Journal', path: 'journal'},
|
||||
{name: 'journal_entry', display: 'Journal Entry', path: 'journal/entry'},
|
||||
{name: 'order_line', display: 'Order Line', path: 'order/line'},
|
||||
{name: 'order', display: 'Order', path: 'order'},
|
||||
{name: 'person', display: 'Person', path: 'person'},
|
||||
{name: 'post', display: 'Archive', path: 'post'},
|
||||
{name: 'post_comment', display: 'Archive Content', path: 'post/comment'},
|
||||
{name: 'user', display: 'User', path: 'user'},
|
||||
];
|
||||
|
||||
if (obj_type) {
|
||||
// Need to loop through known for safety?
|
||||
obj_type_path = obj_type_prop_name.replaceAll('_', '/');
|
||||
|
||||
} else if (obj_type_prop_name) {
|
||||
let found_obj_type_name = null;
|
||||
let found_obj_type_path = null;
|
||||
|
||||
for (let i = 0; i < known_obj_type_li_dict.length; i++) {
|
||||
// console.log(known_obj_type_li_dict[i]);
|
||||
|
||||
// let guessed_obj_type = prop_name.startsWith(known_obj_type_li_dict[i]
|
||||
|
||||
|
||||
if (obj_type_prop_name.startsWith(known_obj_type_li_dict[i].name)) {
|
||||
console.log(`Found ${known_obj_type_li_dict[i].name}`);
|
||||
found_obj_type_name = known_obj_type_li_dict[i].name;
|
||||
found_obj_type_path = known_obj_type_li_dict[i].path;
|
||||
// obj_type_path = obj_type_prop_name.replaceAll('_', '/');
|
||||
obj_type_path = found_obj_type_path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log('Missing required parameters');
|
||||
return false;
|
||||
}
|
||||
|
||||
return obj_type_path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export let ae_util = {
|
||||
iso_datetime_formatter: iso_datetime_formatter,
|
||||
number_w_commas: number_w_commas,
|
||||
@@ -621,5 +849,8 @@ export let ae_util = {
|
||||
create_img_element: create_img_element,
|
||||
create_video_element: create_video_element,
|
||||
count_words: count_words,
|
||||
to_title_case: to_title_case,
|
||||
set_obj_prop_display_name: set_obj_prop_display_name,
|
||||
return_obj_type_path: return_obj_type_path,
|
||||
};
|
||||
// export default ae_util;
|
||||
Reference in New Issue
Block a user