@ngrdt/utils 0.0.6 → 0.0.8

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 (57) hide show
  1. package/index.cjs.d.ts +1 -0
  2. package/index.cjs.js +1 -0
  3. package/index.esm.d.ts +1 -0
  4. package/index.esm.js +1 -0
  5. package/package.json +6 -6
  6. package/src/lib/types/aria.d.ts +219 -0
  7. package/src/lib/types/encodings.d.ts +44 -0
  8. package/src/lib/types/keyboard.d.ts +36 -0
  9. package/src/lib/types/mime-types.d.ts +109 -0
  10. package/src/lib/types/{router.ts → router.d.ts} +1 -1
  11. package/src/lib/types/type.d.ts +13 -0
  12. package/src/lib/utils/array.d.ts +6 -0
  13. package/src/lib/utils/css.d.ts +19 -0
  14. package/src/lib/utils/date-format.d.ts +77 -0
  15. package/src/lib/utils/date.d.ts +60 -0
  16. package/src/lib/utils/file.d.ts +69 -0
  17. package/src/lib/utils/html.d.ts +4 -0
  18. package/src/lib/utils/model.d.ts +22 -0
  19. package/src/lib/utils/names.d.ts +19 -0
  20. package/src/lib/utils/object.d.ts +5 -0
  21. package/src/lib/utils/random.d.ts +4 -0
  22. package/src/lib/utils/rxjs.d.ts +6 -0
  23. package/src/lib/utils/string.d.ts +22 -0
  24. package/.swcrc +0 -29
  25. package/eslint.config.js +0 -22
  26. package/jest.config.ts +0 -30
  27. package/project.json +0 -29
  28. package/rollup.config.js +0 -20
  29. package/src/lib/__test__/array.utils.spec.ts +0 -13
  30. package/src/lib/__test__/css.utils.spec.ts +0 -27
  31. package/src/lib/__test__/date-format.spec.ts +0 -71
  32. package/src/lib/__test__/date.utils.spec.ts +0 -72
  33. package/src/lib/__test__/file-zip.utils.spec.ts +0 -14
  34. package/src/lib/__test__/object.utils.spec.ts +0 -23
  35. package/src/lib/__test__/random.utils.spec.ts +0 -7
  36. package/src/lib/__test__/string.utils.spec.ts +0 -17
  37. package/src/lib/types/aria.ts +0 -334
  38. package/src/lib/types/encodings.ts +0 -273
  39. package/src/lib/types/keyboard.ts +0 -29
  40. package/src/lib/types/mime-types.ts +0 -119
  41. package/src/lib/types/type.ts +0 -43
  42. package/src/lib/utils/array.ts +0 -30
  43. package/src/lib/utils/css.ts +0 -69
  44. package/src/lib/utils/date-format.ts +0 -580
  45. package/src/lib/utils/date.ts +0 -363
  46. package/src/lib/utils/file.ts +0 -258
  47. package/src/lib/utils/html.ts +0 -26
  48. package/src/lib/utils/model.ts +0 -73
  49. package/src/lib/utils/names.ts +0 -73
  50. package/src/lib/utils/object.ts +0 -58
  51. package/src/lib/utils/random.ts +0 -9
  52. package/src/lib/utils/rxjs.ts +0 -30
  53. package/src/lib/utils/string.ts +0 -123
  54. package/tsconfig.json +0 -22
  55. package/tsconfig.lib.json +0 -11
  56. package/tsconfig.spec.json +0 -14
  57. /package/src/{index.ts → index.d.ts} +0 -0
@@ -1,73 +0,0 @@
1
- /**
2
- * From @nx/devkit because it has nodejs as dependency and won't transpile.
3
- * Util function to generate different strings based off the provided name.
4
- *
5
- * Examples:
6
- *
7
- * ```typescript
8
- * names("my-name") // {name: 'my-name', className: 'MyName', propertyName: 'myName', constantName: 'MY_NAME', fileName: 'my-name'}
9
- * names("myName") // {name: 'myName', className: 'MyName', propertyName: 'myName', constantName: 'MY_NAME', fileName: 'my-name'}
10
- * ```
11
- * @param name
12
- */
13
- export function names(name: string): {
14
- name: string;
15
- className: string;
16
- propertyName: string;
17
- constantName: string;
18
- fileName: string;
19
- } {
20
- return {
21
- name,
22
- className: toClassName(name),
23
- propertyName: toPropertyName(name),
24
- constantName: toConstantName(name),
25
- fileName: toFileName(name),
26
- };
27
- }
28
-
29
- /**
30
- * Hyphenated to UpperCamelCase
31
- */
32
- function toClassName(str: string): string {
33
- return toCapitalCase(toPropertyName(str));
34
- }
35
-
36
- /**
37
- * Hyphenated to lowerCamelCase
38
- */
39
- function toPropertyName(s: string): string {
40
- return s
41
- .replace(/([^a-zA-Z0-9])+(.)?/g, (_, __, chr) =>
42
- chr ? chr.toUpperCase() : ''
43
- )
44
- .replace(/[^a-zA-Z\d]/g, '')
45
- .replace(/^([A-Z])/, m => m.toLowerCase());
46
- }
47
-
48
- /**
49
- * Hyphenated to CONSTANT_CASE
50
- */
51
- function toConstantName(s: string): string {
52
- const normalizedS = s.toUpperCase() === s ? s.toLowerCase() : s;
53
- return toFileName(toPropertyName(normalizedS))
54
- .replace(/([^a-zA-Z0-9])/g, '_')
55
- .toUpperCase();
56
- }
57
-
58
- /**
59
- * Upper camelCase to lowercase, hyphenated
60
- */
61
- function toFileName(s: string): string {
62
- return s
63
- .replace(/([a-z\d])([A-Z])/g, '$1_$2')
64
- .toLowerCase()
65
- .replace(/(?!^_)[ _]/g, '-');
66
- }
67
-
68
- /**
69
- * Capitalizes the first letter of a string
70
- */
71
- function toCapitalCase(s: string): string {
72
- return s.charAt(0).toUpperCase() + s.slice(1);
73
- }
@@ -1,58 +0,0 @@
1
- export class RdtObjectUtils {
2
- static pluck<T>(obj: T, path: string | (string | number)[]) {
3
- if (!obj) {
4
- return undefined;
5
- }
6
- const parts = Array.isArray(path) ? path : path.split('.');
7
- let current: any = obj;
8
-
9
- for (const key of parts) {
10
- if (current == undefined) {
11
- return undefined;
12
- }
13
- if (Array.isArray(current) && typeof key === 'string') {
14
- current = current[parseInt(key)];
15
- } else {
16
- current = current[key];
17
- }
18
- }
19
- return current;
20
- }
21
-
22
- static notNullGuard<T>(value: T | undefined | null): value is T {
23
- return value != null;
24
- }
25
-
26
- static expandKey(key: string, value: any) {
27
- const parts = key.split('.');
28
- if (parts.length === 0) {
29
- return value;
30
- }
31
- const first = getObjectFromKey(parts[0]);
32
- let current = first;
33
-
34
- for (let i = 1; i < parts.length; i++) {
35
- const next = getObjectFromKey(parts[i]);
36
- current.obj[current.key] = next.obj;
37
- current = next;
38
- }
39
- current.obj[current.key] = value;
40
-
41
- return first.obj;
42
- }
43
- }
44
-
45
- function getObjectFromKey(key: string) {
46
- const int = parseInt(key);
47
- if (isNaN(int)) {
48
- return {
49
- obj: {} as any,
50
- key: key,
51
- } as const;
52
- } else {
53
- return {
54
- obj: [] as any[],
55
- key: int,
56
- } as const;
57
- }
58
- }
@@ -1,9 +0,0 @@
1
- export class RdtRandomUtils {
2
- static randomId(): string {
3
- return Math.random().toString(36).substring(2);
4
- }
5
-
6
- static trueFalse(): boolean {
7
- return Math.random() < 0.5;
8
- }
9
- }
@@ -1,30 +0,0 @@
1
- import {
2
- Observable,
3
- combineLatest,
4
- map,
5
- startWith,
6
- switchMap,
7
- EMPTY,
8
- of,
9
- } from 'rxjs';
10
-
11
- export class RdtRxUtils {
12
- // Will repeat last value when notifier$ emits anything.
13
- static repeatLatestWhen<T>(notifier$: Observable<any>) {
14
- return (source: Observable<T>) => {
15
- return combineLatest([source, notifier$.pipe(startWith(null))]).pipe(
16
- map(([val]) => val)
17
- );
18
- };
19
- }
20
-
21
- static completeIfNull<T>(source$: Observable<T>): Observable<NonNullable<T>> {
22
- return source$.pipe(
23
- switchMap((value) => (value == null ? EMPTY : of(value)))
24
- );
25
- }
26
-
27
- static makeObservable<T>(value: T | Observable<T>): Observable<T> {
28
- return value instanceof Observable ? value : of(value);
29
- }
30
- }
@@ -1,123 +0,0 @@
1
- import { Params } from '@angular/router';
2
- import { Nullable } from '../types/type';
3
-
4
- export class RdtStringUtils {
5
- static tokenize(value: string | undefined): string[] {
6
- return value ? value.split(/\W+/).filter((tokens) => !!tokens) : [];
7
- }
8
-
9
- static joinPaths(parent: string, child: string) {
10
- const b = parent.endsWith('/');
11
- const p = child.startsWith('/');
12
- if (b && p) {
13
- return parent.slice(0, -1) + child;
14
- } else if (b || p) {
15
- return parent + child;
16
- } else {
17
- return parent + '/' + child;
18
- }
19
- }
20
-
21
- static isAlphabetCharacter(char: string) {
22
- if (char.length > 1) {
23
- return false;
24
- }
25
- return char.toLocaleLowerCase() !== char.toLocaleUpperCase();
26
- }
27
-
28
- static isNumericCharacter(char: string) {
29
- return !isNaN(parseInt(char));
30
- }
31
-
32
- static capitalize(str: string) {
33
- return str.charAt(0).toLocaleUpperCase() + str.slice(1);
34
- }
35
-
36
- static toDataTestId(str: string) {
37
- return RdtStringUtils.removeAccents(str).toLowerCase()?.replace(/ /g, '-');
38
- }
39
-
40
- static removeAccents(str: string) {
41
- return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
42
- }
43
-
44
- static stripTrailingSlash(url: string): string {
45
- const match = url.match(/#|\?|$/);
46
- const pathEndIdx = (match && match.index) || url.length;
47
- const droppedSlashIdx = pathEndIdx - (url[pathEndIdx - 1] === '/' ? 1 : 0);
48
- return url.slice(0, droppedSlashIdx) + url.slice(pathEndIdx);
49
- }
50
-
51
- static createAbsoluteUrl(url: string, baseHref: string) {
52
- return RdtStringUtils.joinPaths(baseHref, url);
53
- }
54
-
55
- static appendQueryParams(url: string, params: Nullable<Params>) {
56
- if (!params || Object.keys(params).length === 0) {
57
- return url;
58
- } else {
59
- const queryParams = new URLSearchParams(params);
60
- return `${url}?${queryParams}`;
61
- }
62
- }
63
-
64
- static localeCompare(
65
- a: Nullable<string>,
66
- b: Nullable<string>,
67
- order: 'asc' | 'desc' = 'asc'
68
- ) {
69
- const mult = order === 'asc' ? 1 : -1;
70
- if (a == b) {
71
- return 0;
72
- } else if (a == null) {
73
- return -mult;
74
- } else if (b == null) {
75
- return mult;
76
- }
77
- return a.localeCompare(b) * mult;
78
- }
79
-
80
- static komixcomlocalReplaceString(url: string) {
81
- const hostname = location.hostname;
82
- const replaceString = url.includes('komix.com')
83
- ? 'komix.com'
84
- : 'komix.local';
85
- const toReplace = hostname.includes('komix.com')
86
- ? 'komix.com'
87
- : 'komix.local';
88
- return { replaceString, toReplace };
89
- }
90
-
91
- static swapChars(src: string, i: number, j: number) {
92
- if (i < 0 || j < 0 || i >= src.length || j >= src.length) {
93
- return src;
94
- }
95
- if (j < i) {
96
- [i, j] = [j, i];
97
- }
98
- return (
99
- src.slice(0, i) + src[j] + src.slice(i + 1, j) + src[i] + src.slice(j + 1)
100
- );
101
- }
102
-
103
- static insertAt(src: string, index: number, value: string) {
104
- return src.slice(0, index) + value + src.slice(index);
105
- }
106
-
107
- static getDataTestId(
108
- label: string,
109
- prefix?: Nullable<string>,
110
- suffix?: Nullable<string>
111
- ) {
112
- let dataTestId = label.toLowerCase()?.replace(/ /g, '-');
113
-
114
- if (prefix) {
115
- dataTestId = `${prefix}__${dataTestId}`;
116
- }
117
- if (suffix) {
118
- dataTestId = `${dataTestId}--${suffix}`;
119
- }
120
-
121
- return RdtStringUtils.removeAccents(dataTestId);
122
- }
123
- }
package/tsconfig.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "commonjs",
5
- "forceConsistentCasingInFileNames": true,
6
- "strict": true,
7
- "noImplicitOverride": true,
8
- "noImplicitReturns": true,
9
- "noFallthroughCasesInSwitch": true,
10
- "noPropertyAccessFromIndexSignature": true
11
- },
12
- "files": [],
13
- "include": [],
14
- "references": [
15
- {
16
- "path": "./tsconfig.lib.json"
17
- },
18
- {
19
- "path": "./tsconfig.spec.json"
20
- }
21
- ]
22
- }
package/tsconfig.lib.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "declaration": true,
6
- "types": ["node"],
7
- "allowJs": true
8
- },
9
- "include": ["src/**/*.ts"],
10
- "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
11
- }
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node"]
7
- },
8
- "include": [
9
- "jest.config.ts",
10
- "src/**/*.test.ts",
11
- "src/**/*.spec.ts",
12
- "src/**/*.d.ts"
13
- ]
14
- }
File without changes