@wireio/shared 1.0.19 → 1.0.21

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.
@@ -1,31 +1,33 @@
1
- import { isArray } from "@wireio/shared/guards/array";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const array_1 = require("@wireio/shared/guards/array");
2
4
  describe("isArray", () => {
3
5
  it("returns true for empty array", () => {
4
- expect(isArray([])).toBe(true);
6
+ expect((0, array_1.isArray)([])).toBe(true);
5
7
  });
6
8
  it("returns true for array with elements", () => {
7
- expect(isArray([1, 2, 3])).toBe(true);
9
+ expect((0, array_1.isArray)([1, 2, 3])).toBe(true);
8
10
  });
9
11
  it("returns true for new Array()", () => {
10
- expect(isArray(new Array())).toBe(true);
12
+ expect((0, array_1.isArray)(new Array())).toBe(true);
11
13
  });
12
14
  it("returns false for null", () => {
13
- expect(isArray(null)).toBe(false);
15
+ expect((0, array_1.isArray)(null)).toBe(false);
14
16
  });
15
17
  it("returns false for undefined", () => {
16
- expect(isArray(undefined)).toBe(false);
18
+ expect((0, array_1.isArray)(undefined)).toBe(false);
17
19
  });
18
20
  it("returns false for object", () => {
19
- expect(isArray({})).toBe(false);
21
+ expect((0, array_1.isArray)({})).toBe(false);
20
22
  });
21
23
  it("returns false for string", () => {
22
- expect(isArray("array")).toBe(false);
24
+ expect((0, array_1.isArray)("array")).toBe(false);
23
25
  });
24
26
  it("returns false for object with length property", () => {
25
- expect(isArray({ length: 0 })).toBe(false);
27
+ expect((0, array_1.isArray)({ length: 0 })).toBe(false);
26
28
  });
27
29
  it("returns false for arguments-like object", () => {
28
- expect(isArray({ 0: "a", 1: "b", length: 2 })).toBe(false);
30
+ expect((0, array_1.isArray)({ 0: "a", 1: "b", length: 2 })).toBe(false);
29
31
  });
30
32
  });
31
33
  //# sourceMappingURL=array.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"array.test.js","sourceRoot":"","sources":["../../../tests/guards/array.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;IAEF,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC5D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { isArray } from \"@wireio/shared/guards/array\"\n\ndescribe(\"isArray\", () => {\n it(\"returns true for empty array\", () => {\n expect(isArray([])).toBe(true)\n })\n\n it(\"returns true for array with elements\", () => {\n expect(isArray([1, 2, 3])).toBe(true)\n })\n\n it(\"returns true for new Array()\", () => {\n expect(isArray(new Array())).toBe(true)\n })\n\n it(\"returns false for null\", () => {\n expect(isArray(null)).toBe(false)\n })\n\n it(\"returns false for undefined\", () => {\n expect(isArray(undefined)).toBe(false)\n })\n\n it(\"returns false for object\", () => {\n expect(isArray({})).toBe(false)\n })\n\n it(\"returns false for string\", () => {\n expect(isArray(\"array\")).toBe(false)\n })\n\n it(\"returns false for object with length property\", () => {\n expect(isArray({ length: 0 })).toBe(false)\n })\n\n it(\"returns false for arguments-like object\", () => {\n expect(isArray({ 0: \"a\", 1: \"b\", length: 2 })).toBe(false)\n })\n})\n"]}
1
+ {"version":3,"file":"array.test.js","sourceRoot":"","sources":["../../../tests/guards/array.test.ts"],"names":[],"mappings":";;AAAA,uDAAqD;AAErD,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACtC,MAAM,CAAC,IAAA,eAAO,EAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CA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IAEF,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,CAAC,IAAA,eAAO,EAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC5D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { isArray } from \"@wireio/shared/guards/array\"\n\ndescribe(\"isArray\", () => {\n it(\"returns true for empty array\", () => {\n expect(isArray([])).toBe(true)\n })\n\n it(\"returns true for array with elements\", () => {\n expect(isArray([1, 2, 3])).toBe(true)\n })\n\n it(\"returns true for new Array()\", () => {\n expect(isArray(new Array())).toBe(true)\n })\n\n it(\"returns false for null\", () => {\n expect(isArray(null)).toBe(false)\n })\n\n it(\"returns false for undefined\", () => {\n expect(isArray(undefined)).toBe(false)\n })\n\n it(\"returns false for object\", () => {\n expect(isArray({})).toBe(false)\n })\n\n it(\"returns false for string\", () => {\n expect(isArray(\"array\")).toBe(false)\n })\n\n it(\"returns false for object with length property\", () => {\n expect(isArray({ length: 0 })).toBe(false)\n })\n\n it(\"returns false for arguments-like object\", () => {\n expect(isArray({ 0: \"a\", 1: \"b\", length: 2 })).toBe(false)\n })\n})\n"]}
@@ -1,76 +1,78 @@
1
- import { assert, AssertError, setGlobalAssertOptions, getAssertOptions, DefaultAssertOptions } from "@wireio/shared/guards/assert";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const assert_1 = require("@wireio/shared/guards/assert");
2
4
  describe("assert", () => {
3
5
  afterEach(() => {
4
- setGlobalAssertOptions({ ...DefaultAssertOptions });
6
+ (0, assert_1.setGlobalAssertOptions)({ ...assert_1.DefaultAssertOptions });
5
7
  });
6
8
  it("does not throw when test is true", () => {
7
- expect(() => assert(true)).not.toThrow();
9
+ expect(() => (0, assert_1.assert)(true)).not.toThrow();
8
10
  });
9
11
  it("throws AssertError when test is false", () => {
10
- expect(() => assert(false)).toThrow(AssertError);
12
+ expect(() => (0, assert_1.assert)(false)).toThrow(assert_1.AssertError);
11
13
  });
12
14
  it("throws with custom message", () => {
13
- expect(() => assert(false, "custom message")).toThrow("custom message");
15
+ expect(() => (0, assert_1.assert)(false, "custom message")).toThrow("custom message");
14
16
  });
15
17
  it("throws the provided error directly", () => {
16
18
  const err = new Error("err");
17
- expect(() => assert(false, err)).toThrow(err);
19
+ expect(() => (0, assert_1.assert)(false, err)).toThrow(err);
18
20
  });
19
21
  it("does not throw when function returns true", () => {
20
- expect(() => assert(() => true)).not.toThrow();
22
+ expect(() => (0, assert_1.assert)(() => true)).not.toThrow();
21
23
  });
22
24
  it("throws when function returns false", () => {
23
- expect(() => assert(() => false)).toThrow(AssertError);
25
+ expect(() => (0, assert_1.assert)(() => false)).toThrow(assert_1.AssertError);
24
26
  });
25
27
  it("throws AssertError when function throws", () => {
26
- expect(() => assert(() => {
28
+ expect(() => (0, assert_1.assert)(() => {
27
29
  throw new Error("boom");
28
- })).toThrow(AssertError);
30
+ })).toThrow(assert_1.AssertError);
29
31
  });
30
32
  });
31
33
  describe("AssertError", () => {
32
34
  it("has cause property", () => {
33
35
  const cause = new Error("original");
34
- const assertErr = new AssertError("wrapper", cause);
36
+ const assertErr = new assert_1.AssertError("wrapper", cause);
35
37
  expect(assertErr.cause).toBe(cause);
36
38
  expect(assertErr.message).toBe("wrapper");
37
39
  });
38
40
  it("cause is undefined when not provided", () => {
39
- const assertErr = new AssertError("no cause");
41
+ const assertErr = new assert_1.AssertError("no cause");
40
42
  expect(assertErr.cause).toBeUndefined();
41
43
  });
42
44
  });
43
45
  describe("assert.lift", () => {
44
46
  it("creates a reusable assertion function that does not throw on pass", () => {
45
- const assertPositive = assert.lift((n) => n > 0, "must be positive");
47
+ const assertPositive = assert_1.assert.lift((n) => n > 0, "must be positive");
46
48
  expect(() => assertPositive(5)).not.toThrow();
47
49
  });
48
50
  it("creates a reusable assertion function that throws on fail", () => {
49
- const assertPositive = assert.lift((n) => n > 0, "must be positive");
50
- expect(() => assertPositive(-1)).toThrow(AssertError);
51
+ const assertPositive = assert_1.assert.lift((n) => n > 0, "must be positive");
52
+ expect(() => assertPositive(-1)).toThrow(assert_1.AssertError);
51
53
  expect(() => assertPositive(-1)).toThrow("must be positive");
52
54
  });
53
55
  it("supports message provider function", () => {
54
- const assertPositive = assert.lift((n) => n > 0, (n) => `${n} is not positive`);
56
+ const assertPositive = assert_1.assert.lift((n) => n > 0, (n) => `${n} is not positive`);
55
57
  expect(() => assertPositive(-3)).toThrow("-3 is not positive");
56
58
  });
57
59
  });
58
60
  describe("setGlobalAssertOptions / getAssertOptions", () => {
59
61
  afterEach(() => {
60
- setGlobalAssertOptions({ ...DefaultAssertOptions });
62
+ (0, assert_1.setGlobalAssertOptions)({ ...assert_1.DefaultAssertOptions });
61
63
  });
62
64
  it("returns default options initially", () => {
63
- const options = getAssertOptions();
65
+ const options = (0, assert_1.getAssertOptions)();
64
66
  expect(options.logErrorsToConsole).toBe(false);
65
67
  });
66
68
  it("updates options via setGlobalAssertOptions", () => {
67
- setGlobalAssertOptions({ logErrorsToConsole: true });
68
- const options = getAssertOptions();
69
+ (0, assert_1.setGlobalAssertOptions)({ logErrorsToConsole: true });
70
+ const options = (0, assert_1.getAssertOptions)();
69
71
  expect(options.logErrorsToConsole).toBe(true);
70
72
  });
71
73
  it("returns a copy of options", () => {
72
- const options1 = getAssertOptions();
73
- const options2 = getAssertOptions();
74
+ const options1 = (0, assert_1.getAssertOptions)();
75
+ const options2 = (0, assert_1.getAssertOptions)();
74
76
  expect(options1).toEqual(options2);
75
77
  expect(options1).not.toBe(options2);
76
78
  });
@@ -1 +1 @@
1
- {"version":3,"file":"assert.test.js","sourceRoot":"","sources":["../../../tests/guards/assert.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,WAAW,EACX,sBAAsB,EACtB,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,8BAA8B,CA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C,EAAE,GAAG,EAAE;QACpD,sBAAsB,CAAC,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAA;QACpD,MAAM,OAAO,GAAG,gBAAgB,EAAE,CAAA;QAClC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,QAAQ,GAAG,gBAAgB,EAAE,CAAA;QACnC,MAAM,QAAQ,GAAG,gBAAgB,EAAE,CAAA;QACnC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QAClC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import {\n assert,\n AssertError,\n setGlobalAssertOptions,\n getAssertOptions,\n DefaultAssertOptions\n} from \"@wireio/shared/guards/assert\"\n\ndescribe(\"assert\", () => {\n afterEach(() => {\n setGlobalAssertOptions({ ...DefaultAssertOptions })\n })\n\n it(\"does not throw when test is true\", () => {\n expect(() => assert(true)).not.toThrow()\n })\n\n it(\"throws AssertError when test is false\", () => {\n expect(() => assert(false)).toThrow(AssertError)\n })\n\n it(\"throws with custom message\", () => {\n expect(() => assert(false, \"custom message\")).toThrow(\"custom message\")\n })\n\n it(\"throws the provided error directly\", () => {\n const err = new Error(\"err\")\n expect(() => assert(false, err)).toThrow(err)\n })\n\n it(\"does not throw when function returns true\", () => {\n expect(() => assert(() => true)).not.toThrow()\n })\n\n it(\"throws when function returns false\", () => {\n expect(() => assert(() => false)).toThrow(AssertError)\n })\n\n it(\"throws AssertError when function throws\", () => {\n expect(() =>\n assert(() => {\n throw new Error(\"boom\")\n })\n ).toThrow(AssertError)\n })\n})\n\ndescribe(\"AssertError\", () => {\n it(\"has cause property\", () => {\n const cause = new Error(\"original\")\n const assertErr = new AssertError(\"wrapper\", cause)\n expect(assertErr.cause).toBe(cause)\n expect(assertErr.message).toBe(\"wrapper\")\n })\n\n it(\"cause is undefined when not provided\", () => {\n const assertErr = new AssertError(\"no cause\")\n expect(assertErr.cause).toBeUndefined()\n })\n})\n\ndescribe(\"assert.lift\", () => {\n it(\"creates a reusable assertion function that does not throw on pass\", () => {\n const assertPositive = assert.lift(\n (n: number) => n > 0,\n \"must be positive\"\n )\n expect(() => assertPositive(5)).not.toThrow()\n })\n\n it(\"creates a reusable assertion function that throws on fail\", () => {\n const assertPositive = assert.lift(\n (n: number) => n > 0,\n \"must be positive\"\n )\n expect(() => assertPositive(-1)).toThrow(AssertError)\n expect(() => assertPositive(-1)).toThrow(\"must be positive\")\n })\n\n it(\"supports message provider function\", () => {\n const assertPositive = assert.lift(\n (n: number) => n > 0,\n (n: number) => `${n} is not positive`\n )\n expect(() => assertPositive(-3)).toThrow(\"-3 is not positive\")\n })\n})\n\ndescribe(\"setGlobalAssertOptions / getAssertOptions\", () => {\n afterEach(() => {\n setGlobalAssertOptions({ ...DefaultAssertOptions })\n })\n\n it(\"returns default options initially\", () => {\n const options = getAssertOptions()\n expect(options.logErrorsToConsole).toBe(false)\n })\n\n it(\"updates options via setGlobalAssertOptions\", () => {\n setGlobalAssertOptions({ logErrorsToConsole: true })\n const options = getAssertOptions()\n expect(options.logErrorsToConsole).toBe(true)\n })\n\n it(\"returns a copy of options\", () => {\n const options1 = getAssertOptions()\n const options2 = getAssertOptions()\n expect(options1).toEqual(options2)\n expect(options1).not.toBe(options2)\n })\n})\n"]}
1
+ {"version":3,"file":"assert.test.js","sourceRoot":"","sources":["../../../tests/guards/assert.test.ts"],"names":[],"mappings":";;AAAA,yDAMqC;AAErC,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,SAAS,CAAC,GAAG,EAAE;QACb,IAAA,+BAAsB,EAAC,EAAE,GAAG,6BAAoB,EAAE,CAAC,CAAA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EAAE,CAAC,CAAA;QACpD,MAAM,OAAO,GAAG,IAAA,yBAAgB,GAAE,CAAA;QAClC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/C,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,QAAQ,GAAG,IAAA,yBAAgB,GAAE,CAAA;QACnC,MAAM,QAAQ,GAAG,IAAA,yBAAgB,GAAE,CAAA;QACnC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QAClC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import {\n assert,\n AssertError,\n setGlobalAssertOptions,\n getAssertOptions,\n DefaultAssertOptions\n} from \"@wireio/shared/guards/assert\"\n\ndescribe(\"assert\", () => {\n afterEach(() => {\n setGlobalAssertOptions({ ...DefaultAssertOptions })\n })\n\n it(\"does not throw when test is true\", () => {\n expect(() => assert(true)).not.toThrow()\n })\n\n it(\"throws AssertError when test is false\", () => {\n expect(() => assert(false)).toThrow(AssertError)\n })\n\n it(\"throws with custom message\", () => {\n expect(() => assert(false, \"custom message\")).toThrow(\"custom message\")\n })\n\n it(\"throws the provided error directly\", () => {\n const err = new Error(\"err\")\n expect(() => assert(false, err)).toThrow(err)\n })\n\n it(\"does not throw when function returns true\", () => {\n expect(() => assert(() => true)).not.toThrow()\n })\n\n it(\"throws when function returns false\", () => {\n expect(() => assert(() => false)).toThrow(AssertError)\n })\n\n it(\"throws AssertError when function throws\", () => {\n expect(() =>\n assert(() => {\n throw new Error(\"boom\")\n })\n ).toThrow(AssertError)\n })\n})\n\ndescribe(\"AssertError\", () => {\n it(\"has cause property\", () => {\n const cause = new Error(\"original\")\n const assertErr = new AssertError(\"wrapper\", cause)\n expect(assertErr.cause).toBe(cause)\n expect(assertErr.message).toBe(\"wrapper\")\n })\n\n it(\"cause is undefined when not provided\", () => {\n const assertErr = new AssertError(\"no cause\")\n expect(assertErr.cause).toBeUndefined()\n })\n})\n\ndescribe(\"assert.lift\", () => {\n it(\"creates a reusable assertion function that does not throw on pass\", () => {\n const assertPositive = assert.lift(\n (n: number) => n > 0,\n \"must be positive\"\n )\n expect(() => assertPositive(5)).not.toThrow()\n })\n\n it(\"creates a reusable assertion function that throws on fail\", () => {\n const assertPositive = assert.lift(\n (n: number) => n > 0,\n \"must be positive\"\n )\n expect(() => assertPositive(-1)).toThrow(AssertError)\n expect(() => assertPositive(-1)).toThrow(\"must be positive\")\n })\n\n it(\"supports message provider function\", () => {\n const assertPositive = assert.lift(\n (n: number) => n > 0,\n (n: number) => `${n} is not positive`\n )\n expect(() => assertPositive(-3)).toThrow(\"-3 is not positive\")\n })\n})\n\ndescribe(\"setGlobalAssertOptions / getAssertOptions\", () => {\n afterEach(() => {\n setGlobalAssertOptions({ ...DefaultAssertOptions })\n })\n\n it(\"returns default options initially\", () => {\n const options = getAssertOptions()\n expect(options.logErrorsToConsole).toBe(false)\n })\n\n it(\"updates options via setGlobalAssertOptions\", () => {\n setGlobalAssertOptions({ logErrorsToConsole: true })\n const options = getAssertOptions()\n expect(options.logErrorsToConsole).toBe(true)\n })\n\n it(\"returns a copy of options\", () => {\n const options1 = getAssertOptions()\n const options2 = getAssertOptions()\n expect(options1).toEqual(options2)\n expect(options1).not.toBe(options2)\n })\n})\n"]}
@@ -1,66 +1,68 @@
1
- import { isNativeClass, isConventionalClass, isClass, createInstanceOfGuard, instanceOf } from "@wireio/shared/guards/class";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const class_1 = require("@wireio/shared/guards/class");
2
4
  describe("isNativeClass", () => {
3
5
  it("returns true for ES6 class", () => {
4
6
  class Foo {
5
7
  }
6
- expect(isNativeClass(Foo)).toBe(true);
8
+ expect((0, class_1.isNativeClass)(Foo)).toBe(true);
7
9
  });
8
10
  it("returns false for regular function", () => {
9
11
  function Foo() { }
10
- expect(isNativeClass(Foo)).toBe(false);
12
+ expect((0, class_1.isNativeClass)(Foo)).toBe(false);
11
13
  });
12
14
  it("returns false for arrow function", () => {
13
15
  const fn = () => { };
14
- expect(isNativeClass(fn)).toBe(false);
16
+ expect((0, class_1.isNativeClass)(fn)).toBe(false);
15
17
  });
16
18
  });
17
19
  describe("isConventionalClass", () => {
18
20
  it("returns true for function with capital first letter", () => {
19
21
  function Foo() { }
20
- expect(isConventionalClass(Foo)).toBe(true);
22
+ expect((0, class_1.isConventionalClass)(Foo)).toBe(true);
21
23
  });
22
24
  it("returns false for function with lowercase first letter", () => {
23
25
  function foo() { }
24
- expect(isConventionalClass(foo)).toBe(false);
26
+ expect((0, class_1.isConventionalClass)(foo)).toBe(false);
25
27
  });
26
28
  it("returns false for non-function", () => {
27
- expect(isConventionalClass("Foo")).toBe(false);
29
+ expect((0, class_1.isConventionalClass)("Foo")).toBe(false);
28
30
  });
29
31
  });
30
32
  describe("isClass", () => {
31
33
  it("returns true for native class", () => {
32
34
  class Bar {
33
35
  }
34
- expect(isClass(Bar)).toBe(true);
36
+ expect((0, class_1.isClass)(Bar)).toBe(true);
35
37
  });
36
38
  it("returns true for conventional class with includeConventional=true", () => {
37
39
  function Bar() { }
38
- expect(isClass(Bar, true)).toBe(true);
40
+ expect((0, class_1.isClass)(Bar, true)).toBe(true);
39
41
  });
40
42
  it("returns false for conventional class with includeConventional=false", () => {
41
43
  function Bar() { }
42
- expect(isClass(Bar, false)).toBe(false);
44
+ expect((0, class_1.isClass)(Bar, false)).toBe(false);
43
45
  });
44
46
  it("returns true for conventional class by default", () => {
45
47
  function Bar() { }
46
- expect(isClass(Bar)).toBe(true);
48
+ expect((0, class_1.isClass)(Bar)).toBe(true);
47
49
  });
48
50
  it("returns false for arrow function", () => {
49
51
  const fn = () => { };
50
- expect(isClass(fn)).toBe(false);
52
+ expect((0, class_1.isClass)(fn)).toBe(false);
51
53
  });
52
54
  });
53
55
  describe("createInstanceOfGuard", () => {
54
56
  it("creates a guard that returns true for instances", () => {
55
57
  class MyClass {
56
58
  }
57
- const guard = createInstanceOfGuard(MyClass);
59
+ const guard = (0, class_1.createInstanceOfGuard)(MyClass);
58
60
  expect(guard(new MyClass())).toBe(true);
59
61
  });
60
62
  it("creates a guard that returns false for non-instances", () => {
61
63
  class MyClass {
62
64
  }
63
- const guard = createInstanceOfGuard(MyClass);
65
+ const guard = (0, class_1.createInstanceOfGuard)(MyClass);
64
66
  expect(guard({})).toBe(false);
65
67
  });
66
68
  });
@@ -68,7 +70,7 @@ describe("instanceOf", () => {
68
70
  it("works as shorthand for createInstanceOfGuard", () => {
69
71
  class MyClass {
70
72
  }
71
- const guard = instanceOf(MyClass);
73
+ const guard = (0, class_1.instanceOf)(MyClass);
72
74
  expect(guard(new MyClass())).toBe(true);
73
75
  expect(guard({})).toBe(false);
74
76
  });
@@ -1 +1 @@
1
- {"version":3,"file":"class.test.js","sourceRoot":"","sources":["../../../tests/guards/class.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,OAAO,EACP,qBAAqB,EACrB,UAAU,EACX,MAAM,6BAA6B,CAAA;AAEpC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;QACpC,MAAM,GAAG;SAAG;QACZ,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,SAAS,GAAG,KAAI,CAAC;QACjB,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,kCAAkC,EAAE,GAA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;QACtD,MAAM,OAAO;SAAG;QAChB,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;QACjC,MAAM,CAAC,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACvC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import {\n isNativeClass,\n isConventionalClass,\n isClass,\n createInstanceOfGuard,\n instanceOf\n} from \"@wireio/shared/guards/class\"\n\ndescribe(\"isNativeClass\", () => {\n it(\"returns true for ES6 class\", () => {\n class Foo {}\n expect(isNativeClass(Foo)).toBe(true)\n })\n\n it(\"returns false for regular function\", () => {\n function Foo() {}\n expect(isNativeClass(Foo)).toBe(false)\n })\n\n it(\"returns false for arrow function\", () => {\n const fn = () => {}\n expect(isNativeClass(fn)).toBe(false)\n })\n})\n\ndescribe(\"isConventionalClass\", () => {\n it(\"returns true for function with capital first letter\", () => {\n function Foo() {}\n expect(isConventionalClass(Foo)).toBe(true)\n })\n\n it(\"returns false for function with lowercase first letter\", () => {\n function foo() {}\n expect(isConventionalClass(foo)).toBe(false)\n })\n\n it(\"returns false for non-function\", () => {\n expect(isConventionalClass(\"Foo\")).toBe(false)\n })\n})\n\ndescribe(\"isClass\", () => {\n it(\"returns true for native class\", () => {\n class Bar {}\n expect(isClass(Bar)).toBe(true)\n })\n\n it(\"returns true for conventional class with includeConventional=true\", () => {\n function Bar() {}\n expect(isClass(Bar, true)).toBe(true)\n })\n\n it(\"returns false for conventional class with includeConventional=false\", () => {\n function Bar() {}\n expect(isClass(Bar, false)).toBe(false)\n })\n\n it(\"returns true for conventional class by default\", () => {\n function Bar() {}\n expect(isClass(Bar)).toBe(true)\n })\n\n it(\"returns false for arrow function\", () => {\n const fn = () => {}\n expect(isClass(fn)).toBe(false)\n })\n})\n\ndescribe(\"createInstanceOfGuard\", () => {\n it(\"creates a guard that returns true for instances\", () => {\n class MyClass {}\n const guard = createInstanceOfGuard(MyClass)\n expect(guard(new MyClass())).toBe(true)\n })\n\n it(\"creates a guard that returns false for non-instances\", () => {\n class MyClass {}\n const guard = createInstanceOfGuard(MyClass)\n expect(guard({})).toBe(false)\n })\n})\n\ndescribe(\"instanceOf\", () => {\n it(\"works as shorthand for createInstanceOfGuard\", () => {\n class MyClass {}\n const guard = instanceOf(MyClass)\n expect(guard(new MyClass())).toBe(true)\n expect(guard({})).toBe(false)\n })\n})\n"]}
1
+ {"version":3,"file":"class.test.js","sourceRoot":"","sources":["../../../tests/guards/class.test.ts"],"names":[],"mappings":";;AAAA,uDAMoC;AAEpC,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;QACpC,MAAM,GAAG;SAAG;QACZ,MAAM,CAAC,IAAA,qBAAa,EAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,SAAS,GAAG,KAAI,CAAC;QACjB,MAAM,CAAC,IAAA,qBAAa,EAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAC1C,MAAM,EAAE,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA;QACnB,MAAM,CAAC,IAAA,qBAAa,EAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,SAAS,GAAG,KAAI,C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K,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import {\n isNativeClass,\n isConventionalClass,\n isClass,\n createInstanceOfGuard,\n instanceOf\n} from \"@wireio/shared/guards/class\"\n\ndescribe(\"isNativeClass\", () => {\n it(\"returns true for ES6 class\", () => {\n class Foo {}\n expect(isNativeClass(Foo)).toBe(true)\n })\n\n it(\"returns false for regular function\", () => {\n function Foo() {}\n expect(isNativeClass(Foo)).toBe(false)\n })\n\n it(\"returns false for arrow function\", () => {\n const fn = () => {}\n expect(isNativeClass(fn)).toBe(false)\n })\n})\n\ndescribe(\"isConventionalClass\", () => {\n it(\"returns true for function with capital first letter\", () => {\n function Foo() {}\n expect(isConventionalClass(Foo)).toBe(true)\n })\n\n it(\"returns false for function with lowercase first letter\", () => {\n function foo() {}\n expect(isConventionalClass(foo)).toBe(false)\n })\n\n it(\"returns false for non-function\", () => {\n expect(isConventionalClass(\"Foo\")).toBe(false)\n })\n})\n\ndescribe(\"isClass\", () => {\n it(\"returns true for native class\", () => {\n class Bar {}\n expect(isClass(Bar)).toBe(true)\n })\n\n it(\"returns true for conventional class with includeConventional=true\", () => {\n function Bar() {}\n expect(isClass(Bar, true)).toBe(true)\n })\n\n it(\"returns false for conventional class with includeConventional=false\", () => {\n function Bar() {}\n expect(isClass(Bar, false)).toBe(false)\n })\n\n it(\"returns true for conventional class by default\", () => {\n function Bar() {}\n expect(isClass(Bar)).toBe(true)\n })\n\n it(\"returns false for arrow function\", () => {\n const fn = () => {}\n expect(isClass(fn)).toBe(false)\n })\n})\n\ndescribe(\"createInstanceOfGuard\", () => {\n it(\"creates a guard that returns true for instances\", () => {\n class MyClass {}\n const guard = createInstanceOfGuard(MyClass)\n expect(guard(new MyClass())).toBe(true)\n })\n\n it(\"creates a guard that returns false for non-instances\", () => {\n class MyClass {}\n const guard = createInstanceOfGuard(MyClass)\n expect(guard({})).toBe(false)\n })\n})\n\ndescribe(\"instanceOf\", () => {\n it(\"works as shorthand for createInstanceOfGuard\", () => {\n class MyClass {}\n const guard = instanceOf(MyClass)\n expect(guard(new MyClass())).toBe(true)\n expect(guard({})).toBe(false)\n })\n})\n"]}
@@ -1,51 +1,53 @@
1
- import { getValue, guard, setGuardErrorHandler } from "@wireio/shared/guards/guard-tools";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const guard_tools_1 = require("@wireio/shared/guards/guard-tools");
2
4
  describe("getValue", () => {
3
5
  afterEach(() => {
4
- setGuardErrorHandler(null);
6
+ (0, guard_tools_1.setGuardErrorHandler)(null);
5
7
  });
6
8
  it("returns the value from the function", () => {
7
- expect(getValue(() => 42)).toBe(42);
9
+ expect((0, guard_tools_1.getValue)(() => 42)).toBe(42);
8
10
  });
9
11
  it("returns default value when function throws", () => {
10
- expect(getValue(() => {
12
+ expect((0, guard_tools_1.getValue)(() => {
11
13
  throw new Error();
12
14
  }, "default")).toBe("default");
13
15
  });
14
16
  it("returns default value when function returns null", () => {
15
- expect(getValue(() => null, "default")).toBe("default");
17
+ expect((0, guard_tools_1.getValue)(() => null, "default")).toBe("default");
16
18
  });
17
19
  it("returns promise resolving to value", async () => {
18
- const result = getValue(() => Promise.resolve(42));
20
+ const result = (0, guard_tools_1.getValue)(() => Promise.resolve(42));
19
21
  await expect(result).resolves.toBe(42);
20
22
  });
21
23
  it("returns promise resolving to default on rejection", async () => {
22
- const result = getValue(() => Promise.reject(new Error()), "default");
24
+ const result = (0, guard_tools_1.getValue)(() => Promise.reject(new Error()), "default");
23
25
  await expect(result).resolves.toBe("default");
24
26
  });
25
27
  });
26
28
  describe("guard", () => {
27
29
  afterEach(() => {
28
- setGuardErrorHandler(null);
30
+ (0, guard_tools_1.setGuardErrorHandler)(null);
29
31
  });
30
32
  it("does not throw for no-op function", () => {
31
- expect(() => guard(() => { })).not.toThrow();
33
+ expect(() => (0, guard_tools_1.guard)(() => { })).not.toThrow();
32
34
  });
33
35
  it("does not throw when function throws", () => {
34
- expect(() => guard(() => {
36
+ expect(() => (0, guard_tools_1.guard)(() => {
35
37
  throw new Error("fail");
36
38
  })).not.toThrow();
37
39
  });
38
40
  });
39
41
  describe("setGuardErrorHandler", () => {
40
42
  afterEach(() => {
41
- setGuardErrorHandler(null);
43
+ (0, guard_tools_1.setGuardErrorHandler)(null);
42
44
  });
43
45
  it("sets global handler that receives errors", () => {
44
46
  const errors = [];
45
- setGuardErrorHandler(err => {
47
+ (0, guard_tools_1.setGuardErrorHandler)(err => {
46
48
  errors.push(err);
47
49
  });
48
- getValue(() => {
50
+ (0, guard_tools_1.getValue)(() => {
49
51
  throw new Error("caught");
50
52
  }, undefined);
51
53
  expect(errors).toHaveLength(1);
@@ -53,11 +55,11 @@ describe("setGuardErrorHandler", () => {
53
55
  });
54
56
  it("can be reset to null", () => {
55
57
  const errors = [];
56
- setGuardErrorHandler(err => {
58
+ (0, guard_tools_1.setGuardErrorHandler)(err => {
57
59
  errors.push(err);
58
60
  });
59
- setGuardErrorHandler(null);
60
- getValue(() => {
61
+ (0, guard_tools_1.setGuardErrorHandler)(null);
62
+ (0, guard_tools_1.getValue)(() => {
61
63
  throw new Error("not caught");
62
64
  }, undefined);
63
65
  expect(errors).toHaveLength(0);
@@ -1 +1 @@
1
- {"version":3,"file":"guard-tools.test.js","sourceRoot":"","sources":["../../../tests/guards/guard-tools.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,KAAK,EACL,oBAAoB,EACrB,MAAM,mCAAmC,CAAA;AAE1C,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,SAAS,CAAC,GAAG,EAAE;QACb,oBAAoB,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACrC,CAAC,CAAC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C,GAAG,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAA;QAC/B,CAAC,EAAE,SAAkB,CAAC,CAAA;QAEtB,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IAChC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import {\n getValue,\n guard,\n setGuardErrorHandler\n} from \"@wireio/shared/guards/guard-tools\"\n\ndescribe(\"getValue\", () => {\n afterEach(() => {\n setGuardErrorHandler(null)\n })\n\n it(\"returns the value from the function\", () => {\n expect(getValue(() => 42)).toBe(42)\n })\n\n it(\"returns default value when function throws\", () => {\n expect(\n getValue(\n () => {\n throw new Error()\n },\n \"default\" as any as never\n )\n ).toBe(\"default\")\n })\n\n it(\"returns default value when function returns null\", () => {\n expect(getValue(() => null, \"default\")).toBe(\"default\")\n })\n\n it(\"returns promise resolving to value\", async () => {\n const result = getValue(() => Promise.resolve(42))\n await expect(result).resolves.toBe(42)\n })\n\n it(\"returns promise resolving to default on rejection\", async () => {\n const result = getValue(\n () => Promise.reject(new Error()),\n \"default\" as any as never\n )\n await expect(result).resolves.toBe(\"default\")\n })\n})\n\ndescribe(\"guard\", () => {\n afterEach(() => {\n setGuardErrorHandler(null)\n })\n\n it(\"does not throw for no-op function\", () => {\n expect(() => guard(() => {})).not.toThrow()\n })\n\n it(\"does not throw when function throws\", () => {\n expect(() =>\n guard(() => {\n throw new Error(\"fail\")\n })\n ).not.toThrow()\n })\n})\n\ndescribe(\"setGuardErrorHandler\", () => {\n afterEach(() => {\n setGuardErrorHandler(null)\n })\n\n it(\"sets global handler that receives errors\", () => {\n const errors: Error[] = []\n setGuardErrorHandler(err => {\n errors.push(err)\n })\n\n getValue(() => {\n throw new Error(\"caught\")\n }, undefined as never)\n\n expect(errors).toHaveLength(1)\n expect(errors[0].message).toBe(\"caught\")\n })\n\n it(\"can be reset to null\", () => {\n const errors: Error[] = []\n setGuardErrorHandler(err => {\n errors.push(err)\n })\n setGuardErrorHandler(null)\n\n getValue(() => {\n throw new Error(\"not caught\")\n }, undefined as never)\n\n expect(errors).toHaveLength(0)\n })\n})\n"]}
1
+ {"version":3,"file":"guard-tools.test.js","sourceRoot":"","sources":["../../../tests/guards/guard-tools.test.ts"],"names":[],"mappings":";;AAAA,mEAI0C;AAE1C,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,SAAS,CAAC,GAAG,EAAE;QACb,IAAA,kCAAoB,EAAC,IAAI,CAAC,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,CAAC,IAAA,sBAAQ,EAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,CACJ,IAAA,sBAAQ,EACN,GAAG,EAAE;YACH,MAAM,IAAI,KAAK,EAAE,CAAA;QACnB,CAAC,EACD,SAAyB,CAC1B,CACF,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,MAAM,CAAC,IAAA,sBAAQ,EAAC,GAAG,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACzD,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;QAClD,MAAM,MAAM,GAAG,IAAA,sBAAQ,EAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;QAClD,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACxC,CAAC,CAAC,CAAA;IAEF,EA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CAAA;QAClB,CAAC,CAAC,CAAA;QAEF,IAAA,sBAAQ,EAAC,GAAG,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC3B,CAAC,EAAE,SAAkB,CAAC,CAAA;QAEtB,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;QAC9B,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,sBAAsB,EAAE,GAAG,EAAE;QAC9B,MAAM,MAAM,GAAY,EAAE,CAAA;QAC1B,IAAA,kCAAoB,EAAC,GAAG,CAAC,EAAE;YACzB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;QACF,IAAA,kCAAoB,EAAC,IAAI,CAAC,CAAA;QAE1B,IAAA,sBAAQ,EAAC,GAAG,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAA;QAC/B,CAAC,EAAE,SAAkB,CAAC,CAAA;QAEtB,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IAChC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import {\n getValue,\n guard,\n setGuardErrorHandler\n} from \"@wireio/shared/guards/guard-tools\"\n\ndescribe(\"getValue\", () => {\n afterEach(() => {\n setGuardErrorHandler(null)\n })\n\n it(\"returns the value from the function\", () => {\n expect(getValue(() => 42)).toBe(42)\n })\n\n it(\"returns default value when function throws\", () => {\n expect(\n getValue(\n () => {\n throw new Error()\n },\n \"default\" as any as never\n )\n ).toBe(\"default\")\n })\n\n it(\"returns default value when function returns null\", () => {\n expect(getValue(() => null, \"default\")).toBe(\"default\")\n })\n\n it(\"returns promise resolving to value\", async () => {\n const result = getValue(() => Promise.resolve(42))\n await expect(result).resolves.toBe(42)\n })\n\n it(\"returns promise resolving to default on rejection\", async () => {\n const result = getValue(\n () => Promise.reject(new Error()),\n \"default\" as any as never\n )\n await expect(result).resolves.toBe(\"default\")\n })\n})\n\ndescribe(\"guard\", () => {\n afterEach(() => {\n setGuardErrorHandler(null)\n })\n\n it(\"does not throw for no-op function\", () => {\n expect(() => guard(() => {})).not.toThrow()\n })\n\n it(\"does not throw when function throws\", () => {\n expect(() =>\n guard(() => {\n throw new Error(\"fail\")\n })\n ).not.toThrow()\n })\n})\n\ndescribe(\"setGuardErrorHandler\", () => {\n afterEach(() => {\n setGuardErrorHandler(null)\n })\n\n it(\"sets global handler that receives errors\", () => {\n const errors: Error[] = []\n setGuardErrorHandler(err => {\n errors.push(err)\n })\n\n getValue(() => {\n throw new Error(\"caught\")\n }, undefined as never)\n\n expect(errors).toHaveLength(1)\n expect(errors[0].message).toBe(\"caught\")\n })\n\n it(\"can be reset to null\", () => {\n const errors: Error[] = []\n setGuardErrorHandler(err => {\n errors.push(err)\n })\n setGuardErrorHandler(null)\n\n getValue(() => {\n throw new Error(\"not caught\")\n }, undefined as never)\n\n expect(errors).toHaveLength(0)\n })\n})\n"]}