@reliverse/relinka 1.1.6 → 1.1.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 (121) hide show
  1. package/dist-npm/components/anykey/index.js +57 -77
  2. package/dist-npm/components/block/block.js +48 -61
  3. package/dist-npm/components/checkbox/index.js +178 -211
  4. package/dist-npm/components/confirm/confirm-main.js +85 -122
  5. package/dist-npm/components/confirm/confirm-three.js +24 -27
  6. package/dist-npm/components/confirm/index.js +36 -45
  7. package/dist-npm/components/core/Separator.js +15 -17
  8. package/dist-npm/components/core/create-prompt.js +101 -124
  9. package/dist-npm/components/core/errors.js +19 -15
  10. package/dist-npm/components/core/hook-engine.js +91 -120
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +16 -6
  13. package/dist-npm/components/core/lines.js +45 -54
  14. package/dist-npm/components/core/make-theme.js +21 -30
  15. package/dist-npm/components/core/position.js +27 -23
  16. package/dist-npm/components/core/promise-polyfill.js +11 -14
  17. package/dist-npm/components/core/screen-manager.js +59 -74
  18. package/dist-npm/components/core/theme.js +22 -32
  19. package/dist-npm/components/core/use-effect.js +9 -15
  20. package/dist-npm/components/core/use-keypress.js +19 -23
  21. package/dist-npm/components/core/use-memo.js +10 -16
  22. package/dist-npm/components/core/use-pagination.js +33 -32
  23. package/dist-npm/components/core/use-prefix.js +40 -38
  24. package/dist-npm/components/core/use-ref.js +2 -5
  25. package/dist-npm/components/core/use-state.js +15 -23
  26. package/dist-npm/components/core/useKeyPress.js +14 -17
  27. package/dist-npm/components/core/usePromptState.js +8 -14
  28. package/dist-npm/components/core/utils.js +7 -16
  29. package/dist-npm/components/date/date.js +173 -204
  30. package/dist-npm/components/editor/index.js +71 -92
  31. package/dist-npm/components/expand/index.js +96 -124
  32. package/dist-npm/components/figures/index.js +283 -294
  33. package/dist-npm/components/input/index.js +61 -87
  34. package/dist-npm/components/input/text-main.js +97 -124
  35. package/dist-npm/components/input/text.js +24 -28
  36. package/dist-npm/components/instance/basic.js +17 -25
  37. package/dist-npm/components/instance/browser.js +14 -18
  38. package/dist-npm/components/instance/reporter/basic.js +46 -65
  39. package/dist-npm/components/instance/reporter/browser.js +44 -47
  40. package/dist-npm/components/instance/reporter/fancy.js +83 -96
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +52 -62
  43. package/dist-npm/components/mono/monoTwo.js +35 -49
  44. package/dist-npm/components/multiselect/group-multiselect.js +55 -71
  45. package/dist-npm/components/multiselect/multi-select-two.js +97 -130
  46. package/dist-npm/components/multiselect/multi-select.js +43 -49
  47. package/dist-npm/components/multiselect/multiselect-main.d.ts +1 -0
  48. package/dist-npm/components/multiselect/multiselect-main.js +158 -145
  49. package/dist-npm/components/multiselect/num-multi-select.js +97 -130
  50. package/dist-npm/components/multiselect/num-multiselect-main.js +24 -35
  51. package/dist-npm/components/next-steps/next-steps.js +23 -25
  52. package/dist-npm/components/number/index.js +78 -112
  53. package/dist-npm/components/number/number-main.js +95 -2
  54. package/dist-npm/components/password/index.js +54 -73
  55. package/dist-npm/components/password/password-main.js +119 -2
  56. package/dist-npm/components/password/password-three.js +26 -30
  57. package/dist-npm/components/progressbar/ProgressBar.js +45 -64
  58. package/dist-npm/components/progressbar/helper.js +33 -40
  59. package/dist-npm/components/progressbar/index.js +1 -1
  60. package/dist-npm/components/prompts/create.js +29 -44
  61. package/dist-npm/components/prompts/index.d.ts +1 -0
  62. package/dist-npm/components/prompts/index.js +46 -45
  63. package/dist-npm/components/prompts/prompt.js +211 -260
  64. package/dist-npm/components/prompts/promptTwo.js +561 -605
  65. package/dist-npm/components/prompts/relinka.js +237 -295
  66. package/dist-npm/components/range/range.js +247 -294
  67. package/dist-npm/components/rawlist/index.js +87 -107
  68. package/dist-npm/components/results/results.js +31 -37
  69. package/dist-npm/components/search/index.js +148 -193
  70. package/dist-npm/components/select/index.js +148 -186
  71. package/dist-npm/components/select/num-select-main.js +27 -27
  72. package/dist-npm/components/select/num-select.js +124 -5
  73. package/dist-npm/components/select/select-key.js +24 -25
  74. package/dist-npm/components/select/select-main.d.ts +1 -0
  75. package/dist-npm/components/select/select-main.js +143 -133
  76. package/dist-npm/components/select/select-three.js +32 -36
  77. package/dist-npm/components/select/select-two.js +94 -87
  78. package/dist-npm/components/spinner/index.js +107 -136
  79. package/dist-npm/components/st-end/end.js +34 -26
  80. package/dist-npm/components/st-end/start.js +29 -15
  81. package/dist-npm/components/toggle/index.js +113 -137
  82. package/dist-npm/components/visual/animate/animate.js +53 -10
  83. package/dist-npm/components/visual/ascii-art/ascii-art.js +12 -1
  84. package/dist-npm/main.js +1 -0
  85. package/dist-npm/testing/index.js +58 -83
  86. package/dist-npm/types/general.d.ts +1 -1
  87. package/dist-npm/types/general.js +0 -1
  88. package/dist-npm/types/index.js +2 -3
  89. package/dist-npm/types/keypress.js +35 -36
  90. package/dist-npm/types/readline.js +0 -1
  91. package/dist-npm/types/relinka.js +0 -1
  92. package/dist-npm/types/utils.js +0 -1
  93. package/dist-npm/utils/box.js +135 -137
  94. package/dist-npm/utils/color.js +65 -74
  95. package/dist-npm/utils/colorize.js +124 -156
  96. package/dist-npm/utils/component.js +532 -657
  97. package/dist-npm/utils/constants.js +64 -63
  98. package/dist-npm/utils/core.js +2 -3
  99. package/dist-npm/utils/decoder.js +244 -223
  100. package/dist-npm/utils/error.js +4 -9
  101. package/dist-npm/utils/errors.js +14 -4
  102. package/dist-npm/utils/format.js +19 -24
  103. package/dist-npm/utils/keypress.js +316 -414
  104. package/dist-npm/utils/log.js +11 -15
  105. package/dist-npm/utils/mapping.js +45 -52
  106. package/dist-npm/utils/messages.js +196 -183
  107. package/dist-npm/utils/platforms.js +16 -20
  108. package/dist-npm/utils/prompt-tmp.js +235 -286
  109. package/dist-npm/utils/prompt-two.js +235 -286
  110. package/dist-npm/utils/readline.js +5 -7
  111. package/dist-npm/utils/skeleton.js +130 -170
  112. package/dist-npm/utils/stream.js +2 -2
  113. package/dist-npm/utils/string.js +44 -58
  114. package/dist-npm/utils/terminal.js +23 -34
  115. package/dist-npm/utils/tree.js +30 -41
  116. package/dist-npm/utils/types.js +0 -1
  117. package/dist-npm/utils/utils.js +8 -8
  118. package/dist-npm/utils/variants.js +36 -44
  119. package/package.json +14 -14
  120. package/dist-npm/mod.js +0 -2
  121. /package/dist-npm/{mod.d.ts → main.d.ts} +0 -0
@@ -1,17 +1,21 @@
1
1
  export class AbortPromptError extends Error {
2
- name = 'AbortPromptError';
3
- message = 'Prompt was aborted';
4
- constructor(options) {
5
- super();
6
- this.cause = options?.cause;
7
- }
8
- }export class CancelPromptError extends Error {
9
- name = 'CancelPromptError';
10
- message = 'Prompt was canceled';
11
- }export class ExitPromptError extends Error {
12
- name = 'ExitPromptError';
13
- }export class HookError extends Error {
14
- name = 'HookError';
15
- }export class ValidationError extends Error {
16
- name = 'ValidationError';
2
+ name = "AbortPromptError";
3
+ message = "Prompt was aborted";
4
+ constructor(options) {
5
+ super();
6
+ this.cause = options?.cause;
7
+ }
8
+ }
9
+ export class CancelPromptError extends Error {
10
+ name = "CancelPromptError";
11
+ message = "Prompt was canceled";
12
+ }
13
+ export class ExitPromptError extends Error {
14
+ name = "ExitPromptError";
15
+ }
16
+ export class HookError extends Error {
17
+ name = "HookError";
18
+ }
19
+ export class ValidationError extends Error {
20
+ name = "ValidationError";
17
21
  }
@@ -1,138 +1,109 @@
1
- import {
2
- AsyncLocalStorage,
3
- AsyncResource,
4
- } from 'node:async_hooks';
5
- import {
6
- HookError,
7
- ValidationError,
8
- } from './errors.js';
9
-
10
- const isFn = (a) => typeof a === 'function';
1
+ import { AsyncLocalStorage, AsyncResource } from "node:async_hooks";
2
+ import { HookError, ValidationError } from "./errors.js";
11
3
  const hookStorage = new AsyncLocalStorage();
12
-
13
4
  function createStore(rl) {
14
- const store = {
15
- rl,
16
- hooks: [],
17
- hooksCleanup: [],
18
- hooksEffect: [],
19
- index: 0,
20
- handleChange() {},
21
- };
22
-
23
- return store;
5
+ const store = {
6
+ rl,
7
+ hooks: [],
8
+ hooksCleanup: [],
9
+ hooksEffect: [],
10
+ index: 0,
11
+ handleChange() {
12
+ }
13
+ };
14
+ return store;
24
15
  }
25
-
26
16
  export function withHooks(rl, cb) {
27
- const store = createStore(rl);
28
-
29
- return hookStorage.run(store, () => {
30
- function cycle(render) {
31
- store.handleChange = () => {
32
- store.index = 0;
33
- render();
34
- };
35
- store.handleChange();
36
- }
37
-
38
- return cb(cycle);
39
- });
17
+ const store = createStore(rl);
18
+ return hookStorage.run(store, () => {
19
+ function cycle(render) {
20
+ store.handleChange = () => {
21
+ store.index = 0;
22
+ render();
23
+ };
24
+ store.handleChange();
25
+ }
26
+ return cb(cycle);
27
+ });
40
28
  }
41
-
42
29
  function getStore() {
43
- const store = hookStorage.getStore();
44
-
45
- if (!store) {
46
- throw new HookError('[Relinka] Hook functions can only be called from within a prompt');
47
- }
48
-
49
- return store;
30
+ const store = hookStorage.getStore();
31
+ if (!store) {
32
+ throw new HookError(
33
+ "[Relinka] Hook functions can only be called from within a prompt"
34
+ );
35
+ }
36
+ return store;
50
37
  }
51
-
52
38
  export function readline() {
53
- return getStore().rl;
39
+ return getStore().rl;
54
40
  }
55
-
56
41
  export function withUpdates(fn) {
57
- const wrapped = (...args) => {
58
- const store = getStore();
59
- let shouldUpdate = false;
60
- const oldHandleChange = store.handleChange;
61
-
62
- store.handleChange = () => {
63
- shouldUpdate = true;
64
- };
65
- const returnValue = fn(...args);
66
-
67
- if (shouldUpdate) {
68
- oldHandleChange();
69
- }
70
-
71
- store.handleChange = oldHandleChange;
72
- return returnValue;
73
- };
74
-
75
- return AsyncResource.bind(wrapped);
76
- }
77
-
78
- export function withPointer(cb) {
42
+ const wrapped = (...args) => {
79
43
  const store = getStore();
80
- const {index} = store;
81
- const pointer = {
82
- get() {
83
- return store.hooks[index];
84
- },
85
- set(value) {
86
- store.hooks[index] = value;
87
- },
88
- initialized: index in store.hooks,
44
+ let shouldUpdate = false;
45
+ const oldHandleChange = store.handleChange;
46
+ store.handleChange = () => {
47
+ shouldUpdate = true;
89
48
  };
90
-
91
- const returnValue = cb(pointer);
92
-
93
- store.index++;
49
+ const returnValue = fn(...args);
50
+ if (shouldUpdate) {
51
+ oldHandleChange();
52
+ }
53
+ store.handleChange = oldHandleChange;
94
54
  return returnValue;
55
+ };
56
+ return AsyncResource.bind(wrapped);
57
+ }
58
+ export function withPointer(cb) {
59
+ const store = getStore();
60
+ const { index } = store;
61
+ const pointer = {
62
+ get() {
63
+ return store.hooks[index];
64
+ },
65
+ set(value) {
66
+ store.hooks[index] = value;
67
+ },
68
+ initialized: index in store.hooks
69
+ };
70
+ const returnValue = cb(pointer);
71
+ store.index++;
72
+ return returnValue;
95
73
  }
96
-
97
74
  export function handleChange() {
98
- getStore().handleChange();
75
+ getStore().handleChange();
99
76
  }
100
-
101
77
  export const effectScheduler = {
102
- queue(cb) {
103
- const store = getStore();
104
- const {index} = store;
105
-
106
- store.hooksEffect.push(() => {
107
- store.hooksCleanup[index]?.();
108
- const cleanFn = cb(readline());
109
-
110
- if (cleanFn != null && !isFn(cleanFn)) {
111
- throw new ValidationError('useEffect return value must be a cleanup function or nothing.');
112
- }
113
-
114
- store.hooksCleanup[index] = cleanFn;
115
- });
116
- },
117
- run() {
118
- const store = getStore();
119
-
120
- withUpdates(() => {
121
- for (const effect of store.hooksEffect) {
122
- effect();
123
- }
124
-
125
- store.hooksEffect.length = 0;
126
- })();
127
- },
128
- clearAll() {
129
- const store = getStore();
130
-
131
- for (const cleanFn of store.hooksCleanup) {
132
- cleanFn?.();
133
- }
134
-
135
- store.hooksEffect.length = 0;
136
- store.hooksCleanup.length = 0;
137
- },
78
+ queue(cb) {
79
+ const store = getStore();
80
+ const { index } = store;
81
+ store.hooksEffect.push(() => {
82
+ store.hooksCleanup[index]?.();
83
+ const cleanFn = cb(readline());
84
+ if (cleanFn != null && typeof cleanFn !== "function") {
85
+ throw new ValidationError(
86
+ "useEffect return value must be a cleanup function or nothing."
87
+ );
88
+ }
89
+ store.hooksCleanup[index] = cleanFn;
90
+ });
91
+ },
92
+ run() {
93
+ const store = getStore();
94
+ withUpdates(() => {
95
+ store.hooksEffect.forEach((effect) => {
96
+ effect();
97
+ });
98
+ store.hooksEffect.length = 0;
99
+ })();
100
+ },
101
+ clearAll() {
102
+ const store = getStore();
103
+ store.hooksCleanup.forEach((cleanFn) => {
104
+ cleanFn?.();
105
+ });
106
+ store.hooksEffect.length = 0;
107
+ store.hooksCleanup.length = 0;
108
+ }
138
109
  };
@@ -1,12 +1,12 @@
1
- export * from './key.js';
2
- export * from './errors.js';
3
- export {usePrefix} from './use-prefix.js';
4
- export {useState} from './use-state.js';
5
- export {useEffect} from './use-effect.js';
6
- export {useMemo} from './use-memo.js';
7
- export {useRef} from './use-ref.js';
8
- export {useKeypress} from './use-keypress.js';
9
- export {makeTheme} from './make-theme.js';
10
- export {usePagination} from './use-pagination.js';
11
- export {createPrompt} from './create-prompt.js';
12
- export {Separator} from './Separator.js';
1
+ export * from "./key.js";
2
+ export * from "./errors.js";
3
+ export { usePrefix } from "./use-prefix.js";
4
+ export { useState } from "./use-state.js";
5
+ export { useEffect } from "./use-effect.js";
6
+ export { useMemo } from "./use-memo.js";
7
+ export { useRef } from "./use-ref.js";
8
+ export { useKeypress } from "./use-keypress.js";
9
+ export { makeTheme } from "./make-theme.js";
10
+ export { usePagination } from "./use-pagination.js";
11
+ export { createPrompt } from "./create-prompt.js";
12
+ export { Separator } from "./Separator.js";
@@ -1,6 +1,16 @@
1
- export const isUpKey = (key) => (key.name === 'up' || key.name === 'k' || key.ctrl && key.name === 'p');
2
- export const isDownKey = (key) => (key.name === 'down' || key.name === 'j' || key.ctrl && key.name === 'n');
3
- export const isSpaceKey = (key) => key.name === 'space';
4
- export const isBackspaceKey = (key) => key.name === 'backspace';
5
- export const isNumberKey = (key) => '123456789'.includes(key.name);
6
- export const isEnterKey = (key) => key.name === 'enter' || key.name === 'return';
1
+ export const isUpKey = (key) => (
2
+
3
+ key.name === "up" ||
4
+ key.name === "k" ||
5
+ key.ctrl && key.name === "p"
6
+ );
7
+ export const isDownKey = (key) => (
8
+
9
+ key.name === "down" ||
10
+ key.name === "j" ||
11
+ key.ctrl && key.name === "n"
12
+ );
13
+ export const isSpaceKey = (key) => key.name === "space";
14
+ export const isBackspaceKey = (key) => key.name === "backspace";
15
+ export const isNumberKey = (key) => "123456789".includes(key.name);
16
+ export const isEnterKey = (key) => key.name === "enter" || key.name === "return";
@@ -1,61 +1,52 @@
1
- import {breakLines} from './utils.js';
2
-
1
+ import { breakLines } from "./utils.js";
3
2
  function split(content, width) {
4
- return breakLines(content, width).split('\n');
3
+ return breakLines(content, width).split("\n");
5
4
  }
6
-
7
5
  function rotate(count, items) {
8
- const max = items.length;
9
- const offset = (count % max + max) % max;
10
-
11
- return [
12
- ...items.slice(offset),
13
- ...items.slice(0, offset),
14
- ];
6
+ const max = items.length;
7
+ const offset = (count % max + max) % max;
8
+ return [...items.slice(offset), ...items.slice(0, offset)];
15
9
  }
16
-
17
- export function lines({items, width, renderItem, active, position: requested, pageSize}) {
18
- const layouts = items.map((item, index) => ({
19
- item,
20
- index,
21
- isActive: index === active,
22
- }));
23
-
24
- const layoutsInPage = rotate(active - requested, layouts).slice(0, pageSize);
25
- const renderItemAt = (index) => layoutsInPage[index] == null ? [] : split(renderItem(layoutsInPage[index]), width);
26
- const pageBuffer = Array.from({
27
- length: pageSize,
28
- });
29
- const activeItem = renderItemAt(requested).slice(0, pageSize);
30
- const position = pageSize >= requested + activeItem.length ? requested : pageSize - activeItem.length;
31
-
32
- pageBuffer.splice(position, activeItem.length, ...activeItem);
33
- let bufferPointer = position + activeItem.length;
34
- let layoutPointer = requested + 1;
35
-
36
- while (bufferPointer < pageSize && layoutPointer < layoutsInPage.length) {
37
- for (const line of renderItemAt(layoutPointer)) {
38
- pageBuffer[bufferPointer++] = line;
39
- if (bufferPointer >= pageSize) {
40
- break;
41
- }
42
- }
43
-
44
- layoutPointer++;
10
+ export function lines({
11
+ items,
12
+ width,
13
+ renderItem,
14
+ active,
15
+ position: requested,
16
+ pageSize
17
+ }) {
18
+ const layouts = items.map((item, index) => ({
19
+ item,
20
+ index,
21
+ isActive: index === active
22
+ }));
23
+ const layoutsInPage = rotate(active - requested, layouts).slice(0, pageSize);
24
+ const renderItemAt = (index) => layoutsInPage[index] == null ? [] : split(renderItem(layoutsInPage[index]), width);
25
+ const pageBuffer = Array.from({ length: pageSize });
26
+ const activeItem = renderItemAt(requested).slice(0, pageSize);
27
+ const position = requested + activeItem.length <= pageSize ? requested : pageSize - activeItem.length;
28
+ pageBuffer.splice(position, activeItem.length, ...activeItem);
29
+ let bufferPointer = position + activeItem.length;
30
+ let layoutPointer = requested + 1;
31
+ while (bufferPointer < pageSize && layoutPointer < layoutsInPage.length) {
32
+ for (const line of renderItemAt(layoutPointer)) {
33
+ pageBuffer[bufferPointer++] = line;
34
+ if (bufferPointer >= pageSize) {
35
+ break;
36
+ }
45
37
  }
46
-
47
- bufferPointer = position - 1;
48
- layoutPointer = requested - 1;
49
- while (bufferPointer >= 0 && layoutPointer >= 0) {
50
- for (const line of renderItemAt(layoutPointer).reverse()) {
51
- pageBuffer[bufferPointer--] = line;
52
- if (bufferPointer < 0) {
53
- break;
54
- }
55
- }
56
-
57
- layoutPointer--;
38
+ layoutPointer++;
39
+ }
40
+ bufferPointer = position - 1;
41
+ layoutPointer = requested - 1;
42
+ while (bufferPointer >= 0 && layoutPointer >= 0) {
43
+ for (const line of renderItemAt(layoutPointer).reverse()) {
44
+ pageBuffer[bufferPointer--] = line;
45
+ if (bufferPointer < 0) {
46
+ break;
47
+ }
58
48
  }
59
-
60
- return pageBuffer.filter((line) => typeof line === 'string');
49
+ layoutPointer--;
50
+ }
51
+ return pageBuffer.filter((line) => typeof line === "string");
61
52
  }
@@ -1,37 +1,28 @@
1
- import {defaultTheme} from './theme.js';
2
-
1
+ import { defaultTheme } from "./theme.js";
3
2
  function isPlainObject(value) {
4
- if (typeof value !== 'object' || value === null) {
5
- return false;
6
- }
7
-
8
- let proto = value;
9
-
10
- while (Object.getPrototypeOf(proto) !== null) {
11
- proto = Object.getPrototypeOf(proto);
12
- }
13
-
14
- return Object.getPrototypeOf(value) === proto;
3
+ if (typeof value !== "object" || value === null) {
4
+ return false;
5
+ }
6
+ let proto = value;
7
+ while (Object.getPrototypeOf(proto) !== null) {
8
+ proto = Object.getPrototypeOf(proto);
9
+ }
10
+ return Object.getPrototypeOf(value) === proto;
15
11
  }
16
-
17
12
  function deepMerge(...objects) {
18
- const output = {};
19
-
20
- for (const obj of objects) {
21
- for (const [key, value] of Object.entries(obj)) {
22
- const prevValue = output[key];
23
- output[key] = isPlainObject(prevValue) && isPlainObject(value) ? deepMerge(prevValue, value) : value;
24
- }
13
+ const output = {};
14
+ for (const obj of objects) {
15
+ for (const [key, value] of Object.entries(obj)) {
16
+ const prevValue = output[key];
17
+ output[key] = isPlainObject(prevValue) && isPlainObject(value) ? deepMerge(prevValue, value) : value;
25
18
  }
26
-
27
- return output;
19
+ }
20
+ return output;
28
21
  }
29
-
30
22
  export function makeTheme(...themes) {
31
- const themesToMerge = [
32
- defaultTheme,
33
- ...themes.filter((theme) => theme != null),
34
- ];
35
-
36
- return deepMerge(...themesToMerge);
23
+ const themesToMerge = [
24
+ defaultTheme,
25
+ ...themes.filter((theme) => theme != null)
26
+ ];
27
+ return deepMerge(...themesToMerge);
37
28
  }
@@ -1,25 +1,29 @@
1
- export function finite({active, pageSize, total}) {
2
- const middle = Math.floor(pageSize / 2);
3
-
4
- if (total <= pageSize || active < middle) {
5
- return active;
6
- }
7
-
8
- if (active >= total - middle) {
9
- return active + pageSize - total;
10
- }
11
-
12
- return middle;
1
+ export function finite({
2
+ active,
3
+ pageSize,
4
+ total
5
+ }) {
6
+ const middle = Math.floor(pageSize / 2);
7
+ if (total <= pageSize || active < middle) {
8
+ return active;
9
+ }
10
+ if (active >= total - middle) {
11
+ return active + pageSize - total;
12
+ }
13
+ return middle;
13
14
  }
14
-
15
- export function infinite({active, lastActive, total, pageSize, pointer}) {
16
- if (total <= pageSize) {
17
- return active;
18
- }
19
-
20
- if (lastActive < active && pageSize > active - lastActive) {
21
- return Math.min(Math.floor(pageSize / 2), pointer + active - lastActive);
22
- }
23
-
24
- return pointer;
15
+ export function infinite({
16
+ active,
17
+ lastActive,
18
+ total,
19
+ pageSize,
20
+ pointer
21
+ }) {
22
+ if (total <= pageSize) {
23
+ return active;
24
+ }
25
+ if (lastActive < active && active - lastActive < pageSize) {
26
+ return Math.min(Math.floor(pageSize / 2), pointer + active - lastActive);
27
+ }
28
+ return pointer;
25
29
  }
@@ -1,16 +1,13 @@
1
1
  export class PromisePolyfill extends Promise {
2
- static withResolver() {
3
- let resolve;
4
- let reject;
5
- const promise = new Promise((res, rej) => {
6
- resolve = res;
7
- reject = rej;
8
- });
9
-
10
- return {
11
- promise,
12
- resolve,
13
- reject,
14
- };
15
- }
2
+
3
+
4
+ static withResolver() {
5
+ let resolve;
6
+ let reject;
7
+ const promise = new Promise((res, rej) => {
8
+ resolve = res;
9
+ reject = rej;
10
+ });
11
+ return { promise, resolve, reject };
12
+ }
16
13
  }