Last round of prettier: npx prettier --write src/
This commit is contained in:
@@ -9,7 +9,10 @@ import {
|
||||
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 { file_extension_icon_lucide } from './ae_utils__file_extension_icon_lucide';
|
||||
import { process_permission_checks, compare_access_levels } from './ae_utils__perm_checks';
|
||||
import {
|
||||
process_permission_checks,
|
||||
compare_access_levels
|
||||
} from './ae_utils__perm_checks';
|
||||
import { iso_datetime_formatter } from './ae_utils__datetime_format';
|
||||
import { is_datetime_recent } from './ae_utils__is_datetime_recent';
|
||||
import { extract_prefixed_form_data } from './ae_utils__extract_prefixed_form_data';
|
||||
@@ -81,7 +84,6 @@ function handle_url_and_message(name: string, value: null | string) {
|
||||
// console.log('Message sent to parent (iframe):', message);
|
||||
}
|
||||
|
||||
|
||||
// ALERT: Not referenced anywhere -2026-02-03
|
||||
function create_a_element({
|
||||
account_id,
|
||||
|
||||
@@ -8,12 +8,22 @@ async function generate_iv() {
|
||||
}
|
||||
|
||||
// Updated 2025-05-08
|
||||
export const encrypt_content = async function encrypt_content(content: string, keyData: string) {
|
||||
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 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: iv.buffer as ArrayBuffer },
|
||||
key,
|
||||
@@ -52,7 +62,10 @@ export const combine_iv_and_base64 = function combine_iv_and_base64(
|
||||
};
|
||||
|
||||
// Updated 2025-05-08
|
||||
export const encrypt_wrapper = async function encrypt_wrapper(content: string, keyData: string) {
|
||||
export const encrypt_wrapper = async function encrypt_wrapper(
|
||||
content: string,
|
||||
keyData: string
|
||||
) {
|
||||
if (!content) {
|
||||
console.error('No content provided. Returning empty string.');
|
||||
return '';
|
||||
@@ -73,11 +86,20 @@ export const decrypt_content = async function decrypt_content(
|
||||
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 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: iv.buffer as ArrayBuffer },
|
||||
key,
|
||||
@@ -89,7 +111,9 @@ export const decrypt_content = async function decrypt_content(
|
||||
};
|
||||
|
||||
// Updated 2025-05-08
|
||||
export const split_iv_and_base64 = function split_iv_and_base64(combined: string) {
|
||||
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: '' };
|
||||
@@ -97,7 +121,9 @@ export const split_iv_and_base64 = function split_iv_and_base64(combined: string
|
||||
const [iv_hex, encrypted_base64_string] = combined.split(':');
|
||||
const base64 = encrypted_base64_string;
|
||||
const match_result = iv_hex.match(/.{1,2}/g);
|
||||
const iv = new Uint8Array((match_result || []).map((byte) => parseInt(byte, 16)));
|
||||
const iv = new Uint8Array(
|
||||
(match_result || []).map((byte) => parseInt(byte, 16))
|
||||
);
|
||||
if (log_lvl) {
|
||||
console.log(`IV: ${iv}; Encrypted:`, base64);
|
||||
}
|
||||
@@ -105,7 +131,10 @@ export const split_iv_and_base64 = function split_iv_and_base64(combined: string
|
||||
};
|
||||
|
||||
// Updated 2025-05-15
|
||||
export const decrypt_wrapper = async function decrypt_wrapper(combined: string, keyData: string) {
|
||||
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;
|
||||
|
||||
@@ -66,7 +66,9 @@ export const iso_datetime_formatter = function iso_datetime_formatter(
|
||||
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');
|
||||
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');
|
||||
@@ -75,7 +77,9 @@ export const iso_datetime_formatter = function iso_datetime_formatter(
|
||||
// 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');
|
||||
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');
|
||||
@@ -93,13 +97,17 @@ export const iso_datetime_formatter = function iso_datetime_formatter(
|
||||
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');
|
||||
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');
|
||||
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');
|
||||
|
||||
@@ -50,7 +50,9 @@ export const extract_prefixed_form_data = function extract_prefixed_form_data({
|
||||
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}`);
|
||||
console.log(
|
||||
`${obj_prop_name}: ${obj_prop_value} type=${typeof obj_prop_value}`
|
||||
);
|
||||
}
|
||||
|
||||
// Trim string values if needed
|
||||
@@ -83,19 +85,31 @@ export const extract_prefixed_form_data = function extract_prefixed_form_data({
|
||||
// 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}`);
|
||||
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 (
|
||||
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}`);
|
||||
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}`);
|
||||
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}`);
|
||||
console.log(
|
||||
`Match: ${prefix})${obj_prop_name} value=${obj_prop_value}`
|
||||
);
|
||||
}
|
||||
data_obj[obj_prop_name] = obj_prop_value;
|
||||
}
|
||||
@@ -107,19 +121,31 @@ export const extract_prefixed_form_data = function extract_prefixed_form_data({
|
||||
} else {
|
||||
// No prefix set
|
||||
if (log_lvl) {
|
||||
console.log(`Checking: ${obj_prop_name} value=${obj_prop_value}`);
|
||||
console.log(
|
||||
`Checking: ${obj_prop_name} value=${obj_prop_value}`
|
||||
);
|
||||
}
|
||||
if (rm_empty_id && obj_prop_name.endsWith('id_random') && !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}`);
|
||||
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}`);
|
||||
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}`);
|
||||
console.log(
|
||||
`Match: ${obj_prop_name} value=${obj_prop_value}`
|
||||
);
|
||||
}
|
||||
data_obj[obj_prop_name] = obj_prop_value;
|
||||
}
|
||||
|
||||
@@ -5,61 +5,63 @@ import * as Lucide from 'lucide-svelte';
|
||||
* @param extension The file extension (e.g., 'pdf', 'jpg').
|
||||
* @returns The Lucide icon component.
|
||||
*/
|
||||
export function file_extension_icon_lucide(extension: string | undefined | null): any {
|
||||
export function file_extension_icon_lucide(
|
||||
extension: string | undefined | null
|
||||
): any {
|
||||
const ext = extension?.toLowerCase() || '';
|
||||
|
||||
|
||||
const icon_map: Record<string, any> = {
|
||||
'pdf': Lucide.FileText,
|
||||
'doc': Lucide.FileText,
|
||||
'docx': Lucide.FileText,
|
||||
'txt': Lucide.FileText,
|
||||
'rtf': Lucide.FileText,
|
||||
|
||||
'xls': Lucide.FileSpreadsheet,
|
||||
'xlsx': Lucide.FileSpreadsheet,
|
||||
'csv': Lucide.FileSpreadsheet,
|
||||
|
||||
'png': Lucide.FileImage,
|
||||
'jpg': Lucide.FileImage,
|
||||
'jpeg': Lucide.FileImage,
|
||||
'gif': Lucide.FileImage,
|
||||
'webp': Lucide.FileImage,
|
||||
'bmp': Lucide.FileImage,
|
||||
'svg': Lucide.FileImage,
|
||||
|
||||
'mp3': Lucide.FileAudio,
|
||||
'wav': Lucide.FileAudio,
|
||||
'm4a': Lucide.FileAudio,
|
||||
'flac': Lucide.FileAudio,
|
||||
'aac': Lucide.FileAudio,
|
||||
'aif': Lucide.FileAudio,
|
||||
'aiff': Lucide.FileAudio,
|
||||
|
||||
'mp4': Lucide.FileVideo,
|
||||
'mkv': Lucide.FileVideo,
|
||||
'mov': Lucide.FileVideo,
|
||||
'avi': Lucide.FileVideo,
|
||||
pdf: Lucide.FileText,
|
||||
doc: Lucide.FileText,
|
||||
docx: Lucide.FileText,
|
||||
txt: Lucide.FileText,
|
||||
rtf: Lucide.FileText,
|
||||
|
||||
xls: Lucide.FileSpreadsheet,
|
||||
xlsx: Lucide.FileSpreadsheet,
|
||||
csv: Lucide.FileSpreadsheet,
|
||||
|
||||
png: Lucide.FileImage,
|
||||
jpg: Lucide.FileImage,
|
||||
jpeg: Lucide.FileImage,
|
||||
gif: Lucide.FileImage,
|
||||
webp: Lucide.FileImage,
|
||||
bmp: Lucide.FileImage,
|
||||
svg: Lucide.FileImage,
|
||||
|
||||
mp3: Lucide.FileAudio,
|
||||
wav: Lucide.FileAudio,
|
||||
m4a: Lucide.FileAudio,
|
||||
flac: Lucide.FileAudio,
|
||||
aac: Lucide.FileAudio,
|
||||
aif: Lucide.FileAudio,
|
||||
aiff: Lucide.FileAudio,
|
||||
|
||||
mp4: Lucide.FileVideo,
|
||||
mkv: Lucide.FileVideo,
|
||||
mov: Lucide.FileVideo,
|
||||
avi: Lucide.FileVideo,
|
||||
'3gp': Lucide.FileVideo,
|
||||
|
||||
'ppt': Lucide.Presentation,
|
||||
'pptx': Lucide.Presentation,
|
||||
'key': Lucide.Presentation,
|
||||
'odp': Lucide.Presentation,
|
||||
|
||||
'zip': Lucide.FileArchive,
|
||||
|
||||
ppt: Lucide.Presentation,
|
||||
pptx: Lucide.Presentation,
|
||||
key: Lucide.Presentation,
|
||||
odp: Lucide.Presentation,
|
||||
|
||||
zip: Lucide.FileArchive,
|
||||
'7z': Lucide.FileArchive,
|
||||
'rar': Lucide.FileArchive,
|
||||
'tar': Lucide.FileArchive,
|
||||
'gz': Lucide.FileArchive,
|
||||
|
||||
'json': Lucide.FileJson,
|
||||
|
||||
'html': Lucide.FileCode,
|
||||
'htm': Lucide.FileCode,
|
||||
'js': Lucide.FileCode,
|
||||
'ts': Lucide.FileCode,
|
||||
'css': Lucide.FileCode,
|
||||
'php': Lucide.FileCode
|
||||
rar: Lucide.FileArchive,
|
||||
tar: Lucide.FileArchive,
|
||||
gz: Lucide.FileArchive,
|
||||
|
||||
json: Lucide.FileJson,
|
||||
|
||||
html: Lucide.FileCode,
|
||||
htm: Lucide.FileCode,
|
||||
js: Lucide.FileCode,
|
||||
ts: Lucide.FileCode,
|
||||
css: Lucide.FileCode,
|
||||
php: Lucide.FileCode
|
||||
};
|
||||
|
||||
return icon_map[ext] || Lucide.File;
|
||||
|
||||
@@ -12,12 +12,18 @@ export const clean_filename = function clean_filename(
|
||||
return '';
|
||||
}
|
||||
|
||||
const cleaned_filename = filename.replace(unacceptable_chars, replacement_char);
|
||||
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) {
|
||||
export const format_bytes = function format_bytes(
|
||||
bytes: number,
|
||||
decimals: number = 2
|
||||
) {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
|
||||
const k = 1024;
|
||||
@@ -30,14 +36,19 @@ export const format_bytes = function format_bytes(bytes: number, decimals: numbe
|
||||
};
|
||||
|
||||
// Updated 2024-08-12
|
||||
export const guess_file_name = function guess_file_name(filename_string: 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('.'));
|
||||
const file_name = filename_string.substring(
|
||||
0,
|
||||
filename_string.lastIndexOf('.')
|
||||
);
|
||||
// console.log(file_name);
|
||||
return file_name;
|
||||
} else {
|
||||
@@ -46,7 +57,9 @@ export const guess_file_name = function guess_file_name(filename_string: string)
|
||||
};
|
||||
|
||||
// Updated 2024-08-12
|
||||
export const guess_file_extension = function guess_file_extension(filename_string: string) {
|
||||
export const guess_file_extension = function guess_file_extension(
|
||||
filename_string: string
|
||||
) {
|
||||
// console.log('*** guess_file_extension() ***');
|
||||
if (!filename_string) {
|
||||
return '';
|
||||
@@ -57,21 +70,27 @@ export const guess_file_extension = function guess_file_extension(filename_strin
|
||||
}
|
||||
|
||||
const file_extension =
|
||||
filename_string.substring(filename_string.lastIndexOf('.') + 1, filename_string.length) ||
|
||||
filename_string;
|
||||
filename_string.substring(
|
||||
filename_string.lastIndexOf('.') + 1,
|
||||
filename_string.length
|
||||
) || filename_string;
|
||||
// console.log(file_extension);
|
||||
return file_extension;
|
||||
};
|
||||
|
||||
// Updated 2024-08-12
|
||||
export const get_file_hash = async function get_file_hash(file: File): Promise<string> {
|
||||
export const get_file_hash = async function get_file_hash(
|
||||
file: File
|
||||
): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const file_reader = new FileReader();
|
||||
|
||||
file_reader.onload = async function () {
|
||||
const result = file_reader.result;
|
||||
if (!result || typeof result === 'string') {
|
||||
console.log('File was not read completely or is in wrong format');
|
||||
console.log(
|
||||
'File was not read completely or is in wrong format'
|
||||
);
|
||||
reject('Error reading the file');
|
||||
return;
|
||||
}
|
||||
@@ -84,7 +103,9 @@ export const get_file_hash = async function get_file_hash(file: File): Promise<s
|
||||
|
||||
const hash_buffer = await crypto.subtle.digest('SHA-256', 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_hex = hash_array
|
||||
.map((b) => b.toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
|
||||
resolve(hash_hex);
|
||||
};
|
||||
|
||||
@@ -4,17 +4,22 @@
|
||||
*/
|
||||
export function format_html(html: string): string {
|
||||
if (!html) return '';
|
||||
|
||||
|
||||
let indent = 0;
|
||||
const tab = ' ';
|
||||
return html
|
||||
.replace(/>\s*</g, '>\n<') // Add newlines between tags
|
||||
.split('\n')
|
||||
.map(line => {
|
||||
.map((line) => {
|
||||
line = line.trim();
|
||||
if (line.match(/<\//)) indent--; // Decrease indent for closing tags
|
||||
const out = tab.repeat(Math.max(0, indent)) + line;
|
||||
if (line.match(/<[^\/!]/) && !line.match(/\/>/) && !line.match(/<\//)) indent++; // Increase indent for opening tags
|
||||
if (
|
||||
line.match(/<[^\/!]/) &&
|
||||
!line.match(/\/>/) &&
|
||||
!line.match(/<\//)
|
||||
)
|
||||
indent++; // Increase indent for opening tags
|
||||
return out;
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
@@ -9,7 +9,9 @@ export const is_datetime_recent = function is_datetime_recent({
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** is_datetime_recent() *** datetime=${datetime} minutes=${minutes}`);
|
||||
console.log(
|
||||
`*** is_datetime_recent() *** datetime=${datetime} minutes=${minutes}`
|
||||
);
|
||||
}
|
||||
|
||||
const now: any = new Date();
|
||||
|
||||
@@ -17,7 +17,10 @@ export const access_level_order = [
|
||||
* Compares two access levels based on the hierarchy.
|
||||
* @returns 1 if level_a is higher, -1 if level_b is higher, 0 if equal.
|
||||
*/
|
||||
export const compare_access_levels = function (level_a: string, level_b: string): number {
|
||||
export const compare_access_levels = function (
|
||||
level_a: string,
|
||||
level_b: string
|
||||
): number {
|
||||
const index_a = access_level_order.indexOf(level_a || 'anonymous');
|
||||
const index_b = access_level_order.indexOf(level_b || 'anonymous');
|
||||
|
||||
@@ -30,7 +33,9 @@ export const compare_access_levels = function (level_a: string, level_b: string)
|
||||
// NOTE: I know there is a better more efficient way to do this, but I don't have time for that right now.
|
||||
// Reminder: super > manager > administrator > trusted > public > authenticated > anonymous
|
||||
// Super is the highest level. Anonymous is the lowest level.
|
||||
export const process_permission_checks = function process_permission_checks(access_type: string) {
|
||||
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 = {};
|
||||
|
||||
|
||||
@@ -17,7 +17,9 @@ import type { key_val } from './ae_utils';
|
||||
*/
|
||||
// Updated 2022-02-11
|
||||
|
||||
export const process_data_string = function process_data_string(data_string: string) {
|
||||
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) {
|
||||
@@ -70,14 +72,18 @@ export const process_data_string = function process_data_string(data_string: str
|
||||
obj['type'] = 'url';
|
||||
obj['url'] = data_string;
|
||||
} else {
|
||||
console.log('The unknown data string type was found. Returning the string part.');
|
||||
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['str'] = unknown_str;
|
||||
}
|
||||
} else {
|
||||
console.log('The data string type was not found. Returning the entire string.');
|
||||
console.log(
|
||||
'The data string type was not found. Returning the entire string.'
|
||||
);
|
||||
console.log(data_string);
|
||||
|
||||
obj['qr_type'] = 'UNKNOWN';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export function return_obj_type_path({
|
||||
obj_type = null,
|
||||
obj_type_prop_name = null
|
||||
}: {
|
||||
obj_type?: string | null,
|
||||
obj_type_prop_name?: string | null
|
||||
export function return_obj_type_path({
|
||||
obj_type = null,
|
||||
obj_type_prop_name = null
|
||||
}: {
|
||||
obj_type?: string | null;
|
||||
obj_type_prop_name?: string | null;
|
||||
}) {
|
||||
console.log('*** return_obj_type_path() ***');
|
||||
|
||||
@@ -14,29 +14,69 @@ export function return_obj_type_path({
|
||||
{ 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: '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_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_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_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_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: '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: 'post_comment',
|
||||
display: 'Archive Content',
|
||||
path: 'post/comment'
|
||||
},
|
||||
{ name: 'user', display: 'User', path: 'user' }
|
||||
];
|
||||
|
||||
|
||||
@@ -76,7 +76,10 @@ export function set_obj_prop_display_name({
|
||||
// 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, '');
|
||||
prop_display_name = prop_name.replace(
|
||||
known_obj_type_li_dict[i].name,
|
||||
''
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -101,7 +104,10 @@ export function set_obj_prop_display_name({
|
||||
// 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, '');
|
||||
prop_display_name = prop_name.replace(
|
||||
known_obj_type_li_dict[i].name,
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -20,7 +20,8 @@ export function to_title_case(text_string: string) {
|
||||
array[index - 3] !== ':' &&
|
||||
array[index + 1] !== ':' &&
|
||||
/* Ignore small words that start a hyphenated phrase */
|
||||
(array[index + 1] !== '-' || (array[index - 1] === '-' && array[index + 1] === '-'))
|
||||
(array[index + 1] !== '-' ||
|
||||
(array[index - 1] === '-' && array[index + 1] === '-'))
|
||||
) {
|
||||
return current.toLowerCase();
|
||||
}
|
||||
@@ -36,9 +37,12 @@ export function to_title_case(text_string: string) {
|
||||
}
|
||||
|
||||
/* Capitalize the first letter */
|
||||
return current.replace(alphanumericPattern, function (match: string) {
|
||||
return match.toUpperCase();
|
||||
});
|
||||
return current.replace(
|
||||
alphanumericPattern,
|
||||
function (match: string) {
|
||||
return match.toUpperCase();
|
||||
}
|
||||
);
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { compare_access_levels, process_permission_checks, access_level_order } from './ae_utils__perm_checks';
|
||||
import {
|
||||
compare_access_levels,
|
||||
process_permission_checks,
|
||||
access_level_order
|
||||
} from './ae_utils__perm_checks';
|
||||
|
||||
describe('Permission Hierarchy Tests', () => {
|
||||
describe('compare_access_levels', () => {
|
||||
@@ -15,7 +19,9 @@ describe('Permission Hierarchy Tests', () => {
|
||||
it('should correctly identify downgrades', () => {
|
||||
// Low to High should return -1
|
||||
expect(compare_access_levels('manager', 'super')).toBe(-1);
|
||||
expect(compare_access_levels('anonymous', 'authenticated')).toBe(-1);
|
||||
expect(compare_access_levels('anonymous', 'authenticated')).toBe(
|
||||
-1
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 0 for equal levels', () => {
|
||||
@@ -25,7 +31,9 @@ describe('Permission Hierarchy Tests', () => {
|
||||
|
||||
it('should handle null/empty as anonymous', () => {
|
||||
expect(compare_access_levels('trusted', '')).toBe(1);
|
||||
expect(compare_access_levels(null as any, 'authenticated')).toBe(-1);
|
||||
expect(compare_access_levels(null as any, 'authenticated')).toBe(
|
||||
-1
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user