web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

commit aa24dc24645da97eb68cba03cb94dd30b420923e
parent e07ea9d407467d7987f8afa732a2972c08a4bf18
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Fri, 15 Nov 2024 01:31:06 +0000

apps-lib: edit document utils

Diffstat:
Mapps-lib/src/lib/utils/document.ts | 16++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/apps-lib/src/lib/utils/document.ts b/apps-lib/src/lib/utils/document.ts @@ -14,13 +14,25 @@ export const els_id_pref = (id_pref: string): Element[] | undefined => { return undefined; }; -export const els_id_pref_index = (id_pref: string, num_index: number, orientation: `greater` | `lesser` = `greater`): Element[] | undefined => { +export const els_id_pref_index = (id_pref: string, num_index: number, orientation: `greater` | `lesser` | `not` = `greater`, inclusive: boolean = true): Element[] | undefined => { const els = document.querySelectorAll(`[id^="${`${id_pref}-`.replaceAll(`--`, `-`)}"]`); if (els && els.length) return Array.from(els).filter(el => { const match = el.id.match(/(?<=^|\-)[0-9]\d*(?=\-)/) if (match) { const num = parseInt(match[0], 10); - return orientation === `greater` ? num >= num_index : num <= num_index; + switch (orientation) { + case `greater`: { + if (inclusive) return num >= num_index; + else return num > num_index; + } + case `lesser`: { + if (inclusive) return num <= num_index; + else return num < num_index; + } + case `not`: { + return num !== num_index; + } + } } return false; });