@hkdigital/lib-sveltekit 0.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +104 -0
  2. package/dist/classes/index.d.ts +2 -0
  3. package/dist/classes/index.js +2 -0
  4. package/dist/classes/stores/SubscribersCount.d.ts +39 -0
  5. package/dist/classes/stores/SubscribersCount.js +107 -0
  6. package/dist/classes/stores/index.d.ts +1 -0
  7. package/dist/classes/stores/index.js +1 -0
  8. package/dist/classes/streams/LogTransformStream.d.ts +4 -0
  9. package/dist/classes/streams/LogTransformStream.js +19 -0
  10. package/dist/classes/streams/ServerEventsStore.d.ts +22 -0
  11. package/dist/classes/streams/ServerEventsStore.js +110 -0
  12. package/dist/classes/streams/TimeStampSource.d.ts +13 -0
  13. package/dist/classes/streams/TimeStampSource.js +26 -0
  14. package/dist/classes/streams/index.d.ts +3 -0
  15. package/dist/classes/streams/index.js +3 -0
  16. package/dist/components/area/HkArea.svelte +49 -0
  17. package/dist/components/area/HkArea.svelte.d.ts +12 -0
  18. package/dist/components/area/HkGridArea.svelte +77 -0
  19. package/dist/components/area/HkGridArea.svelte.d.ts +20 -0
  20. package/dist/components/area/index.d.ts +2 -0
  21. package/dist/components/area/index.js +2 -0
  22. package/dist/components/icon/HkIcon.svelte +86 -0
  23. package/dist/components/icon/HkIcon.svelte.d.ts +10 -0
  24. package/dist/components/icon/HkTabIcon.svelte +112 -0
  25. package/dist/components/icon/HkTabIcon.svelte.d.ts +19 -0
  26. package/dist/components/icon/index.d.ts +3 -0
  27. package/dist/components/icon/index.js +4 -0
  28. package/dist/components/icon/typedef.d.ts +13 -0
  29. package/dist/components/icon/typedef.js +16 -0
  30. package/dist/components/index.d.ts +1 -0
  31. package/dist/components/index.js +2 -0
  32. package/dist/components/layout/HkAppLayout.state.svelte.d.ts +6 -0
  33. package/dist/components/layout/HkAppLayout.state.svelte.js +25 -0
  34. package/dist/components/layout/HkAppLayout.svelte +251 -0
  35. package/dist/components/layout/HkAppLayout.svelte.d.ts +8 -0
  36. package/dist/components/layout/HkGridLayers.svelte +72 -0
  37. package/dist/components/layout/HkGridLayers.svelte.d.ts +20 -0
  38. package/dist/components/layout/index.d.ts +3 -0
  39. package/dist/components/layout/index.js +9 -0
  40. package/dist/components/tab-bar/HkTabBar.state.svelte.d.ts +54 -0
  41. package/dist/components/tab-bar/HkTabBar.state.svelte.js +149 -0
  42. package/dist/components/tab-bar/HkTabBar.svelte +74 -0
  43. package/dist/components/tab-bar/HkTabBar.svelte.d.ts +16 -0
  44. package/dist/components/tab-bar/HkTabBarSelector.state.svelte.d.ts +19 -0
  45. package/dist/components/tab-bar/HkTabBarSelector.state.svelte.js +93 -0
  46. package/dist/components/tab-bar/HkTabBarSelector.svelte +49 -0
  47. package/dist/components/tab-bar/HkTabBarSelector.svelte.d.ts +17 -0
  48. package/dist/components/tab-bar/index.d.ts +5 -0
  49. package/dist/components/tab-bar/index.js +17 -0
  50. package/dist/components/tab-bar/typedef.d.ts +6 -0
  51. package/dist/components/tab-bar/typedef.js +8 -0
  52. package/dist/constants/index.d.ts +2 -0
  53. package/dist/constants/index.js +2 -0
  54. package/dist/constants/regexp/index.d.ts +3 -0
  55. package/dist/constants/regexp/index.js +31 -0
  56. package/dist/constants/regexp/inspiratie.js__ +95 -0
  57. package/dist/constants/regexp/text.d.ts +47 -0
  58. package/dist/constants/regexp/text.js +49 -0
  59. package/dist/constants/regexp/user.d.ts +6 -0
  60. package/dist/constants/regexp/user.js +33 -0
  61. package/dist/constants/regexp/web.d.ts +1 -0
  62. package/dist/constants/regexp/web.js +3 -0
  63. package/dist/constants/time.d.ts +19 -0
  64. package/dist/constants/time.js +28 -0
  65. package/dist/css/test.css +3 -0
  66. package/dist/css/utilities.postcss +44 -0
  67. package/dist/index.d.ts +1 -0
  68. package/dist/index.js +9 -0
  69. package/dist/server/index.d.ts +1 -0
  70. package/dist/server/index.js +1 -0
  71. package/dist/server/logger.d.ts +24 -0
  72. package/dist/server/logger.js +94 -0
  73. package/dist/states/index.d.ts +1 -0
  74. package/dist/states/index.js +1 -0
  75. package/dist/states/navigation.svelte.d.ts +23 -0
  76. package/dist/states/navigation.svelte.js +55 -0
  77. package/dist/stores/index.d.ts +1 -0
  78. package/dist/stores/index.js +1 -0
  79. package/dist/stores/theme.d.ts +28 -0
  80. package/dist/stores/theme.js +80 -0
  81. package/dist/util/expect/index.d.ts +39 -0
  82. package/dist/util/expect/index.js +145 -0
  83. package/dist/util/function.js__ +150 -0
  84. package/dist/util/index.d.ts +2 -0
  85. package/dist/util/index.js +2 -0
  86. package/dist/util/singleton/index.d.ts +34 -0
  87. package/dist/util/singleton/index.js +97 -0
  88. package/dist/util/svelte/index.d.ts +2 -0
  89. package/dist/util/svelte/index.js +2 -0
  90. package/dist/util/svelte/observe/index.d.ts +10 -0
  91. package/dist/util/svelte/observe/index.js +49 -0
  92. package/dist/util/svelte/state-context/index.d.ts +17 -0
  93. package/dist/util/svelte/state-context/index.js +83 -0
  94. package/dist/util/time.js__ +330 -0
  95. package/dist/valibot/index.d.ts +3 -0
  96. package/dist/valibot/index.js +30 -0
  97. package/dist/valibot/user.d.ts +6 -0
  98. package/dist/valibot/user.js +23 -0
  99. package/dist/zod/all.d.ts +6 -0
  100. package/dist/zod/all.js +33 -0
  101. package/dist/zod/generic.d.ts +6 -0
  102. package/dist/zod/generic.js +11 -0
  103. package/dist/zod/javascript.d.ts +8 -0
  104. package/dist/zod/javascript.js +32 -0
  105. package/dist/zod/user.d.ts +9 -0
  106. package/dist/zod/user.js +16 -0
  107. package/dist/zod/web.d.ts +21 -0
  108. package/dist/zod/web.js +57 -0
  109. package/package.json +144 -0
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @typedef {import('./typedef.js').Tab} Tab
3
+ */
4
+ export class HkTabBarState {
5
+ /** @type {Tab[]} */
6
+ tabs: Tab[];
7
+ /** @type {*} */
8
+ tabBarElement: any;
9
+ /** @type {HTMLElement[]} */
10
+ tabElements: HTMLElement[];
11
+ currentTabIndex: number;
12
+ /** @type {Tab|null} */
13
+ currentTab: Tab | null;
14
+ /**
15
+ * Set tab contents
16
+ *
17
+ * @param {Tab[]} tabs
18
+ */
19
+ setTabs(tabs: Tab[]): void;
20
+ /**
21
+ * Navigate to the route that is specified on the current tab (if any)
22
+ */
23
+ navigate(): void;
24
+ /**
25
+ * Select the tab that has a route property that matches the current
26
+ * browser location pathname
27
+ *
28
+ * @note the pathname starts with a '/'
29
+ *
30
+ * @param {string} [pathname]
31
+ * If not specified, pathname from the browser's location will be used
32
+ */
33
+ selectTabByPathName(pathname?: string): void;
34
+ /**
35
+ * Select a tab by its index in the array this.tabs
36
+ *
37
+ * @param {number} index
38
+ */
39
+ selectTabByIndex(index: number): void;
40
+ /**
41
+ * Link a tab to a DOM element
42
+ * - An reference is stored as property
43
+ * - This reference can be used by extensions of this tab bar,
44
+ * e.g. to manipulate the visual appearance of the tabs
45
+ *
46
+ * @param {number} index
47
+ * @param {HTMLElement} tabElement
48
+ */
49
+ linkTab(index: number, tabElement: HTMLElement): void;
50
+ }
51
+ export const createOrGetState: (instanceKey?: string | Symbol) => HkTabBarState;
52
+ export const createState: (instanceKey?: string | Symbol) => HkTabBarState;
53
+ export const getState: (instanceKey?: string | Symbol) => HkTabBarState;
54
+ export type Tab = import("./typedef.js").Tab;
@@ -0,0 +1,149 @@
1
+ import { defineStateContext } from '../../util/svelte/state-context/index.js';
2
+ import { nav } from '../../states/navigation.svelte.js';
3
+
4
+ import { goto } from '$app/navigation';
5
+
6
+ /**
7
+ * @typedef {import('./typedef.js').Tab} Tab
8
+ */
9
+
10
+ /* ------------------------------------------------------- Define state class */
11
+
12
+ export class HkTabBarState {
13
+ /** @type {Tab[]} */
14
+ tabs = $state.raw([]);
15
+
16
+ /** @type {*} */
17
+ tabBarElement = $state();
18
+
19
+ /** @type {HTMLElement[]} */
20
+ tabElements = [];
21
+
22
+ currentTabIndex = $state(-1);
23
+
24
+ /** @type {Tab|null} */
25
+ currentTab = $state(null);
26
+
27
+ // /** @type {boolean} */
28
+ // ready = $derived(this.currentTab !== null);
29
+
30
+ constructor() {
31
+ $effect.pre(() => {
32
+ // > Update this.currentTab
33
+
34
+ const tabs = this.tabs;
35
+
36
+ if (!this.tabs?.length || this.currentTabIndex === -1) {
37
+ this.currentTab = null;
38
+ } else {
39
+ const index = this.currentTabIndex;
40
+ const tabValue = tabs[index] ?? null;
41
+
42
+ // console.log('Selected active tab', index, tabValue);
43
+
44
+ this.currentTab = tabValue;
45
+ }
46
+ });
47
+ } // end constructor
48
+
49
+ /**
50
+ * Set tab contents
51
+ *
52
+ * @param {Tab[]} tabs
53
+ */
54
+ setTabs(tabs) {
55
+ // console.log('setTabs', tabs);
56
+ this.tabs = tabs;
57
+
58
+ if (this.currentTabIndex >= tabs.length) {
59
+ this.currentTabIndex = 0;
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Navigate to the route that is specified on the current tab (if any)
65
+ */
66
+ navigate() {
67
+ if (!this.currentTab || !this.currentTab.route) {
68
+ return;
69
+ }
70
+
71
+ goto(this.currentTab.route);
72
+ }
73
+
74
+ /**
75
+ * Select the tab that has a route property that matches the current
76
+ * browser location pathname
77
+ *
78
+ * @note the pathname starts with a '/'
79
+ *
80
+ * @param {string} [pathname]
81
+ * If not specified, pathname from the browser's location will be used
82
+ */
83
+ selectTabByPathName(pathname) {
84
+ if (!this.tabs.length) {
85
+ return;
86
+ }
87
+
88
+ if (!pathname) {
89
+ pathname = nav.pathname;
90
+ }
91
+
92
+ // console.log(`selectTabByPathName [${pathname}]`);
93
+
94
+ const tabs = this.tabs;
95
+
96
+ // > Try to find an exact match
97
+
98
+ for (let j = 0, n = tabs.length; j < n; j = j + 1) {
99
+ const tab = tabs[j];
100
+
101
+ if (tab.route && tab.route === pathname) {
102
+ //console.log('Found tab by route', tab);
103
+ this.selectTabByIndex(j);
104
+
105
+ return;
106
+ }
107
+ } // end for
108
+
109
+ // > Try to find a match using a route prefix
110
+
111
+ for (let j = 0, n = tabs.length; j < n; j = j + 1) {
112
+ const tab = tabs[j];
113
+
114
+ if (tab.routePrefix && pathname.startsWith(tab.routePrefix)) {
115
+ //console.log('Found tab by route prefix', tab);
116
+ this.selectTabByIndex(j);
117
+
118
+ return;
119
+ }
120
+ } // end for
121
+ }
122
+
123
+ /**
124
+ * Select a tab by its index in the array this.tabs
125
+ *
126
+ * @param {number} index
127
+ */
128
+ selectTabByIndex(index) {
129
+ // console.log(`Select tab by index [${index}]`);
130
+ this.currentTabIndex = index;
131
+ }
132
+
133
+ /**
134
+ * Link a tab to a DOM element
135
+ * - An reference is stored as property
136
+ * - This reference can be used by extensions of this tab bar,
137
+ * e.g. to manipulate the visual appearance of the tabs
138
+ *
139
+ * @param {number} index
140
+ * @param {HTMLElement} tabElement
141
+ */
142
+ linkTab(index, tabElement) {
143
+ this.tabElements[index] = tabElement;
144
+ }
145
+ } // end class
146
+
147
+ /* -------------------------------------- Export create & get state functions */
148
+
149
+ export const [createOrGetState, createState, getState] = defineStateContext(HkTabBarState);
@@ -0,0 +1,74 @@
1
+ <script>
2
+ /**
3
+ * TabBar component
4
+ *
5
+ * Following component guidelines from Skeleton
6
+ * @see https://next.skeleton.dev/docs/resources/contribute/components
7
+ */
8
+
9
+ import { createOrGetState } from './HkTabBar.state.svelte';
10
+
11
+ import { HkGridArea } from '../area/index.js';
12
+
13
+ /**
14
+ * @type {{
15
+ * cols?: number,
16
+ * base?: string,
17
+ * bg?: string,
18
+ * padding?: string,
19
+ * margin?: string,
20
+ * classes?: string,
21
+ * style?: string,
22
+ * instanceKey?: Symbol | string,
23
+ * children: import('svelte').Snippet,
24
+ * onmount?: function,
25
+ * domElem?: HTMLElement
26
+ * } & { [attr: string]: * }}
27
+ */
28
+ let {
29
+ // Functional
30
+ cols = 3,
31
+
32
+ // Style
33
+ base,
34
+ bg,
35
+ padding,
36
+ margin,
37
+ classes,
38
+
39
+ style,
40
+
41
+ // State
42
+ instanceKey,
43
+
44
+ // Snippets
45
+ children,
46
+
47
+ // Event handlers
48
+ onmount,
49
+
50
+ // DOM Elements
51
+ domElem = $bindable(),
52
+
53
+ // Rest attributes
54
+ ...attrs
55
+ } = $props();
56
+
57
+ createOrGetState(instanceKey);
58
+
59
+ //grid-cols-[repeat({cols},minmax(0,auto))]
60
+ </script>
61
+
62
+ <HkGridArea
63
+ data-hk-tab-bar
64
+ base="justify-center content-stretch items-center {base}"
65
+ style="grid-template-columns: repeat({cols}, minmax(0,auto)); {style}"
66
+ boxBg={bg}
67
+ boxPadding={padding}
68
+ boxMargin={margin}
69
+ bind:boxDomElem={domElem}
70
+ {classes}
71
+ {...attrs}
72
+ >
73
+ {@render children()}
74
+ </HkGridArea>
@@ -0,0 +1,16 @@
1
+ export default HkTabBar;
2
+ declare const HkTabBar: import("svelte").Component<{
3
+ cols?: number;
4
+ base?: string;
5
+ bg?: string;
6
+ padding?: string;
7
+ margin?: string;
8
+ classes?: string;
9
+ style?: string;
10
+ instanceKey?: Symbol | string;
11
+ children: import("svelte").Snippet;
12
+ onmount?: Function;
13
+ domElem?: HTMLElement;
14
+ } & {
15
+ [attr: string]: any;
16
+ }, {}, "domElem">;
@@ -0,0 +1,19 @@
1
+ export class HkTabBarSelectorState {
2
+ /** @type {HTMLElement|undefined} */
3
+ /** @type {number} */
4
+ selectorWidth: number;
5
+ selectorStyle: string;
6
+ /** @type {DOMRect[]} */
7
+ iconSizes: DOMRect[];
8
+ /**
9
+ * Link the tab bar selector to a tab bar state
10
+ *
11
+ * @param {import('./HkTabBar.svelte').TabBarState} tabBarState
12
+ */
13
+ linkToTabBarState(tabBarState: import("./HkTabBar.svelte").TabBarState): void;
14
+ tabBarState: any;
15
+ #private;
16
+ }
17
+ export const createOrGetState: (instanceKey?: string | Symbol) => HkTabBarSelectorState;
18
+ export const createState: (instanceKey?: string | Symbol) => HkTabBarSelectorState;
19
+ export const getState: (instanceKey?: string | Symbol) => HkTabBarSelectorState;
@@ -0,0 +1,93 @@
1
+ import { defineStateContext } from '../../util/svelte/state-context/index.js';
2
+
3
+ import { useResizeObserver } from '../../util/svelte/observe/index.js';
4
+
5
+ /* ------------------------------------------------------- Define state class */
6
+
7
+ export class HkTabBarSelectorState {
8
+ /** @type {HTMLElement|undefined} */
9
+ // outer = $state.raw();
10
+ // outerBox = $state.raw();
11
+
12
+ /** @type {number} */
13
+ // tabBarWidth = $state(0);
14
+
15
+ selectorWidth = $state(0);
16
+ selectorStyle = $state('');
17
+
18
+ //currentTabIndex;
19
+
20
+ /** @type {DOMRect[]} */
21
+ iconSizes = [];
22
+
23
+ constructor() {
24
+ // $effect(() => {
25
+ // if (this.outer) {
26
+ // this.outerBox = this.outer.getBoundingClientRect();
27
+ // }
28
+ // });
29
+ }
30
+
31
+ /**
32
+ * Link the tab bar selector to a tab bar state
33
+ *
34
+ * @param {import('./HkTabBar.svelte').TabBarState} tabBarState
35
+ */
36
+ linkToTabBarState(tabBarState) {
37
+ // console.log('setBottomBar', bottomBarState);
38
+
39
+ // if this.bottomBarState > error
40
+
41
+ this.tabBarState = tabBarState;
42
+
43
+ $effect(() => {
44
+ tabBarState.currentTabIndex;
45
+
46
+ // console.log('currentTabIndex $effect');
47
+
48
+ this.#updateSelector();
49
+ });
50
+
51
+ useResizeObserver(
52
+ () => tabBarState.tabBarElement,
53
+ (entries) => {
54
+ this.#updateSelector();
55
+ }
56
+ );
57
+ }
58
+
59
+ /**
60
+ * Update the size and position of the selector
61
+ */
62
+ #updateSelector() {
63
+ if (!this.tabBarState) {
64
+ return;
65
+ }
66
+
67
+ const { currentTabIndex, tabBarElement, tabElements } = this.tabBarState;
68
+
69
+ const tabElem = tabElements[currentTabIndex];
70
+
71
+ if (!tabElem || !tabBarElement) {
72
+ return;
73
+ }
74
+
75
+ const tabElemRect = tabElem.getBoundingClientRect();
76
+
77
+ const tabBarRect = tabBarElement.getBoundingClientRect();
78
+
79
+ // const offsetX = (iconWidth - selectorWidth) / 2 - outerBox.x;
80
+ const offsetX = (tabElemRect.width - this.selectorWidth) / 2 - tabBarRect.x;
81
+
82
+ const x = tabElemRect.x + offsetX;
83
+ const w = tabBarRect.width;
84
+
85
+ this.selectorStyle = `left: ${(100 * x) / w}%; opacity: 1;`;
86
+
87
+ // console.log('selectorStyle', this.selectorStyle);
88
+ }
89
+ }
90
+
91
+ /* -------------------------------------- Export create & get state functions */
92
+
93
+ export const [createOrGetState, createState, getState] = defineStateContext(HkTabBarSelectorState);
@@ -0,0 +1,49 @@
1
+ <script>
2
+ // prettier-ignore
3
+ // import { getTabBarSelectorState }
4
+ // from "./HkTabBarSelector.state.svelte.js";
5
+
6
+ import { createOrGetState }
7
+ from "./HkTabBarSelector.state.svelte.js";
8
+
9
+ /**
10
+ * @type {{
11
+ * base?: string,
12
+ * bg?: string,
13
+ * classes?: string,
14
+ * boxBase?: string,
15
+ * boxBg?: string,
16
+ * boxPadding?: string,
17
+ * boxMargin?: string,
18
+ * boxClasses?: string,
19
+ * boxAttrs?: { [attr: string]: * },
20
+ * instanceKey?: Symbol | string
21
+ * } & { [attr: string]: * }}
22
+ */
23
+ let {
24
+ // Style
25
+ base,
26
+ bg,
27
+ classes,
28
+ boxBase,
29
+ boxBg,
30
+ boxClasses,
31
+
32
+ // State
33
+ instanceKey
34
+ } = $props();
35
+
36
+ const selectorState = createOrGetState(instanceKey);
37
+ </script>
38
+
39
+ <div
40
+ data-hk-tab-bar-selector-box
41
+ class="g-tab-bar-h w-full {boxBase} {boxBg} {boxClasses}"
42
+ >
43
+ <div
44
+ data-hk-tab-bar-selector
45
+ bind:clientWidth={selectorState.selectorWidth}
46
+ class="relative opacity-0 {base} {bg} {classes}"
47
+ style={selectorState.selectorStyle}
48
+ ></div>
49
+ </div>
@@ -0,0 +1,17 @@
1
+ export default HkTabBarSelector;
2
+ declare const HkTabBarSelector: import("svelte").Component<{
3
+ base?: string;
4
+ bg?: string;
5
+ classes?: string;
6
+ boxBase?: string;
7
+ boxBg?: string;
8
+ boxPadding?: string;
9
+ boxMargin?: string;
10
+ boxClasses?: string;
11
+ boxAttrs?: {
12
+ [attr: string]: any;
13
+ };
14
+ instanceKey?: Symbol | string;
15
+ } & {
16
+ [attr: string]: any;
17
+ }, {}, "">;
@@ -0,0 +1,5 @@
1
+ export { default as HkTabBar } from "./HkTabBar.svelte";
2
+ export { default as HkTabBarSelector } from "./HkTabBarSelector.svelte";
3
+ export * from "./typedef.js";
4
+ export { createOrGetState as createOrGetTabBarState, createState as createTabBarState, getState as getTabBarState } from "./HkTabBar.state.svelte.js";
5
+ export { createOrGetState as createOrGetTabBarSelectorState, createState as createTabBarSelectorState, getState as getTabBarSelectorState } from "./HkTabBarSelector.state.svelte.js";
@@ -0,0 +1,17 @@
1
+ export {
2
+ createOrGetState as createOrGetTabBarState,
3
+ createState as createTabBarState,
4
+ getState as getTabBarState
5
+ } from './HkTabBar.state.svelte.js';
6
+
7
+ export { default as HkTabBar } from './HkTabBar.svelte';
8
+
9
+ export {
10
+ createOrGetState as createOrGetTabBarSelectorState,
11
+ createState as createTabBarSelectorState,
12
+ getState as getTabBarSelectorState
13
+ } from './HkTabBarSelector.state.svelte.js';
14
+
15
+ export { default as HkTabBarSelector } from './HkTabBarSelector.svelte';
16
+
17
+ export * from './typedef.js';
@@ -0,0 +1,6 @@
1
+ export type Tab = {
2
+ icon: import("../icon/typedef.js").IconSource;
3
+ label?: string;
4
+ route?: string;
5
+ routePrefix?: string;
6
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @typedef {object} Tab
3
+ * @property {import('../icon/typedef.js').IconSource} icon
4
+ * @property {string} [label]
5
+ *
6
+ * @property {string} [route]
7
+ * @property {string} [routePrefix]
8
+ */
@@ -0,0 +1,2 @@
1
+ export * as regexp from "./regexp/index.js";
2
+ export * as time from "./time.js";
@@ -0,0 +1,2 @@
1
+ export * as regexp from './regexp/index.js';
2
+ export * as time from './time.js';
@@ -0,0 +1,3 @@
1
+ export * from "./text.js";
2
+ export * from "./user.js";
3
+ export * from "./web.js";
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Index file for various regexp categories
3
+ *
4
+ * @note
5
+ * To enable unicode search, use the unicode flag 'u'.
6
+ *
7
+ * \p and \P are only supported in Unicode-aware mode. In Unicode-unaware mode,
8
+ * they are identity escapes for the p or P character.
9
+ *
10
+ * @note
11
+ * To enable unicode symbols that consist of multiple 'code points'(characters),
12
+ * such a some emoji, you must use the flag 'v'.
13
+ *
14
+ * @eg
15
+ * const re = new RegExp('^[${Latin_Number}]', 'u');
16
+ *
17
+ * @eg
18
+ * const re = new RegExp('^[${Symbols_Emoji}]', 'v');
19
+ *
20
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/
21
+ * Reference/Regular_expressions/Unicode_character_class_escape
22
+ *
23
+ * @see https://javascript.info/regexp-unicode
24
+ *
25
+ * @see https://v8.dev/features/regexp-v-flag
26
+ *
27
+ * @see https://www.regular-expressions.info/unicode.html
28
+ */
29
+ export * from './text.js';
30
+ export * from './user.js';
31
+ export * from './web.js';
@@ -0,0 +1,95 @@
1
+ //
2
+ // EXT_LATIN_TOKENS_LC
3
+ // - Extended list of latin tokens, works for most latin languages
4
+ //
5
+ // @note
6
+ // Both upper- and lower case extended latin tokens are:
7
+ // "ŠŒŽšœžŸñÑÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðòóôõöøùúûüýþÿ"
8
+ //
9
+ // TODO:
10
+ // Replace with unicode property escapes when supported ES2018
11
+ // (not yet supported by MS Edge 12)
12
+ // https://github.com/tc39/proposal-regexp-unicode-property-escapes
13
+ // http://unicode.org/Public/UNIDATA/PropertyValueAliases.txt
14
+ // https://www.fileformat.info/info/unicode/category/index.htm
15
+ // https://github.com/danielberndt/babel-plugin-utf-8-regex/
16
+ // blob/master/src/transformer.js
17
+ //
18
+ export const EXT_LATIN_TOKENS_LC = 'šœžÿñàáâãäåæçèéêëìíîïðòóôõöøùúûüýþß';
19
+
20
+ // RegExp and RegExp part constants
21
+
22
+ // TODO:
23
+ // regexAstralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
24
+ // "-~.,`'\"‘’“”„±€$@%&¡¿©®"
25
+ // REP_PUNCTUATION = ",.¡!¿?;:-";
26
+
27
+ export const C = {
28
+ EXT_LATIN_TOKENS_LC,
29
+ REP_NUMBER: '0-9',
30
+ REP_LETTER_LC: `a-z${EXT_LATIN_TOKENS_LC}`,
31
+ REP_LETTER_NUMBER_LC: `0-9a-z${EXT_LATIN_TOKENS_LC}`
32
+ };
33
+
34
+ export const RE_EMAIL = new RegExp(
35
+ '^(([^<>()[\\]\\.,;:\\s@"]+(.[^<>()[\\]\\.,;:\\s@"]+)*)|(".+"))@((([' +
36
+ '\\-' +
37
+ C.REP_LETTER_NUMBER_LC +
38
+ ']+\\.)+[' +
39
+ C.REP_LETTER_LC +
40
+ ']{2,}))$',
41
+ 'i'
42
+ );
43
+
44
+ // export const RE_URL = << TODO
45
+
46
+ export const RE_PHONE =
47
+ /(^\+[0-9]{2}|^\+[0-9]{2}\(0\)|^\(\+[0-9]{2}\)\(0\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\-\s]{10}$)/;
48
+
49
+ export const RE_POSTCODE_DUTCH = /^[1-9]{1}[0-9]{3} ?[A-Za-z]{2}$/;
50
+
51
+ export const RE_PLACE_DUTCH = new RegExp(
52
+ "^['`]{0,1}" +
53
+ `[${C.REP_LETTER_LC}]{0,}` +
54
+ '[-\\s]{0,1}' +
55
+ `[${C.REP_LETTER_LC}]{2,}$`,
56
+ 'i'
57
+ );
58
+
59
+ // export const RE_NAME =
60
+ // new RegExp( `^[${C.REP_LETTER_LC}\\s-\`']{2,}$`, "i" );
61
+
62
+ export const RE_NAME = new RegExp(
63
+ `^[${C.REP_LETTER_LC}]{1}` + `[${C.REP_LETTER_LC}\\s-\`'\\.]{0,}$`,
64
+ 'i'
65
+ );
66
+
67
+ export const RE_FANTASY_NAME = new RegExp(
68
+ '^[' +
69
+ C.REP_LETTER_NUMBER_LC +
70
+ "\\x20!@#\\$%\\^&\\*\\(\\)-_+=\\|:;'\"'`~<,>.?/\\\\]{2,}$",
71
+ 'i'
72
+ );
73
+
74
+ export const RE_ADDRESS = new RegExp(
75
+ '^[' + C.REP_LETTER_NUMBER_LC + '.,°\\s-]{2,}$',
76
+ 'i'
77
+ );
78
+
79
+ export const RE_HAS_A_LETTER_OR_NUMBER = new RegExp('[a-z0-9]+', 'i');
80
+
81
+ export const RE_MULTIPLE_SPACES = new RegExp('[\\s]{2,}', 'g');
82
+ // export const RE_MULTIPLE_SPACES = / +/g
83
+
84
+ export const RE_LABEL = new RegExp('^[a-z0-9_-]{2,}$');
85
+
86
+ export const RE_COLLECTION_NAME = new RegExp('^[a-z0-9\\s-_]{1,}$', 'i');
87
+
88
+ export const RE_URI_COMPONENT = new RegExp(
89
+ '^[' + C.REP_LETTER_LC + '\\s-_]{1,}$',
90
+ 'i'
91
+ );
92
+
93
+ //
94
+ // @see https://usefulshortcuts.com/alt-codes/accents-alt-codes.php
95
+ //