@knime/utils 1.11.0 → 1.11.2

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 (86) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +67 -14
  3. package/dist/globals.d.ts +8 -0
  4. package/dist/index.js +714 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/src/capitalize.d.ts +20 -0
  7. package/dist/src/capitalize.d.ts.map +1 -0
  8. package/dist/src/dateMinMaxCheck.d.ts +19 -0
  9. package/dist/src/dateMinMaxCheck.d.ts.map +1 -0
  10. package/dist/src/debounce.d.ts +4 -0
  11. package/dist/src/debounce.d.ts.map +1 -0
  12. package/dist/src/fileExtensions.d.ts +33 -0
  13. package/dist/src/fileExtensions.d.ts.map +1 -0
  14. package/dist/src/filters.d.ts +13 -0
  15. package/dist/src/filters.d.ts.map +1 -0
  16. package/dist/src/format.d.ts +39 -0
  17. package/dist/src/format.d.ts.map +1 -0
  18. package/dist/src/formatHotkeys.d.ts +17 -0
  19. package/dist/src/formatHotkeys.d.ts.map +1 -0
  20. package/dist/src/getDeepActiveElement.d.ts +3 -0
  21. package/dist/src/getDeepActiveElement.d.ts.map +1 -0
  22. package/{src/getWrappedAroundIndex.ts → dist/src/getWrappedAroundIndex.d.ts} +3 -2
  23. package/dist/src/getWrappedAroundIndex.d.ts.map +1 -0
  24. package/{src/hotkeys.ts → dist/src/hotkeys.d.ts} +4 -17
  25. package/dist/src/hotkeys.d.ts.map +1 -0
  26. package/dist/src/index.d.ts +29 -0
  27. package/dist/src/index.d.ts.map +1 -0
  28. package/dist/src/intervalUtils.d.ts +114 -0
  29. package/dist/src/intervalUtils.d.ts.map +1 -0
  30. package/{src/localTimezone.ts → dist/src/localTimezone.d.ts} +3 -2
  31. package/dist/src/localTimezone.d.ts.map +1 -0
  32. package/dist/src/navigator.d.ts +11 -0
  33. package/dist/src/navigator.d.ts.map +1 -0
  34. package/{src/numIntegerDigits.ts → dist/src/numIntegerDigits.d.ts} +3 -2
  35. package/dist/src/numIntegerDigits.d.ts.map +1 -0
  36. package/dist/src/promise/createAbortablePromise.d.ts +32 -0
  37. package/dist/src/promise/createAbortablePromise.d.ts.map +1 -0
  38. package/dist/src/promise/createUnwrappedPromise.d.ts +7 -0
  39. package/dist/src/promise/createUnwrappedPromise.d.ts.map +1 -0
  40. package/dist/src/promise/index.d.ts +4 -0
  41. package/dist/src/promise/index.d.ts.map +1 -0
  42. package/dist/src/promise/retryPromise.d.ts +16 -0
  43. package/dist/src/promise/retryPromise.d.ts.map +1 -0
  44. package/dist/src/sanitization.d.ts +8 -0
  45. package/dist/src/sanitization.d.ts.map +1 -0
  46. package/dist/src/sleep.d.ts +5 -0
  47. package/dist/src/sleep.d.ts.map +1 -0
  48. package/dist/src/truncateString.d.ts +3 -0
  49. package/dist/src/truncateString.d.ts.map +1 -0
  50. package/dist/src/updateDate.d.ts +11 -0
  51. package/dist/src/updateDate.d.ts.map +1 -0
  52. package/{src/updateTime.ts → dist/src/updateTime.d.ts} +3 -11
  53. package/dist/src/updateTime.d.ts.map +1 -0
  54. package/dist/test-utils/index.d.ts +3 -0
  55. package/dist/test-utils/index.d.ts.map +1 -0
  56. package/dist/test-utils/index.js +40 -0
  57. package/dist/test-utils/index.js.map +1 -0
  58. package/dist/test-utils/muteConsole.d.ts +8 -0
  59. package/dist/test-utils/muteConsole.d.ts.map +1 -0
  60. package/package.json +51 -33
  61. package/src/capitalize.ts +0 -45
  62. package/src/dateMinMaxCheck.ts +0 -68
  63. package/src/debounce.ts +0 -28
  64. package/src/fileExtensions.ts +0 -87
  65. package/src/filters.ts +0 -114
  66. package/src/format.ts +0 -113
  67. package/src/formatHotkeys.ts +0 -98
  68. package/src/getDeepActiveElement.ts +0 -9
  69. package/src/index.ts +0 -76
  70. package/src/intervalUtils.ts +0 -434
  71. package/src/navigator.ts +0 -13
  72. package/src/promise/createAbortablePromise.ts +0 -56
  73. package/src/promise/createUnwrappedPromise.ts +0 -17
  74. package/src/promise/index.ts +0 -3
  75. package/src/promise/retryPromise.ts +0 -45
  76. package/src/sanitization.ts +0 -72
  77. package/src/sleep.ts +0 -6
  78. package/src/truncateString.ts +0 -7
  79. package/src/updateDate.ts +0 -23
  80. package/src/uploadManager/index.ts +0 -370
  81. package/test-utils/index.ts +0 -3
  82. package/test-utils/muteConsole.ts +0 -54
  83. /package/{src/audit → audit}/README.md +0 -0
  84. /package/{src/audit → audit}/bulkAudit.js +0 -0
  85. /package/{src/audit → audit}/cli.js +0 -0
  86. /package/{src/config/globals.d.ts → globals.d.ts} +0 -0
package/src/filters.ts DELETED
@@ -1,114 +0,0 @@
1
- /**
2
- * These definitions can be used to filter an array. Each entry should contain a method normalize which can be used to
3
- * compile any filter settings and a method "test" which takes the compiled result, additional settings and the item to
4
- * be matched/filtered
5
- * */
6
- interface FilterDefinition<SearchTerm, Normalized, Testable> {
7
- id: string;
8
- normalize: (
9
- searchTerm: SearchTerm,
10
- caseSensitiveSearch: boolean,
11
- ) => Normalized;
12
- test: (
13
- text: Testable,
14
- normalizedSearchTerm: Normalized,
15
- caseSensitiveSearch: boolean,
16
- inverseSearch: boolean,
17
- ) => boolean;
18
- }
19
-
20
- interface StringTest {
21
- test(str: string): boolean;
22
- }
23
-
24
- type SearchFilterDefinition = FilterDefinition<string, string, string>;
25
- type PatternFilterDefinition = FilterDefinition<
26
- string,
27
- RegExp | StringTest,
28
- string
29
- >;
30
- type TypeFilterDefinition = FilterDefinition<
31
- string[],
32
- StringTest,
33
- string | undefined
34
- >;
35
-
36
- const modeDefinitions = [
37
- {
38
- id: "search",
39
- normalize(searchTerm, caseSensitiveSearch) {
40
- return caseSensitiveSearch ? searchTerm : searchTerm.toLowerCase();
41
- },
42
- test(text, normalizedSearchTerm, caseSensitiveSearch, inverseSearch) {
43
- const testText = caseSensitiveSearch ? text : text.toLowerCase();
44
- const matches = testText.includes(normalizedSearchTerm);
45
- return inverseSearch ? !matches : matches;
46
- },
47
- } satisfies SearchFilterDefinition,
48
- {
49
- id: "wildcard",
50
- normalize(searchTerm, caseSensitiveSearch) {
51
- // Do a regex search, explicitly matching start and end of the search term.
52
- // All regex special character except from "* and ?" (wildcards) are escaped.
53
- if (searchTerm.length > 0) {
54
- const escapedSearchTerm = searchTerm.replace(
55
- /[-[\]{}()+.,\\^$|#\s]/g,
56
- "\\$&",
57
- );
58
- const wildcardSearchTerm = escapedSearchTerm
59
- .replace(/\*/g, ".*")
60
- .replace(/\?/g, ".?");
61
- searchTerm = `^${wildcardSearchTerm}$`;
62
- } else {
63
- return { test: () => false };
64
- }
65
- try {
66
- const flags = caseSensitiveSearch ? "" : "i";
67
- return new RegExp(searchTerm, flags);
68
- } catch (_error) {
69
- // In case of an invalid regular expression, an impossible
70
- // regex is returned, not matching anything.
71
- return /$^/;
72
- }
73
- },
74
- test(text, normalizedSearchTerm, caseSensitiveSearch, inverseSearch) {
75
- const matches = normalizedSearchTerm.test(text);
76
- return inverseSearch ? !matches : matches;
77
- },
78
- } satisfies PatternFilterDefinition,
79
- {
80
- id: "regex",
81
- normalize(searchTerm, caseSensitiveSearch) {
82
- try {
83
- const flags = caseSensitiveSearch ? "" : "i";
84
- return new RegExp(`^(${searchTerm})$`, flags);
85
- } catch (_error) {
86
- // In case of an invalid regular expression, an impossible
87
- // regex is returned, not matching anything.
88
- return /$^/;
89
- }
90
- },
91
- test(text, normalizedSearchTerm, caseSensitiveSearch, inverseSearch) {
92
- const matches = normalizedSearchTerm.test(text);
93
- return inverseSearch ? !matches : matches;
94
- },
95
- } satisfies PatternFilterDefinition,
96
- {
97
- id: "type",
98
- normalize(selectedTypes) {
99
- return { test: (type: string) => selectedTypes.includes(type) };
100
- },
101
- test(type, normalizedSearchTerm) {
102
- if (typeof type === "undefined") {
103
- return false;
104
- }
105
- return normalizedSearchTerm.test(type);
106
- },
107
- } satisfies TypeFilterDefinition,
108
- ];
109
-
110
- // convert [{id: "key1", text: "asdf"}, ...] to {"key1": {id:"key1", text: "asdf"} ... }
111
- export const filters: Record<
112
- string,
113
- FilterDefinition<unknown, unknown, unknown>
114
- > = Object.assign({}, ...modeDefinitions.map((obj) => ({ [obj.id]: obj })));
package/src/format.ts DELETED
@@ -1,113 +0,0 @@
1
- import { filesize } from "filesize";
2
-
3
- import getLocalTimeZone from "./localTimezone";
4
- /**
5
- * Converts the specified date String to human readable text containing the day, month, and year.
6
- * Example: '2018-07-31T09:44:31+00:00' => 'Jul 31, 2018'
7
- *
8
- * @param dateString String representation of the Date to format
9
- * @param useTimeZone to set the timeZone where the user is located, and display local date and time
10
- * @returns human readable date String
11
- */
12
- export const formatDateString = (
13
- dateString: string | number,
14
- useTimeZone = false,
15
- ) => {
16
- const date = new Date(dateString);
17
-
18
- // @ts-expect-error Argument of type 'Date' is not assignable to parameter of type 'number'
19
- if (isNaN(date)) {
20
- throw Error("Invalid Date format");
21
- }
22
-
23
- const baseDateOptions: Intl.DateTimeFormatOptions = {
24
- day: "numeric",
25
- month: "short",
26
- year: "numeric",
27
- };
28
-
29
- // This only works for the default locale of en-US, as support of other locals in node js might not be available
30
- // See for example this issue https://github.com/nodejs/node/issues/8500
31
- const dateOptions: Intl.DateTimeFormatOptions = useTimeZone
32
- ? { ...baseDateOptions, timeZone: getLocalTimeZone() }
33
- : baseDateOptions;
34
-
35
- return date.toLocaleDateString("en-US", dateOptions);
36
- };
37
-
38
- /**
39
- * Converts the specified time String to human readable text containing the hour (12-hour) and minute.
40
- * Example: '2018-07-31T09:44:31+00:00' => '9:44 AM'
41
- *
42
- * @param timeString String representation of the Date (including time) to format
43
- * @param useTimeZone to set the timeZone where the user is located, and display local date and time
44
- * @returns human readable time String
45
- */
46
- export const formatTimeString = (
47
- timeString: string | number,
48
- useTimeZone = false,
49
- ) => {
50
- const time = new Date(timeString);
51
-
52
- // @ts-expect-error Argument of type 'Date' is not assignable to parameter of type 'number'
53
- if (isNaN(time)) {
54
- throw Error("Invalid Date format");
55
- }
56
-
57
- // This only works for the default locale of en-US, as support of other locals in node js might not be available
58
- // See for example this issue https://github.com/nodejs/node/issues/8500
59
- const baseTimeOptions: Intl.DateTimeFormatOptions = {
60
- hour: "numeric",
61
- minute: "2-digit",
62
- };
63
-
64
- const timeOptions: Intl.DateTimeFormatOptions = useTimeZone
65
- ? { ...baseTimeOptions, timeZone: getLocalTimeZone() }
66
- : baseTimeOptions;
67
-
68
- return time.toLocaleTimeString("en-US", timeOptions);
69
- };
70
-
71
- /**
72
- * Converts the specified time String to human readable text containing the date (day, month, year) and time (hour,
73
- * minute; 12-hour).
74
- * Example: '2018-07-31T09:44:31+00:00' => 'Jul 31, 2018 9:44 AM'
75
- *
76
- * @param dateTimeString String representation of the Date (including time and date) to format
77
- * @param useTimeZone to set the timeZone where the user is located, and display local date and time
78
- * @returns human readable date/time String
79
- */
80
- export const formatDateTimeString = (
81
- dateTimeString: string | number,
82
- useTimeZone = false,
83
- ) => {
84
- return `${formatDateString(dateTimeString, useTimeZone)} ${formatTimeString(
85
- dateTimeString,
86
- useTimeZone,
87
- )}`;
88
- };
89
-
90
- /**
91
- * Converts the specified date and time to the user time zone with option to display (day, month, year) only or with time (hour,
92
- * minute; 12-hour).
93
- *
94
- * @param showTime String representation of the Date to convert and format
95
- * @param String | number} date String representation of the Date to convert and format
96
- * @returns human readable date/time String converted to user time zone
97
- */
98
- export const formatLocalDateTimeString = (date: string, showTime: boolean) =>
99
- showTime ? formatDateTimeString(date, true) : formatDateString(date, true);
100
-
101
- export const formatFileSize = (bytes: number, decimals = 1): string => {
102
- const safeBytes = Number.isFinite(bytes) && bytes >= 0 ? bytes : 0;
103
- const safeDecimals =
104
- Number.isFinite(decimals) && decimals >= 0 ? Math.floor(decimals) : 0;
105
-
106
- return filesize(safeBytes, {
107
- output: "string",
108
- base: 2,
109
- standard: "iec",
110
- round: safeDecimals,
111
- pad: true,
112
- }) as string;
113
- };
@@ -1,98 +0,0 @@
1
- import { isMac } from "./navigator";
2
-
3
- type Keys =
4
- | "F1"
5
- | "F2"
6
- | "F3"
7
- | "F4"
8
- | "F5"
9
- | "F6"
10
- | "F7"
11
- | "F8"
12
- | "F9"
13
- | "F10"
14
- | "F11"
15
- | "F12"
16
- | "PageUp"
17
- | "PageDown"
18
- | "ArrowUp"
19
- | "ArrowRight"
20
- | "ArrowDown"
21
- | "ArrowLeft"
22
- | "Delete"
23
- | "Enter"
24
- | "Backspace"
25
- | "Home"
26
- | "End"
27
- | " "; // Space;
28
-
29
- type Modifiers = "CtrlOrCmd" | "Ctrl" | "Alt" | "Shift";
30
-
31
- // creates loose autocomplete by using a union of the passed-in type
32
- // and the entire `string` set *except* the passed-in type
33
- type LooseAutoComplete<T extends string> = T | Omit<string, T>;
34
-
35
- export type NumberRange = `${number}-${number}`;
36
- export type KnownHotkey = Keys | Modifiers | NumberRange;
37
-
38
- export type Hotkey = LooseAutoComplete<Keys | Modifiers>;
39
-
40
- const globalKeyMap = {
41
- ArrowUp: "↑",
42
- ArrowDown: "↓",
43
- ArrowLeft: "←",
44
- ArrowRight: "→",
45
- Enter: "↵",
46
- " ": "Space", // we use event.key and there space is an actual space not the code "Space"
47
- CtrlOrCmd: "Ctrl",
48
- } as const;
49
-
50
- const MacOSkeyMap = {
51
- Shift: "⇧",
52
- Delete: "⌫",
53
- CtrlOrCmd: "⌘",
54
- Ctrl: "⌃",
55
- Alt: "⌥",
56
- Enter: "↩",
57
- } as const;
58
-
59
- type KeyFormatMap = typeof MacOSkeyMap | typeof globalKeyMap;
60
-
61
- /**
62
- * Returns a string representation of a single hotkey. Replaces some special key names with symbols
63
- */
64
- export const formatHotkey = (hotkey: Hotkey): string => {
65
- /**
66
- * Returns the symbol corresponding to the `key` based on the given
67
- * `formatMap`. Otherwise, if not found, returns the same `key` value given
68
- */
69
- const mapSymbols = (formatMap: KeyFormatMap) => (key: Hotkey) =>
70
- formatMap[key as keyof KeyFormatMap] ?? key;
71
-
72
- /**
73
- * Pipe function implementation. Receives a list of functions to execute in order
74
- * and will pipe the parameter passed at the end to each function returning the final output
75
- */
76
- const pipe = <T extends () => string>(
77
- ...fns: Array<(...args: Hotkey[]) => ReturnType<T>>
78
- ) => fns.reduce((f, g) => (arg) => g(f(arg)));
79
-
80
- const macKeyFormatter = pipe(
81
- mapSymbols(MacOSkeyMap),
82
- mapSymbols(globalKeyMap),
83
- );
84
-
85
- const generalKeyFormatter = mapSymbols(globalKeyMap);
86
-
87
- return isMac() ? macKeyFormatter(hotkey) : generalKeyFormatter(hotkey);
88
- };
89
-
90
- export const getDefaultSeparator = () => " ";
91
-
92
- /**
93
- * Returns a string representation of a list of hotkeys. Replaces some special key names with symbols
94
- */
95
- export const formatHotkeys = (
96
- hotkeys: Array<Hotkey>,
97
- getSeparator = getDefaultSeparator,
98
- ) => hotkeys.map(formatHotkey).join(getSeparator());
@@ -1,9 +0,0 @@
1
- const getDeepActiveElement = () => {
2
- let element = document?.activeElement;
3
- while (element?.shadowRoot) {
4
- element = element?.shadowRoot?.activeElement;
5
- }
6
- return element;
7
- };
8
-
9
- export default getDeepActiveElement;
package/src/index.ts DELETED
@@ -1,76 +0,0 @@
1
- import { capitalize, caseFormatter } from "./capitalize";
2
- import { isAfterMaxDate, isBeforeMinDate } from "./dateMinMaxCheck";
3
- import debounce from "./debounce";
4
- import { filters } from "./filters";
5
- import {
6
- formatDateString,
7
- formatDateTimeString,
8
- formatFileSize,
9
- formatLocalDateTimeString,
10
- formatTimeString,
11
- } from "./format";
12
- import {
13
- formatHotkey,
14
- formatHotkeys,
15
- getDefaultSeparator,
16
- } from "./formatHotkeys";
17
- import type {
18
- Hotkey as _Hotkey,
19
- KnownHotkey as _KnownHotkey,
20
- } from "./formatHotkeys";
21
- import getDeepActiveElement from "./getDeepActiveElement";
22
- import getWrappedAroundIndex from "./getWrappedAroundIndex";
23
- import * as intervalUtils from "./intervalUtils";
24
- import getLocalTimeZone from "./localTimezone";
25
- import * as navigatorUtils from "./navigator";
26
- import numIntegerDigits from "./numIntegerDigits";
27
- import * as promise from "./promise";
28
- import { sanitization } from "./sanitization";
29
- import sleep from "./sleep";
30
- import truncateString from "./truncateString";
31
- import updateDate from "./updateDate";
32
- import updateTime from "./updateTime";
33
- import type {
34
- UploaderManagerConfig as _UploadManagerConfig,
35
- UploadStateName as _UploadStateName,
36
- } from "./uploadManager";
37
- import * as uploadManager from "./uploadManager";
38
-
39
- const hotkeys = { formatHotkeys, formatHotkey, getDefaultSeparator };
40
-
41
- export type Hotkey = _Hotkey;
42
- export type KnownHotkey = _KnownHotkey;
43
-
44
- export type UploaderConfig = _UploadManagerConfig;
45
- export type UploadStateName = _UploadStateName;
46
-
47
- export * from "./fileExtensions";
48
- export * from "./hotkeys";
49
-
50
- export {
51
- uploadManager,
52
- promise,
53
- capitalize,
54
- caseFormatter,
55
- debounce,
56
- filters,
57
- formatDateString,
58
- formatDateTimeString,
59
- formatFileSize,
60
- getDeepActiveElement,
61
- formatLocalDateTimeString,
62
- formatTimeString,
63
- getLocalTimeZone,
64
- getWrappedAroundIndex,
65
- hotkeys,
66
- isAfterMaxDate,
67
- isBeforeMinDate,
68
- intervalUtils,
69
- navigatorUtils,
70
- numIntegerDigits,
71
- sleep,
72
- truncateString,
73
- updateDate,
74
- updateTime,
75
- sanitization,
76
- };