@maz-ui/utils 4.0.0-beta.7 → 4.0.0
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 +181 -0
- package/dist/helpers/index.js +58 -42
- package/dist/helpers/kebabCase.js +6 -0
- package/dist/helpers/normalizeString.js +31 -8
- package/dist/helpers/pascalCase.js +16 -0
- package/dist/helpers/snakeCase.js +6 -0
- package/dist/index.js +54 -50
- package/dist/types/helpers/index.d.ts +8 -0
- package/dist/types/helpers/kebabCase.d.ts +1 -0
- package/dist/types/helpers/normalizeString.d.ts +6 -0
- package/dist/types/helpers/snakeCase.d.ts +1 -0
- package/dist/types/index.d.ts +0 -1
- package/package.json +11 -23
- package/dist/chunks/chunk-hooks.DXGlb1Dd.js +0 -2471
- package/dist/chunks/magic-string.es.BQ9KnLz-.js +0 -659
- package/dist/formatters/__tests__/capitalize.spec.js +0 -10
- package/dist/formatters/__tests__/currency.spec.js +0 -24
- package/dist/formatters/__tests__/date.spec.js +0 -20
- package/dist/formatters/__tests__/number.spec.js +0 -16
- package/dist/formatters/__tests__/telephone.spec.js +0 -11
- package/dist/formatters/index.js +0 -14
- package/dist/formatters/pascalCase.js +0 -8
- package/dist/helpers/__tests__/NormalizeString.spec.js +0 -43
- package/dist/helpers/__tests__/ScriptLoader.spec.js +0 -67
- package/dist/helpers/__tests__/SwipeHandler.spec.js +0 -54
- package/dist/helpers/__tests__/checkAvailability.spec.js +0 -46
- package/dist/helpers/__tests__/countryCodeToUnicodeFlag.spec.js +0 -16
- package/dist/helpers/__tests__/debounceId.spec.js +0 -16
- package/dist/helpers/__tests__/debouneCallback.spec.js +0 -12
- package/dist/helpers/__tests__/isEqual.spec.js +0 -46
- package/dist/helpers/__tests__/isStandaloneMode.spec.js +0 -8586
- package/dist/helpers/__tests__/sleep.spec.js +0 -16
- package/dist/helpers/__tests__/throttle.spec.js +0 -43
- package/dist/helpers/__tests__/throttleId.spec.js +0 -22
- package/dist/helpers/__tests__/userVisibility.spec.js +0 -58
- package/dist/types/formatters/index.d.ts +0 -6
- /package/dist/{formatters → helpers}/camelCase.js +0 -0
- /package/dist/{formatters → helpers}/capitalize.js +0 -0
- /package/dist/{formatters → helpers}/formatCurrency.js +0 -0
- /package/dist/{formatters → helpers}/formatDate.js +0 -0
- /package/dist/{formatters → helpers}/formatNumber.js +0 -0
- /package/dist/{formatters → helpers}/formatPhoneNumber.js +0 -0
- /package/dist/types/{formatters → helpers}/camelCase.d.ts +0 -0
- /package/dist/types/{formatters → helpers}/capitalize.d.ts +0 -0
- /package/dist/types/{formatters → helpers}/formatCurrency.d.ts +0 -0
- /package/dist/types/{formatters → helpers}/formatDate.d.ts +0 -0
- /package/dist/types/{formatters → helpers}/formatNumber.d.ts +0 -0
- /package/dist/types/{formatters → helpers}/formatPhoneNumber.d.ts +0 -0
- /package/dist/types/{formatters → helpers}/pascalCase.d.ts +0 -0
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { sleep as i } from "../sleep.js";
|
|
2
|
-
describe("given sleep function", () => {
|
|
3
|
-
describe("when called with a duration", () => {
|
|
4
|
-
it("then it should resolve after the specified duration", async () => {
|
|
5
|
-
vi.useFakeTimers();
|
|
6
|
-
const e = 1e3, t = i(e);
|
|
7
|
-
expect(vi.getTimerCount()).toBe(1), vi.advanceTimersByTime(e), await t, expect(vi.getTimerCount()).toBe(0), vi.useRealTimers();
|
|
8
|
-
});
|
|
9
|
-
}), describe("when called with zero duration", () => {
|
|
10
|
-
it("then it should resolve immediately", async () => {
|
|
11
|
-
vi.useFakeTimers();
|
|
12
|
-
const e = i(0);
|
|
13
|
-
expect(vi.getTimerCount()).toBe(1), vi.advanceTimersByTime(0), await e, expect(vi.getTimerCount()).toBe(0), vi.useRealTimers();
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { throttle as i } from "../throttle.js";
|
|
2
|
-
describe("given throttle function", () => {
|
|
3
|
-
beforeEach(() => {
|
|
4
|
-
vi.useFakeTimers();
|
|
5
|
-
}), afterEach(() => {
|
|
6
|
-
vi.useRealTimers();
|
|
7
|
-
}), describe("when calling the throttled function for the first time", () => {
|
|
8
|
-
it("then it should call the original function immediately", () => {
|
|
9
|
-
const e = vi.fn();
|
|
10
|
-
i(e, 1e3)(), expect(e).toHaveBeenCalledTimes(1);
|
|
11
|
-
});
|
|
12
|
-
}), describe("when calling the throttled function multiple times within the time limit", () => {
|
|
13
|
-
it("then it should not call the original function more than once", () => {
|
|
14
|
-
const e = vi.fn(), t = i(e, 1e3);
|
|
15
|
-
t(), t(), t(), expect(e).toHaveBeenCalledTimes(1), vi.advanceTimersByTime(1001), expect(e).toHaveBeenCalledTimes(2);
|
|
16
|
-
});
|
|
17
|
-
}), describe("when calling the throttled function after the time limit has elapsed", () => {
|
|
18
|
-
it("then it should call the original function again", () => {
|
|
19
|
-
const e = vi.fn(), t = i(e, 500);
|
|
20
|
-
t(), vi.advanceTimersByTime(2e3), t(), vi.advanceTimersByTime(500), expect(e).toHaveBeenCalledTimes(2);
|
|
21
|
-
});
|
|
22
|
-
}), describe("when calling the throttled function with arguments", () => {
|
|
23
|
-
it("then it should pass the arguments to the original function", () => {
|
|
24
|
-
const e = vi.fn();
|
|
25
|
-
i(e, 1e3)(1, "test"), expect(e).toHaveBeenCalledWith(1, "test");
|
|
26
|
-
});
|
|
27
|
-
}), describe("when calling the throttled function with a specific context", () => {
|
|
28
|
-
it("then it should preserve the context", () => {
|
|
29
|
-
const e = {
|
|
30
|
-
value: 0,
|
|
31
|
-
func: vi.fn(function() {
|
|
32
|
-
this.value++;
|
|
33
|
-
})
|
|
34
|
-
};
|
|
35
|
-
i(e.func, 1e3).call(e), expect(e.value).toBe(1);
|
|
36
|
-
});
|
|
37
|
-
}), describe("when calling the throttled function repeatedly", () => {
|
|
38
|
-
it("then it should cancel the previous timeout", () => {
|
|
39
|
-
const e = vi.fn(), t = i(e, 1e3);
|
|
40
|
-
t(), vi.advanceTimersByTime(200), t(), vi.advanceTimersByTime(500), t(), vi.advanceTimersByTime(1e3), expect(e).toHaveBeenCalledTimes(2);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { throttleId as i } from "../throttleId.js";
|
|
2
|
-
describe("given throttleId function", () => {
|
|
3
|
-
describe("when calling a throttled function multiple times within the interval", () => {
|
|
4
|
-
it("then it should only execute once immediately and queue the next call", async () => {
|
|
5
|
-
vi.useFakeTimers();
|
|
6
|
-
const e = vi.fn().mockResolvedValue("result"), t = i("test", e, 1e3);
|
|
7
|
-
t(1), await vi.advanceTimersByTimeAsync(300), t(2), await vi.advanceTimersByTimeAsync(300), t(3), expect(e).toHaveBeenCalledTimes(1), expect(e).toHaveBeenCalledWith(1), await vi.advanceTimersByTimeAsync(1e3), expect(e).toHaveBeenCalledTimes(2), expect(e).toHaveBeenLastCalledWith(3), vi.useRealTimers();
|
|
8
|
-
});
|
|
9
|
-
}), describe("when calling throttled functions with different identifiers", () => {
|
|
10
|
-
it("then it should execute separately for each identifier", () => {
|
|
11
|
-
vi.useFakeTimers();
|
|
12
|
-
const e = vi.fn().mockResolvedValue("result"), t = i("id1", e, 1e3), n = i("id2", e, 1e3);
|
|
13
|
-
t(1), n(2), expect(e).toHaveBeenCalledTimes(2), expect(e).toHaveBeenNthCalledWith(1, 1), expect(e).toHaveBeenNthCalledWith(2, 2), vi.useRealTimers();
|
|
14
|
-
});
|
|
15
|
-
}), describe("when the throttled function throws an error", () => {
|
|
16
|
-
it("then it should reject with the error", async () => {
|
|
17
|
-
vi.useFakeTimers();
|
|
18
|
-
const e = vi.fn().mockRejectedValue(new Error("Test error")), t = i("test", e, 1e3);
|
|
19
|
-
await expect(t()).rejects.toThrow("Test error"), vi.useRealTimers();
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { sleep as c } from "../sleep.js";
|
|
2
|
-
import { UserVisibility as n } from "../userVisibility.js";
|
|
3
|
-
function o(i) {
|
|
4
|
-
return document.dispatchEvent(new Event(i));
|
|
5
|
-
}
|
|
6
|
-
function s(i) {
|
|
7
|
-
Object.defineProperty(document, "visibilityState", {
|
|
8
|
-
value: i,
|
|
9
|
-
writable: !0
|
|
10
|
-
}), o("visibilitychange");
|
|
11
|
-
}
|
|
12
|
-
const a = 300;
|
|
13
|
-
let e;
|
|
14
|
-
const l = {
|
|
15
|
-
timeout: a,
|
|
16
|
-
// 5 minutes
|
|
17
|
-
once: !1,
|
|
18
|
-
immediate: !1
|
|
19
|
-
};
|
|
20
|
-
let t;
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
e = vi.fn(), s("visible"), t = new n(e, l);
|
|
23
|
-
});
|
|
24
|
-
afterAll(() => {
|
|
25
|
-
t = void 0;
|
|
26
|
-
});
|
|
27
|
-
describe("user-visibility.ts", () => {
|
|
28
|
-
describe("given app want trigger user idle", () => {
|
|
29
|
-
describe("when instance is launch", () => {
|
|
30
|
-
it("then instance is IdleTimeout", async () => {
|
|
31
|
-
if (expect(t).toBeInstanceOf(n), await c(a), t) {
|
|
32
|
-
const i = vitest.spyOn(t, "addEventListener");
|
|
33
|
-
t.addEventListener(), expect(i).toHaveBeenCalled();
|
|
34
|
-
}
|
|
35
|
-
}), it("then instance emit callback on demand", () => {
|
|
36
|
-
t?.emitCallback(), expect(e).toHaveBeenCalled();
|
|
37
|
-
}), it("then instance emit callback after timeout", async () => {
|
|
38
|
-
s("hidden"), expect(e).not.toHaveBeenCalled(), await c(a), expect(e).toHaveBeenCalled();
|
|
39
|
-
}), it("then instance is destroy", () => {
|
|
40
|
-
t?.destroy();
|
|
41
|
-
});
|
|
42
|
-
}), describe('when instance has immediate option to "true"', () => {
|
|
43
|
-
it("then instance have called callback", () => {
|
|
44
|
-
new n(e, {
|
|
45
|
-
...l,
|
|
46
|
-
immediate: !0
|
|
47
|
-
}), expect(e).toHaveBeenCalledWith({ isVisible: !0 });
|
|
48
|
-
});
|
|
49
|
-
}), describe('when instance has once option to "true"', () => {
|
|
50
|
-
it("then instance have called callback and is destroy", async () => {
|
|
51
|
-
s("hidden"), new n(e, {
|
|
52
|
-
...l,
|
|
53
|
-
once: !0
|
|
54
|
-
}), await c(a), expect(e).toHaveBeenCalledWith({ isVisible: !1 });
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|