feat: Migrate ESLint to flat config and resolve initial linting errors
Migrated the ESLint configuration to the new flat config format () and addressed several initial linting errors. Key changes include: - Updated ESLint configuration to treat as warnings instead of errors. - Fixed errors in by declaring and . - Corrected error in by using instead of an out-of-scope . - Resolved error in by replacing the undefined directive with the component. - Addressed errors in by replacing with and with . - Fixed errors in by importing necessary modules (, , ) and adding missing props (, , , , ).
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
// Import external files first. Eventually this will be broken up in to smaller files.
|
||||
import { clean_filename, format_bytes, guess_file_name, guess_file_extension, get_file_hash } from './ae_utils__files';
|
||||
import { get_obj_li_w_match_prop} from './ae_utils__get_obj_li_w_match_prop';
|
||||
import {
|
||||
clean_filename,
|
||||
format_bytes,
|
||||
guess_file_name,
|
||||
guess_file_extension,
|
||||
get_file_hash
|
||||
} from './ae_utils__files';
|
||||
import { get_obj_li_w_match_prop } from './ae_utils__get_obj_li_w_match_prop';
|
||||
import { file_extension_icon } from './ae_utils__file_extension_icon';
|
||||
import { process_permission_checks } from './ae_utils__perm_checks';
|
||||
import { iso_datetime_formatter } from './ae_utils__datetime_format';
|
||||
@@ -10,24 +16,27 @@ import { to_title_case } from './ae_utils__to_title_case';
|
||||
import { process_data_string } from './ae_utils__process_data_string';
|
||||
import { set_obj_prop_display_name } from './ae_utils__set_obj_prop_display_name';
|
||||
import { return_obj_type_path } from './ae_utils__return_obj_type_path';
|
||||
import { combine_iv_and_base64, encrypt_content, encrypt_wrapper, decrypt_content, decrypt_wrapper } from './ae_utils__crypto';
|
||||
|
||||
import {
|
||||
combine_iv_and_base64,
|
||||
encrypt_content,
|
||||
encrypt_wrapper,
|
||||
decrypt_content,
|
||||
decrypt_wrapper
|
||||
} from './ae_utils__crypto';
|
||||
|
||||
export type key_str = {
|
||||
[key: string]: string;
|
||||
[key: string]: string;
|
||||
};
|
||||
|
||||
export type key_val = {
|
||||
[key: string]: any;
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
|
||||
/* This utility function will add commas to a number. */
|
||||
function number_w_commas(x) {
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
|
||||
|
||||
// This function will update the URL and send a message to the parent window (iframe).
|
||||
// The name should be something like "example_id".
|
||||
// Svelte specific:
|
||||
@@ -35,80 +44,113 @@ function number_w_commas(x) {
|
||||
// Updated 2024-03-02
|
||||
// import { pushState, replaceState } from '$app/navigation';
|
||||
|
||||
function handle_url_and_message(name: string, value: null | string) {
|
||||
console.log(`*** handle_url_and_message() *** name=${name} value=${value}`);
|
||||
|
||||
const location = window.location.href;
|
||||
// console.log('location:', location);
|
||||
const url = new URL(location);
|
||||
// console.log('url:', url);
|
||||
|
||||
function handle_url_and_message(name: string, value: null|string) {
|
||||
console.log(`*** handle_url_and_message() *** name=${name} value=${value}`);
|
||||
if (value) {
|
||||
url.searchParams.set(name, value);
|
||||
history.pushState({}, '', url);
|
||||
|
||||
let location = window.location.href;
|
||||
// console.log('location:', location);
|
||||
const url = new URL(location);
|
||||
// console.log('url:', url);
|
||||
// console.log('url:', url);
|
||||
// pushState(url.href, {});
|
||||
// pushState(url.search, {});
|
||||
// replaceState(url.href, {});
|
||||
|
||||
if (value) {
|
||||
url.searchParams.set(name, value);
|
||||
history.pushState({}, '', url);
|
||||
const message = { name: value };
|
||||
window.parent.postMessage(message, '*');
|
||||
} else {
|
||||
url.searchParams.delete(name);
|
||||
history.pushState({}, '', url);
|
||||
|
||||
// console.log('url:', url);
|
||||
// pushState(url.href, {});
|
||||
// pushState(url.search, {});
|
||||
// replaceState(url.href, {});
|
||||
// console.log('url:', url);
|
||||
// pushState({}, '', url.search);
|
||||
// pushState(url.href, {});
|
||||
// replaceState(url.href, {});
|
||||
|
||||
let message = {name: value};
|
||||
window.parent.postMessage(message, "*");
|
||||
} else {
|
||||
url.searchParams.delete(name);
|
||||
history.pushState({}, '', url);
|
||||
|
||||
// console.log('url:', url);
|
||||
// pushState({}, '', url.search);
|
||||
// pushState(url.href, {});
|
||||
// replaceState(url.href, {});
|
||||
|
||||
let message = {name: null};
|
||||
window.parent.postMessage(message, "*");
|
||||
}
|
||||
// console.log('Message sent to parent (iframe):', message);
|
||||
const message = { name: null };
|
||||
window.parent.postMessage(message, '*');
|
||||
}
|
||||
// console.log('Message sent to parent (iframe):', message);
|
||||
}
|
||||
|
||||
|
||||
function create_a_element({account_id, base_url, hosted_file_id, filename=null, extension=null, text="Download", class_li='text-blue-500'}) {
|
||||
return `<a href="${base_url}/hosted_file/${hosted_file_id}/download?x_no_account_id_token=${account_id}&filename=${filename}" class="${class_li}">${text}</a>`;
|
||||
function create_a_element({
|
||||
account_id,
|
||||
base_url,
|
||||
hosted_file_id,
|
||||
filename = null,
|
||||
extension = null,
|
||||
text = 'Download',
|
||||
class_li = 'text-blue-500'
|
||||
}) {
|
||||
return `<a href="${base_url}/hosted_file/${hosted_file_id}/download?x_no_account_id_token=${account_id}&filename=${filename}" class="${class_li}">${text}</a>`;
|
||||
}
|
||||
|
||||
function create_img_element({account_id, base_url, hosted_file_id, filename=null, extension=null, class_li='max-w-64', style="", inc_link=false}) {
|
||||
let img_html = '';
|
||||
if (filename) {
|
||||
img_html = `<img src="${base_url}/hosted_file/${hosted_file_id}/download?x_no_account_id_token=${account_id}&filename=${filename}" class="${class_li}" style="${style}" />`;
|
||||
} else {
|
||||
img_html = `<img src="${base_url}/hosted_file/${hosted_file_id}/download?x_no_account_id_token=${account_id}" class="${class_li}" style="${style}" />`;
|
||||
}
|
||||
function create_img_element({
|
||||
account_id,
|
||||
base_url,
|
||||
hosted_file_id,
|
||||
filename = null,
|
||||
extension = null,
|
||||
class_li = 'max-w-64',
|
||||
style = '',
|
||||
inc_link = false
|
||||
}) {
|
||||
let img_html = '';
|
||||
if (filename) {
|
||||
img_html = `<img src="${base_url}/hosted_file/${hosted_file_id}/download?x_no_account_id_token=${account_id}&filename=${filename}" class="${class_li}" style="${style}" />`;
|
||||
} else {
|
||||
img_html = `<img src="${base_url}/hosted_file/${hosted_file_id}/download?x_no_account_id_token=${account_id}" class="${class_li}" style="${style}" />`;
|
||||
}
|
||||
|
||||
if (inc_link) {
|
||||
let a_html = create_a_element({account_id: account_id, base_url: base_url, hosted_file_id: hosted_file_id, filename: filename, extension: extension});
|
||||
img_html = `<div class="ae_img ae_a">${img_html}${a_html}</div>`;
|
||||
}
|
||||
if (inc_link) {
|
||||
const a_html = create_a_element({
|
||||
account_id: account_id,
|
||||
base_url: base_url,
|
||||
hosted_file_id: hosted_file_id,
|
||||
filename: filename,
|
||||
extension: extension
|
||||
});
|
||||
img_html = `<div class="ae_img ae_a">${img_html}${a_html}</div>`;
|
||||
}
|
||||
|
||||
return img_html;
|
||||
return img_html;
|
||||
}
|
||||
|
||||
function create_video_element({account_id, base_url, hosted_file_id, filename=null, extension=null, class_li='max-w-64', inc_link=false}) {
|
||||
let video_html = '';
|
||||
if (filename) {
|
||||
video_html = `<video src="${base_url}/hosted_file/${hosted_file_id}/download?x_no_account_id_token=${account_id}&filename=${filename}" controls class="${class_li}"></video>`;
|
||||
} else {
|
||||
video_html = `<video src="${base_url}/hosted_file/${hosted_file_id}/download?x_no_account_id_token=${account_id}" controls class="${class_li}"></video>`;
|
||||
}
|
||||
function create_video_element({
|
||||
account_id,
|
||||
base_url,
|
||||
hosted_file_id,
|
||||
filename = null,
|
||||
extension = null,
|
||||
class_li = 'max-w-64',
|
||||
inc_link = false
|
||||
}) {
|
||||
let video_html = '';
|
||||
if (filename) {
|
||||
video_html = `<video src="${base_url}/hosted_file/${hosted_file_id}/download?x_no_account_id_token=${account_id}&filename=${filename}" controls class="${class_li}"></video>`;
|
||||
} else {
|
||||
video_html = `<video src="${base_url}/hosted_file/${hosted_file_id}/download?x_no_account_id_token=${account_id}" controls class="${class_li}"></video>`;
|
||||
}
|
||||
|
||||
if (inc_link) {
|
||||
let a_html = create_a_element({account_id: account_id, base_url: base_url, hosted_file_id: hosted_file_id, filename: filename, extension: extension});
|
||||
video_html = `<div class="ae_video ae_a">${video_html}${a_html}</div>`;
|
||||
}
|
||||
if (inc_link) {
|
||||
const a_html = create_a_element({
|
||||
account_id: account_id,
|
||||
base_url: base_url,
|
||||
hosted_file_id: hosted_file_id,
|
||||
filename: filename,
|
||||
extension: extension
|
||||
});
|
||||
video_html = `<div class="ae_video ae_a">${video_html}${a_html}</div>`;
|
||||
}
|
||||
|
||||
return video_html;
|
||||
return video_html;
|
||||
}
|
||||
|
||||
|
||||
// // Clear the quick access type
|
||||
// function clear_access_type() {
|
||||
// // NOTE: I think it makes since to reset this to anonymous even if logged in as an admin or similar.
|
||||
@@ -127,146 +169,138 @@ function create_video_element({account_id, base_url, hosted_file_id, filename=nu
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
// This function will take a long string (sentences or paragraphs) of text and return an estimated number of words.
|
||||
function count_words(text: string) {
|
||||
if (!text || text.length < 1) {
|
||||
return false;
|
||||
}
|
||||
let count = text.trim().split(/\s+/).length;
|
||||
if (!text || text.length < 1) {
|
||||
return false;
|
||||
}
|
||||
const count = text.trim().split(/\s+/).length;
|
||||
|
||||
return count;
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2024-06-19
|
||||
// This function behaves weirdly. It needs to be reviewed and updated.
|
||||
export let shorten_string = function shorten_string(
|
||||
{
|
||||
string,
|
||||
max_length = 45,
|
||||
begin_length = 15,
|
||||
end_length = 5,
|
||||
wildcard_length = 3
|
||||
}: {
|
||||
string: undefined|string,
|
||||
max_length?: number,
|
||||
begin_length?: number,
|
||||
end_length?: number,
|
||||
wildcard_length?: number
|
||||
}
|
||||
) {
|
||||
// console.log('*** shorten_filename() ***');
|
||||
export const shorten_string = function shorten_string({
|
||||
string,
|
||||
max_length = 45,
|
||||
begin_length = 15,
|
||||
end_length = 5,
|
||||
wildcard_length = 3
|
||||
}: {
|
||||
string: undefined | string;
|
||||
max_length?: number;
|
||||
begin_length?: number;
|
||||
end_length?: number;
|
||||
wildcard_length?: number;
|
||||
}) {
|
||||
// console.log('*** shorten_filename() ***');
|
||||
|
||||
if (!string || typeof string != 'string') {
|
||||
// console.log('Invalid string value passed');
|
||||
// return false;
|
||||
return '';
|
||||
}
|
||||
if (!string || typeof string != 'string') {
|
||||
// console.log('Invalid string value passed');
|
||||
// return false;
|
||||
return '';
|
||||
}
|
||||
|
||||
// NOTE: max_length is not the actual end result length. The actual max will be 45 characters.
|
||||
// 20 part 1 characters, 5 part 2 characters, 20 part 3 characters
|
||||
// NOTE: max_length is not the actual end result length. The actual max will be 45 characters.
|
||||
// 20 part 1 characters, 5 part 2 characters, 20 part 3 characters
|
||||
|
||||
// let length = string.length;
|
||||
let char_over = string.length-max_length;
|
||||
let new_string = null;
|
||||
let wildcards = char_over;
|
||||
if (char_over > 0) {
|
||||
let part1 = string.slice(0, begin_length);
|
||||
// let length = string.length;
|
||||
const char_over = string.length - max_length;
|
||||
let new_string = null;
|
||||
let wildcards = char_over;
|
||||
if (char_over > 0) {
|
||||
const part1 = string.slice(0, begin_length);
|
||||
|
||||
let part2 = '';
|
||||
if (char_over > 5) {
|
||||
wildcards = 5;
|
||||
} else {
|
||||
}
|
||||
let part2 = '';
|
||||
if (char_over > 5) {
|
||||
wildcards = 5;
|
||||
} else {
|
||||
}
|
||||
|
||||
if (wildcard_length) {
|
||||
part2 = '.'.repeat(wildcard_length);
|
||||
} else {
|
||||
part2 = '.'.repeat(wildcards);
|
||||
}
|
||||
if (wildcard_length) {
|
||||
part2 = '.'.repeat(wildcard_length);
|
||||
} else {
|
||||
part2 = '.'.repeat(wildcards);
|
||||
}
|
||||
|
||||
let part3 = string.slice(end_length*-1);
|
||||
|
||||
new_string = part1+part2+part3;
|
||||
} else {
|
||||
new_string = string;
|
||||
}
|
||||
return new_string;
|
||||
}
|
||||
const part3 = string.slice(end_length * -1);
|
||||
|
||||
new_string = part1 + part2 + part3;
|
||||
} else {
|
||||
new_string = string;
|
||||
}
|
||||
return new_string;
|
||||
};
|
||||
|
||||
// Updated 2024-06-19
|
||||
// This function should return a shorted version of a filename if over the max length. It should always contain at least the first character of the original filename and the complete extension.
|
||||
// Example 1: The Original Long File Name.pdf -> The Orig....pdf
|
||||
// Example 2: The Original Long File Name.html -> The Ori....html
|
||||
function shorten_filename(
|
||||
{
|
||||
filename,
|
||||
max_length = 20,
|
||||
slice_end_at = 15,
|
||||
max_end_length = 5
|
||||
}: {
|
||||
filename: string,
|
||||
max_length?: number,
|
||||
slice_end_at?: number,
|
||||
max_end_length?: number
|
||||
}
|
||||
) {
|
||||
// console.log('*** shorten_filename() ***');
|
||||
function shorten_filename({
|
||||
filename,
|
||||
max_length = 20,
|
||||
slice_end_at = 15,
|
||||
max_end_length = 5
|
||||
}: {
|
||||
filename: string;
|
||||
max_length?: number;
|
||||
slice_end_at?: number;
|
||||
max_end_length?: number;
|
||||
}) {
|
||||
// console.log('*** shorten_filename() ***');
|
||||
|
||||
if (typeof filename !== 'string' || filename.length <= max_length) {
|
||||
return filename;
|
||||
}
|
||||
if (typeof filename !== 'string' || filename.length <= max_length) {
|
||||
return filename;
|
||||
}
|
||||
|
||||
let new_filename = null;
|
||||
let char_over = filename.length - max_length;
|
||||
let wildcards = char_over - 4; // The number of characters over the max length
|
||||
if (wildcards < 1) {
|
||||
return filename; // No point in changing the filename?
|
||||
}
|
||||
let new_filename = null;
|
||||
const char_over = filename.length - max_length;
|
||||
let wildcards = char_over - 4; // The number of characters over the max length
|
||||
if (wildcards < 1) {
|
||||
return filename; // No point in changing the filename?
|
||||
}
|
||||
|
||||
let part_1 = filename.slice(0, slice_end_at);
|
||||
if (wildcards > 3) {
|
||||
wildcards = 3;
|
||||
} else {
|
||||
}
|
||||
let part_2 = '.'.repeat(wildcards);
|
||||
let part_3 = filename.slice(max_end_length*-1);
|
||||
const part_1 = filename.slice(0, slice_end_at);
|
||||
if (wildcards > 3) {
|
||||
wildcards = 3;
|
||||
} else {
|
||||
}
|
||||
const part_2 = '.'.repeat(wildcards);
|
||||
const part_3 = filename.slice(max_end_length * -1);
|
||||
|
||||
new_filename = part_1+part_2+part_3;
|
||||
new_filename = part_1 + part_2 + part_3;
|
||||
|
||||
return new_filename;
|
||||
return new_filename;
|
||||
}
|
||||
|
||||
|
||||
export let ae_util = {
|
||||
is_datetime_recent: is_datetime_recent,
|
||||
process_permission_checks: process_permission_checks,
|
||||
iso_datetime_formatter: iso_datetime_formatter,
|
||||
clean_filename: clean_filename,
|
||||
format_bytes: format_bytes,
|
||||
number_w_commas: number_w_commas,
|
||||
guess_file_name: guess_file_name,
|
||||
guess_file_extension: guess_file_extension,
|
||||
get_file_hash: get_file_hash,
|
||||
get_obj_li_w_match_prop: get_obj_li_w_match_prop,
|
||||
extract_prefixed_form_data: extract_prefixed_form_data,
|
||||
process_data_string: process_data_string,
|
||||
handle_url_and_message: handle_url_and_message,
|
||||
create_a_element: create_a_element,
|
||||
create_img_element: create_img_element,
|
||||
create_video_element: create_video_element,
|
||||
count_words: count_words,
|
||||
to_title_case: to_title_case,
|
||||
shorten_string: shorten_string,
|
||||
shorten_filename: shorten_filename,
|
||||
file_extension_icon: file_extension_icon,
|
||||
set_obj_prop_display_name: set_obj_prop_display_name,
|
||||
return_obj_type_path: return_obj_type_path,
|
||||
combine_iv_and_base64: combine_iv_and_base64,
|
||||
encrypt_content: encrypt_content,
|
||||
encrypt_wrapper: encrypt_wrapper,
|
||||
decrypt_content: decrypt_content,
|
||||
decrypt_wrapper: decrypt_wrapper,
|
||||
export const ae_util = {
|
||||
is_datetime_recent: is_datetime_recent,
|
||||
process_permission_checks: process_permission_checks,
|
||||
iso_datetime_formatter: iso_datetime_formatter,
|
||||
clean_filename: clean_filename,
|
||||
format_bytes: format_bytes,
|
||||
number_w_commas: number_w_commas,
|
||||
guess_file_name: guess_file_name,
|
||||
guess_file_extension: guess_file_extension,
|
||||
get_file_hash: get_file_hash,
|
||||
get_obj_li_w_match_prop: get_obj_li_w_match_prop,
|
||||
extract_prefixed_form_data: extract_prefixed_form_data,
|
||||
process_data_string: process_data_string,
|
||||
handle_url_and_message: handle_url_and_message,
|
||||
create_a_element: create_a_element,
|
||||
create_img_element: create_img_element,
|
||||
create_video_element: create_video_element,
|
||||
count_words: count_words,
|
||||
to_title_case: to_title_case,
|
||||
shorten_string: shorten_string,
|
||||
shorten_filename: shorten_filename,
|
||||
file_extension_icon: file_extension_icon,
|
||||
set_obj_prop_display_name: set_obj_prop_display_name,
|
||||
return_obj_type_path: return_obj_type_path,
|
||||
combine_iv_and_base64: combine_iv_and_base64,
|
||||
encrypt_content: encrypt_content,
|
||||
encrypt_wrapper: encrypt_wrapper,
|
||||
decrypt_content: decrypt_content,
|
||||
decrypt_wrapper: decrypt_wrapper
|
||||
};
|
||||
|
||||
@@ -1,121 +1,127 @@
|
||||
let log_lvl = 0; // 0 = no logging, 1 = some logging, 2 = all logging
|
||||
const log_lvl = 0; // 0 = no logging, 1 = some logging, 2 = all logging
|
||||
|
||||
// Updated 2025-05-08
|
||||
async function generate_iv() {
|
||||
const data = new Uint8Array(16);
|
||||
crypto.getRandomValues(data);
|
||||
return data;
|
||||
const data = new Uint8Array(16);
|
||||
crypto.getRandomValues(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
// Updated 2025-05-08
|
||||
export let encrypt_content = async function encrypt_content(
|
||||
content: string,
|
||||
keyData: string
|
||||
) {
|
||||
const iv = await generate_iv();
|
||||
const keyBytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(keyData));
|
||||
const key = await crypto.subtle.importKey('raw', keyBytes, { name: 'AES-CBC' }, false, ['encrypt']);
|
||||
const encodedContent = await crypto.subtle.encrypt({ name: 'AES-CBC', iv }, key, new TextEncoder().encode(content));
|
||||
const base64 = btoa(String.fromCharCode(...new Uint8Array(encodedContent)));
|
||||
if (log_lvl) {
|
||||
console.log(`IV: ${iv}; Encrypted:`, base64);
|
||||
}
|
||||
return { base64, iv };
|
||||
}
|
||||
export const encrypt_content = async function encrypt_content(content: string, keyData: string) {
|
||||
const iv = await generate_iv();
|
||||
const keyBytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(keyData));
|
||||
const key = await crypto.subtle.importKey('raw', keyBytes, { name: 'AES-CBC' }, false, [
|
||||
'encrypt'
|
||||
]);
|
||||
const encodedContent = await crypto.subtle.encrypt(
|
||||
{ name: 'AES-CBC', iv },
|
||||
key,
|
||||
new TextEncoder().encode(content)
|
||||
);
|
||||
const base64 = btoa(String.fromCharCode(...new Uint8Array(encodedContent)));
|
||||
if (log_lvl) {
|
||||
console.log(`IV: ${iv}; Encrypted:`, base64);
|
||||
}
|
||||
return { base64, iv };
|
||||
};
|
||||
|
||||
// Updated 2025-05-08
|
||||
export let combine_iv_and_base64 = function combine_iv_and_base64(
|
||||
base64: string,
|
||||
iv: Uint8Array
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`IV: ${iv}; Encrypted:`, base64);
|
||||
}
|
||||
export const combine_iv_and_base64 = function combine_iv_and_base64(
|
||||
base64: string,
|
||||
iv: Uint8Array
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`IV: ${iv}; Encrypted:`, base64);
|
||||
}
|
||||
|
||||
// Combine the IV and encrypted content
|
||||
const combined = Array.from(iv).map(byte => byte.toString(16).padStart(2, '0')).join('') + ':' + base64;
|
||||
if (log_lvl) {
|
||||
console.log('Combined IV and Base64:', combined);
|
||||
}
|
||||
// const ivBase64 = btoa(String.fromCharCode(...iv));
|
||||
// const combined = `${ivBase64}:${base64}`;
|
||||
// console.log('Combined IV and Base64 v2:', combined);
|
||||
return combined;
|
||||
}
|
||||
// Combine the IV and encrypted content
|
||||
const combined =
|
||||
Array.from(iv)
|
||||
.map((byte) => byte.toString(16).padStart(2, '0'))
|
||||
.join('') +
|
||||
':' +
|
||||
base64;
|
||||
if (log_lvl) {
|
||||
console.log('Combined IV and Base64:', combined);
|
||||
}
|
||||
// const ivBase64 = btoa(String.fromCharCode(...iv));
|
||||
// const combined = `${ivBase64}:${base64}`;
|
||||
// console.log('Combined IV and Base64 v2:', combined);
|
||||
return combined;
|
||||
};
|
||||
|
||||
// Updated 2025-05-08
|
||||
export let encrypt_wrapper = async function encrypt_wrapper(
|
||||
content: string,
|
||||
keyData: string
|
||||
) {
|
||||
if (!content) {
|
||||
console.error('No content provided. Returning empty string.');
|
||||
return '';
|
||||
}
|
||||
if (!keyData) {
|
||||
console.error('No keyData provided. Returning empty string.');
|
||||
return '';
|
||||
}
|
||||
const { base64, iv } = await encrypt_content(content, keyData);
|
||||
const combined = combine_iv_and_base64(base64, iv);
|
||||
return combined;
|
||||
}
|
||||
export const encrypt_wrapper = async function encrypt_wrapper(content: string, keyData: string) {
|
||||
if (!content) {
|
||||
console.error('No content provided. Returning empty string.');
|
||||
return '';
|
||||
}
|
||||
if (!keyData) {
|
||||
console.error('No keyData provided. Returning empty string.');
|
||||
return '';
|
||||
}
|
||||
const { base64, iv } = await encrypt_content(content, keyData);
|
||||
const combined = combine_iv_and_base64(base64, iv);
|
||||
return combined;
|
||||
};
|
||||
|
||||
// This does not handle errors (invalid key/password) well.
|
||||
// Updated 2025-05-08
|
||||
export let decrypt_content = async function decrypt_content(
|
||||
base64Content: string,
|
||||
iv: Uint8Array,
|
||||
keyData: string
|
||||
) {
|
||||
const keyBytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(keyData));
|
||||
const key = await crypto.subtle.importKey('raw', keyBytes, { name: 'AES-CBC' }, false, ['decrypt']);
|
||||
const encryptedContent = Uint8Array.from(atob(base64Content), c => c.charCodeAt(0));
|
||||
const decryptedContent = await crypto.subtle.decrypt({ name: 'AES-CBC', iv }, key, encryptedContent);
|
||||
const decodedContent = new TextDecoder().decode(decryptedContent);
|
||||
// console.log('Decrypted Content:', decodedContent);
|
||||
return decodedContent;
|
||||
}
|
||||
export const decrypt_content = async function decrypt_content(
|
||||
base64Content: string,
|
||||
iv: Uint8Array,
|
||||
keyData: string
|
||||
) {
|
||||
const keyBytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(keyData));
|
||||
const key = await crypto.subtle.importKey('raw', keyBytes, { name: 'AES-CBC' }, false, [
|
||||
'decrypt'
|
||||
]);
|
||||
const encryptedContent = Uint8Array.from(atob(base64Content), (c) => c.charCodeAt(0));
|
||||
const decryptedContent = await crypto.subtle.decrypt(
|
||||
{ name: 'AES-CBC', iv },
|
||||
key,
|
||||
encryptedContent
|
||||
);
|
||||
const decodedContent = new TextDecoder().decode(decryptedContent);
|
||||
// console.log('Decrypted Content:', decodedContent);
|
||||
return decodedContent;
|
||||
};
|
||||
|
||||
// Updated 2025-05-08
|
||||
export let split_iv_and_base64 = function split_iv_and_base64(
|
||||
combined: string
|
||||
) {
|
||||
if (!combined) {
|
||||
console.error('No combined string provided. Returning empty object.');
|
||||
return { iv: new Uint8Array(), base64: '' };
|
||||
}
|
||||
let [iv_hex, encrypted_base64_string] = combined.split(':');
|
||||
let base64 = encrypted_base64_string
|
||||
let iv = new Uint8Array(iv_hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
|
||||
if (log_lvl) {
|
||||
console.log(`IV: ${iv}; Encrypted:`, base64);
|
||||
}
|
||||
return { iv, base64 };
|
||||
}
|
||||
export const split_iv_and_base64 = function split_iv_and_base64(combined: string) {
|
||||
if (!combined) {
|
||||
console.error('No combined string provided. Returning empty object.');
|
||||
return { iv: new Uint8Array(), base64: '' };
|
||||
}
|
||||
const [iv_hex, encrypted_base64_string] = combined.split(':');
|
||||
const base64 = encrypted_base64_string;
|
||||
const iv = new Uint8Array(iv_hex.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
||||
if (log_lvl) {
|
||||
console.log(`IV: ${iv}; Encrypted:`, base64);
|
||||
}
|
||||
return { iv, base64 };
|
||||
};
|
||||
|
||||
// Updated 2025-05-15
|
||||
export let decrypt_wrapper = async function decrypt_wrapper(
|
||||
combined: string,
|
||||
keyData: string
|
||||
) {
|
||||
if (!combined) {
|
||||
console.error('No combined string provided. Returning empty string.');
|
||||
return false;
|
||||
}
|
||||
const { iv, base64 } = split_iv_and_base64(combined);
|
||||
console.log(`IV: ${iv}; Encrypted:`, base64);
|
||||
let decrypted;
|
||||
try {
|
||||
decrypted = await decrypt_content(base64, iv, keyData);
|
||||
if (log_lvl > 1) {
|
||||
console.log(`IV: ${iv}; Decrypted:`, decrypted);
|
||||
} else if (log_lvl) {
|
||||
console.log(`IV: ${iv}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Decryption failed:', error);
|
||||
return false;
|
||||
}
|
||||
return decrypted;
|
||||
}
|
||||
export const decrypt_wrapper = async function decrypt_wrapper(combined: string, keyData: string) {
|
||||
if (!combined) {
|
||||
console.error('No combined string provided. Returning empty string.');
|
||||
return false;
|
||||
}
|
||||
const { iv, base64 } = split_iv_and_base64(combined);
|
||||
console.log(`IV: ${iv}; Encrypted:`, base64);
|
||||
let decrypted;
|
||||
try {
|
||||
decrypted = await decrypt_content(base64, iv, keyData);
|
||||
if (log_lvl > 1) {
|
||||
console.log(`IV: ${iv}; Decrypted:`, decrypted);
|
||||
} else if (log_lvl) {
|
||||
console.log(`IV: ${iv}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Decryption failed:', error);
|
||||
return false;
|
||||
}
|
||||
return decrypted;
|
||||
};
|
||||
|
||||
@@ -1,176 +1,176 @@
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
export let iso_datetime_formatter = function iso_datetime_formatter(
|
||||
raw_datetime: null|string|Date = null,
|
||||
named_format: string = 'datetime_iso_no_seconds', // date_iso, datetime_iso_no_seconds
|
||||
time_24_hours: boolean = false
|
||||
) {
|
||||
// console.log('*** iso_datetime_formatter() ***');
|
||||
export const iso_datetime_formatter = function iso_datetime_formatter(
|
||||
raw_datetime: null | string | Date = null,
|
||||
named_format: string = 'datetime_iso_no_seconds', // date_iso, datetime_iso_no_seconds
|
||||
time_24_hours: boolean = false
|
||||
) {
|
||||
// console.log('*** iso_datetime_formatter() ***');
|
||||
|
||||
// https://en.wikipedia.org/wiki/ISO_8601
|
||||
// https://day.js.org/docs/en/display/format
|
||||
// ISO 8601-1:2019 includes the T before the time portion
|
||||
// ISO 8601-1:2019 midnight may only be referred to as "00:00", corresponding to the beginning of a calendar day
|
||||
// and "24:00" is no longer allowed corresponding to the end of a day
|
||||
// 60 is only used to denote an added leap second
|
||||
// https://en.wikipedia.org/wiki/ISO_8601
|
||||
// https://day.js.org/docs/en/display/format
|
||||
// ISO 8601-1:2019 includes the T before the time portion
|
||||
// ISO 8601-1:2019 midnight may only be referred to as "00:00", corresponding to the beginning of a calendar day
|
||||
// and "24:00" is no longer allowed corresponding to the end of a day
|
||||
// 60 is only used to denote an added leap second
|
||||
|
||||
// ISO 8601 UTC: 2021-03-04T19:04:44+00:00
|
||||
// ISO 8601 UTC: 2021-03-04T19:04:44Z
|
||||
// ISO 8601 UTC: 20210304T190444Z
|
||||
// ISO 8601 UTC: 2021-03-04T19:04:44+00:00
|
||||
// ISO 8601 UTC: 2021-03-04T19:04:44Z
|
||||
// ISO 8601 UTC: 20210304T190444Z
|
||||
|
||||
// datetime_iso 'YYYY-MM-DD HH:mm:ss'
|
||||
// datetime_iso_12 'YYYY-MM-DD hh:mm:ss A'
|
||||
// datetime_iso_12_short 'YY-MM-DD hh:mm A'
|
||||
// datetime_iso_tz 'YYYY-MM-DD HH:mm:ss Z'
|
||||
// datetime_iso 'YYYY-MM-DD HH:mm:ss'
|
||||
// datetime_iso_12 'YYYY-MM-DD hh:mm:ss A'
|
||||
// datetime_iso_12_short 'YY-MM-DD hh:mm A'
|
||||
// datetime_iso_tz 'YYYY-MM-DD HH:mm:ss Z'
|
||||
|
||||
// datetime_12_no_seconds 'YYYY-MM-DD hh:mm A'
|
||||
// datetime_12_no_seconds 'YYYY-MM-DD hh:mm A'
|
||||
|
||||
// datetime_long 'dddd, MMMM D, YYYY hh:mm:ss A'
|
||||
// datetime_medium 'ddd, MMM D, YYYY hh:mm:ss A'
|
||||
// datetime_short 'MMM D, YY hh:mm A'
|
||||
// datetime_long 'dddd, MMMM D, YYYY hh:mm:ss A'
|
||||
// datetime_medium 'ddd, MMM D, YYYY hh:mm:ss A'
|
||||
// datetime_short 'MMM D, YY hh:mm A'
|
||||
|
||||
// date_iso 'YYYY-MM-DD'
|
||||
// date_iso 'YYYY-MM-DD'
|
||||
|
||||
// date_long 'dddd, MMMM D, YYYY'
|
||||
// date_medium 'ddd, MMM D, YYYY'
|
||||
// date_short 'MMM D, YY'
|
||||
// date_long 'dddd, MMMM D, YYYY'
|
||||
// date_medium 'ddd, MMM D, YYYY'
|
||||
// date_short 'MMM D, YY'
|
||||
|
||||
// time_iso 'HH:mm:ss'
|
||||
// time_iso_12 'hh:mm:ss A'
|
||||
// time_iso_tz 'HH:mm:ss Z'
|
||||
// time_iso_12_tz 'hh:mm:ss A Z'
|
||||
// time_iso 'HH:mm:ss'
|
||||
// time_iso_12 'hh:mm:ss A'
|
||||
// time_iso_tz 'HH:mm:ss Z'
|
||||
// time_iso_12_tz 'hh:mm:ss A Z'
|
||||
|
||||
// time_long 'hh:mm:ss A'
|
||||
// time_medium 'h:m:s A'
|
||||
// time_short 'hh:mm A'
|
||||
// time_long 'hh:mm:ss A'
|
||||
// time_medium 'h:m:s A'
|
||||
// time_short 'hh:mm A'
|
||||
|
||||
// dayjs(raw_datetime).format('dddd, MMMM D, YYYY hh:mm:ss A');
|
||||
// dayjs(raw_datetime).format('dddd, MMMM D, YYYY hh:mm:ss A');
|
||||
|
||||
if (!raw_datetime) {
|
||||
raw_datetime = new Date(); // Get the current datetime if one was not passed.
|
||||
}
|
||||
if (!raw_datetime) {
|
||||
raw_datetime = new Date(); // Get the current datetime if one was not passed.
|
||||
}
|
||||
|
||||
let datetime_string = null;
|
||||
let datetime_string = null;
|
||||
|
||||
switch (named_format) {
|
||||
case 'datetime_iso':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD HH:mm:ss');
|
||||
break;
|
||||
case 'datetime_iso_no_seconds':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD HH:mm');
|
||||
break;
|
||||
case 'datetime_iso_12_short':
|
||||
datetime_string = dayjs(raw_datetime).format('YY-MM-DD hh:mm A');
|
||||
break;
|
||||
case 'datetime_iso_12_short_month':
|
||||
datetime_string = dayjs(raw_datetime).format('MM-DD hh:mm A');
|
||||
break;
|
||||
case 'datetime_iso_tz':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD HH:mm:ss Z');
|
||||
break;
|
||||
case 'datetime_iso_12_no_seconds':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD hh:mm A');
|
||||
break;
|
||||
// case 'datetime_12_no_seconds':
|
||||
// datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD hh:mm A');
|
||||
// break;
|
||||
case 'datetime_us':
|
||||
datetime_string = dayjs(raw_datetime).format('MM/DD/YYYY hh:mm:ss A');
|
||||
break;
|
||||
case 'datetime_short':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YY HH:mm');
|
||||
break;
|
||||
case 'datetime_12_short':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YY hh:mm A');
|
||||
break;
|
||||
case 'datetime_medium':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YYYY H:mm');
|
||||
break;
|
||||
case 'datetime_12_medium':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YYYY h:mm A');
|
||||
break;
|
||||
case 'datetime_long':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D, YYYY HH:mm');
|
||||
break;
|
||||
case 'datetime_12_long':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D, YYYY hh:mm A');
|
||||
break;
|
||||
case 'datetime_medium_sec':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YYYY H:mm:ss');
|
||||
break;
|
||||
case 'datetime_12_medium_sec':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YYYY h:mm:ss A');
|
||||
break;
|
||||
case 'datetime_short_month':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D hh:mm A');
|
||||
break;
|
||||
case 'datetime_long_month':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D hh:mm A');
|
||||
break;
|
||||
case 'datetime_short_day':
|
||||
datetime_string = dayjs(raw_datetime).format('D hh:mm A');
|
||||
break;
|
||||
case 'date_iso':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD');
|
||||
break;
|
||||
case 'date_us':
|
||||
datetime_string = dayjs(raw_datetime).format('MM/DD/YYYY');
|
||||
break;
|
||||
case 'date_long_month_day':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D');
|
||||
break;
|
||||
case 'date_short':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YY');
|
||||
break;
|
||||
case 'date_short_no_year':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D');
|
||||
break;
|
||||
case 'date_long':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D, YYYY');
|
||||
break;
|
||||
case 'date_full':
|
||||
datetime_string = dayjs(raw_datetime).format('dddd, MMMM D, YYYY');
|
||||
break;
|
||||
case 'date_full_no_year':
|
||||
datetime_string = dayjs(raw_datetime).format('dddd, MMMM D');
|
||||
break;
|
||||
case 'time_iso':
|
||||
datetime_string = dayjs(raw_datetime).format('HH:mm:ss');
|
||||
break;
|
||||
case 'time_iso_12_tz':
|
||||
datetime_string = dayjs(raw_datetime).format('hh:mm:ss A Z');
|
||||
break;
|
||||
case 'time_long':
|
||||
datetime_string = dayjs(raw_datetime).format('HH:mm:ss');
|
||||
break;
|
||||
case 'time_12_long':
|
||||
datetime_string = dayjs(raw_datetime).format('hh:mm:ss A');
|
||||
break;
|
||||
case 'time_short':
|
||||
datetime_string = dayjs(raw_datetime).format('HH:mm');
|
||||
break;
|
||||
case 'time_short_no_leading':
|
||||
datetime_string = dayjs(raw_datetime).format('H:mm');
|
||||
break;
|
||||
case 'time_12_short':
|
||||
datetime_string = dayjs(raw_datetime).format('hh:mm A');
|
||||
break;
|
||||
case 'time_12_short_no_leading':
|
||||
datetime_string = dayjs(raw_datetime).format('h:mm A');
|
||||
break;
|
||||
case 'week_long':
|
||||
datetime_string = dayjs(raw_datetime).format('dddd');
|
||||
break;
|
||||
case 'week_medium':
|
||||
datetime_string = dayjs(raw_datetime).format('ddd');
|
||||
break;
|
||||
case 'week_short':
|
||||
datetime_string = dayjs(raw_datetime).format('dd');
|
||||
break;
|
||||
default:
|
||||
// console.log(`The named format passed (${named_format}) did not match a common name. Trying to format with the named format value.`);
|
||||
datetime_string = dayjs(raw_datetime).format(named_format);
|
||||
// datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD HH:mm:ss');
|
||||
}
|
||||
return datetime_string;
|
||||
}
|
||||
switch (named_format) {
|
||||
case 'datetime_iso':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD HH:mm:ss');
|
||||
break;
|
||||
case 'datetime_iso_no_seconds':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD HH:mm');
|
||||
break;
|
||||
case 'datetime_iso_12_short':
|
||||
datetime_string = dayjs(raw_datetime).format('YY-MM-DD hh:mm A');
|
||||
break;
|
||||
case 'datetime_iso_12_short_month':
|
||||
datetime_string = dayjs(raw_datetime).format('MM-DD hh:mm A');
|
||||
break;
|
||||
case 'datetime_iso_tz':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD HH:mm:ss Z');
|
||||
break;
|
||||
case 'datetime_iso_12_no_seconds':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD hh:mm A');
|
||||
break;
|
||||
// case 'datetime_12_no_seconds':
|
||||
// datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD hh:mm A');
|
||||
// break;
|
||||
case 'datetime_us':
|
||||
datetime_string = dayjs(raw_datetime).format('MM/DD/YYYY hh:mm:ss A');
|
||||
break;
|
||||
case 'datetime_short':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YY HH:mm');
|
||||
break;
|
||||
case 'datetime_12_short':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YY hh:mm A');
|
||||
break;
|
||||
case 'datetime_medium':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YYYY H:mm');
|
||||
break;
|
||||
case 'datetime_12_medium':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YYYY h:mm A');
|
||||
break;
|
||||
case 'datetime_long':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D, YYYY HH:mm');
|
||||
break;
|
||||
case 'datetime_12_long':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D, YYYY hh:mm A');
|
||||
break;
|
||||
case 'datetime_medium_sec':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YYYY H:mm:ss');
|
||||
break;
|
||||
case 'datetime_12_medium_sec':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YYYY h:mm:ss A');
|
||||
break;
|
||||
case 'datetime_short_month':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D hh:mm A');
|
||||
break;
|
||||
case 'datetime_long_month':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D hh:mm A');
|
||||
break;
|
||||
case 'datetime_short_day':
|
||||
datetime_string = dayjs(raw_datetime).format('D hh:mm A');
|
||||
break;
|
||||
case 'date_iso':
|
||||
datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD');
|
||||
break;
|
||||
case 'date_us':
|
||||
datetime_string = dayjs(raw_datetime).format('MM/DD/YYYY');
|
||||
break;
|
||||
case 'date_long_month_day':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D');
|
||||
break;
|
||||
case 'date_short':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D, YY');
|
||||
break;
|
||||
case 'date_short_no_year':
|
||||
datetime_string = dayjs(raw_datetime).format('MMM D');
|
||||
break;
|
||||
case 'date_long':
|
||||
datetime_string = dayjs(raw_datetime).format('MMMM D, YYYY');
|
||||
break;
|
||||
case 'date_full':
|
||||
datetime_string = dayjs(raw_datetime).format('dddd, MMMM D, YYYY');
|
||||
break;
|
||||
case 'date_full_no_year':
|
||||
datetime_string = dayjs(raw_datetime).format('dddd, MMMM D');
|
||||
break;
|
||||
case 'time_iso':
|
||||
datetime_string = dayjs(raw_datetime).format('HH:mm:ss');
|
||||
break;
|
||||
case 'time_iso_12_tz':
|
||||
datetime_string = dayjs(raw_datetime).format('hh:mm:ss A Z');
|
||||
break;
|
||||
case 'time_long':
|
||||
datetime_string = dayjs(raw_datetime).format('HH:mm:ss');
|
||||
break;
|
||||
case 'time_12_long':
|
||||
datetime_string = dayjs(raw_datetime).format('hh:mm:ss A');
|
||||
break;
|
||||
case 'time_short':
|
||||
datetime_string = dayjs(raw_datetime).format('HH:mm');
|
||||
break;
|
||||
case 'time_short_no_leading':
|
||||
datetime_string = dayjs(raw_datetime).format('H:mm');
|
||||
break;
|
||||
case 'time_12_short':
|
||||
datetime_string = dayjs(raw_datetime).format('hh:mm A');
|
||||
break;
|
||||
case 'time_12_short_no_leading':
|
||||
datetime_string = dayjs(raw_datetime).format('h:mm A');
|
||||
break;
|
||||
case 'week_long':
|
||||
datetime_string = dayjs(raw_datetime).format('dddd');
|
||||
break;
|
||||
case 'week_medium':
|
||||
datetime_string = dayjs(raw_datetime).format('ddd');
|
||||
break;
|
||||
case 'week_short':
|
||||
datetime_string = dayjs(raw_datetime).format('dd');
|
||||
break;
|
||||
default:
|
||||
// console.log(`The named format passed (${named_format}) did not match a common name. Trying to format with the named format value.`);
|
||||
datetime_string = dayjs(raw_datetime).format(named_format);
|
||||
// datetime_string = dayjs(raw_datetime).format('YYYY-MM-DD HH:mm:ss');
|
||||
}
|
||||
return datetime_string;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
type key_val = {
|
||||
[key: string]: any;
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
/* This utility function looks for any form data with the prefixed name passed and returns a new object.
|
||||
@@ -11,118 +11,122 @@ type key_val = {
|
||||
* REMINDER: An unchecked checkbox will not be sent in the form data. This is a browser thing.
|
||||
* Updated 2023-12-22
|
||||
*/
|
||||
export let extract_prefixed_form_data = function extract_prefixed_form_data(
|
||||
{
|
||||
prefix = null,
|
||||
form_data = {},
|
||||
rm_empty_id = true,
|
||||
rm_empty = false,
|
||||
trim_values = false,
|
||||
bool_tf_str = false,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
prefix: string|null,
|
||||
form_data: any,
|
||||
rm_empty_id?: boolean,
|
||||
rm_empty?: boolean,
|
||||
trim_values?: boolean,
|
||||
bool_tf_str?: boolean,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log('*** extract_prefixed_form_data() ***');
|
||||
if (prefix) {
|
||||
console.log(`Looking for prefixed fields: ${prefix}; Removing emptry ID fields: ${rm_empty_id}; Removing empty fields: ${rm_empty}; Trim string values: ${trim_values}; Convert true/false string values to boolean: ${bool_tf_str}`);
|
||||
} else {
|
||||
console.log(`No prefix set. Looking at all fields. Removing emptry ID fields: ${rm_empty_id}; Removing empty fields: ${rm_empty}; Trim string values: ${trim_values}; Convert true/false string values to boolean: ${bool_tf_str}`);
|
||||
}
|
||||
}
|
||||
if (log_lvl > 1) {
|
||||
console.log('Form Data:');
|
||||
console.log(form_data);
|
||||
}
|
||||
export const extract_prefixed_form_data = function extract_prefixed_form_data({
|
||||
prefix = null,
|
||||
form_data = {},
|
||||
rm_empty_id = true,
|
||||
rm_empty = false,
|
||||
trim_values = false,
|
||||
bool_tf_str = false,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
prefix: string | null;
|
||||
form_data: any;
|
||||
rm_empty_id?: boolean;
|
||||
rm_empty?: boolean;
|
||||
trim_values?: boolean;
|
||||
bool_tf_str?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log('*** extract_prefixed_form_data() ***');
|
||||
if (prefix) {
|
||||
console.log(
|
||||
`Looking for prefixed fields: ${prefix}; Removing emptry ID fields: ${rm_empty_id}; Removing empty fields: ${rm_empty}; Trim string values: ${trim_values}; Convert true/false string values to boolean: ${bool_tf_str}`
|
||||
);
|
||||
} else {
|
||||
console.log(
|
||||
`No prefix set. Looking at all fields. Removing emptry ID fields: ${rm_empty_id}; Removing empty fields: ${rm_empty}; Trim string values: ${trim_values}; Convert true/false string values to boolean: ${bool_tf_str}`
|
||||
);
|
||||
}
|
||||
}
|
||||
if (log_lvl > 1) {
|
||||
console.log('Form Data:');
|
||||
console.log(form_data);
|
||||
}
|
||||
|
||||
// const data_obj: any = {}; // future TS
|
||||
let data_obj: key_val = {};
|
||||
for (let field of form_data) {
|
||||
let [obj_prop_name, obj_prop_value] = field;
|
||||
if (log_lvl > 1) {
|
||||
console.log(`${obj_prop_name}: ${obj_prop_value} type=${typeof obj_prop_value}`);
|
||||
}
|
||||
// const data_obj: any = {}; // future TS
|
||||
const data_obj: key_val = {};
|
||||
for (const field of form_data) {
|
||||
let [obj_prop_name, obj_prop_value] = field;
|
||||
if (log_lvl > 1) {
|
||||
console.log(`${obj_prop_name}: ${obj_prop_value} type=${typeof obj_prop_value}`);
|
||||
}
|
||||
|
||||
// Trim string values if needed
|
||||
if (trim_values && typeof obj_prop_value === 'string') {
|
||||
if (log_lvl && obj_prop_value.trim() != obj_prop_value) {
|
||||
console.log('Trimming string value!');
|
||||
obj_prop_value = obj_prop_value.trim();
|
||||
}
|
||||
}
|
||||
// Trim string values if needed
|
||||
if (trim_values && typeof obj_prop_value === 'string') {
|
||||
if (log_lvl && obj_prop_value.trim() != obj_prop_value) {
|
||||
console.log('Trimming string value!');
|
||||
obj_prop_value = obj_prop_value.trim();
|
||||
}
|
||||
}
|
||||
|
||||
// Convert string to boolean if needed
|
||||
if (bool_tf_str && typeof obj_prop_value === 'string') {
|
||||
// console.log('Flag set for converting true/false string values to boolean!');
|
||||
// Convert string to boolean if needed
|
||||
if (bool_tf_str && typeof obj_prop_value === 'string') {
|
||||
// console.log('Flag set for converting true/false string values to boolean!');
|
||||
|
||||
if (obj_prop_value.toLowerCase() === 'true') {
|
||||
if (log_lvl) {
|
||||
console.log('Converting string to boolean value: true');
|
||||
}
|
||||
obj_prop_value = true;
|
||||
} else if (obj_prop_value.toLowerCase() === 'false') {
|
||||
if (log_lvl) {
|
||||
console.log('Converting string to boolean value: false');
|
||||
}
|
||||
obj_prop_value = false;
|
||||
}
|
||||
}
|
||||
if (obj_prop_value.toLowerCase() === 'true') {
|
||||
if (log_lvl) {
|
||||
console.log('Converting string to boolean value: true');
|
||||
}
|
||||
obj_prop_value = true;
|
||||
} else if (obj_prop_value.toLowerCase() === 'false') {
|
||||
if (log_lvl) {
|
||||
console.log('Converting string to boolean value: false');
|
||||
}
|
||||
obj_prop_value = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix && obj_prop_name.startsWith(prefix)) { // Prefix set
|
||||
// if (obj_prop_name.startsWith(prefix)) {
|
||||
obj_prop_name = obj_prop_name.replace(prefix, '');
|
||||
if (log_lvl) {
|
||||
console.log(`Checking: (${prefix})${obj_prop_name} value=${obj_prop_value}`);
|
||||
}
|
||||
if (rm_empty_id && obj_prop_name.endsWith('id_random') && !obj_prop_value) {
|
||||
if (log_lvl) {
|
||||
console.log(`Match but empty *_id_random. Ignoring/removing: ${obj_prop_name}`);
|
||||
}
|
||||
} else if (rm_empty && !obj_prop_value) {
|
||||
if (log_lvl) {
|
||||
console.log(`Match but empty. Ignoring/removing: ${obj_prop_name}`);
|
||||
}
|
||||
} else {
|
||||
if (log_lvl) {
|
||||
console.log(`Match: ${prefix})${obj_prop_name} value=${obj_prop_value}`);
|
||||
}
|
||||
data_obj[obj_prop_name] = obj_prop_value;
|
||||
}
|
||||
} else if (prefix && !obj_prop_name.startsWith(prefix)) { // Prefix set
|
||||
if (log_lvl > 1) {
|
||||
console.log('Did not start with prefix. Ignoring');
|
||||
}
|
||||
} else { // No prefix set
|
||||
if (log_lvl) {
|
||||
console.log(`Checking: ${obj_prop_name} value=${obj_prop_value}`);
|
||||
}
|
||||
if (rm_empty_id && obj_prop_name.endsWith('id_random') && !obj_prop_value) {
|
||||
if (log_lvl > 1) {
|
||||
console.log(`Match but empty *_id_random. Ignoring/removing: ${obj_prop_name}`);
|
||||
}
|
||||
} else if (rm_empty && !obj_prop_value) {
|
||||
if (log_lvl > 1) {
|
||||
console.log(`Match but empty. Ignoring/removing: ${obj_prop_name}`);
|
||||
}
|
||||
} else {
|
||||
if (log_lvl > 1) {
|
||||
console.log(`Match: ${obj_prop_name} value=${obj_prop_value}`);
|
||||
}
|
||||
data_obj[obj_prop_name] = obj_prop_value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (log_lvl > 1) {
|
||||
console.log(data_obj);
|
||||
}
|
||||
return data_obj;
|
||||
}
|
||||
if (prefix && obj_prop_name.startsWith(prefix)) {
|
||||
// Prefix set
|
||||
// if (obj_prop_name.startsWith(prefix)) {
|
||||
obj_prop_name = obj_prop_name.replace(prefix, '');
|
||||
if (log_lvl) {
|
||||
console.log(`Checking: (${prefix})${obj_prop_name} value=${obj_prop_value}`);
|
||||
}
|
||||
if (rm_empty_id && obj_prop_name.endsWith('id_random') && !obj_prop_value) {
|
||||
if (log_lvl) {
|
||||
console.log(`Match but empty *_id_random. Ignoring/removing: ${obj_prop_name}`);
|
||||
}
|
||||
} else if (rm_empty && !obj_prop_value) {
|
||||
if (log_lvl) {
|
||||
console.log(`Match but empty. Ignoring/removing: ${obj_prop_name}`);
|
||||
}
|
||||
} else {
|
||||
if (log_lvl) {
|
||||
console.log(`Match: ${prefix})${obj_prop_name} value=${obj_prop_value}`);
|
||||
}
|
||||
data_obj[obj_prop_name] = obj_prop_value;
|
||||
}
|
||||
} else if (prefix && !obj_prop_name.startsWith(prefix)) {
|
||||
// Prefix set
|
||||
if (log_lvl > 1) {
|
||||
console.log('Did not start with prefix. Ignoring');
|
||||
}
|
||||
} else {
|
||||
// No prefix set
|
||||
if (log_lvl) {
|
||||
console.log(`Checking: ${obj_prop_name} value=${obj_prop_value}`);
|
||||
}
|
||||
if (rm_empty_id && obj_prop_name.endsWith('id_random') && !obj_prop_value) {
|
||||
if (log_lvl > 1) {
|
||||
console.log(`Match but empty *_id_random. Ignoring/removing: ${obj_prop_name}`);
|
||||
}
|
||||
} else if (rm_empty && !obj_prop_value) {
|
||||
if (log_lvl > 1) {
|
||||
console.log(`Match but empty. Ignoring/removing: ${obj_prop_name}`);
|
||||
}
|
||||
} else {
|
||||
if (log_lvl > 1) {
|
||||
console.log(`Match: ${obj_prop_name} value=${obj_prop_value}`);
|
||||
}
|
||||
data_obj[obj_prop_name] = obj_prop_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (log_lvl > 1) {
|
||||
console.log(data_obj);
|
||||
}
|
||||
return data_obj;
|
||||
};
|
||||
|
||||
@@ -1,51 +1,50 @@
|
||||
import type { key_str } from "./ae_utils";
|
||||
import type { key_str } from './ae_utils';
|
||||
|
||||
// Updated 2024-06-19
|
||||
export function file_extension_icon(
|
||||
extension: string) {
|
||||
// console.log('*** file_extension_icon() ***');
|
||||
let file_icons: key_str = {
|
||||
'file': 'file',
|
||||
'3gp': 'file-video',
|
||||
'7z': 'file-archive',
|
||||
'aac': 'file-audio',
|
||||
'ac3': 'file-audio',
|
||||
'aif': 'file-audio',
|
||||
'aiff': 'file-audio',
|
||||
'avi': 'file-video',
|
||||
'bmp': 'file-image',
|
||||
'csv': 'file-csv',
|
||||
'doc': 'file-word',
|
||||
'docx': 'file-word',
|
||||
'eps': 'file-image',
|
||||
'flac': 'file-audio',
|
||||
'gif': 'file-image',
|
||||
'htm': 'file-code',
|
||||
'html': 'file-code',
|
||||
'jpeg': 'file-image',
|
||||
'jpg': 'file-image',
|
||||
'key': 'file-powerpoint',
|
||||
'mkv': 'file-video',
|
||||
'mov': 'file-video',
|
||||
'mp3': 'file-audio',
|
||||
'mp4': 'file-video',
|
||||
'odp': 'file-powerpoint',
|
||||
'pdf': 'file-pdf',
|
||||
'png': 'file-image',
|
||||
'ppt': 'file-powerpoint',
|
||||
'pptx': 'file-powerpoint',
|
||||
'txt': 'file-alt',
|
||||
'wav': 'file-audio',
|
||||
'webp': 'file-image',
|
||||
'xls': 'file-excel',
|
||||
'xlsx': 'file-excel',
|
||||
'zip': 'file-archive'
|
||||
};
|
||||
export function file_extension_icon(extension: string) {
|
||||
// console.log('*** file_extension_icon() ***');
|
||||
const file_icons: key_str = {
|
||||
file: 'file',
|
||||
'3gp': 'file-video',
|
||||
'7z': 'file-archive',
|
||||
aac: 'file-audio',
|
||||
ac3: 'file-audio',
|
||||
aif: 'file-audio',
|
||||
aiff: 'file-audio',
|
||||
avi: 'file-video',
|
||||
bmp: 'file-image',
|
||||
csv: 'file-csv',
|
||||
doc: 'file-word',
|
||||
docx: 'file-word',
|
||||
eps: 'file-image',
|
||||
flac: 'file-audio',
|
||||
gif: 'file-image',
|
||||
htm: 'file-code',
|
||||
html: 'file-code',
|
||||
jpeg: 'file-image',
|
||||
jpg: 'file-image',
|
||||
key: 'file-powerpoint',
|
||||
mkv: 'file-video',
|
||||
mov: 'file-video',
|
||||
mp3: 'file-audio',
|
||||
mp4: 'file-video',
|
||||
odp: 'file-powerpoint',
|
||||
pdf: 'file-pdf',
|
||||
png: 'file-image',
|
||||
ppt: 'file-powerpoint',
|
||||
pptx: 'file-powerpoint',
|
||||
txt: 'file-alt',
|
||||
wav: 'file-audio',
|
||||
webp: 'file-image',
|
||||
xls: 'file-excel',
|
||||
xlsx: 'file-excel',
|
||||
zip: 'file-archive'
|
||||
};
|
||||
|
||||
if (file_icons[extension]) {
|
||||
return file_icons[extension];
|
||||
} else {
|
||||
// return null;
|
||||
return file_icons['file'];
|
||||
}
|
||||
if (file_icons[extension]) {
|
||||
return file_icons[extension];
|
||||
} else {
|
||||
// return null;
|
||||
return file_icons['file'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,85 +2,85 @@
|
||||
|
||||
// Use a defined list of unacceptable characters to remove from a filename.
|
||||
// Updated 2024-10-18
|
||||
export let clean_filename = function clean_filename(filename: any|string, unacceptable_chars: RegExp = /[ <>:"/\\|?*]/g, replacement_char: string = '_') {
|
||||
// console.log('*** clean_filename() ***');
|
||||
if (!filename) {
|
||||
return '';
|
||||
}
|
||||
export const clean_filename = function clean_filename(
|
||||
filename: any | string,
|
||||
unacceptable_chars: RegExp = /[ <>:"/\\|?*]/g,
|
||||
replacement_char: string = '_'
|
||||
) {
|
||||
// console.log('*** clean_filename() ***');
|
||||
if (!filename) {
|
||||
return '';
|
||||
}
|
||||
|
||||
let cleaned_filename = filename.replace(unacceptable_chars, replacement_char);
|
||||
// console.log(cleaned_filename);
|
||||
return cleaned_filename;
|
||||
}
|
||||
const cleaned_filename = filename.replace(unacceptable_chars, replacement_char);
|
||||
// console.log(cleaned_filename);
|
||||
return cleaned_filename;
|
||||
};
|
||||
|
||||
export const format_bytes = function format_bytes(bytes: number, decimals: number = 2) {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
|
||||
export let format_bytes = function format_bytes(
|
||||
bytes: number,
|
||||
decimals: number = 2
|
||||
) {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
const k = 1024;
|
||||
const dm = decimals < 0 ? 0 : decimals;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
|
||||
const k = 1024;
|
||||
const dm = decimals < 0 ? 0 : decimals;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
||||
}
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
||||
};
|
||||
|
||||
// Updated 2024-08-12
|
||||
export let guess_file_name = function guess_file_name(filename_string: string) {
|
||||
// console.log('*** guess_file_name() ***');
|
||||
if (!filename_string) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (filename_string.includes('.')) {
|
||||
let file_name = filename_string.substring(0, filename_string.lastIndexOf('.'));
|
||||
// console.log(file_name);
|
||||
return file_name;
|
||||
} else {
|
||||
return filename_string;
|
||||
}
|
||||
}
|
||||
export const guess_file_name = function guess_file_name(filename_string: string) {
|
||||
// console.log('*** guess_file_name() ***');
|
||||
if (!filename_string) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (filename_string.includes('.')) {
|
||||
const file_name = filename_string.substring(0, filename_string.lastIndexOf('.'));
|
||||
// console.log(file_name);
|
||||
return file_name;
|
||||
} else {
|
||||
return filename_string;
|
||||
}
|
||||
};
|
||||
|
||||
// Updated 2024-08-12
|
||||
export let guess_file_extension = function guess_file_extension(filename_string: string) {
|
||||
// console.log('*** guess_file_extension() ***');
|
||||
if (!filename_string) {
|
||||
return '';
|
||||
}
|
||||
export const guess_file_extension = function guess_file_extension(filename_string: string) {
|
||||
// console.log('*** guess_file_extension() ***');
|
||||
if (!filename_string) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!filename_string.includes('.')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
let file_extension = filename_string.substring(filename_string.lastIndexOf('.') + 1, filename_string.length) || filename_string;
|
||||
// console.log(file_extension);
|
||||
return file_extension;
|
||||
}
|
||||
if (!filename_string.includes('.')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const file_extension =
|
||||
filename_string.substring(filename_string.lastIndexOf('.') + 1, filename_string.length) ||
|
||||
filename_string;
|
||||
// console.log(file_extension);
|
||||
return file_extension;
|
||||
};
|
||||
|
||||
// Updated 2024-08-12
|
||||
export let get_file_hash = async function get_file_hash(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let file_reader = new FileReader();
|
||||
export const get_file_hash = async function get_file_hash(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const file_reader = new FileReader();
|
||||
|
||||
file_reader.onload = async function() {
|
||||
if (file_reader.result.byteLength !== file.size) {
|
||||
console.log('File was not read completely');
|
||||
reject("Error reading the file");
|
||||
}
|
||||
file_reader.onload = async function () {
|
||||
if (file_reader.result.byteLength !== file.size) {
|
||||
console.log('File was not read completely');
|
||||
reject('Error reading the file');
|
||||
}
|
||||
|
||||
const hash_buffer = await crypto.subtle.digest('SHA-256', file_reader.result);
|
||||
const hash_array = Array.from(new Uint8Array(hash_buffer));
|
||||
const hash_hex = hash_array.map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
const hash_buffer = await crypto.subtle.digest('SHA-256', file_reader.result);
|
||||
const hash_array = Array.from(new Uint8Array(hash_buffer));
|
||||
const hash_hex = hash_array.map((b) => b.toString(16).padStart(2, '0')).join('');
|
||||
|
||||
resolve(hash_hex);
|
||||
};
|
||||
resolve(hash_hex);
|
||||
};
|
||||
|
||||
file_reader.readAsArrayBuffer(file);
|
||||
});
|
||||
}
|
||||
file_reader.readAsArrayBuffer(file);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,46 +1,43 @@
|
||||
|
||||
/* Returns a list of objects that have a matching property value. */
|
||||
// Updated 2023-06-28
|
||||
export let get_obj_li_w_match_prop = function get_obj_li_w_match_prop(
|
||||
{
|
||||
obj_li,
|
||||
property,
|
||||
value,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_li: any[],
|
||||
property: string,
|
||||
value: any,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log('Search Object List:', obj_li);
|
||||
console.log(`Property: ${property}`);
|
||||
console.log(`Value: ${value}`);
|
||||
}
|
||||
if (log_lvl > 1) {
|
||||
console.log(`Type Of: ${typeof value}`);
|
||||
}
|
||||
export const get_obj_li_w_match_prop = function get_obj_li_w_match_prop({
|
||||
obj_li,
|
||||
property,
|
||||
value,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_li: any[];
|
||||
property: string;
|
||||
value: any;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log('Search Object List:', obj_li);
|
||||
console.log(`Property: ${property}`);
|
||||
console.log(`Value: ${value}`);
|
||||
}
|
||||
if (log_lvl > 1) {
|
||||
console.log(`Type Of: ${typeof value}`);
|
||||
}
|
||||
|
||||
// Create an empty array to store the matching objects.
|
||||
const matching_obj_li = [];
|
||||
// Create an empty array to store the matching objects.
|
||||
const matching_obj_li = [];
|
||||
|
||||
// Iterate through the list of objects.
|
||||
for (const object of obj_li) {
|
||||
// Check if the object has the specified property and the value of the property matches the specified value.
|
||||
if (object.hasOwnProperty(property)) {
|
||||
// console.log('Has property at least....', object[property], typeof object[property]);
|
||||
}
|
||||
if (object.hasOwnProperty(property) && object[property] === value) {
|
||||
// Add the object to the array of matching objects.
|
||||
matching_obj_li.push(object);
|
||||
}
|
||||
}
|
||||
// Iterate through the list of objects.
|
||||
for (const object of obj_li) {
|
||||
// Check if the object has the specified property and the value of the property matches the specified value.
|
||||
if (object.hasOwnProperty(property)) {
|
||||
// console.log('Has property at least....', object[property], typeof object[property]);
|
||||
}
|
||||
if (object.hasOwnProperty(property) && object[property] === value) {
|
||||
// Add the object to the array of matching objects.
|
||||
matching_obj_li.push(object);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the array of matching objects.
|
||||
if (log_lvl > 1) {
|
||||
console.log('Matching Object List:', matching_obj_li);
|
||||
}
|
||||
return matching_obj_li;
|
||||
}
|
||||
// Return the array of matching objects.
|
||||
if (log_lvl > 1) {
|
||||
console.log('Matching Object List:', matching_obj_li);
|
||||
}
|
||||
return matching_obj_li;
|
||||
};
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
// Function to check if the file (or anything) timestamp was created within the last X minutes
|
||||
export let is_datetime_recent = function is_datetime_recent(
|
||||
{
|
||||
datetime,
|
||||
minutes,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
datetime: string,
|
||||
minutes: number,
|
||||
log_lvl?: number
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** is_datetime_recent() *** datetime=${datetime} minutes=${minutes}`);
|
||||
}
|
||||
export const is_datetime_recent = function is_datetime_recent({
|
||||
datetime,
|
||||
minutes,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
datetime: string;
|
||||
minutes: number;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** is_datetime_recent() *** datetime=${datetime} minutes=${minutes}`);
|
||||
}
|
||||
|
||||
let now: any = new Date();
|
||||
let then: any = new Date(datetime);
|
||||
const now: any = new Date();
|
||||
const then: any = new Date(datetime);
|
||||
|
||||
let diff = now - then;
|
||||
let diff_minutes = Math.floor(diff / 60000);
|
||||
const diff = now - then;
|
||||
const diff_minutes = Math.floor(diff / 60000);
|
||||
|
||||
if (diff_minutes < minutes) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (diff_minutes < minutes) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,199 +1,199 @@
|
||||
type key_val = {
|
||||
[key: string]: any;
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
// NOTE: I know there is a better more efficient way to do this, but I don't have time for that right now.
|
||||
export let process_permission_checks = function process_permission_checks(access_type: string) {
|
||||
// let access_checks = { 'access_type': null, 'super_check': null };
|
||||
let access_checks: key_val = {};
|
||||
export const process_permission_checks = function process_permission_checks(access_type: string) {
|
||||
// let access_checks = { 'access_type': null, 'super_check': null };
|
||||
const access_checks: key_val = {};
|
||||
|
||||
if (access_type == 'super') {
|
||||
access_checks.allow_access = true;
|
||||
access_checks.access_type = 'super';
|
||||
if (access_type == 'super') {
|
||||
access_checks.allow_access = true;
|
||||
access_checks.access_type = 'super';
|
||||
|
||||
access_checks.super_check = true;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = true;
|
||||
access_checks.anonymous_check = false;
|
||||
access_checks.super_check = true;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = true;
|
||||
access_checks.anonymous_check = false;
|
||||
|
||||
access_checks.super_access = true;
|
||||
access_checks.manager_access = true;
|
||||
access_checks.administrator_access = true;
|
||||
access_checks.support_access = true;
|
||||
access_checks.assistant_access = true;
|
||||
access_checks.trusted_access = true;
|
||||
access_checks.verified_access = true;
|
||||
access_checks.provisional_access = true;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'manager') {
|
||||
access_checks.allow_access = true;
|
||||
access_checks.access_type = 'manager';
|
||||
access_checks.super_access = true;
|
||||
access_checks.manager_access = true;
|
||||
access_checks.administrator_access = true;
|
||||
access_checks.support_access = true;
|
||||
access_checks.assistant_access = true;
|
||||
access_checks.trusted_access = true;
|
||||
access_checks.verified_access = true;
|
||||
access_checks.provisional_access = true;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'manager') {
|
||||
access_checks.allow_access = true;
|
||||
access_checks.access_type = 'manager';
|
||||
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = true;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = true;
|
||||
access_checks.anonymous_check = false;
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = true;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = true;
|
||||
access_checks.anonymous_check = false;
|
||||
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = true;
|
||||
access_checks.administrator_access = true;
|
||||
access_checks.support_access = true;
|
||||
access_checks.assistant_access = true;
|
||||
access_checks.trusted_access = true;
|
||||
access_checks.verified_access = true;
|
||||
access_checks.provisional_access = true;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'administrator') {
|
||||
access_checks.allow_access = true;
|
||||
access_checks.access_type = 'administrator';
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = true;
|
||||
access_checks.administrator_access = true;
|
||||
access_checks.support_access = true;
|
||||
access_checks.assistant_access = true;
|
||||
access_checks.trusted_access = true;
|
||||
access_checks.verified_access = true;
|
||||
access_checks.provisional_access = true;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'administrator') {
|
||||
access_checks.allow_access = true;
|
||||
access_checks.access_type = 'administrator';
|
||||
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = true;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = false;
|
||||
access_checks.anonymous_check = false;
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = true;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = false;
|
||||
access_checks.anonymous_check = false;
|
||||
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = true;
|
||||
access_checks.support_access = true;
|
||||
access_checks.assistant_access = true;
|
||||
access_checks.trusted_access = true;
|
||||
access_checks.verified_access = true;
|
||||
access_checks.provisional_access = true;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'trusted') {
|
||||
access_checks.allow_access = true; // Should this be true?? -2024-10-03
|
||||
access_checks.access_type = 'trusted';
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = true;
|
||||
access_checks.support_access = true;
|
||||
access_checks.assistant_access = true;
|
||||
access_checks.trusted_access = true;
|
||||
access_checks.verified_access = true;
|
||||
access_checks.provisional_access = true;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'trusted') {
|
||||
access_checks.allow_access = true; // Should this be true?? -2024-10-03
|
||||
access_checks.access_type = 'trusted';
|
||||
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = true;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = true;
|
||||
access_checks.anonymous_check = false;
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = true;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = true;
|
||||
access_checks.anonymous_check = false;
|
||||
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = false;
|
||||
access_checks.support_access = false;
|
||||
access_checks.assistant_access = false;
|
||||
access_checks.trusted_access = true;
|
||||
access_checks.verified_access = true;
|
||||
access_checks.provisional_access = true;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'public') {
|
||||
access_checks.access_type = 'public';
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = false;
|
||||
access_checks.support_access = false;
|
||||
access_checks.assistant_access = false;
|
||||
access_checks.trusted_access = true;
|
||||
access_checks.verified_access = true;
|
||||
access_checks.provisional_access = true;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'public') {
|
||||
access_checks.access_type = 'public';
|
||||
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = true;
|
||||
access_checks.authenticated_check = false;
|
||||
access_checks.anonymous_check = false;
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = true;
|
||||
access_checks.authenticated_check = false;
|
||||
access_checks.anonymous_check = false;
|
||||
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = false;
|
||||
access_checks.support_access = false;
|
||||
access_checks.assistant_access = false;
|
||||
access_checks.trusted_access = false;
|
||||
access_checks.verified_access = false;
|
||||
access_checks.provisional_access = false;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'authenticated') {
|
||||
access_checks.access_type = 'authenticated';
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = false;
|
||||
access_checks.support_access = false;
|
||||
access_checks.assistant_access = false;
|
||||
access_checks.trusted_access = false;
|
||||
access_checks.verified_access = false;
|
||||
access_checks.provisional_access = false;
|
||||
access_checks.public_access = true;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else if (access_type == 'authenticated') {
|
||||
access_checks.access_type = 'authenticated';
|
||||
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = true;
|
||||
access_checks.anonymous_check = false;
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = true;
|
||||
access_checks.anonymous_check = false;
|
||||
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = false;
|
||||
access_checks.support_access = false;
|
||||
access_checks.assistant_access = false;
|
||||
access_checks.trusted_access = false;
|
||||
access_checks.verified_access = false;
|
||||
access_checks.provisional_access = false;
|
||||
access_checks.public_access = false;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else {
|
||||
access_checks.access_type = 'anonymous';
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = false;
|
||||
access_checks.support_access = false;
|
||||
access_checks.assistant_access = false;
|
||||
access_checks.trusted_access = false;
|
||||
access_checks.verified_access = false;
|
||||
access_checks.provisional_access = false;
|
||||
access_checks.public_access = false;
|
||||
access_checks.authenticated_access = true;
|
||||
access_checks.anonymous_access = true;
|
||||
} else {
|
||||
access_checks.access_type = 'anonymous';
|
||||
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = false;
|
||||
access_checks.anonymous_check = true;
|
||||
access_checks.super_check = false;
|
||||
access_checks.manager_check = false;
|
||||
access_checks.administrator_check = false;
|
||||
access_checks.support_check = false;
|
||||
access_checks.assistant_check = false;
|
||||
access_checks.trusted_check = false;
|
||||
access_checks.verified_check = false;
|
||||
access_checks.provisional_check = false;
|
||||
access_checks.public_check = false;
|
||||
access_checks.authenticated_check = false;
|
||||
access_checks.anonymous_check = true;
|
||||
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = false;
|
||||
access_checks.support_access = false;
|
||||
access_checks.assistant_access = false;
|
||||
access_checks.trusted_access = false;
|
||||
access_checks.verified_access = false;
|
||||
access_checks.provisional_access = false;
|
||||
access_checks.public_access = false;
|
||||
access_checks.authenticated_access = false;
|
||||
access_checks.anonymous_access = true;
|
||||
}
|
||||
access_checks.super_access = false;
|
||||
access_checks.manager_access = false;
|
||||
access_checks.administrator_access = false;
|
||||
access_checks.support_access = false;
|
||||
access_checks.assistant_access = false;
|
||||
access_checks.trusted_access = false;
|
||||
access_checks.verified_access = false;
|
||||
access_checks.provisional_access = false;
|
||||
access_checks.public_access = false;
|
||||
access_checks.authenticated_access = false;
|
||||
access_checks.anonymous_access = true;
|
||||
}
|
||||
|
||||
return access_checks;
|
||||
}
|
||||
return access_checks;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { key_val } from "./ae_utils";
|
||||
import type { key_val } from './ae_utils';
|
||||
|
||||
/* This utility function processes specific data string.
|
||||
* MECARD
|
||||
@@ -14,78 +14,77 @@ import type { key_val } from "./ae_utils";
|
||||
* gn: Given First Name
|
||||
* fn: Family Last Name
|
||||
* em: Email Address
|
||||
*/
|
||||
*/
|
||||
// Updated 2022-02-11
|
||||
|
||||
export const process_data_string = function process_data_string(data_string: string) {
|
||||
console.log('*** process_data_string() ***');
|
||||
// console.log(data_string);
|
||||
if (!data_string || data_string.length < 1) {
|
||||
console.log('No data string found.');
|
||||
return false;
|
||||
}
|
||||
|
||||
export let process_data_string = function process_data_string(data_string: string) {
|
||||
console.log('*** process_data_string() ***');
|
||||
// console.log(data_string);
|
||||
if (!data_string || data_string.length < 1) {
|
||||
console.log('No data string found.');
|
||||
return false;
|
||||
}
|
||||
const obj: key_val = {};
|
||||
|
||||
let obj: key_val = {};
|
||||
const colon_index = data_string.indexOf(':');
|
||||
if (colon_index) {
|
||||
const data_string_type = data_string.slice(0, colon_index);
|
||||
console.log(data_string_type);
|
||||
|
||||
let colon_index = data_string.indexOf(':');
|
||||
if (colon_index) {
|
||||
let data_string_type = data_string.slice(0, colon_index);
|
||||
console.log(data_string_type);
|
||||
obj['qr_type'] = data_string_type;
|
||||
|
||||
obj['qr_type'] = data_string_type;
|
||||
if (data_string_type == 'MECARD') {
|
||||
const mecard_str = data_string.slice(colon_index + 1);
|
||||
console.log(mecard_str);
|
||||
|
||||
if (data_string_type == 'MECARD') {
|
||||
let mecard_str = data_string.slice(colon_index + 1);
|
||||
console.log(mecard_str);
|
||||
obj['str'] = mecard_str;
|
||||
} else if (data_string_type == 'OBJ') {
|
||||
const key_value_str = data_string.slice(colon_index + 1);
|
||||
console.log(key_value_str);
|
||||
const key_value_array = key_value_str.split(',');
|
||||
// console.log(key_value_array);
|
||||
const ot_colon_index = key_value_array[0].indexOf(':');
|
||||
const obj_type = key_value_array[0].slice(ot_colon_index + 1);
|
||||
// console.log(obj_type);
|
||||
const oi_colon_index = key_value_array[1].indexOf(':');
|
||||
const obj_id = key_value_array[1].slice(oi_colon_index + 1);
|
||||
// console.log(obj_id);
|
||||
obj['type'] = obj_type;
|
||||
obj['id'] = obj_id;
|
||||
} else if (data_string_type == 'JSON') {
|
||||
const partial_json_str = data_string.slice(colon_index + 1);
|
||||
console.log(partial_json_str);
|
||||
const json_str = `{${partial_json_str}}`;
|
||||
console.log(json_str);
|
||||
|
||||
obj['str'] = mecard_str;
|
||||
} else if (data_string_type == 'OBJ') {
|
||||
let key_value_str = data_string.slice(colon_index + 1);
|
||||
console.log(key_value_str);
|
||||
let key_value_array = key_value_str.split(',');
|
||||
// console.log(key_value_array);
|
||||
let ot_colon_index = key_value_array[0].indexOf(':');
|
||||
let obj_type = key_value_array[0].slice(ot_colon_index + 1);
|
||||
// console.log(obj_type);
|
||||
let oi_colon_index = key_value_array[1].indexOf(':');
|
||||
let obj_id = key_value_array[1].slice(oi_colon_index + 1);
|
||||
// console.log(obj_id);
|
||||
obj['type'] = obj_type;
|
||||
obj['id'] = obj_id;
|
||||
} else if (data_string_type == 'JSON') {
|
||||
let partial_json_str = data_string.slice(colon_index + 1);
|
||||
console.log(partial_json_str);
|
||||
let json_str = `{${partial_json_str}}`;
|
||||
console.log(json_str);
|
||||
obj['json'] = JSON.parse(json_str);
|
||||
} else if (data_string_type == 'STR') {
|
||||
const str = data_string.slice(colon_index + 1);
|
||||
console.log(str);
|
||||
|
||||
obj['json'] = JSON.parse(json_str);
|
||||
} else if (data_string_type == 'STR') {
|
||||
let str = data_string.slice(colon_index + 1);
|
||||
console.log(str);
|
||||
obj['str'] = str;
|
||||
} else if (data_string_type == 'http' || data_string_type == 'https') {
|
||||
console.log(`http or https: ${data_string}`);
|
||||
|
||||
obj['str'] = str;
|
||||
} else if (data_string_type == 'http' || data_string_type == 'https') {
|
||||
console.log(`http or https: ${data_string}`);
|
||||
obj['type'] = 'url';
|
||||
obj['url'] = data_string;
|
||||
} else {
|
||||
console.log('The unknown data string type was found. Returning the string part.');
|
||||
const unknown_str = data_string.slice(colon_index + 1);
|
||||
console.log(unknown_str);
|
||||
|
||||
obj['type'] = 'url';
|
||||
obj['url'] = data_string;
|
||||
} else {
|
||||
console.log('The unknown data string type was found. Returning the string part.');
|
||||
let unknown_str = data_string.slice(colon_index + 1);
|
||||
console.log(unknown_str);
|
||||
obj['str'] = unknown_str;
|
||||
}
|
||||
} else {
|
||||
console.log('The data string type was not found. Returning the entire string.');
|
||||
console.log(data_string);
|
||||
|
||||
obj['str'] = unknown_str;
|
||||
}
|
||||
} else {
|
||||
console.log('The data string type was not found. Returning the entire string.');
|
||||
console.log(data_string);
|
||||
obj['qr_type'] = 'UNKNOWN';
|
||||
obj['str'] = data_string;
|
||||
// return false;
|
||||
}
|
||||
|
||||
obj['qr_type'] = 'UNKNOWN';
|
||||
obj['str'] = data_string;
|
||||
// return false;
|
||||
}
|
||||
|
||||
console.log(obj);
|
||||
return obj; // Returns an object
|
||||
console.log(obj);
|
||||
return obj; // Returns an object
|
||||
};
|
||||
|
||||
@@ -1,66 +1,87 @@
|
||||
export function return_obj_type_path({ obj_type = null, obj_type_prop_name = null }) {
|
||||
console.log('*** return_obj_type_path() ***');
|
||||
console.log('*** return_obj_type_path() ***');
|
||||
|
||||
let obj_type_path = null;
|
||||
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'];
|
||||
const 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' },
|
||||
];
|
||||
const 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('_', '/');
|
||||
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;
|
||||
|
||||
} 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;
|
||||
}
|
||||
|
||||
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;
|
||||
return obj_type_path;
|
||||
}
|
||||
|
||||
@@ -1,98 +1,124 @@
|
||||
import { to_title_case } from "./ae_utils__to_title_case";
|
||||
import { to_title_case } from './ae_utils__to_title_case';
|
||||
|
||||
// Updated 2023-08-18
|
||||
export 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() ***');
|
||||
export 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;
|
||||
}
|
||||
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'];
|
||||
const 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'
|
||||
];
|
||||
|
||||
const 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 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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// 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, '');
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if (obj_type) {
|
||||
// prop_display_name = prop_name.replace(obj_type, '');
|
||||
// } else {
|
||||
}
|
||||
}
|
||||
|
||||
// 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');
|
||||
|
||||
// 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 (replace_underscores) {
|
||||
prop_display_name = prop_display_name.replaceAll('_', ' ');
|
||||
}
|
||||
if (title_case) {
|
||||
prop_display_name = to_title_case(prop_display_name);
|
||||
}
|
||||
|
||||
if (title_case) {
|
||||
prop_display_name = to_title_case(prop_display_name);
|
||||
}
|
||||
|
||||
// console.log(prop_display_name);
|
||||
return prop_display_name;
|
||||
// console.log(prop_display_name);
|
||||
return prop_display_name;
|
||||
}
|
||||
|
||||
@@ -1,42 +1,43 @@
|
||||
/* Adapted from: To Title Case © 2018 David Gouch | https://github.com/gouch/to-title-case */
|
||||
// eslint-disable-next-line no-extend-native
|
||||
|
||||
export 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 = /([ :–—-])/;
|
||||
// console.log('*** to_title_case() ***');
|
||||
const smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|v.?|vs.?|via)$/i;
|
||||
const alphanumericPattern = /([A-Za-z0-9\u00C0-\u00FF])/;
|
||||
const 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();
|
||||
}
|
||||
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 intentional capitalization */
|
||||
if (current.substr(1).search(/[A-Z]|\../) > -1) {
|
||||
return current;
|
||||
}
|
||||
|
||||
/* Ignore URLs */
|
||||
if (array[index + 1] === ':' && array[index + 2] !== '') {
|
||||
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('');
|
||||
/* Capitalize the first letter */
|
||||
return current.replace(alphanumericPattern, function (match) {
|
||||
return match.toUpperCase();
|
||||
});
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user