@tacdaed/fragments 1.0.0-beta.4 → 1.0.0-beta.5
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.
- package/README.md +16 -11
- package/assets/styles/scss/_all.scss +0 -1
- package/fesm2022/tacdaed-fragments.mjs +8928 -0
- package/index.d.ts +3929 -0
- package/package.json +34 -22
- package/assets/resources/fonts/OpenSans/OpenSans-Italic-VariableFont_wdth_wght.ttf +0 -0
- package/assets/resources/fonts/OpenSans/OpenSans-VariableFont_wdth_wght.ttf +0 -0
- package/assets/resources/fonts/Roboto/Roboto-Black.ttf +0 -0
- package/assets/resources/fonts/Roboto/Roboto-BlackItalic.ttf +0 -0
- package/assets/resources/fonts/Roboto/Roboto-Bold.ttf +0 -0
- package/assets/resources/fonts/Roboto/Roboto-BoldItalic.ttf +0 -0
- package/assets/resources/fonts/Roboto/Roboto-Italic.ttf +0 -0
- package/assets/resources/fonts/Roboto/Roboto-Light.ttf +0 -0
- package/assets/resources/fonts/Roboto/Roboto-LightItalic.ttf +0 -0
- package/assets/resources/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/assets/resources/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
- package/assets/resources/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/assets/resources/fonts/Roboto/Roboto-Thin.ttf +0 -0
- package/assets/resources/fonts/Roboto/Roboto-ThinItalic.ttf +0 -0
- package/assets/styles/scss/_fonts.scss +0 -122
- package/ng-package.json +0 -20
- package/src/lib/components/accordion/accordion.component.html +0 -103
- package/src/lib/components/accordion/accordion.component.scss +0 -382
- package/src/lib/components/accordion/accordion.component.spec.ts +0 -147
- package/src/lib/components/accordion/accordion.component.ts +0 -211
- package/src/lib/components/accordion/accordion.type.ts +0 -82
- package/src/lib/components/breadcrumb/breadcrumb.component.html +0 -43
- package/src/lib/components/breadcrumb/breadcrumb.component.scss +0 -112
- package/src/lib/components/breadcrumb/breadcrumb.component.spec.ts +0 -33
- package/src/lib/components/breadcrumb/breadcrumb.component.ts +0 -103
- package/src/lib/components/breadcrumb/breadcrumb.interface.ts +0 -7
- package/src/lib/components/button/button.component.html +0 -57
- package/src/lib/components/button/button.component.scss +0 -445
- package/src/lib/components/button/button.component.spec.ts +0 -99
- package/src/lib/components/button/button.component.ts +0 -143
- package/src/lib/components/button/button.type.ts +0 -7
- package/src/lib/components/card/card.component.html +0 -44
- package/src/lib/components/card/card.component.scss +0 -114
- package/src/lib/components/card/card.component.spec.ts +0 -65
- package/src/lib/components/card/card.component.ts +0 -21
- package/src/lib/components/card/card.type.ts +0 -3
- package/src/lib/components/code-block/code-block.component.html +0 -55
- package/src/lib/components/code-block/code-block.component.scss +0 -122
- package/src/lib/components/code-block/code-block.component.spec.ts +0 -81
- package/src/lib/components/code-block/code-block.component.ts +0 -302
- package/src/lib/components/code-block/code-block.interface.ts +0 -28
- package/src/lib/components/code-block/code-block.type.ts +0 -73
- package/src/lib/components/decorative/sparkle-field/sparkle-field.component.html +0 -14
- package/src/lib/components/decorative/sparkle-field/sparkle-field.component.scss +0 -20
- package/src/lib/components/decorative/sparkle-field/sparkle-field.component.spec.ts +0 -38
- package/src/lib/components/decorative/sparkle-field/sparkle-field.component.ts +0 -181
- package/src/lib/components/input/input-base.ts +0 -187
- package/src/lib/components/input/input-calendar/input-calendar.component.html +0 -76
- package/src/lib/components/input/input-calendar/input-calendar.component.scss +0 -179
- package/src/lib/components/input/input-calendar/input-calendar.component.spec.ts +0 -44
- package/src/lib/components/input/input-calendar/input-calendar.component.ts +0 -299
- package/src/lib/components/input/input-checkbox/input-checkbox.component.html +0 -37
- package/src/lib/components/input/input-checkbox/input-checkbox.component.scss +0 -128
- package/src/lib/components/input/input-checkbox/input-checkbox.component.spec.ts +0 -43
- package/src/lib/components/input/input-checkbox/input-checkbox.component.ts +0 -112
- package/src/lib/components/input/input-checkbox-group/input-checkbox-group.component.html +0 -43
- package/src/lib/components/input/input-checkbox-group/input-checkbox-group.component.scss +0 -140
- package/src/lib/components/input/input-checkbox-group/input-checkbox-group.component.spec.ts +0 -62
- package/src/lib/components/input/input-checkbox-group/input-checkbox-group.component.ts +0 -136
- package/src/lib/components/input/input-clock-picker/input-clock-picker.component.html +0 -81
- package/src/lib/components/input/input-clock-picker/input-clock-picker.component.scss +0 -228
- package/src/lib/components/input/input-clock-picker/input-clock-picker.component.spec.ts +0 -62
- package/src/lib/components/input/input-clock-picker/input-clock-picker.component.ts +0 -178
- package/src/lib/components/input/input-consts.ts +0 -132
- package/src/lib/components/input/input-date/input-date-validators.ts +0 -41
- package/src/lib/components/input/input-date/input-date.component.html +0 -41
- package/src/lib/components/input/input-date/input-date.component.scss +0 -95
- package/src/lib/components/input/input-date/input-date.component.spec.ts +0 -43
- package/src/lib/components/input/input-date/input-date.component.ts +0 -359
- package/src/lib/components/input/input-date-time/input-date-time.component.html +0 -70
- package/src/lib/components/input/input-date-time/input-date-time.component.scss +0 -133
- package/src/lib/components/input/input-date-time/input-date-time.component.spec.ts +0 -36
- package/src/lib/components/input/input-date-time/input-date-time.component.ts +0 -387
- package/src/lib/components/input/input-file-upload/input-file-upload.component.html +0 -89
- package/src/lib/components/input/input-file-upload/input-file-upload.component.scss +0 -171
- package/src/lib/components/input/input-file-upload/input-file-upload.component.spec.ts +0 -43
- package/src/lib/components/input/input-file-upload/input-file-upload.component.ts +0 -351
- package/src/lib/components/input/input-interface.ts +0 -8
- package/src/lib/components/input/input-number/input-number-validators.ts +0 -0
- package/src/lib/components/input/input-number/input-number.component.html +0 -51
- package/src/lib/components/input/input-number/input-number.component.scss +0 -140
- package/src/lib/components/input/input-number/input-number.component.spec.ts +0 -44
- package/src/lib/components/input/input-number/input-number.component.ts +0 -343
- package/src/lib/components/input/input-radio-group/input-radio-group.component.html +0 -44
- package/src/lib/components/input/input-radio-group/input-radio-group.component.scss +0 -139
- package/src/lib/components/input/input-radio-group/input-radio-group.component.spec.ts +0 -58
- package/src/lib/components/input/input-radio-group/input-radio-group.component.ts +0 -132
- package/src/lib/components/input/input-slider/input-slider.component.html +0 -111
- package/src/lib/components/input/input-slider/input-slider.component.scss +0 -203
- package/src/lib/components/input/input-slider/input-slider.component.spec.ts +0 -46
- package/src/lib/components/input/input-slider/input-slider.component.ts +0 -410
- package/src/lib/components/input/input-text/input-text-validators.ts +0 -67
- package/src/lib/components/input/input-text/input-text.component.html +0 -71
- package/src/lib/components/input/input-text/input-text.component.scss +0 -118
- package/src/lib/components/input/input-text/input-text.component.spec.ts +0 -55
- package/src/lib/components/input/input-text/input-text.component.ts +0 -215
- package/src/lib/components/input/input-time/input-time-validators.ts +0 -42
- package/src/lib/components/input/input-time/input-time.component.html +0 -92
- package/src/lib/components/input/input-time/input-time.component.scss +0 -191
- package/src/lib/components/input/input-time/input-time.component.spec.ts +0 -39
- package/src/lib/components/input/input-time/input-time.component.ts +0 -691
- package/src/lib/components/input/input-toggle-switch/input-toggle-switch.component.html +0 -36
- package/src/lib/components/input/input-toggle-switch/input-toggle-switch.component.scss +0 -121
- package/src/lib/components/input/input-toggle-switch/input-toggle-switch.component.spec.ts +0 -54
- package/src/lib/components/input/input-toggle-switch/input-toggle-switch.component.ts +0 -117
- package/src/lib/components/input/input-type.ts +0 -18
- package/src/lib/components/input/input-validation/input-validation.component.html +0 -19
- package/src/lib/components/input/input-validation/input-validation.component.scss +0 -39
- package/src/lib/components/input/input-validation/input-validation.component.spec.ts +0 -45
- package/src/lib/components/input/input-validation/input-validation.component.ts +0 -13
- package/src/lib/components/input/input.pipe.ts +0 -14
- package/src/lib/components/layout/container/container.component.html +0 -1
- package/src/lib/components/layout/container/container.component.scss +0 -33
- package/src/lib/components/layout/container/container.component.ts +0 -32
- package/src/lib/components/layout/container/container.type.ts +0 -1
- package/src/lib/components/layout/divider/divider.component.html +0 -1
- package/src/lib/components/layout/divider/divider.component.scss +0 -60
- package/src/lib/components/layout/divider/divider.component.ts +0 -38
- package/src/lib/components/layout/divider/divider.type.ts +0 -2
- package/src/lib/components/layout/section/section.component.html +0 -21
- package/src/lib/components/layout/section/section.component.scss +0 -43
- package/src/lib/components/layout/section/section.component.ts +0 -33
- package/src/lib/components/layout/section/section.type.ts +0 -2
- package/src/lib/components/layout/separator/separator.component.html +0 -9
- package/src/lib/components/layout/separator/separator.component.scss +0 -52
- package/src/lib/components/layout/separator/separator.component.ts +0 -25
- package/src/lib/components/layout/separator/separator.type.ts +0 -1
- package/src/lib/components/loader/content-blur/content-blur.component.html +0 -13
- package/src/lib/components/loader/content-blur/content-blur.component.scss +0 -43
- package/src/lib/components/loader/content-blur/content-blur.component.spec.ts +0 -42
- package/src/lib/components/loader/content-blur/content-blur.component.ts +0 -34
- package/src/lib/components/loader/loader.type.ts +0 -2
- package/src/lib/components/loader/progress-bar/progress-bar.component.html +0 -26
- package/src/lib/components/loader/progress-bar/progress-bar.component.scss +0 -151
- package/src/lib/components/loader/progress-bar/progress-bar.component.spec.ts +0 -47
- package/src/lib/components/loader/progress-bar/progress-bar.component.ts +0 -28
- package/src/lib/components/loader/progress-bar/progress-bar.type.ts +0 -8
- package/src/lib/components/loader/pulse-loader/pulse-loader.component.html +0 -12
- package/src/lib/components/loader/pulse-loader/pulse-loader.component.scss +0 -202
- package/src/lib/components/loader/pulse-loader/pulse-loader.component.spec.ts +0 -55
- package/src/lib/components/loader/pulse-loader/pulse-loader.component.ts +0 -73
- package/src/lib/components/loader/pulse-loader/pulse-loader.type.ts +0 -6
- package/src/lib/components/loader/skeleton-loader/skeleton-loader.component.html +0 -13
- package/src/lib/components/loader/skeleton-loader/skeleton-loader.component.scss +0 -113
- package/src/lib/components/loader/skeleton-loader/skeleton-loader.component.spec.ts +0 -37
- package/src/lib/components/loader/skeleton-loader/skeleton-loader.component.ts +0 -51
- package/src/lib/components/loader/skeleton-loader/skeleton-loader.type.ts +0 -6
- package/src/lib/components/loader/spinner/spinner.component.html +0 -20
- package/src/lib/components/loader/spinner/spinner.component.scss +0 -137
- package/src/lib/components/loader/spinner/spinner.component.spec.ts +0 -43
- package/src/lib/components/loader/spinner/spinner.component.ts +0 -32
- package/src/lib/components/loader/spinner/spinner.type.ts +0 -6
- package/src/lib/components/modal/modal.component.html +0 -47
- package/src/lib/components/modal/modal.component.scss +0 -139
- package/src/lib/components/modal/modal.component.spec.ts +0 -60
- package/src/lib/components/modal/modal.component.ts +0 -83
- package/src/lib/components/modal/modal.type.ts +0 -9
- package/src/lib/components/morph/blob-moph/blob-moprh.component.spec.ts +0 -79
- package/src/lib/components/morph/blob-moph/blob-moprh.component.ts +0 -96
- package/src/lib/components/morph/blob-moph/blob-morph.component.html +0 -34
- package/src/lib/components/morph/blob-moph/blob-morph.component.scss +0 -7
- package/src/lib/components/morph/morph.abstract.ts +0 -13
- package/src/lib/components/pagination/pagination.interface.ts +0 -4
- package/src/lib/components/pagination/small-pagination/small-pagination.component.html +0 -61
- package/src/lib/components/pagination/small-pagination/small-pagination.component.scss +0 -187
- package/src/lib/components/pagination/small-pagination/small-pagination.component.spec.ts +0 -88
- package/src/lib/components/pagination/small-pagination/small-pagination.component.ts +0 -177
- package/src/lib/components/selection-lists/multi-select/multi-select.component.html +0 -170
- package/src/lib/components/selection-lists/multi-select/multi-select.component.scss +0 -312
- package/src/lib/components/selection-lists/multi-select/multi-select.component.spec.ts +0 -61
- package/src/lib/components/selection-lists/multi-select/multi-select.component.ts +0 -372
- package/src/lib/components/selection-lists/selection-list/selection-list.component.html +0 -125
- package/src/lib/components/selection-lists/selection-list/selection-list.component.scss +0 -267
- package/src/lib/components/selection-lists/selection-list/selection-list.component.spec.ts +0 -66
- package/src/lib/components/selection-lists/selection-list/selection-list.component.ts +0 -315
- package/src/lib/components/selection-lists/selection-lists-base.ts +0 -35
- package/src/lib/components/selection-lists/selection-lists-const.ts +0 -17
- package/src/lib/components/selection-lists/selection-lists-interface.ts +0 -7
- package/src/lib/components/selection-lists/selection-lists.type.ts +0 -1
- package/src/lib/components/side-nav/side-nav.component.html +0 -101
- package/src/lib/components/side-nav/side-nav.component.scss +0 -295
- package/src/lib/components/side-nav/side-nav.component.spec.ts +0 -0
- package/src/lib/components/side-nav/side-nav.component.ts +0 -18
- package/src/lib/components/side-nav/side-nav.type.ts +0 -28
- package/src/lib/components/snackbar/snackbar.component.html +0 -33
- package/src/lib/components/snackbar/snackbar.component.scss +0 -195
- package/src/lib/components/snackbar/snackbar.component.ts +0 -112
- package/src/lib/components/snackbar/snackbar.type.ts +0 -27
- package/src/lib/components/status/chip/chip.component.html +0 -51
- package/src/lib/components/status/chip/chip.component.scss +0 -149
- package/src/lib/components/status/chip/chip.component.spec.ts +0 -62
- package/src/lib/components/status/chip/chip.component.ts +0 -83
- package/src/lib/components/status/chip/chip.type.ts +0 -42
- package/src/lib/components/status/directives/badge/badge.directive.spec.ts +0 -60
- package/src/lib/components/status/directives/badge/badge.directive.ts +0 -190
- package/src/lib/components/status/directives/badge/badge.interface.ts +0 -19
- package/src/lib/components/status/pill/pill.component.html +0 -40
- package/src/lib/components/status/pill/pill.component.scss +0 -113
- package/src/lib/components/status/pill/pill.component.spec.ts +0 -47
- package/src/lib/components/status/pill/pill.component.ts +0 -83
- package/src/lib/components/status/pill/pill.type.ts +0 -42
- package/src/lib/components/status/status.interface.ts +0 -57
- package/src/lib/components/status/status.type.ts +0 -62
- package/src/lib/components/status/tag/tag.component.html +0 -39
- package/src/lib/components/status/tag/tag.component.scss +0 -140
- package/src/lib/components/status/tag/tag.component.spec.ts +0 -47
- package/src/lib/components/status/tag/tag.component.ts +0 -83
- package/src/lib/components/status/tag/tag.type.ts +0 -42
- package/src/lib/components/stepper/stepper.component.html +0 -83
- package/src/lib/components/stepper/stepper.component.scss +0 -196
- package/src/lib/components/stepper/stepper.component.ts +0 -482
- package/src/lib/components/stepper/stepper.type.ts +0 -60
- package/src/lib/components/table/table.component.html +0 -438
- package/src/lib/components/table/table.component.scss +0 -259
- package/src/lib/components/table/table.component.spec.ts +0 -117
- package/src/lib/components/table/table.component.ts +0 -215
- package/src/lib/components/table/table.enum.ts +0 -4
- package/src/lib/components/table/table.function.ts +0 -47
- package/src/lib/components/table/table.interface.ts +0 -143
- package/src/lib/components/table/table.pipe.ts +0 -62
- package/src/lib/components/table/table.type.ts +0 -15
- package/src/lib/components/tabs/tabs.component.html +0 -88
- package/src/lib/components/tabs/tabs.component.scss +0 -305
- package/src/lib/components/tabs/tabs.component.spec.ts +0 -94
- package/src/lib/components/tabs/tabs.component.ts +0 -282
- package/src/lib/components/tabs/tabs.type.ts +0 -81
- package/src/lib/components/title-bar/title-bar.component.html +0 -21
- package/src/lib/components/title-bar/title-bar.component.scss +0 -139
- package/src/lib/components/title-bar/title-bar.component.spec.ts +0 -44
- package/src/lib/components/title-bar/title-bar.component.ts +0 -13
- package/src/lib/components/toast/toast.component.html +0 -36
- package/src/lib/components/toast/toast.component.scss +0 -241
- package/src/lib/components/toast/toast.component.ts +0 -165
- package/src/lib/components/toast/toast.type.ts +0 -37
- package/src/lib/components/toast-stack/toast-stack.component.html +0 -30
- package/src/lib/components/toast-stack/toast-stack.component.scss +0 -35
- package/src/lib/components/toast-stack/toast-stack.component.ts +0 -51
- package/src/lib/consts/country-prefix.ts +0 -244
- package/src/lib/directives/tooltip/popover.directive.ts +0 -274
- package/src/lib/directives/tooltip/tooltip.directive.spec.ts +0 -86
- package/src/lib/directives/tooltip/tooltip.directive.ts +0 -234
- package/src/lib/directives/tooltip/tooltip.interface.ts +0 -29
- package/src/lib/directives/tooltip/tooltip.type.ts +0 -9
- package/src/lib/interfaces/common.interfaces.ts +0 -4
- package/src/lib/pipes/chunk.pipe.ts +0 -16
- package/src/lib/pipes/safe-html.pipe.ts +0 -14
- package/src/lib/pipes/sanitize-html.pipe.ts +0 -23
- package/src/lib/types/base.types.ts +0 -23
- package/src/lib/types/common.types.ts +0 -98
- package/src/lib/types/form.types.ts +0 -5
- package/src/lib/utils/common.utils.ts +0 -53
- package/src/lib/utils/date.utils.ts +0 -474
- package/src/lib/utils/number.utils.ts +0 -16
- package/src/lib/utils/uuid.utils.ts +0 -39
- package/src/public-api.ts +0 -114
- package/tsconfig.lib.json +0 -17
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -9
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export type TBaseStyle =
|
|
2
|
-
| 'default'
|
|
3
|
-
| 'primary'
|
|
4
|
-
| 'secondary'
|
|
5
|
-
| 'tertiary'
|
|
6
|
-
| 'dark'
|
|
7
|
-
| 'light'
|
|
8
|
-
| 'info'
|
|
9
|
-
| 'success'
|
|
10
|
-
| 'warning'
|
|
11
|
-
| 'danger'
|
|
12
|
-
| 'outline-primary'
|
|
13
|
-
| 'outline-secondary'
|
|
14
|
-
| 'outline-tertiary'
|
|
15
|
-
| 'outline-dark'
|
|
16
|
-
| 'outline-light'
|
|
17
|
-
| 'outline-info'
|
|
18
|
-
| 'outline-success'
|
|
19
|
-
| 'outline-warning'
|
|
20
|
-
| 'outline-danger';
|
|
21
|
-
|
|
22
|
-
export type TBaseSize = 'small' | 'medium' | 'large';
|
|
23
|
-
export type TBasePosition = 'top' | 'left' | 'right' | 'bottom';
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a value that can be used in Angular's `ngClass` directive
|
|
3
|
-
* to determine whether a class should be applied.
|
|
4
|
-
* - `boolean`: apply class if true, remove if false
|
|
5
|
-
* - `number`: treated as truthy if non-zero, falsy if zero
|
|
6
|
-
* - `string`: directly represents a class name
|
|
7
|
-
* - `null` or `undefined`: no class applied
|
|
8
|
-
*/
|
|
9
|
-
export type NgClassValue = boolean | number | string | null | undefined;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Describes the different formats supported by a custom implementation
|
|
13
|
-
* of Angular's `ngClass`. It allows:
|
|
14
|
-
* - A single class name as a string
|
|
15
|
-
* - An array of class names
|
|
16
|
-
* - A Set of class names
|
|
17
|
-
* - An object map where keys are class names and values determine whether they should be applied
|
|
18
|
-
* - `null` or `undefined` to apply no classes
|
|
19
|
-
*/
|
|
20
|
-
export type TCustomNgClass =
|
|
21
|
-
| string
|
|
22
|
-
| string[]
|
|
23
|
-
| Set<string>
|
|
24
|
-
| { [klass: string]: NgClassValue }
|
|
25
|
-
| null
|
|
26
|
-
| undefined;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Creates a type that removes the properties of `U` from `T`
|
|
30
|
-
* by marking them as optional and setting their type to `never`.
|
|
31
|
-
* Useful for constructing mutually exclusive types.
|
|
32
|
-
*/
|
|
33
|
-
export type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Constructs an exclusive OR (XOR) type between `T` and `U`.
|
|
37
|
-
* Ensures that either `T` or `U` is allowed, but not both at the same time.
|
|
38
|
-
* - If both are objects, it enforces mutual exclusivity at the property level.
|
|
39
|
-
* - If not objects, it falls back to a simple union (`T | U`).
|
|
40
|
-
*/
|
|
41
|
-
export type XOR<T, U> = T | U extends object
|
|
42
|
-
? (Without<T, U> & U) | (Without<U, T> & T)
|
|
43
|
-
: T | U;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Represents a generic function type that takes a single argument of any type
|
|
47
|
-
* and returns a value of type `T`.
|
|
48
|
-
*
|
|
49
|
-
* @template T The return type of the function.
|
|
50
|
-
*/
|
|
51
|
-
export type GenericFunction<T> = (arg0: unknown) => T;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Represents a mutually exclusive type between `T` and `K`.
|
|
55
|
-
* Only one of the two types can be used at a time.
|
|
56
|
-
*
|
|
57
|
-
* @template T The first type option.
|
|
58
|
-
* @template K The second type option.
|
|
59
|
-
*/
|
|
60
|
-
export type TBehaviourAction<T, K> = XOR<T, K>;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Represents an array that contains at least one element of type `T`.
|
|
64
|
-
* Ensures that the array is never empty by requiring an element at index 0.
|
|
65
|
-
*
|
|
66
|
-
* @template T The type of the elements in the array.
|
|
67
|
-
*/
|
|
68
|
-
export type ArrayOneOrMore<T> = { 0: T } & Array<T>;
|
|
69
|
-
|
|
70
|
-
export type DateFormat =
|
|
71
|
-
| "dd/MM/yyyy"
|
|
72
|
-
| "MM/dd/yyyy"
|
|
73
|
-
| "yyyy-MM-dd"
|
|
74
|
-
| "dd-MM-yyyy"
|
|
75
|
-
| "dd.MM.yyyy"
|
|
76
|
-
| "yyyy/MM/dd"
|
|
77
|
-
| "MMM dd, yyyy"
|
|
78
|
-
| "MMMM dd, yyyy"
|
|
79
|
-
| "dd MMM yyyy"
|
|
80
|
-
| "dd MMMM yyyy"
|
|
81
|
-
| "yyyyMMdd";
|
|
82
|
-
|
|
83
|
-
export type TimeFormat = "HH:mm:ss" | "HH:mm" | "hh:mm:ss a" | "hh:mm a";
|
|
84
|
-
|
|
85
|
-
export type DateTimeFormat =
|
|
86
|
-
| "dd/MM/yyyy HH:mm"
|
|
87
|
-
| "dd/MM/yyyy HH:mm:ss"
|
|
88
|
-
| "MM/dd/yyyy HH:mm"
|
|
89
|
-
| "MM/dd/yyyy hh:mm a"
|
|
90
|
-
| "yyyy-MM-dd'T'HH:mm"
|
|
91
|
-
| "yyyy-MM-dd'T'HH:mm:ss"
|
|
92
|
-
| "dd MMM yyyy HH:mm"
|
|
93
|
-
| "dd MMM yyyy hh:mm a"
|
|
94
|
-
| "MMMM dd, yyyy HH:mm"
|
|
95
|
-
| "MMMM dd, yyyy hh:mm a"
|
|
96
|
-
| "yyyyMMdd HH:mm"
|
|
97
|
-
| "yyyyMMdd HH:mm:ss";
|
|
98
|
-
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ActivatedRoute } from '@angular/router';
|
|
2
|
-
|
|
3
|
-
type direction = 'asc' | 'desc';
|
|
4
|
-
|
|
5
|
-
export function generateId(value?: string): string {
|
|
6
|
-
const valueRandom: number = Math.floor(Math.random() * 10000000) + 1;
|
|
7
|
-
return value ? value + '-' + valueRandom : String(valueRandom);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function generateNumberId(): number {
|
|
11
|
-
return Math.floor(Math.random() * 10000000) + 1;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function isObjectEmpty(obj: any): boolean {
|
|
15
|
-
return Object.keys(obj).length <= 0;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function paginationList<T>(
|
|
19
|
-
lista: Array<T>,
|
|
20
|
-
pageSize: number,
|
|
21
|
-
page: number
|
|
22
|
-
) {
|
|
23
|
-
lista = lista.slice(+pageSize * (+page - 1), +pageSize * +page);
|
|
24
|
-
return lista;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function orderList<T>(
|
|
28
|
-
lista: Array<T>,
|
|
29
|
-
orderFields: any,
|
|
30
|
-
direction: direction
|
|
31
|
-
) {
|
|
32
|
-
orderFields = Array.isArray(orderFields)
|
|
33
|
-
? orderFields.join('.')
|
|
34
|
-
: orderFields;
|
|
35
|
-
lista.sort((a: any, b: any) => {
|
|
36
|
-
if (direction === 'asc') {
|
|
37
|
-
return a[orderFields] > b[orderFields] ? 1 : -1;
|
|
38
|
-
} else {
|
|
39
|
-
return a[orderFields] < b[orderFields] ? 1 : -1;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
return lista;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function getActivatedRouteChild(
|
|
46
|
-
activatedRoute: ActivatedRoute
|
|
47
|
-
): ActivatedRoute {
|
|
48
|
-
if (activatedRoute.firstChild) {
|
|
49
|
-
return getActivatedRouteChild(activatedRoute.firstChild);
|
|
50
|
-
} else {
|
|
51
|
-
return activatedRoute;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,474 +0,0 @@
|
|
|
1
|
-
import { InputTimePartial } from "../components/input/input-type";
|
|
2
|
-
import { DateFormat, DateTimeFormat, TimeFormat } from "../types/common.types";
|
|
3
|
-
|
|
4
|
-
export function isValidDate(dateString: string, format: DateFormat = "yyyy-MM-dd"): boolean {
|
|
5
|
-
if (format !== 'yyyy-MM-dd') {
|
|
6
|
-
const isoString = convertStringToISODate(dateString, format);
|
|
7
|
-
|
|
8
|
-
if (!isoString)
|
|
9
|
-
return false;
|
|
10
|
-
|
|
11
|
-
const dateObj = new Date(isoString);
|
|
12
|
-
return !isNaN(dateObj.getTime());
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const dateObject: Date = new Date(dateString);
|
|
16
|
-
return !isNaN(dateObject.getTime());
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Checks if a given datetime string matches a given format and represents a valid date/time.
|
|
21
|
-
*/
|
|
22
|
-
export function isValidDateTime(
|
|
23
|
-
dateTimeString: string,
|
|
24
|
-
format: DateTimeFormat = "yyyy-MM-dd'T'HH:mm"
|
|
25
|
-
): boolean {
|
|
26
|
-
if (!dateTimeString)
|
|
27
|
-
return false;
|
|
28
|
-
|
|
29
|
-
// If it's not the standard ISO-like format, convert it manually
|
|
30
|
-
if (format !== "yyyy-MM-dd'T'HH:mm" && format !== "yyyy-MM-dd'T'HH:mm:ss") {
|
|
31
|
-
const isoString = convertStringToISODateTime(dateTimeString, format);
|
|
32
|
-
|
|
33
|
-
if (!isoString)
|
|
34
|
-
return false;
|
|
35
|
-
|
|
36
|
-
const dateObj = new Date(isoString);
|
|
37
|
-
return !isNaN(dateObj.getTime());
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// If it's already in ISO-like format, just check directly
|
|
41
|
-
const dateObject = new Date(dateTimeString);
|
|
42
|
-
return !isNaN(dateObject.getTime());
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function convertStringToISODate(dateString: string, format: DateFormat = "yyyy-MM-dd"): string | null {
|
|
46
|
-
const formatRegex: RegExp = buildDateFormatRegex(format);
|
|
47
|
-
const match = formatRegex.exec(dateString);
|
|
48
|
-
|
|
49
|
-
if (!match?.groups) return null;
|
|
50
|
-
|
|
51
|
-
const { day, month, year } = match.groups;
|
|
52
|
-
|
|
53
|
-
const d = parseInt(day, 10);
|
|
54
|
-
const m = parseInt(month, 10) - 1;
|
|
55
|
-
let y = parseInt(year, 10);
|
|
56
|
-
|
|
57
|
-
if (year.length === 2) {
|
|
58
|
-
y += y >= 70 ? 1900 : 2000;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const date = new Date(y, m, d);
|
|
62
|
-
|
|
63
|
-
if (date.getFullYear() !== y || date.getMonth() !== m || date.getDate() !== d) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return date.toISOString();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Converts a date-time string (in a given format) to an ISO 8601 string.
|
|
72
|
-
* Returns null if invalid or if the string doesn't match the format.
|
|
73
|
-
*/
|
|
74
|
-
export function convertStringToISODateTime(
|
|
75
|
-
dateTimeString: string,
|
|
76
|
-
format: DateTimeFormat = "yyyy-MM-dd'T'HH:mm"
|
|
77
|
-
): string | null {
|
|
78
|
-
const formatRegex: RegExp = buildDateTimeFormatRegex(format);
|
|
79
|
-
const match = formatRegex.exec(dateTimeString.trim());
|
|
80
|
-
|
|
81
|
-
if (!match?.groups) return null;
|
|
82
|
-
|
|
83
|
-
const { day, month, year, hour, minute, second, period } = match.groups;
|
|
84
|
-
|
|
85
|
-
const d = parseInt(day, 10);
|
|
86
|
-
const m = parseInt(month, 10) - 1;
|
|
87
|
-
let y = parseInt(year, 10);
|
|
88
|
-
let h = parseInt(hour ?? '0', 10);
|
|
89
|
-
const min = parseInt(minute ?? '0', 10);
|
|
90
|
-
const s = parseInt(second ?? '0', 10);
|
|
91
|
-
|
|
92
|
-
// Handle two-digit years
|
|
93
|
-
if (year.length === 2) {
|
|
94
|
-
y += y >= 70 ? 1900 : 2000;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Handle AM/PM
|
|
98
|
-
if (period) {
|
|
99
|
-
const p = period.toUpperCase();
|
|
100
|
-
if (p === 'PM' && h < 12) h += 12;
|
|
101
|
-
if (p === 'AM' && h === 12) h = 0;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const date = new Date(y, m, d, h, min, s);
|
|
105
|
-
|
|
106
|
-
// Validation: ensure components didn’t overflow
|
|
107
|
-
if (
|
|
108
|
-
date.getFullYear() !== y ||
|
|
109
|
-
date.getMonth() !== m ||
|
|
110
|
-
date.getDate() !== d ||
|
|
111
|
-
date.getHours() !== h ||
|
|
112
|
-
date.getMinutes() !== min ||
|
|
113
|
-
date.getSeconds() !== s
|
|
114
|
-
) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return date.toISOString();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function convertStringToDate(dateString: string, format: DateFormat = "yyyy-MM-dd"): Date | null {
|
|
122
|
-
const formatRegex: RegExp = buildDateFormatRegex(format);
|
|
123
|
-
const match = formatRegex.exec(dateString);
|
|
124
|
-
|
|
125
|
-
if (!match?.groups) return null;
|
|
126
|
-
|
|
127
|
-
const { day, month, year } = match.groups;
|
|
128
|
-
|
|
129
|
-
const d = parseInt(day, 10);
|
|
130
|
-
const m = parseInt(month, 10) - 1;
|
|
131
|
-
let y = parseInt(year, 10);
|
|
132
|
-
|
|
133
|
-
if (year.length === 2) {
|
|
134
|
-
y += y >= 70 ? 1900 : 2000;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return new Date(y, m, d);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function convertStringToTime(
|
|
141
|
-
timeString: string,
|
|
142
|
-
format: TimeFormat = "HH:mm"
|
|
143
|
-
): number | null {
|
|
144
|
-
const regex = buildTimeFormatRegex(format);
|
|
145
|
-
const match = regex.exec(timeString);
|
|
146
|
-
|
|
147
|
-
if (!match?.groups) return null;
|
|
148
|
-
|
|
149
|
-
let hours = 0;
|
|
150
|
-
const minutes = match.groups["minute"] ? parseInt(match.groups["minute"], 10) : 0;
|
|
151
|
-
const seconds = match.groups["second"] ? parseInt(match.groups["second"], 10) : 0;
|
|
152
|
-
|
|
153
|
-
if (match.groups["hour24"]) {
|
|
154
|
-
hours = parseInt(match.groups["hour24"], 10);
|
|
155
|
-
} else if (match.groups["hour12"]) {
|
|
156
|
-
hours = parseInt(match.groups["hour12"], 10);
|
|
157
|
-
const period = match.groups["period"]?.toUpperCase();
|
|
158
|
-
if (period) {
|
|
159
|
-
if (hours === 12) hours = period === "AM" ? 0 : 12;
|
|
160
|
-
else if (period === "PM") hours += 12;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return hours * 3600 + minutes * 60 + seconds;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Converts a datetime string (based on a given format) into a Date object.
|
|
169
|
-
* Returns null if parsing fails or values are invalid.
|
|
170
|
-
*/
|
|
171
|
-
export function convertStringToDateTime(
|
|
172
|
-
dateTimeString: string,
|
|
173
|
-
format: DateTimeFormat = "yyyy-MM-dd'T'HH:mm"
|
|
174
|
-
): Date | null {
|
|
175
|
-
const regex = buildDateTimeFormatRegex(format);
|
|
176
|
-
const match = regex.exec(dateTimeString.trim());
|
|
177
|
-
|
|
178
|
-
if (!match?.groups) return null;
|
|
179
|
-
|
|
180
|
-
const separatorMatch = format.match(/( |T)/);
|
|
181
|
-
let datePart: string = format;
|
|
182
|
-
let timePart: string | null = null;
|
|
183
|
-
|
|
184
|
-
if (separatorMatch) {
|
|
185
|
-
const separator = separatorMatch[0];
|
|
186
|
-
const parts = format.split(separator);
|
|
187
|
-
datePart = parts[0];
|
|
188
|
-
timePart = parts[1] ?? null;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const dateString = timePart
|
|
192
|
-
? dateTimeString.split(/T| /)[0]
|
|
193
|
-
: dateTimeString;
|
|
194
|
-
|
|
195
|
-
const timeString = timePart
|
|
196
|
-
? dateTimeString.split(/T| /)[1]
|
|
197
|
-
: undefined;
|
|
198
|
-
|
|
199
|
-
const date = convertStringToDate(dateString, datePart as any);
|
|
200
|
-
if (!date) return null;
|
|
201
|
-
|
|
202
|
-
let totalSeconds = 0;
|
|
203
|
-
if (timeString && timePart) {
|
|
204
|
-
const seconds = convertStringToTime(timeString, timePart as any);
|
|
205
|
-
if (seconds == null) return null;
|
|
206
|
-
totalSeconds = seconds;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const hours = Math.floor(totalSeconds / 3600);
|
|
210
|
-
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
211
|
-
const seconds = totalSeconds % 60;
|
|
212
|
-
|
|
213
|
-
date.setHours(hours, minutes, seconds, 0);
|
|
214
|
-
|
|
215
|
-
return date;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Builds a regex to validate date strings based on the provided format.
|
|
220
|
-
* Supports formats like "dd/MM/yyyy", "MM-dd-yyyy", "yyyy.MM.dd", etc.
|
|
221
|
-
* @param format The date format string
|
|
222
|
-
*/
|
|
223
|
-
export function buildDateFormatRegex(format: string): RegExp {
|
|
224
|
-
const escaped = format.replace(/[-/.]/g, m => `\\${m}`);
|
|
225
|
-
|
|
226
|
-
const pattern = escaped
|
|
227
|
-
.replace("dd", "(?<day>\\d{2})")
|
|
228
|
-
.replace("MM", "(?<month>\\d{2})")
|
|
229
|
-
.replace("yyyy", "(?<year>\\d{4})")
|
|
230
|
-
.replace("yy", "(?<year>\\d{2})");
|
|
231
|
-
|
|
232
|
-
return new RegExp(`^${pattern}$`);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Builds a regex to validate time strings based on the provided format.
|
|
237
|
-
* Supports formats like "HH:mm", "hh:mm a", "HH:mm:ss", etc.
|
|
238
|
-
* @param format The time format string
|
|
239
|
-
*/
|
|
240
|
-
export function buildTimeFormatRegex(format: string): RegExp {
|
|
241
|
-
const escaped = format.replace(/[-:. ]/g, m => `\\${m}`);
|
|
242
|
-
const pattern = escaped
|
|
243
|
-
.replace("HH", "(?<hour24>[01]?[0-9]|2[0-3])")
|
|
244
|
-
.replace("hh", "(?<hour12>0?[1-9]|1[0-2])")
|
|
245
|
-
.replace("mm", "(?<minute>[0-5]?[0-9])")
|
|
246
|
-
.replace("ss", "(?<second>[0-5]?[0-9])")
|
|
247
|
-
.replace("a", "(?<period>AM|PM|am|pm)");
|
|
248
|
-
|
|
249
|
-
return new RegExp(`^${pattern}$`);
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Builds a regex to match full date-time strings.
|
|
253
|
-
* Handles both date and time tokens in a single format string (with optional AM/PM).
|
|
254
|
-
*/
|
|
255
|
-
export function buildDateTimeFormatRegex(format: string): RegExp {
|
|
256
|
-
// Try to find a separator between date and time parts
|
|
257
|
-
const separatorMatch = format.match(/( |T)/);
|
|
258
|
-
if (!separatorMatch) {
|
|
259
|
-
// Fallback: only date
|
|
260
|
-
return buildDateFormatRegex(format);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const separator = separatorMatch[0];
|
|
264
|
-
|
|
265
|
-
// Handle formats like "MM/dd/yyyy hh:mm a" or "dd/MM/yyyy HH:mm:ss"
|
|
266
|
-
const firstSplit = format.split(separator);
|
|
267
|
-
|
|
268
|
-
// If there's an AM/PM part, join everything after the first split back together
|
|
269
|
-
const datePart = firstSplit[0];
|
|
270
|
-
const timePart = firstSplit.slice(1).join(separator);
|
|
271
|
-
|
|
272
|
-
const dateRegexSource = buildDateFormatRegex(datePart)
|
|
273
|
-
.source.replace(/^\^|\$$/g, '');
|
|
274
|
-
const timeRegexSource = buildTimeFormatRegex(timePart)
|
|
275
|
-
.source.replace(/^\^|\$$/g, '');
|
|
276
|
-
|
|
277
|
-
const fullPattern = `^${dateRegexSource}${separator}${timeRegexSource}$`;
|
|
278
|
-
return new RegExp(fullPattern);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Converts a Date object into a string according to the specified format.
|
|
283
|
-
*/
|
|
284
|
-
export function formatDateToString(date: Date, format: DateFormat = 'yyyy-MM-dd'): string {
|
|
285
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
286
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
287
|
-
const year = String(date.getFullYear());
|
|
288
|
-
|
|
289
|
-
const shortMonthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
290
|
-
const longMonthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
291
|
-
|
|
292
|
-
return format
|
|
293
|
-
.replace("dd", day)
|
|
294
|
-
.replace("MM", month)
|
|
295
|
-
.replace("yyyy", year)
|
|
296
|
-
.replace("yy", year.slice(-2))
|
|
297
|
-
.replace("MMM", shortMonthNames[date.getMonth()])
|
|
298
|
-
.replace("MMMM", longMonthNames[date.getMonth()]);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
export function formatDateTimeToString(
|
|
302
|
-
date: Date,
|
|
303
|
-
format: DateTimeFormat = "yyyy-MM-dd'T'HH:mm"
|
|
304
|
-
): string {
|
|
305
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
306
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
307
|
-
const year = String(date.getFullYear());
|
|
308
|
-
|
|
309
|
-
const hours24 = String(date.getHours()).padStart(2, "0");
|
|
310
|
-
const hours12Raw = date.getHours() % 12 || 12;
|
|
311
|
-
const hours12 = String(hours12Raw).padStart(2, "0");
|
|
312
|
-
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
313
|
-
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
314
|
-
const ampm = date.getHours() >= 12 ? "PM" : "AM";
|
|
315
|
-
|
|
316
|
-
const shortMonthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
317
|
-
const longMonthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
318
|
-
|
|
319
|
-
return format
|
|
320
|
-
// Date replacements
|
|
321
|
-
.replace("dd", day)
|
|
322
|
-
.replace("MM", month)
|
|
323
|
-
.replace("yyyy", year)
|
|
324
|
-
.replace("yy", year.slice(-2))
|
|
325
|
-
.replace("MMM", shortMonthNames[date.getMonth()])
|
|
326
|
-
.replace("MMMM", longMonthNames[date.getMonth()])
|
|
327
|
-
// Time replacements
|
|
328
|
-
.replace("HH", hours24)
|
|
329
|
-
.replace("hh", hours12)
|
|
330
|
-
.replace("mm", minutes)
|
|
331
|
-
.replace("ss", seconds)
|
|
332
|
-
.replace("a", ampm);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/** Extracts AM/PM from a time string and returns the core time without it */
|
|
336
|
-
export function extractMeridiem(time: string): { coreTime: string; meridiem?: 'AM' | 'PM' } {
|
|
337
|
-
const meridiemRegex = /\s?(AM|PM)$/i;
|
|
338
|
-
const match = meridiemRegex.exec(time.trim());
|
|
339
|
-
if (match) {
|
|
340
|
-
return { coreTime: time.replace(meridiemRegex, '').trim(), meridiem: match[1].toUpperCase() as 'AM' | 'PM' };
|
|
341
|
-
}
|
|
342
|
-
return { coreTime: time.trim() };
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/** Safely parse a number and clamp it to a range, or return NaN if invalid */
|
|
346
|
-
export function parseAndClamp(value?: string, min = 0, max = 59): number {
|
|
347
|
-
const num = value ? Number(value) : NaN;
|
|
348
|
-
return !isNaN(num) ? Math.min(Math.max(num, min), max) : NaN;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/** Pads a number with leading zero, or returns placeholder if NaN */
|
|
352
|
-
export function padOrPlaceholder(num: number, placeholder: string): string {
|
|
353
|
-
return !isNaN(num) ? String(num).padStart(2, '0') : placeholder;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/** Determine meridiem if not explicitly provided */
|
|
357
|
-
export function resolveMeridiem(meridiem?: 'AM' | 'PM', hours?: number): 'AM' | 'PM' {
|
|
358
|
-
if (meridiem) return meridiem;
|
|
359
|
-
if (hours !== undefined && !isNaN(hours)) return hours >= 12 ? 'PM' : 'AM';
|
|
360
|
-
return 'AM';
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/** Main function refactored to use small utilities */
|
|
364
|
-
export function formatTimeToString(
|
|
365
|
-
time: string,
|
|
366
|
-
format: TimeFormat = 'HH:mm',
|
|
367
|
-
partialTime?: InputTimePartial
|
|
368
|
-
): string {
|
|
369
|
-
if (!time) return '';
|
|
370
|
-
|
|
371
|
-
const { coreTime, meridiem } = extractMeridiem(time);
|
|
372
|
-
const segments = coreTime.split(':');
|
|
373
|
-
|
|
374
|
-
const hours = parseAndClamp(segments[0], 0, 23);
|
|
375
|
-
const minutes = parseAndClamp(segments[1], 0, 59);
|
|
376
|
-
const seconds = parseAndClamp(segments[2], 0, 59);
|
|
377
|
-
|
|
378
|
-
const h = padOrPlaceholder(hours, 'HH');
|
|
379
|
-
const m = padOrPlaceholder(minutes, 'mm');
|
|
380
|
-
const s = padOrPlaceholder(seconds, 'ss');
|
|
381
|
-
const a = resolveMeridiem(meridiem, hours);
|
|
382
|
-
|
|
383
|
-
if (partialTime) {
|
|
384
|
-
switch (partialTime) {
|
|
385
|
-
case 'hour': return h;
|
|
386
|
-
case 'minute': return m;
|
|
387
|
-
case 'second': return s;
|
|
388
|
-
case 'meridiem': return a;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
return format
|
|
393
|
-
.replace('HH', h)
|
|
394
|
-
.replace('hh', h)
|
|
395
|
-
.replace('mm', m)
|
|
396
|
-
.replace('ss', s)
|
|
397
|
-
.replace('a', a);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Converts a time string into total minutes.
|
|
402
|
-
* Supports optional seconds and AM/PM.
|
|
403
|
-
*
|
|
404
|
-
* @param time Time string ("HH:mm", "HH:mm:ss", or "hh:mm AM/PM").
|
|
405
|
-
* @returns Total minutes (including fractional for seconds), or null if invalid.
|
|
406
|
-
*/
|
|
407
|
-
export function parseTimeToMinutes(time: string): number | null {
|
|
408
|
-
const regex = /^(\d{1,2}):(\d{2})(?::(\d{2}))?\s*(AM|PM)?$/i;
|
|
409
|
-
const match = regex.exec(time);
|
|
410
|
-
|
|
411
|
-
if (!match) return null;
|
|
412
|
-
|
|
413
|
-
let hours = parseInt(match[1], 10);
|
|
414
|
-
const minutes = parseInt(match[2], 10);
|
|
415
|
-
const seconds = match[3] ? parseInt(match[3], 10) : 0;
|
|
416
|
-
const period = match[4]?.toUpperCase();
|
|
417
|
-
|
|
418
|
-
if (period) {
|
|
419
|
-
if (hours === 12) {
|
|
420
|
-
hours = period === "AM" ? 0 : 12;
|
|
421
|
-
} else if (period === "PM") {
|
|
422
|
-
hours += 12;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
return hours * 60 + minutes + seconds / 60;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* Determines if the given time format uses a 12-hour (meridiem) format.
|
|
431
|
-
* Example: "hh:mm a" → true, "HH:mm" → false
|
|
432
|
-
*/
|
|
433
|
-
export function isMeridiemFormat(format?: TimeFormat | null): boolean {
|
|
434
|
-
if (!format) return false;
|
|
435
|
-
return format.includes('a') || format.includes('A');
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Extracts and returns the time format part of a DateTime format string.
|
|
440
|
-
* Example: "dd/MM/yyyy HH:mm" → "HH:mm"
|
|
441
|
-
*/
|
|
442
|
-
export function extractTimeFormat(dateTimeFormat: string): TimeFormat | null {
|
|
443
|
-
const regex = /\b[Hh]{1,2}:mm(?::ss)?(?:\s?[aA])?\b/;
|
|
444
|
-
const match = regex.exec(dateTimeFormat);
|
|
445
|
-
|
|
446
|
-
if (!match) return null;
|
|
447
|
-
|
|
448
|
-
const timePart = match[0].trim();
|
|
449
|
-
|
|
450
|
-
const allowedFormats: TimeFormat[] = ['HH:mm', 'HH:mm:ss', 'hh:mm a', 'hh:mm:ss a'];
|
|
451
|
-
return allowedFormats.includes(timePart as TimeFormat) ? (timePart as TimeFormat) : null;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Calculates the rotation angle (in degrees) for an hour hand on a 12-hour clock.
|
|
456
|
-
*
|
|
457
|
-
* @param hour - The hour value as a string (0-23 or 0-12).
|
|
458
|
-
* @returns The rotation angle in degrees, where 0 degrees is at 12 o'clock.
|
|
459
|
-
*/
|
|
460
|
-
export function calculateHourDegree(hour: string): number {
|
|
461
|
-
const num = Number.parseInt(hour, 10);
|
|
462
|
-
return ((num % 12) * 30 - 90);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* Calculates the rotation angle (in degrees) for a minute hand on a clock.
|
|
467
|
-
*
|
|
468
|
-
* @param minute - The minute value as a string (0-59).
|
|
469
|
-
* @returns The rotation angle in degrees, where 0 degrees is at 12 o'clock.
|
|
470
|
-
*/
|
|
471
|
-
export function calculateMinuteDegree(minute: string): number {
|
|
472
|
-
const num = Number.parseInt(minute, 10);
|
|
473
|
-
return (num * 6 - 90);
|
|
474
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalizes the value of an <input type="number">.
|
|
3
|
-
*
|
|
4
|
-
* - Returns a valid number if the input contains a numeric value
|
|
5
|
-
* - Returns null if the input is empty or not a valid number
|
|
6
|
-
*
|
|
7
|
-
* This helper ensures consistency between the raw input value
|
|
8
|
-
* and the form control value, preventing unintended NaN values.
|
|
9
|
-
*
|
|
10
|
-
* @param input The HTML input element of type "number"
|
|
11
|
-
* @returns number | null
|
|
12
|
-
*/
|
|
13
|
-
export function normalizeNumber(input: HTMLInputElement): number | null {
|
|
14
|
-
const num = input.valueAsNumber;
|
|
15
|
-
return isNaN(num) ? null : num;
|
|
16
|
-
}
|