@ngrdt/utils 0.0.5 → 0.0.6

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 (58) hide show
  1. package/.swcrc +29 -0
  2. package/eslint.config.js +22 -0
  3. package/jest.config.ts +30 -0
  4. package/package.json +7 -5
  5. package/project.json +29 -0
  6. package/rollup.config.js +20 -0
  7. package/src/index.ts +17 -0
  8. package/src/lib/__test__/array.utils.spec.ts +13 -0
  9. package/src/lib/__test__/css.utils.spec.ts +27 -0
  10. package/src/lib/__test__/date-format.spec.ts +71 -0
  11. package/src/lib/__test__/date.utils.spec.ts +72 -0
  12. package/src/lib/__test__/file-zip.utils.spec.ts +14 -0
  13. package/src/lib/__test__/object.utils.spec.ts +23 -0
  14. package/src/lib/__test__/random.utils.spec.ts +7 -0
  15. package/src/lib/__test__/string.utils.spec.ts +17 -0
  16. package/src/lib/types/aria.ts +334 -0
  17. package/src/lib/types/encodings.ts +273 -0
  18. package/src/lib/types/keyboard.ts +29 -0
  19. package/src/lib/types/mime-types.ts +119 -0
  20. package/src/lib/{router.utils.d.ts → types/router.ts} +1 -1
  21. package/src/lib/types/type.ts +43 -0
  22. package/src/lib/utils/array.ts +30 -0
  23. package/src/lib/utils/css.ts +69 -0
  24. package/src/lib/utils/date-format.ts +580 -0
  25. package/src/lib/utils/date.ts +363 -0
  26. package/src/lib/utils/file.ts +258 -0
  27. package/src/lib/utils/html.ts +26 -0
  28. package/src/lib/utils/model.ts +73 -0
  29. package/src/lib/utils/names.ts +73 -0
  30. package/src/lib/utils/object.ts +58 -0
  31. package/src/lib/utils/random.ts +9 -0
  32. package/src/lib/utils/rxjs.ts +30 -0
  33. package/src/lib/utils/string.ts +123 -0
  34. package/tsconfig.json +22 -0
  35. package/tsconfig.lib.json +11 -0
  36. package/tsconfig.spec.json +14 -0
  37. package/index.cjs.d.ts +0 -1
  38. package/index.cjs.js +0 -1
  39. package/index.esm.d.ts +0 -1
  40. package/index.esm.js +0 -1
  41. package/src/index.d.ts +0 -17
  42. package/src/lib/array.utils.d.ts +0 -6
  43. package/src/lib/color.utils.d.ts +0 -5
  44. package/src/lib/css.utils.d.ts +0 -14
  45. package/src/lib/date-format.d.ts +0 -77
  46. package/src/lib/date.utils.d.ts +0 -60
  47. package/src/lib/encodings.d.ts +0 -44
  48. package/src/lib/file.utils.d.ts +0 -69
  49. package/src/lib/html.utils.d.ts +0 -4
  50. package/src/lib/keyboard.utils.d.ts +0 -36
  51. package/src/lib/mime-types.d.ts +0 -109
  52. package/src/lib/model.utils.d.ts +0 -22
  53. package/src/lib/names.d.ts +0 -19
  54. package/src/lib/object.utils.d.ts +0 -5
  55. package/src/lib/random.utils.d.ts +0 -4
  56. package/src/lib/rxjs.utils.d.ts +0 -6
  57. package/src/lib/string.utils.d.ts +0 -22
  58. package/src/lib/type.utils.d.ts +0 -13
@@ -0,0 +1,119 @@
1
+ export enum RdtMimeType {
2
+ DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
3
+ XLSX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
4
+ PDF = 'application/pdf',
5
+ TXT = 'text/plain',
6
+ CSV = 'text/csv',
7
+ ZIP = 'application/zip',
8
+ JPG = 'image/jpeg',
9
+ PNG = 'image/png',
10
+ GIF = 'image/gif',
11
+ SVG = 'image/svg+xml',
12
+ HTML = 'text/html',
13
+ XML = 'application/xml',
14
+ JSON = 'application/json',
15
+ MP3 = 'audio/mpeg',
16
+ MP4 = 'video/mp4',
17
+ OGG = 'audio/ogg',
18
+ WEBM = 'video/webm',
19
+ WAV = 'audio/wav',
20
+ AVI = 'video/x-msvideo',
21
+ MPEG = 'video/mpeg',
22
+ WEBP = 'image/webp',
23
+ ICO = 'image/x-icon',
24
+ TTF = 'font/ttf',
25
+ WOFF = 'font/woff',
26
+ WOFF2 = 'font/woff2',
27
+ EOT = 'application/vnd.ms-fontobject',
28
+ OTF = 'font/otf',
29
+ PPTX = 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
30
+ PPT = 'application/vnd.ms-powerpoint',
31
+ XLS = 'application/vnd.ms-excel',
32
+ DOC = 'application/msword',
33
+ ODT = 'application/vnd.oasis.opendocument.text',
34
+ ODS = 'application/vnd.oasis.opendocument.spreadsheet',
35
+ ODP = 'application/vnd.oasis.opendocument.presentation',
36
+ ODF = 'application/vnd.oasis.opendocument.formula',
37
+ RAR = 'application/vnd.rar',
38
+ TAR = 'application/x-tar',
39
+ GZIP = 'application/gzip',
40
+ BZIP2 = 'application/x-bzip2',
41
+ XZ = 'application/x-xz',
42
+ SEVENZ = 'application/x-7z-compressed',
43
+ RAR5 = 'application/x-rar-compressed',
44
+ WMA = 'audio/x-ms-wma',
45
+ WMV = 'video/x-ms-wmv',
46
+ FLV = 'video/x-flv',
47
+ OGV = 'video/ogg',
48
+ BIN = 'application/octet-stream',
49
+ }
50
+
51
+ export enum RdtCombinedMimeType {
52
+ IMAGE = 'image/*',
53
+ AUDIO = 'audio/*',
54
+ VIDEO = 'video/*',
55
+ FONT = 'font/*',
56
+ DOCUMENT = `${RdtMimeType.DOC},${RdtMimeType.DOCX},${RdtMimeType.ODT},${RdtMimeType.PDF},${RdtMimeType.TXT},${RdtMimeType.CSV}`,
57
+ SPREADSHEET = `${RdtMimeType.XLS},${RdtMimeType.XLSX},${RdtMimeType.ODS}`,
58
+ PRESENTATION = `${RdtMimeType.PPT},${RdtMimeType.PPTX},${RdtMimeType.ODP}`,
59
+ ARCHIVE = `${RdtMimeType.ZIP},${RdtMimeType.RAR},${RdtMimeType.TAR},${RdtMimeType.GZIP},${RdtMimeType.BZIP2},${RdtMimeType.XZ},${RdtMimeType.SEVENZ},${RdtMimeType.RAR5}`,
60
+ }
61
+
62
+ export const EXTENSION_BY_MIME_TYPE = {
63
+ [RdtMimeType.DOCX]: 'docx',
64
+ [RdtMimeType.XLSX]: 'xlsx',
65
+ [RdtMimeType.PDF]: 'pdf',
66
+ [RdtMimeType.TXT]: 'txt',
67
+ [RdtMimeType.CSV]: 'csv',
68
+ [RdtMimeType.ZIP]: 'zip',
69
+ [RdtMimeType.JPG]: 'jpg',
70
+ [RdtMimeType.PNG]: 'png',
71
+ [RdtMimeType.GIF]: 'gif',
72
+ [RdtMimeType.SVG]: 'svg',
73
+ [RdtMimeType.HTML]: 'html',
74
+ [RdtMimeType.XML]: 'xml',
75
+ [RdtMimeType.JSON]: 'json',
76
+ [RdtMimeType.MP3]: 'mp3',
77
+ [RdtMimeType.MP4]: 'mp4',
78
+ [RdtMimeType.OGG]: 'ogg',
79
+ [RdtMimeType.WEBM]: 'webm',
80
+ [RdtMimeType.WAV]: 'wav',
81
+ [RdtMimeType.AVI]: 'avi',
82
+ [RdtMimeType.MPEG]: 'mpeg',
83
+ [RdtMimeType.WEBP]: 'webp',
84
+ [RdtMimeType.ICO]: 'ico',
85
+ [RdtMimeType.TTF]: 'ttf',
86
+ [RdtMimeType.WOFF]: 'woff',
87
+ [RdtMimeType.WOFF2]: 'woff2',
88
+ [RdtMimeType.EOT]: 'eot',
89
+ [RdtMimeType.OTF]: 'otf',
90
+ [RdtMimeType.PPTX]: 'pptx',
91
+ [RdtMimeType.PPT]: 'ppt',
92
+ [RdtMimeType.XLS]: 'xls',
93
+ [RdtMimeType.DOC]: 'doc',
94
+ [RdtMimeType.ODT]: 'odt',
95
+ [RdtMimeType.ODS]: 'ods',
96
+ [RdtMimeType.ODP]: 'odp',
97
+ [RdtMimeType.ODF]: 'odf',
98
+ [RdtMimeType.RAR]: 'rar',
99
+ [RdtMimeType.TAR]: 'tar',
100
+ [RdtMimeType.GZIP]: 'gz',
101
+ [RdtMimeType.BZIP2]: 'bz2',
102
+ [RdtMimeType.XZ]: 'xz',
103
+ [RdtMimeType.SEVENZ]: '7z',
104
+ [RdtMimeType.RAR5]: 'rar',
105
+ [RdtMimeType.WMA]: 'wma',
106
+ [RdtMimeType.WMV]: 'wmv',
107
+ [RdtMimeType.FLV]: 'flv',
108
+ [RdtMimeType.OGV]: 'ogv',
109
+ [RdtMimeType.BIN]: 'bin',
110
+ } as const;
111
+
112
+ export const MIME_TYPE_BY_EXTENSION: Record<
113
+ (typeof EXTENSION_BY_MIME_TYPE)[keyof typeof EXTENSION_BY_MIME_TYPE],
114
+ RdtMimeType
115
+ > = {} as any;
116
+
117
+ for (const [key, value] of Object.entries(EXTENSION_BY_MIME_TYPE)) {
118
+ MIME_TYPE_BY_EXTENSION[value] = key as RdtMimeType;
119
+ }
@@ -1 +1 @@
1
- export type WindowOpenTargetType = '_blank' | '_self' | '_parent' | '_top';
1
+ export type WindowOpenTargetType = '_blank' | '_self' | '_parent' | '_top';
@@ -0,0 +1,43 @@
1
+ export type TypesAreEqual<T, U> = [T] extends [U]
2
+ ? [U] extends [T]
3
+ ? true
4
+ : false
5
+ : false;
6
+
7
+ export type DotNotationPath<T> = keyof T extends string
8
+ ? PathImpl2<T> extends infer P
9
+ ? P extends string | keyof T
10
+ ? P
11
+ : keyof T
12
+ : keyof T
13
+ : never;
14
+ export type StringKey<T, TGrid = T> = keyof T & keyof TGrid & string;
15
+ export type Nullable<T> = T | null | undefined;
16
+
17
+ // Internal
18
+
19
+ type IsAny<T> = unknown extends T
20
+ ? [keyof T] extends [never]
21
+ ? false
22
+ : true
23
+ : false;
24
+ type ExcludeArrayKeys<T> = T extends ArrayLike<any>
25
+ ? Exclude<keyof T, keyof any[]>
26
+ : keyof T;
27
+
28
+ type PathImpl<T, Key extends keyof T> = Key extends string
29
+ ? IsAny<T[Key]> extends true
30
+ ? never
31
+ : T[Key] extends Record<string, any>
32
+ ?
33
+ | `${Key}.${PathImpl<T[Key], ExcludeArrayKeys<T[Key]>> & string}`
34
+ | `${Key}.${ExcludeArrayKeys<T[Key]> & string}`
35
+ : never
36
+ : never;
37
+ type PathImpl2<T> = PathImpl<T, keyof T> | keyof T;
38
+
39
+ export type NullPartial<T> = {
40
+ [key in keyof T]: T[key] | null;
41
+ };
42
+
43
+ export type Modify<T, R> = Omit<T, keyof R> & R;
@@ -0,0 +1,30 @@
1
+ import { Nullable } from '../types/type';
2
+
3
+ export class RdtArrayUtils {
4
+ static removeAt<T>(array: T[], index: number): T[] {
5
+ if (index < 0 || index > array.length) {
6
+ throw new Error(
7
+ `Out of bounds! Array length: ${array.length}, index: ${index}`
8
+ );
9
+ }
10
+
11
+ return [...array.slice(0, index), ...array.slice(index + 1)];
12
+ }
13
+
14
+ static insertAt<T>(array: T[], index: number, item: T): T[] {
15
+ if (index < 0 || index > array.length) {
16
+ throw new Error(
17
+ `Out of bounds! Array length: ${array.length}, index: ${index}`
18
+ );
19
+ }
20
+
21
+ return [...array.slice(0, index), item, ...array.slice(index)];
22
+ }
23
+
24
+ static isEqual<T>(a: Nullable<Readonly<T[]>>, b: Nullable<Readonly<T[]>>) {
25
+ if (!a || !b) {
26
+ return !a === !b;
27
+ }
28
+ return a.length === b.length && a.every((el) => b.indexOf(el) > -1);
29
+ }
30
+ }
@@ -0,0 +1,69 @@
1
+ export class RdtCssUtils {
2
+ static normalizeColor(color: string) {
3
+ const normalized = color.trim();
4
+
5
+ if (this.isHexColor(normalized)) {
6
+ return RdtCssUtils.normalizeHex(normalized);
7
+ } else if (this.isRgbColor(normalized)) {
8
+ return RdtCssUtils.normalizeRgb(normalized);
9
+ } else if (this.isRgbaColor(normalized)) {
10
+ return RdtCssUtils.normalizeRgba(normalized);
11
+ }
12
+
13
+ return null;
14
+ }
15
+
16
+ private static normalizeHex(color: string) {
17
+ const matches = color.match(RdtCssUtils.hexRegex);
18
+ if (!matches) {
19
+ return null;
20
+ }
21
+
22
+ return `#${matches[2]}`;
23
+ }
24
+
25
+ private static normalizeRgb(color: string) {
26
+ const matches = color.match(RdtCssUtils.rgbRegex);
27
+ if (!matches) {
28
+ return null;
29
+ }
30
+
31
+ return `rgb(${matches[2]},${matches[3]},${matches[4]})`;
32
+ }
33
+
34
+ private static normalizeRgba(color: string) {
35
+ const matches = color.match(RdtCssUtils.rgbaRegex);
36
+ if (!matches) {
37
+ return null;
38
+ }
39
+
40
+ return `rgba(${matches[2]},${matches[3]},${matches[4]},${matches[5]})`;
41
+ }
42
+
43
+ private static isRgbColor(color: string) {
44
+ return RdtCssUtils.rgbRegex.test(color);
45
+ }
46
+
47
+ private static isHexColor(color: string): boolean {
48
+ return RdtCssUtils.hexRegex.test(color);
49
+ }
50
+
51
+ private static isRgbaColor(color: string) {
52
+ return RdtCssUtils.rgbaRegex.test(color);
53
+ }
54
+
55
+ private static rgbRegex =
56
+ /^(rgb)?\(?\s*([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\s*\)?$/;
57
+ private static rgbaRegex =
58
+ /^(rgba)?\(?\s*([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\W+((0(\.\d+)?)|(1(\.0)?))\s*\)?$/;
59
+ private static hexRegex = /^(#?)([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
60
+ }
61
+
62
+ export type RdtHorizontalDirection = 'left' | 'right';
63
+ export type RdtVerticalDirection = 'up' | 'down';
64
+
65
+ export interface RdtRgbColor {
66
+ r: number;
67
+ g: number;
68
+ b: number;
69
+ }