type-fns 1.18.0 → 1.20.1

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 (38) hide show
  1. package/dist/checks/isAFunction.d.ts +1 -1
  2. package/dist/checks/isAFunction.js.map +1 -1
  3. package/dist/checks/isAPromise.d.ts +1 -1
  4. package/dist/checks/isAPromise.js.map +1 -1
  5. package/dist/checks/isNotNull.test.js +4 -13
  6. package/dist/checks/isNotNull.test.js.map +1 -1
  7. package/dist/checks/isNotPromise.d.ts +5 -0
  8. package/dist/checks/isNotPromise.js +9 -0
  9. package/dist/checks/isNotPromise.js.map +1 -0
  10. package/dist/checks/isNotUndefined.test.js +4 -13
  11. package/dist/checks/isNotUndefined.test.js.map +1 -1
  12. package/dist/checks/isOfEnum.d.ts +2 -1
  13. package/dist/checks/isOfEnum.js.map +1 -1
  14. package/dist/companions/omit.js +1 -1
  15. package/dist/companions/omit.js.map +1 -1
  16. package/dist/companions/pick.js +1 -1
  17. package/dist/companions/pick.js.map +1 -1
  18. package/dist/index.d.ts +2 -0
  19. package/dist/index.js +2 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/types/Empty.d.ts +8 -0
  22. package/dist/types/Empty.js +3 -0
  23. package/dist/types/Empty.js.map +1 -0
  24. package/dist/types/PickAny.test.js +8 -17
  25. package/dist/types/PickAny.test.js.map +1 -1
  26. package/dist/types/PickOne.test.js +8 -17
  27. package/dist/types/PickOne.test.js.map +1 -1
  28. package/dist/wrappers/withAssure.d.ts +1 -1
  29. package/dist/wrappers/withAssure.js +3 -4
  30. package/dist/wrappers/withAssure.js.map +1 -1
  31. package/license.md +21 -0
  32. package/package.json +9 -12
  33. package/dist/deps.d.ts +0 -1
  34. package/dist/deps.js +0 -6
  35. package/dist/deps.js.map +0 -1
  36. package/dist/utils/environment.d.ts +0 -8
  37. package/dist/utils/environment.js +0 -58
  38. package/dist/utils/environment.js.map +0 -1
@@ -1 +1 @@
1
- export declare const isAFunction: (obj: any) => obj is Function;
1
+ export declare const isAFunction: (obj: unknown) => obj is Function;
@@ -1 +1 @@
1
- {"version":3,"file":"isAFunction.js","sourceRoot":"","sources":["../../src/checks/isAFunction.ts"],"names":[],"mappings":";;;AAAA,wDAAwD;AACjD,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAmB,EAAE,CACvD,OAAO,GAAG,KAAK,UAAU,CAAC;AADf,QAAA,WAAW,eACI"}
1
+ {"version":3,"file":"isAFunction.js","sourceRoot":"","sources":["../../src/checks/isAFunction.ts"],"names":[],"mappings":";;;AAAA,wDAAwD;AACjD,MAAM,WAAW,GAAG,CAAC,GAAY,EAAmB,EAAE,CAC3D,OAAO,GAAG,KAAK,UAAU,CAAC;AADf,QAAA,WAAW,eACI"}
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * checks whether the value is a promise
3
3
  */
4
- export declare const isAPromise: <T = any>(obj: any) => obj is Promise<T>;
4
+ export declare const isAPromise: <T = any>(obj: unknown) => obj is Promise<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"isAPromise.js","sourceRoot":"","sources":["../../src/checks/isAPromise.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,UAAU,GAAG,CAAU,GAAQ,EAAqB,EAAE,CACjE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;AADlB,QAAA,UAAU,cACQ"}
1
+ {"version":3,"file":"isAPromise.js","sourceRoot":"","sources":["../../src/checks/isAPromise.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,UAAU,GAAG,CAAU,GAAY,EAAqB,EAAE,CACrE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;AADlB,QAAA,UAAU,cACQ"}
@@ -1,28 +1,19 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  /* eslint-disable @typescript-eslint/no-unused-vars */
13
4
  const __1 = require("..");
14
5
  describe('isNotNull', () => {
15
- it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
6
+ it('should constrain type correctly', async () => {
16
7
  const maybeNumber = undefined; // valid
17
8
  if ((0, __1.isNotNull)(maybeNumber)) {
18
9
  const defNumber = maybeNumber; // valid
19
10
  }
20
- }));
11
+ });
21
12
  });
22
13
  describe('NotNull', () => {
23
- it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
14
+ it('should constrain type correctly', async () => {
24
15
  const notMaybeNumber = 821;
25
16
  const onlyNumber = notMaybeNumber; // valid
26
- }));
17
+ });
27
18
  });
28
19
  //# sourceMappingURL=isNotNull.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"isNotNull.test.js","sourceRoot":"","sources":["../../src/checks/isNotNull.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sDAAsD;AACtD,0BAAwC;AAExC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAG/C,MAAM,WAAW,GAAgB,SAAgB,CAAC,CAAC,QAAQ;QAE3D,IAAI,IAAA,aAAS,EAAC,WAAW,CAAC,EAAE,CAAC;YAC3B,MAAM,SAAS,GAAW,WAAW,CAAC,CAAC,QAAQ;QACjD,CAAC;IACH,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAG/C,MAAM,cAAc,GAAyB,GAAU,CAAC;QACxD,MAAM,UAAU,GAAW,cAAc,CAAC,CAAC,QAAQ;IACrD,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"isNotNull.test.js","sourceRoot":"","sources":["../../src/checks/isNotNull.test.ts"],"names":[],"mappings":";;AAAA,sDAAsD;AACtD,0BAAwC;AAExC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;QAG/C,MAAM,WAAW,GAAgB,SAAgB,CAAC,CAAC,QAAQ;QAE3D,IAAI,IAAA,aAAS,EAAC,WAAW,CAAC,EAAE,CAAC;YAC3B,MAAM,SAAS,GAAW,WAAW,CAAC,CAAC,QAAQ;QACjD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;QAG/C,MAAM,cAAc,GAAyB,GAAU,CAAC;QACxD,MAAM,UAAU,GAAW,cAAc,CAAC,CAAC,QAAQ;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export type NotPromise<T> = T extends Promise<any> ? never : T;
2
+ /**
3
+ * checks whether the value is a promise
4
+ */
5
+ export declare const isNotPromise: <T = any>(obj: unknown) => obj is NotPromise<T>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNotPromise = void 0;
4
+ /**
5
+ * checks whether the value is a promise
6
+ */
7
+ const isNotPromise = (obj) => Promise.resolve(obj) === obj;
8
+ exports.isNotPromise = isNotPromise;
9
+ //# sourceMappingURL=isNotPromise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isNotPromise.js","sourceRoot":"","sources":["../../src/checks/isNotPromise.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACI,MAAM,YAAY,GAAG,CAAU,GAAY,EAAwB,EAAE,CAC1E,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;AADlB,QAAA,YAAY,gBACM"}
@@ -1,28 +1,19 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  /* eslint-disable @typescript-eslint/no-unused-vars */
13
4
  const __1 = require("..");
14
5
  describe('isNotUndefined', () => {
15
- it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
6
+ it('should constrain type correctly', async () => {
16
7
  const maybeNumber = undefined; // valid
17
8
  if ((0, __1.isNotUndefined)(maybeNumber)) {
18
9
  const defNumber = maybeNumber; // valid
19
10
  }
20
- }));
11
+ });
21
12
  });
22
13
  describe('NotUndefined', () => {
23
- it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
14
+ it('should constrain type correctly', async () => {
24
15
  const notMaybeNumber = 821;
25
16
  const onlyNumber = notMaybeNumber; // valid
26
- }));
17
+ });
27
18
  });
28
19
  //# sourceMappingURL=isNotUndefined.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"isNotUndefined.test.js","sourceRoot":"","sources":["../../src/checks/isNotUndefined.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sDAAsD;AACtD,0BAAkD;AAElD,QAAQ,CAAC,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wrappers/withAssure';
1
2
  /**
2
3
  * a generic fn that allows us to create type checks for enums. for example:
3
4
  * ```ts
@@ -26,4 +27,4 @@ export declare const createIsOfEnum: <T extends {
26
27
  [index: string]: string | number;
27
28
  [index: number]: string | number;
28
29
  [index: symbol]: string | number;
29
- }>(e: T) => import("../wrappers/withAssure").AssessWithAssure<string | number | symbol, T[keyof T]>;
30
+ }>(e: T) => AssessWithAssure<string | number | symbol, T[keyof T]>;
@@ -1 +1 @@
1
- {"version":3,"file":"isOfEnum.js","sourceRoot":"","sources":["../../src/checks/isOfEnum.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAEpD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,cAAc,GAAG,CAG5B,CAAI,EACJ,EAAE;IACF,MAAM,KAAK,GAAG,CAAC,KAA+B,EAAuB,EAAE,CACrE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAmB,CAAC,CAAC;IACjD,OAAO,IAAA,uBAAU,EAAC,KAAK,CAAC,CAAC;AAC3B,CAAC,CAAC;AARW,QAAA,cAAc,kBAQzB"}
1
+ {"version":3,"file":"isOfEnum.js","sourceRoot":"","sources":["../../src/checks/isOfEnum.ts"],"names":[],"mappings":";;;AAAA,uDAAsE;AAEtE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,MAAM,cAAc,GAAG,CAG5B,CAAI,EACoD,EAAE;IAC1D,MAAM,KAAK,GAAG,CAAC,KAA+B,EAAuB,EAAE,CACrE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAmB,CAAC,CAAC;IACjD,OAAO,IAAA,uBAAU,EAAC,KAAK,CAAC,CAAC;AAC3B,CAAC,CAAC;AARW,QAAA,cAAc,kBAQzB"}
@@ -9,7 +9,7 @@ const omit = (obj, keys) => Object.entries(obj).reduce((summary, [key, value]) =
9
9
  if (keys.includes(key))
10
10
  return summary;
11
11
  // if it is not within specified keys, add it
12
- return Object.assign(Object.assign({}, summary), { [key]: value });
12
+ return { ...summary, [key]: value };
13
13
  }, {});
14
14
  exports.omit = omit;
15
15
  //# sourceMappingURL=omit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"omit.js","sourceRoot":"","sources":["../../src/companions/omit.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,IAAI,GAAG,CAIlB,GAAM,EACN,IAAO,EACa,EAAE,CACtB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;IACnD,iEAAiE;IACjE,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC;IAEvC,6CAA6C;IAC7C,uCAAY,OAAO,KAAE,CAAC,GAAG,CAAC,EAAE,KAAK,IAAG;AACtC,CAAC,EAAE,EAAyB,CAAQ,CAAC;AAb1B,QAAA,IAAI,QAasB"}
1
+ {"version":3,"file":"omit.js","sourceRoot":"","sources":["../../src/companions/omit.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,IAAI,GAAG,CAIlB,GAAM,EACN,IAAO,EACa,EAAE,CACtB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;IACnD,iEAAiE;IACjE,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC;IAEvC,6CAA6C;IAC7C,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC;AACtC,CAAC,EAAE,EAAyB,CAAQ,CAAC;AAb1B,QAAA,IAAI,QAasB"}
@@ -9,7 +9,7 @@ const pick = (obj, keys) => Object.entries(obj).reduce((summary, [key, value]) =
9
9
  if (!keys.includes(key))
10
10
  return summary;
11
11
  // if it is within specified keys, add it
12
- return Object.assign(Object.assign({}, summary), { [key]: value });
12
+ return { ...summary, [key]: value };
13
13
  }, {});
14
14
  exports.pick = pick;
15
15
  //# sourceMappingURL=pick.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pick.js","sourceRoot":"","sources":["../../src/companions/pick.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,IAAI,GAAG,CAIlB,GAAM,EACN,IAAO,EACa,EAAE,CACtB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;IACnD,qEAAqE;IACrE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC;IAExC,yCAAyC;IACzC,uCAAY,OAAO,KAAE,CAAC,GAAG,CAAC,EAAE,KAAK,IAAG;AACtC,CAAC,EAAE,EAAyB,CAAQ,CAAC;AAb1B,QAAA,IAAI,QAasB"}
1
+ {"version":3,"file":"pick.js","sourceRoot":"","sources":["../../src/companions/pick.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,IAAI,GAAG,CAIlB,GAAM,EACN,IAAO,EACa,EAAE,CACtB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;IACnD,qEAAqE;IACrE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC;IAExC,yCAAyC;IACzC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC;AACtC,CAAC,EAAE,EAAyB,CAAQ,CAAC;AAb1B,QAAA,IAAI,QAasB"}
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export * from './checks/isAPromise';
9
9
  export * from './types/PickOne';
10
10
  export * from './checks/isNotNull';
11
11
  export * from './checks/isNotUndefined';
12
+ export * from './checks/isNotPromise';
12
13
  export * from './types/DropFirst';
13
14
  export * from './companions/omit';
14
15
  export * from './companions/pick';
@@ -16,3 +17,4 @@ export * from './types/Literalize';
16
17
  export * from './wrappers/withAssure';
17
18
  export * from './checks/isKeyOf';
18
19
  export * from './types/PickAny';
20
+ export * from './types/Empty';
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ __exportStar(require("./checks/isAPromise"), exports);
25
25
  __exportStar(require("./types/PickOne"), exports);
26
26
  __exportStar(require("./checks/isNotNull"), exports);
27
27
  __exportStar(require("./checks/isNotUndefined"), exports);
28
+ __exportStar(require("./checks/isNotPromise"), exports);
28
29
  __exportStar(require("./types/DropFirst"), exports);
29
30
  __exportStar(require("./companions/omit"), exports);
30
31
  __exportStar(require("./companions/pick"), exports);
@@ -32,4 +33,5 @@ __exportStar(require("./types/Literalize"), exports);
32
33
  __exportStar(require("./wrappers/withAssure"), exports);
33
34
  __exportStar(require("./checks/isKeyOf"), exports);
34
35
  __exportStar(require("./types/PickAny"), exports);
36
+ __exportStar(require("./types/Empty"), exports);
35
37
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,mDAAiC;AACjC,uDAAqC;AACrC,qDAAmC;AACnC,oDAAkC;AAClC,qDAAmC;AACnC,uDAAqC;AACrC,sDAAoC;AACpC,kDAAgC;AAChC,qDAAmC;AACnC,0DAAwC;AACxC,oDAAkC;AAClC,oDAAkC;AAClC,oDAAkC;AAClC,qDAAmC;AACnC,wDAAsC;AACtC,mDAAiC;AACjC,kDAAgC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,mDAAiC;AACjC,uDAAqC;AACrC,qDAAmC;AACnC,oDAAkC;AAClC,qDAAmC;AACnC,uDAAqC;AACrC,sDAAoC;AACpC,kDAAgC;AAChC,qDAAmC;AACnC,0DAAwC;AACxC,wDAAsC;AACtC,oDAAkC;AAClC,oDAAkC;AAClC,oDAAkC;AAClC,qDAAmC;AACnC,wDAAsC;AACtC,mDAAiC;AACjC,kDAAgC;AAChC,gDAA8B"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * the shape of an empty object
3
+ *
4
+ * usecase
5
+ * - the type `{}` unfortunately actually means "anything not null and not undefined" in typescript
6
+ * - this exposes a type that represents a literal Empty object
7
+ */
8
+ export type Empty = Record<string, never>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Empty.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Empty.js","sourceRoot":"","sources":["../../src/types/Empty.ts"],"names":[],"mappings":""}
@@ -1,33 +1,24 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  describe('PickAny', () => {
13
- it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
14
- const findFlowers = (input) => __awaiter(void 0, void 0, void 0, function* () {
4
+ it('should constrain type correctly', async () => {
5
+ const findFlowers = async (input) => {
15
6
  // ...
16
- });
7
+ };
17
8
  // you can find by color
18
- yield findFlowers({
9
+ await findFlowers({
19
10
  color: {
20
11
  petals: 'white',
21
12
  },
22
13
  });
23
14
  // you can find by size
24
- yield findFlowers({
15
+ await findFlowers({
25
16
  size: {
26
17
  choice: 'LARGE',
27
18
  },
28
19
  });
29
20
  // you can find by both
30
- yield findFlowers({
21
+ await findFlowers({
31
22
  color: {
32
23
  petals: 'white',
33
24
  },
@@ -36,10 +27,10 @@ describe('PickAny', () => {
36
27
  },
37
28
  });
38
29
  // you can't find by neither
39
- yield findFlowers({
30
+ await findFlowers({
40
31
  // @ts-expect-error - cant be neither
41
32
  size: {},
42
33
  });
43
- }));
34
+ });
44
35
  });
45
36
  //# sourceMappingURL=PickAny.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PickAny.test.js","sourceRoot":"","sources":["../../src/types/PickAny.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAC/C,MAAM,WAAW,GAAG,CAClB,KAOE,EACF,EAAE;YACF,MAAM;QACR,CAAC,CAAA,CAAC;QAEF,wBAAwB;QACxB,MAAM,WAAW,CAAC;YAChB,KAAK,EAAE;gBACL,MAAM,EAAE,OAAO;aAChB;SACF,CAAC,CAAC;QAEH,uBAAuB;QACvB,MAAM,WAAW,CAAC;YAChB,IAAI,EAAE;gBACJ,MAAM,EAAE,OAAO;aAChB;SACF,CAAC,CAAC;QAEH,uBAAuB;QACvB,MAAM,WAAW,CAAC;YAChB,KAAK,EAAE;gBACL,MAAM,EAAE,OAAO;aAChB;YACD,IAAI,EAAE;gBACJ,MAAM,EAAE,OAAO;aAChB;SACF,CAAC,CAAC;QAEH,4BAA4B;QAC5B,MAAM,WAAW,CAAC;YAChB,qCAAqC;YACrC,IAAI,EAAE,EAAE;SACT,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"PickAny.test.js","sourceRoot":"","sources":["../../src/types/PickAny.test.ts"],"names":[],"mappings":";;AAEA,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;QAC/C,MAAM,WAAW,GAAG,KAAK,EACvB,KAOE,EACF,EAAE;YACF,MAAM;QACR,CAAC,CAAC;QAEF,wBAAwB;QACxB,MAAM,WAAW,CAAC;YAChB,KAAK,EAAE;gBACL,MAAM,EAAE,OAAO;aAChB;SACF,CAAC,CAAC;QAEH,uBAAuB;QACvB,MAAM,WAAW,CAAC;YAChB,IAAI,EAAE;gBACJ,MAAM,EAAE,OAAO;aAChB;SACF,CAAC,CAAC;QAEH,uBAAuB;QACvB,MAAM,WAAW,CAAC;YAChB,KAAK,EAAE;gBACL,MAAM,EAAE,OAAO;aAChB;YACD,IAAI,EAAE;gBACJ,MAAM,EAAE,OAAO;aAChB;SACF,CAAC,CAAC;QAEH,4BAA4B;QAC5B,MAAM,WAAW,CAAC;YAChB,qCAAqC;YACrC,IAAI,EAAE,EAAE;SACT,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,33 +1,24 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  describe('PickOne', () => {
13
- it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
14
- const findWrench = (_a) => __awaiter(void 0, [_a], void 0, function* ({}) {
4
+ it('should constrain type correctly', async () => {
5
+ const findWrench = async ({}) => {
15
6
  // ...
16
- });
7
+ };
17
8
  // you can find by metric
18
- yield findWrench({
9
+ await findWrench({
19
10
  size: {
20
11
  metric: { millimeters: 16 },
21
12
  },
22
13
  });
23
14
  // you can find by imperial
24
- yield findWrench({
15
+ await findWrench({
25
16
  size: {
26
17
  imperial: { inches: '5/16' },
27
18
  },
28
19
  });
29
20
  // you can't find by both
30
- yield findWrench({
21
+ await findWrench({
31
22
  // @ts-expect-error - cant be both
32
23
  size: {
33
24
  metric: { millimeters: 16 },
@@ -35,10 +26,10 @@ describe('PickOne', () => {
35
26
  },
36
27
  });
37
28
  // you can't find by neither
38
- yield findWrench({
29
+ await findWrench({
39
30
  // @ts-expect-error - cant be neither
40
31
  size: {},
41
32
  });
42
- }));
33
+ });
43
34
  });
44
35
  //# sourceMappingURL=PickOne.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PickOne.test.js","sourceRoot":"","sources":["../../src/types/PickOne.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAC/C,MAAM,UAAU,GAAG,KAehB,EAAE,4CAfqB,EAezB;YACC,MAAM;QACR,CAAC,CAAA,CAAC;QAEF,yBAAyB;QACzB,MAAM,UAAU,CAAC;YACf,IAAI,EAAE;gBACJ,MAAM,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE;aAC5B;SACF,CAAC,CAAC;QAEH,2BAA2B;QAC3B,MAAM,UAAU,CAAC;YACf,IAAI,EAAE;gBACJ,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;aAC7B;SACF,CAAC,CAAC;QAEH,yBAAyB;QACzB,MAAM,UAAU,CAAC;YACf,kCAAkC;YAClC,IAAI,EAAE;gBACJ,MAAM,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE;gBAC3B,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;aAC7B;SACF,CAAC,CAAC;QAEH,4BAA4B;QAC5B,MAAM,UAAU,CAAC;YACf,qCAAqC;YACrC,IAAI,EAAE,EAAE;SACT,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"PickOne.test.js","sourceRoot":"","sources":["../../src/types/PickOne.test.ts"],"names":[],"mappings":";;AAEA,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;QAC/C,MAAM,UAAU,GAAG,KAAK,EAAE,EAezB,EAAE,EAAE;YACH,MAAM;QACR,CAAC,CAAC;QAEF,yBAAyB;QACzB,MAAM,UAAU,CAAC;YACf,IAAI,EAAE;gBACJ,MAAM,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE;aAC5B;SACF,CAAC,CAAC;QAEH,2BAA2B;QAC3B,MAAM,UAAU,CAAC;YACf,IAAI,EAAE;gBACJ,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;aAC7B;SACF,CAAC,CAAC;QAEH,yBAAyB;QACzB,MAAM,UAAU,CAAC;YACf,kCAAkC;YAClC,IAAI,EAAE;gBACJ,MAAM,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE;gBAC3B,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;aAC7B;SACF,CAAC,CAAC;QAEH,4BAA4B;QAC5B,MAAM,UAAU,CAAC;YACf,qCAAqC;YACrC,IAAI,EAAE,EAAE;SACT,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { HelpfulError } from '@ehmpathy/error-fns';
1
+ import { HelpfulError } from 'helpful-errors';
2
2
  export type AssessIsOfTypeMethod<I, C extends I> = (input: I) => input is C;
3
3
  export type AssureIsOfTypeMethod<I, C extends I> = (input: I) => C;
4
4
  export interface AssessWithAssure<I, C extends I> {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withAssure = exports.asAssure = exports.AssureIsOfTypeRejectionError = void 0;
4
- const error_fns_1 = require("@ehmpathy/error-fns");
5
- class AssureIsOfTypeRejectionError extends error_fns_1.HelpfulError {
4
+ const helpful_errors_1 = require("helpful-errors");
5
+ class AssureIsOfTypeRejectionError extends helpful_errors_1.HelpfulError {
6
6
  }
7
7
  exports.AssureIsOfTypeRejectionError = AssureIsOfTypeRejectionError;
8
8
  /**
@@ -17,8 +17,7 @@ exports.AssureIsOfTypeRejectionError = AssureIsOfTypeRejectionError;
17
17
  * - simplicity++ -> readability++ -> speed++ && maintainability++
18
18
  */
19
19
  const asAssure = (assess, options) => {
20
- var _a;
21
- const name = (_a = options === null || options === void 0 ? void 0 : options.name) !== null && _a !== void 0 ? _a : assess.name; // todo: get resource name more reliably
20
+ const name = options?.name ?? assess.name; // todo: get resource name more reliably
22
21
  const assure = (input) => assess(input)
23
22
  ? input
24
23
  : (() => {
@@ -1 +1 @@
1
- {"version":3,"file":"withAssure.js","sourceRoot":"","sources":["../../src/wrappers/withAssure.ts"],"names":[],"mappings":";;;AAAA,mDAAmD;AAUnD,MAAa,4BAA6B,SAAQ,wBAAY;CAAG;AAAjE,oEAAiE;AAEjE;;;;;;;;;;GAUG;AACI,MAAM,QAAQ,GAAG,CACtB,MAAkC,EAClC,OAA0B,EACE,EAAE;;IAC9B,MAAM,IAAI,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,mCAAI,MAAM,CAAC,IAAI,CAAC,CAAC,wCAAwC;IACnF,MAAM,MAAM,GAAG,CAAC,KAAQ,EAAE,EAAE,CAC1B,MAAM,CAAC,KAAK,CAAC;QACX,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,CAAC,GAAG,EAAE;YACJ,MAAM,IAAI,4BAA4B,CACpC,wDAAwD,IAAI,GAA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K,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK;aACjD,CACF,CAAC;QACJ,CAAC,CAAC,EAAE,CAAC;IACX,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAlBW,QAAA,QAAQ,YAkBnB;AAEF;;;;;;;;;;;;;;GAcG;AACI,MAAM,UAAU,GAAG,CACxB,MAAkC,EAClC,OAA0B,EACF,EAAE;IAC1B,MAAM,MAAM,GAAG,IAAA,gBAAQ,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,UACb,GAAG,KAAgC;QAEnC,OAAO,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC;IAC1B,CAGC,CAAC;IACF,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAhBW,QAAA,UAAU,cAgBrB"}
package/license.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 ehmpathy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "type-fns",
3
3
  "author": "ehmpathy",
4
4
  "description": "A set of types, type checks, and type guards for simpler, safer, and easier to read code.",
5
- "version": "1.18.0",
5
+ "version": "1.20.1",
6
6
  "repository": "ehmpathy/type-fns",
7
7
  "homepage": "https://github.com/ehmpathy/type-fns",
8
8
  "keywords": [
@@ -49,12 +49,11 @@
49
49
  "prepublish": "npm run build",
50
50
  "preversion": "npm run prepush",
51
51
  "postversion": "git push origin HEAD --tags --no-verify",
52
- "postinstall": "[ -d .git ] && npx husky install || exit 0"
52
+ "postinstall": "[ -d .git ] && npm run prepare:husky || exit 0",
53
+ "prepare:husky": "npx husky install && chmod ug+x .husky/*"
53
54
  },
54
55
  "dependencies": {
55
- "@ehmpathy/error-fns": "1.0.2",
56
- "type-fns": "1.16.0",
57
- "uuid": "9.0.0"
56
+ "helpful-errors": "^1.3.8"
58
57
  },
59
58
  "devDependencies": {
60
59
  "@commitlint/cli": "19.3.0",
@@ -62,13 +61,12 @@
62
61
  "@trivago/prettier-plugin-sort-imports": "4.3.0",
63
62
  "@tsconfig/node-lts-strictest": "18.12.1",
64
63
  "@types/jest": "29.2.4",
65
- "@types/uuid": "9.0.0",
66
64
  "@typescript-eslint/eslint-plugin": "7.8.0",
67
65
  "@typescript-eslint/parser": "7.8.0",
68
66
  "core-js": "3.26.1",
69
- "cz-conventional-changelog": "3.3.0",
70
- "declapract": "0.11.5",
71
- "declapract-typescript-ehmpathy": "0.33.6",
67
+ "cz-conventional-changelog": "3.0.1",
68
+ "declapract": "0.12.3",
69
+ "declapract-typescript-ehmpathy": "0.39.9",
72
70
  "depcheck": "1.4.3",
73
71
  "eslint": "8.56.0",
74
72
  "eslint-config-airbnb-typescript": "18.0.0",
@@ -78,11 +76,10 @@
78
76
  "husky": "8.0.3",
79
77
  "jest": "29.3.1",
80
78
  "prettier": "2.8.1",
81
- "test-fns": "1.3.0",
79
+ "test-fns": "1.6.0",
82
80
  "ts-jest": "29.1.3",
83
81
  "ts-node": "10.9.2",
84
- "typescript": "5.4.5",
85
- "uuid": "^3.3.3"
82
+ "typescript": "5.4.5"
86
83
  },
87
84
  "config": {
88
85
  "commitizen": {
package/dist/deps.d.ts DELETED
@@ -1 +0,0 @@
1
- export { v4 as uuid } from 'uuid';
package/dist/deps.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uuid = void 0;
4
- var uuid_1 = require("uuid");
5
- Object.defineProperty(exports, "uuid", { enumerable: true, get: function () { return uuid_1.v4; } });
6
- //# sourceMappingURL=deps.js.map
package/dist/deps.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"deps.js","sourceRoot":"","sources":["../src/deps.ts"],"names":[],"mappings":";;;AAAA,6BAAkC;AAAzB,4FAAA,EAAE,OAAQ"}
@@ -1,8 +0,0 @@
1
- export declare enum Stage {
2
- PRODUCTION = "prod",
3
- DEVELOPMENT = "dev",
4
- TEST = "test"
5
- }
6
- export declare const isOfStage: import("type-fns").AssessWithAssure<string | number | symbol, Stage>;
7
- export declare const stage: Stage;
8
- export declare const serviceClientStage: Stage;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serviceClientStage = exports.stage = exports.isOfStage = exports.Stage = void 0;
4
- const error_fns_1 = require("@ehmpathy/error-fns");
5
- const type_fns_1 = require("type-fns");
6
- var Stage;
7
- (function (Stage) {
8
- Stage["PRODUCTION"] = "prod";
9
- Stage["DEVELOPMENT"] = "dev";
10
- Stage["TEST"] = "test";
11
- })(Stage || (exports.Stage = Stage = {}));
12
- exports.isOfStage = (0, type_fns_1.createIsOfEnum)(Stage);
13
- /**
14
- * verify that the server is on UTC timezone
15
- *
16
- * why?
17
- * - non UTC timezone usage causes problems and takes a while to track down
18
- * - by failing fast if the server our code runs in is not in UTC, we avoid these issues
19
- * =>
20
- * - create a pit of success
21
- */
22
- const TIMEZONE = process.env.TZ;
23
- if (TIMEZONE !== 'UTC')
24
- throw new error_fns_1.UnexpectedCodePathError('env.TZ is not set to UTC. this can cause issues. please set the env var', { found: TIMEZONE, desire: 'UTC' });
25
- /**
26
- * this allows us to infer what the stage should be in environments that do not have STAGE specified
27
- * - e.g., when running locally
28
- * - e.g., when running tests
29
- */
30
- const inferStageFromNodeEnv = () => {
31
- const nodeEnv = process.env.NODE_ENV; // default to test if not defined
32
- if (!nodeEnv)
33
- throw new Error('process.env.NODE_ENV must be defined');
34
- if (nodeEnv === 'production')
35
- return Stage.PRODUCTION;
36
- if (nodeEnv === 'development')
37
- return Stage.DEVELOPMENT;
38
- if (nodeEnv === 'test')
39
- return Stage.TEST;
40
- throw new Error(`unexpected nodeEnv '${nodeEnv}'`);
41
- };
42
- /**
43
- * a method that exposes relevant environmental variables in a standard way
44
- */
45
- const getEnvironment = () => {
46
- var _a;
47
- const stage = (_a = process.env.STAGE) !== null && _a !== void 0 ? _a : inferStageFromNodeEnv(); // figure it out from NODE_ENV if not explicitly defined
48
- if (!stage)
49
- throw new Error('process.env.STAGE must be defined');
50
- if (!(0, exports.isOfStage)(stage))
51
- throw new Error(`invalid stage defined '${stage}'`);
52
- return { stage };
53
- };
54
- // export stage immediately, since it does not change
55
- exports.stage = getEnvironment().stage;
56
- // export service client stage
57
- exports.serviceClientStage = exports.stage === Stage.PRODUCTION ? Stage.PRODUCTION : Stage.DEVELOPMENT; // i.e., if its prod, hit prod. otherwise, dev
58
- //# sourceMappingURL=environment.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":";;;AAAA,mDAA8D;AAC9D,uCAA0C;AAE1C,IAAY,KAIX;AAJD,WAAY,KAAK;IACf,4BAAmB,CAAA;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