type-fns 0.7.0 → 0.9.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/dist/checks/hasId.d.ts +1 -1
- package/dist/checks/hasId.js +2 -1
- package/dist/checks/hasId.js.map +1 -1
- package/dist/checks/hasId.test.d.ts +1 -0
- package/dist/checks/hasId.test.js +16 -0
- package/dist/checks/hasId.test.js.map +1 -0
- package/dist/checks/hasMetadata.d.ts +2 -2
- package/dist/checks/hasMetadata.js +9 -2
- package/dist/checks/hasMetadata.js.map +1 -1
- package/dist/checks/hasMetadata.test.d.ts +1 -0
- package/dist/checks/hasMetadata.test.js +18 -0
- package/dist/checks/hasMetadata.test.js.map +1 -0
- package/dist/checks/hasUuid.d.ts +1 -1
- package/dist/checks/hasUuid.js +2 -1
- package/dist/checks/hasUuid.js.map +1 -1
- package/dist/checks/hasUuid.test.d.ts +1 -0
- package/dist/checks/hasUuid.test.js +16 -0
- package/dist/checks/hasUuid.test.js.map +1 -0
- package/dist/checks/isAFunction.js +3 -1
- package/dist/checks/isAFunction.js.map +1 -1
- package/dist/checks/isAPromise.d.ts +1 -1
- package/dist/checks/isAPromise.js +2 -1
- package/dist/checks/isAPromise.js.map +1 -1
- package/dist/checks/isAPromise.test.d.ts +1 -0
- package/dist/checks/isAPromise.test.js +25 -0
- package/dist/checks/isAPromise.test.js.map +1 -0
- package/dist/checks/isNotNull.d.ts +1 -1
- package/dist/checks/isNotNull.js +2 -1
- package/dist/checks/isNotNull.js.map +1 -1
- package/dist/checks/isNotNull.test.d.ts +1 -0
- package/dist/checks/isNotNull.test.js +28 -0
- package/dist/checks/isNotNull.test.js.map +1 -0
- package/dist/checks/isNotUndefined.d.ts +1 -1
- package/dist/checks/isNotUndefined.js +2 -1
- package/dist/checks/isNotUndefined.js.map +1 -1
- package/dist/checks/isNotUndefined.test.d.ts +1 -0
- package/dist/checks/isNotUndefined.test.js +28 -0
- package/dist/checks/isNotUndefined.test.js.map +1 -0
- package/dist/checks/isOfEnum.d.ts +5 -6
- package/dist/checks/isOfEnum.js +2 -1
- package/dist/checks/isOfEnum.js.map +1 -1
- package/dist/checks/isOfEnum.test.d.ts +1 -0
- package/dist/checks/isOfEnum.test.js +19 -0
- package/dist/checks/isOfEnum.test.js.map +1 -0
- package/dist/checks/isPresent.js +2 -1
- package/dist/checks/isPresent.js.map +1 -1
- package/dist/checks/isPresent.test.d.ts +1 -0
- package/dist/checks/isPresent.test.js +25 -0
- package/dist/checks/isPresent.test.js.map +1 -0
- package/dist/companions/omit.d.ts +4 -0
- package/dist/companions/omit.js +15 -0
- package/dist/companions/omit.js.map +1 -0
- package/dist/companions/pick.d.ts +4 -0
- package/dist/companions/pick.js +15 -0
- package/dist/companions/pick.js.map +1 -0
- package/dist/deps.d.ts +1 -0
- package/dist/deps.js +6 -0
- package/dist/deps.js.map +1 -0
- package/dist/domain/constants.d.ts +3 -0
- package/dist/domain/constants.js +5 -0
- package/dist/domain/constants.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/types/DropFirst.d.ts +10 -0
- package/dist/types/DropFirst.js +3 -0
- package/dist/types/DropFirst.js.map +1 -0
- package/dist/types/DropFirst.test.d.ts +1 -0
- package/dist/types/DropFirst.test.js +12 -0
- package/dist/types/DropFirst.test.js.map +1 -0
- package/dist/types/PickOne.d.ts +1 -1
- package/dist/types/PickOne.test.d.ts +1 -0
- package/dist/types/PickOne.test.js +38 -0
- package/dist/types/PickOne.test.js.map +1 -0
- package/dist/utils/environment.d.ts +7 -0
- package/dist/utils/environment.js +41 -0
- package/dist/utils/environment.js.map +1 -0
- package/dist/utils/errors/UnexpectedCodePathError.d.ts +9 -0
- package/dist/utils/errors/UnexpectedCodePathError.js +17 -0
- package/dist/utils/errors/UnexpectedCodePathError.js.map +1 -0
- package/dist/wrappers/withNot.js +2 -1
- package/dist/wrappers/withNot.js.map +1 -1
- package/dist/wrappers/withNot.test.d.ts +1 -0
- package/dist/wrappers/withNot.test.js +17 -0
- package/dist/wrappers/withNot.test.js.map +1 -0
- package/package.json +54 -34
- package/{README.md → readme.md} +14 -0
- package/changelog.md +0 -65
package/dist/checks/hasId.d.ts
CHANGED
package/dist/checks/hasId.js
CHANGED
package/dist/checks/hasId.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hasId.js","sourceRoot":"","sources":["../../src/checks/hasId.ts"],"names":[],"mappings":";;;AAKA;;GAEG;
|
|
1
|
+
{"version":3,"file":"hasId.js","sourceRoot":"","sources":["../../src/checks/hasId.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACI,MAAM,KAAK,GAAG,CACnB,GAAM,EACW,EAAE;IACnB,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;AAClB,CAAC,CAAC;AAJW,QAAA,KAAK,SAIhB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const hasId_1 = require("./hasId");
|
|
4
|
+
describe('hasId', () => {
|
|
5
|
+
it('should return true if an object has an id', () => {
|
|
6
|
+
const obj = { id: 821, name: 'bob' };
|
|
7
|
+
const itHasId = (0, hasId_1.hasId)(obj);
|
|
8
|
+
expect(itHasId).toEqual(true);
|
|
9
|
+
});
|
|
10
|
+
it('should return false if an object does not have an id', () => {
|
|
11
|
+
const obj = { name: 'bob' };
|
|
12
|
+
const itHasId = (0, hasId_1.hasId)(obj);
|
|
13
|
+
expect(itHasId).toEqual(false);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=hasId.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasId.test.js","sourceRoot":"","sources":["../../src/checks/hasId.test.ts"],"names":[],"mappings":";;AAAA,mCAAgC;AAEhC,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,GAAG,GAAkC,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QACpE,MAAM,OAAO,GAAG,IAAA,aAAK,EAAC,GAAG,CAAC,CAAC;QAC3B,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,GAAG,GAAkC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAC3D,MAAM,OAAO,GAAG,IAAA,aAAK,EAAC,GAAG,CAAC,CAAC;QAC3B,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -5,7 +5,7 @@ declare const typicalMetadataKeys: readonly ["id", "uuid", "createdAt", "updated
|
|
|
5
5
|
/**
|
|
6
6
|
* these are the keys most commonly used metadata keys
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
type TypicalMetadataKeys = typeof typicalMetadataKeys[number];
|
|
9
9
|
/**
|
|
10
10
|
* asserts that any optional metadata keys of the object will now be required
|
|
11
11
|
*
|
|
@@ -22,7 +22,7 @@ declare type TypicalMetadataKeys = typeof typicalMetadataKeys[number];
|
|
|
22
22
|
* - this type does not _add_ any metadata properties to the type definition
|
|
23
23
|
* - i.e., if a metadata key was not already present on the object's type - it will not be added
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export type HasMetadata<T extends Record<string, any>, MetadataKeys = TypicalMetadataKeys> = T & Required<Pick<T, keyof T & // that are on the object
|
|
26
26
|
MetadataKeys>>;
|
|
27
27
|
/**
|
|
28
28
|
* for an object of type T, asserts that the object HasMetadata<T, K> for all listed metadata keys K
|
|
@@ -4,7 +4,13 @@ exports.hasMetadata = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* these are the keys most commonly used metadata keys
|
|
6
6
|
*/
|
|
7
|
-
const typicalMetadataKeys = [
|
|
7
|
+
const typicalMetadataKeys = [
|
|
8
|
+
'id',
|
|
9
|
+
'uuid',
|
|
10
|
+
'createdAt',
|
|
11
|
+
'updatedAt',
|
|
12
|
+
'effectiveAt',
|
|
13
|
+
];
|
|
8
14
|
/**
|
|
9
15
|
* for an object of type T, asserts that the object HasMetadata<T, K> for all listed metadata keys K
|
|
10
16
|
*
|
|
@@ -17,5 +23,6 @@ const typicalMetadataKeys = ['id', 'uuid', 'createdAt', 'updatedAt', 'effectiveA
|
|
|
17
23
|
*
|
|
18
24
|
* see more information about the `HasMetadata` type in its jsdoc on-hover documentation
|
|
19
25
|
*/
|
|
20
|
-
|
|
26
|
+
const hasMetadata = (obj, keys = typicalMetadataKeys) => keys.every((key) => obj[key] !== undefined);
|
|
27
|
+
exports.hasMetadata = hasMetadata;
|
|
21
28
|
//# sourceMappingURL=hasMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hasMetadata.js","sourceRoot":"","sources":["../../src/checks/hasMetadata.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAM,mBAAmB,GAAG,
|
|
1
|
+
{"version":3,"file":"hasMetadata.js","sourceRoot":"","sources":["../../src/checks/hasMetadata.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAM,mBAAmB,GAAG;IAC1B,IAAI;IACJ,MAAM;IACN,WAAW;IACX,WAAW;IACX,aAAa;CACL,CAAC;AAmCX;;;;;;;;;;;GAWG;AACI,MAAM,WAAW,GAAG,CAIzB,GAAM,EACN,OAAuB,mBAA4C,EACvB,EAAE,CAC9C,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC;AAPjC,QAAA,WAAW,eAOsB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const __1 = require("..");
|
|
4
|
+
describe('HasMetadata', () => {
|
|
5
|
+
it('should enable accessing an optional metadata property of a type', () => {
|
|
6
|
+
const pot = { id: 123, age: 72 };
|
|
7
|
+
expect(pot.id.toFixed).toBeDefined(); // no type errors
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
describe('hasMetadata', () => {
|
|
11
|
+
it('should enable accessing an optional metadata property of a type', () => {
|
|
12
|
+
const pot = { id: 123, age: 72 };
|
|
13
|
+
if (!(0, __1.hasMetadata)(pot, ['id']))
|
|
14
|
+
throw new Error('doesnt have metadata');
|
|
15
|
+
expect(pot.id.toFixed).toBeDefined();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=hasMetadata.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasMetadata.test.js","sourceRoot":"","sources":["../../src/checks/hasMetadata.test.ts"],"names":[],"mappings":";;AAAA,0BAAiC;AAGjC,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;QAEzE,MAAM,GAAG,GAA2B,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;QACzD,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,iBAAiB;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;QAEzE,MAAM,GAAG,GAAc,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;QAC5C,IAAI,CAAC,IAAA,eAAW,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QACvE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/checks/hasUuid.d.ts
CHANGED
package/dist/checks/hasUuid.js
CHANGED
|
@@ -4,7 +4,8 @@ exports.hasUuid = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* checks whether not an object that may have a uuid does have the uuid, at runtime
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
const hasUuid = (obj) => {
|
|
8
8
|
return typeof obj.uuid === 'string';
|
|
9
9
|
};
|
|
10
|
+
exports.hasUuid = hasUuid;
|
|
10
11
|
//# sourceMappingURL=hasUuid.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hasUuid.js","sourceRoot":"","sources":["../../src/checks/hasUuid.ts"],"names":[],"mappings":";;;AAKA;;GAEG;
|
|
1
|
+
{"version":3,"file":"hasUuid.js","sourceRoot":"","sources":["../../src/checks/hasUuid.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACI,MAAM,OAAO,GAAG,CACrB,GAAM,EACa,EAAE;IACrB,OAAO,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC;AACtC,CAAC,CAAC;AAJW,QAAA,OAAO,WAIlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const hasUuid_1 = require("./hasUuid");
|
|
4
|
+
describe('hasUuid', () => {
|
|
5
|
+
it('should return true if an object has an id', () => {
|
|
6
|
+
const obj = { uuid: 'uuid', name: 'bob' };
|
|
7
|
+
const itHasUuid = (0, hasUuid_1.hasUuid)(obj);
|
|
8
|
+
expect(itHasUuid).toEqual(true);
|
|
9
|
+
});
|
|
10
|
+
it('should return false if an object does not have an id', () => {
|
|
11
|
+
const obj = { name: 'bob' };
|
|
12
|
+
const itHasUuid = (0, hasUuid_1.hasUuid)(obj);
|
|
13
|
+
expect(itHasUuid).toEqual(false);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=hasUuid.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasUuid.test.js","sourceRoot":"","sources":["../../src/checks/hasUuid.test.ts"],"names":[],"mappings":";;AAAA,uCAAoC;AAEpC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,GAAG,GAAoC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAC3E,MAAM,SAAS,GAAG,IAAA,iBAAO,EAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,GAAG,GAAoC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAC7D,MAAM,SAAS,GAAG,IAAA,iBAAO,EAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isAFunction = void 0;
|
|
4
|
-
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
5
|
+
const isAFunction = (obj) => typeof obj === 'function';
|
|
6
|
+
exports.isAFunction = isAFunction;
|
|
5
7
|
//# sourceMappingURL=isAFunction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isAFunction.js","sourceRoot":"","sources":["../../src/checks/isAFunction.ts"],"names":[],"mappings":";;;
|
|
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"}
|
|
@@ -4,5 +4,6 @@ exports.isAPromise = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* checks whether the value is a promise
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
const isAPromise = (obj) => Promise.resolve(obj) === obj;
|
|
8
|
+
exports.isAPromise = isAPromise;
|
|
8
9
|
//# sourceMappingURL=isAPromise.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isAPromise.js","sourceRoot":"","sources":["../../src/checks/isAPromise.ts"],"names":[],"mappings":";;;AAAA;;GAEG;
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const isAPromise_1 = require("./isAPromise");
|
|
4
|
+
describe('isAPromise', () => {
|
|
5
|
+
it('should return true for promises', () => {
|
|
6
|
+
const descision = (0, isAPromise_1.isAPromise)(Promise.resolve('hello'));
|
|
7
|
+
expect(descision).toEqual(true);
|
|
8
|
+
});
|
|
9
|
+
it('should return false for not promises', () => {
|
|
10
|
+
const descision = (0, isAPromise_1.isAPromise)('hello');
|
|
11
|
+
expect(descision).toEqual(false);
|
|
12
|
+
});
|
|
13
|
+
it('should be usable to narrow the typescript type', () => {
|
|
14
|
+
// imagine we didn't know whether soonerOrLater is a promise or a string
|
|
15
|
+
const soonerOrLater = Promise.resolve('hello');
|
|
16
|
+
// we can use this check to narrow down the typescript type and do operations specific to each type
|
|
17
|
+
if ((0, isAPromise_1.isAPromise)(soonerOrLater)) {
|
|
18
|
+
void soonerOrLater.then(() => 'done');
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
void soonerOrLater.toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=isAPromise.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAPromise.test.js","sourceRoot":"","sources":["../../src/checks/isAPromise.test.ts"],"names":[],"mappings":";;AAAA,6CAA0C;AAE1C,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,SAAS,GAAG,IAAA,uBAAU,EAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QACvD,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,SAAS,GAAG,IAAA,uBAAU,EAAC,OAAO,CAAC,CAAC;QACtC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,wEAAwE;QACxE,MAAM,aAAa,GAA6B,OAAO,CAAC,OAAO,CAC7D,OAAO,CACD,CAAC;QAET,mGAAmG;QACnG,IAAI,IAAA,uBAAU,EAAC,aAAa,CAAC,EAAE;YAC7B,KAAK,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;SACvC;aAAM;YACL,KAAK,aAAa,CAAC,WAAW,EAAE,CAAC;SAClC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/checks/isNotNull.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isNotNull.js","sourceRoot":"","sources":["../../src/checks/isNotNull.ts"],"names":[],"mappings":";;;AAQA;;GAEG;
|
|
1
|
+
{"version":3,"file":"isNotNull.js","sourceRoot":"","sources":["../../src/checks/isNotNull.ts"],"names":[],"mappings":";;;AAQA;;GAEG;AACI,MAAM,SAAS,GAAG,CAAI,GAAM,EAAqB,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC;AAA3D,QAAA,SAAS,aAAkD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
13
|
+
const __1 = require("..");
|
|
14
|
+
describe('isNotNull', () => {
|
|
15
|
+
it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const maybeNumber = undefined; // valid
|
|
17
|
+
if ((0, __1.isNotNull)(maybeNumber)) {
|
|
18
|
+
const defNumber = maybeNumber; // valid
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
});
|
|
22
|
+
describe('NotNull', () => {
|
|
23
|
+
it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const notMaybeNumber = 821;
|
|
25
|
+
const onlyNumber = notMaybeNumber; // valid
|
|
26
|
+
}));
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=isNotNull.test.js.map
|
|
@@ -0,0 +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;YAC1B,MAAM,SAAS,GAAW,WAAW,CAAC,CAAC,QAAQ;SAChD;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"}
|
|
@@ -4,5 +4,6 @@ exports.isNotUndefined = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* checks whether the value is not undefined
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
const isNotUndefined = (val) => typeof val !== 'undefined';
|
|
8
|
+
exports.isNotUndefined = isNotUndefined;
|
|
8
9
|
//# sourceMappingURL=isNotUndefined.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isNotUndefined.js","sourceRoot":"","sources":["../../src/checks/isNotUndefined.ts"],"names":[],"mappings":";;;AAQA;;GAEG;
|
|
1
|
+
{"version":3,"file":"isNotUndefined.js","sourceRoot":"","sources":["../../src/checks/isNotUndefined.ts"],"names":[],"mappings":";;;AAQA;;GAEG;AACI,MAAM,cAAc,GAAG,CAAI,GAAM,EAA0B,EAAE,CAClE,OAAO,GAAG,KAAK,WAAW,CAAC;AADhB,QAAA,cAAc,kBACE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
13
|
+
const __1 = require("..");
|
|
14
|
+
describe('isNotUndefined', () => {
|
|
15
|
+
it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const maybeNumber = undefined; // valid
|
|
17
|
+
if ((0, __1.isNotUndefined)(maybeNumber)) {
|
|
18
|
+
const defNumber = maybeNumber; // valid
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
});
|
|
22
|
+
describe('NotUndefined', () => {
|
|
23
|
+
it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const notMaybeNumber = 821;
|
|
25
|
+
const onlyNumber = notMaybeNumber; // valid
|
|
26
|
+
}));
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=isNotUndefined.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isNotUndefined.test.js","sourceRoot":"","sources":["../../src/checks/isNotUndefined.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sDAAsD;AACtD,0BAAkD;AAElD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAG/C,MAAM,WAAW,GAAgB,SAAgB,CAAC,CAAC,QAAQ;QAE3D,IAAI,IAAA,kBAAc,EAAC,WAAW,CAAC,EAAE;YAC/B,MAAM,SAAS,GAAW,WAAW,CAAC,CAAC,QAAQ;SAChD;IACH,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,iCAAiC,EAAE,GAAS,EAAE;QAG/C,MAAM,cAAc,GAA8B,GAAU,CAAC;QAC7D,MAAM,UAAU,GAAW,cAAc,CAAC,CAAC,QAAQ;IACrD,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `Something` = `any`, with the exclusion of `null` and `undefined`
|
|
3
|
-
*/
|
|
4
|
-
declare type Something = {};
|
|
5
1
|
/**
|
|
6
2
|
* a generic fn that allows us to create type checks for enums. for example:
|
|
7
3
|
* ```ts
|
|
@@ -23,5 +19,8 @@ declare type Something = {};
|
|
|
23
19
|
*
|
|
24
20
|
* ref: https://stackoverflow.com/a/58278753/3068233
|
|
25
21
|
*/
|
|
26
|
-
export declare const createIsOfEnum: <T
|
|
27
|
-
|
|
22
|
+
export declare const createIsOfEnum: <T extends {
|
|
23
|
+
[index: string]: string | number;
|
|
24
|
+
[index: number]: string | number;
|
|
25
|
+
[index: symbol]: string | number;
|
|
26
|
+
}>(e: T) => (token: string | number | symbol) => token is T[keyof T];
|
package/dist/checks/isOfEnum.js
CHANGED
|
@@ -22,5 +22,6 @@ exports.createIsOfEnum = void 0;
|
|
|
22
22
|
*
|
|
23
23
|
* ref: https://stackoverflow.com/a/58278753/3068233
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
const createIsOfEnum = (e) => (token) => Object.values(e).includes(token);
|
|
26
|
+
exports.createIsOfEnum = createIsOfEnum;
|
|
26
27
|
//# sourceMappingURL=isOfEnum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isOfEnum.js","sourceRoot":"","sources":["../../src/checks/isOfEnum.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"isOfEnum.js","sourceRoot":"","sources":["../../src/checks/isOfEnum.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,MAAM,cAAc,GACzB,CAAmE,CAAI,EAAE,EAAE,CAC3E,CAAC,KAA+B,EAAuB,EAAE,CACvD,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAmB,CAAC,CAAC;AAHtC,QAAA,cAAc,kBAGwB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const isOfEnum_1 = require("./isOfEnum");
|
|
4
|
+
describe('isOfEnum', () => {
|
|
5
|
+
it('can be used for custom enums correctly', () => {
|
|
6
|
+
let Planet;
|
|
7
|
+
(function (Planet) {
|
|
8
|
+
Planet["VENUS"] = "VENUS";
|
|
9
|
+
Planet["EARTH"] = "EARTH";
|
|
10
|
+
Planet["MARS"] = "MARS";
|
|
11
|
+
})(Planet || (Planet = {}));
|
|
12
|
+
const isPlanet = (0, isOfEnum_1.createIsOfEnum)(Planet);
|
|
13
|
+
const earthIsPlanet = isPlanet('EARTH');
|
|
14
|
+
const plutoIsPlanet = isPlanet('PLUTO');
|
|
15
|
+
expect(earthIsPlanet).toEqual(true);
|
|
16
|
+
expect(plutoIsPlanet).toEqual(false);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=isOfEnum.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isOfEnum.test.js","sourceRoot":"","sources":["../../src/checks/isOfEnum.test.ts"],"names":[],"mappings":";;AAAA,yCAA4C;AAE5C,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,IAAK,MAIJ;QAJD,WAAK,MAAM;YACT,yBAAe,CAAA;YACf,yBAAe,CAAA;YACf,uBAAa,CAAA;QACf,CAAC,EAJI,MAAM,KAAN,MAAM,QAIV;QACD,MAAM,QAAQ,GAAG,IAAA,yBAAc,EAAC,MAAM,CAAC,CAAC;QACxC,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;QACxC,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;QACxC,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/checks/isPresent.js
CHANGED
|
@@ -6,5 +6,6 @@ exports.isPresent = void 0;
|
|
|
6
6
|
*
|
|
7
7
|
* https://github.com/microsoft/TypeScript/issues/16069#issuecomment-566222173
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
const isPresent = (t) => t !== undefined && t !== null;
|
|
10
|
+
exports.isPresent = isPresent;
|
|
10
11
|
//# sourceMappingURL=isPresent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPresent.js","sourceRoot":"","sources":["../../src/checks/isPresent.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"isPresent.js","sourceRoot":"","sources":["../../src/checks/isPresent.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,SAAS,GAAG,CAAI,CAA8B,EAAU,EAAE,CACrE,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC;AADnB,QAAA,SAAS,aACU"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const isPresent_1 = require("./isPresent");
|
|
4
|
+
describe('isPresent', () => {
|
|
5
|
+
it('should return false if is null', () => {
|
|
6
|
+
expect((0, isPresent_1.isPresent)(null)).toEqual(false);
|
|
7
|
+
});
|
|
8
|
+
it('should return false if is undefined', () => {
|
|
9
|
+
expect((0, isPresent_1.isPresent)(null)).toEqual(false);
|
|
10
|
+
});
|
|
11
|
+
it('should return true if is falsy', () => {
|
|
12
|
+
expect((0, isPresent_1.isPresent)(false)).toEqual(true);
|
|
13
|
+
expect((0, isPresent_1.isPresent)(0)).toEqual(true);
|
|
14
|
+
expect((0, isPresent_1.isPresent)('')).toEqual(true);
|
|
15
|
+
});
|
|
16
|
+
it('should be useful in having correct types after filtering', () => {
|
|
17
|
+
const stringsOrNulls = ['hello', '', null, 'world', undefined]; // type = `(string | null | undefined)[]`
|
|
18
|
+
const strings = stringsOrNulls.filter(isPresent_1.isPresent); // type = string[]
|
|
19
|
+
// check that it did what we expected in runtime
|
|
20
|
+
expect(strings).toEqual(['hello', '', 'world']);
|
|
21
|
+
// check that it successfully informed typescript of this too
|
|
22
|
+
strings.map((string) => string.toUpperCase()); // This should not throw a type error, because the filter should have told typescript it took out the nulls
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=isPresent.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isPresent.test.js","sourceRoot":"","sources":["../../src/checks/isPresent.test.ts"],"names":[],"mappings":";;AAAA,2CAAwC;AAExC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACxC,MAAM,CAAC,IAAA,qBAAS,EAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,CAAC,IAAA,qBAAS,EAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACxC,MAAM,CAAC,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,CAAC,IAAA,qBAAS,EAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,CAAC,IAAA,qBAAS,EAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;QAClE,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,yCAAyC;QACzG,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,qBAAS,CAAC,CAAC,CAAC,kBAAkB;QAEpE,gDAAgD;QAChD,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;QAEhD,6DAA6D;QAC7D,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,2GAA2G;IAC5J,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.omit = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* a companion to the `Omit` type, returns a new object without the omitted attributes
|
|
6
|
+
*/
|
|
7
|
+
const omit = (obj, keys) => Object.entries(obj).reduce((summary, [key, value]) => {
|
|
8
|
+
// if key is in the specified keys, dont add it to the new object
|
|
9
|
+
if (keys.includes(key))
|
|
10
|
+
return summary;
|
|
11
|
+
// if it is not within specified keys, add it
|
|
12
|
+
return Object.assign(Object.assign({}, summary), { [key]: value });
|
|
13
|
+
}, {});
|
|
14
|
+
exports.omit = omit;
|
|
15
|
+
//# sourceMappingURL=omit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omit.js","sourceRoot":"","sources":["../../src/companions/omit.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,IAAI,GAAG,CAClB,GAAM,EACN,IAAiB,EACa,EAAE,CAChC,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;AAV1B,QAAA,IAAI,QAUsB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pick = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* a companion to the `Pick` type, returns a new object with only the picked attributes
|
|
6
|
+
*/
|
|
7
|
+
const pick = (obj, keys) => Object.entries(obj).reduce((summary, [key, value]) => {
|
|
8
|
+
// if key is not in the specified keys, dont add it to the new object
|
|
9
|
+
if (!keys.includes(key))
|
|
10
|
+
return summary;
|
|
11
|
+
// if it is within specified keys, add it
|
|
12
|
+
return Object.assign(Object.assign({}, summary), { [key]: value });
|
|
13
|
+
}, {});
|
|
14
|
+
exports.pick = pick;
|
|
15
|
+
//# sourceMappingURL=pick.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pick.js","sourceRoot":"","sources":["../../src/companions/pick.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,IAAI,GAAG,CAClB,GAAM,EACN,IAAiB,EACa,EAAE,CAChC,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;AAV1B,QAAA,IAAI,QAUsB"}
|
package/dist/deps.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { v4 as uuid } from 'uuid';
|
package/dist/deps.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deps.js","sourceRoot":"","sources":["../src/deps.ts"],"names":[],"mappings":";;;AAAA,6BAAkC;AAAzB,4FAAA,EAAE,OAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/domain/constants.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
8
12
|
}));
|
|
9
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
17
|
__exportStar(require("./checks/hasId"), exports);
|
|
@@ -21,4 +25,7 @@ __exportStar(require("./checks/isAPromise"), exports);
|
|
|
21
25
|
__exportStar(require("./types/PickOne"), exports);
|
|
22
26
|
__exportStar(require("./checks/isNotNull"), exports);
|
|
23
27
|
__exportStar(require("./checks/isNotUndefined"), exports);
|
|
28
|
+
__exportStar(require("./types/DropFirst"), exports);
|
|
29
|
+
__exportStar(require("./companions/omit"), exports);
|
|
30
|
+
__exportStar(require("./companions/pick"), exports);
|
|
24
31
|
//# 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":"
|
|
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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* drop the first type in an array
|
|
3
|
+
*
|
|
4
|
+
* example use cases
|
|
5
|
+
* - reference all parameters except first in typescript
|
|
6
|
+
*
|
|
7
|
+
* ref
|
|
8
|
+
* - https://stackoverflow.com/questions/63024617/how-to-reference-all-parameters-except-first-in-typescript
|
|
9
|
+
*/
|
|
10
|
+
export type DropFirst<T extends unknown[]> = T extends [any, ...infer U] ? U : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DropFirst.js","sourceRoot":"","sources":["../../src/types/DropFirst.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
4
|
+
describe('DropFirst', () => {
|
|
5
|
+
it('should be drop the first type in an array', () => {
|
|
6
|
+
const numStrStr = [1, '2', '3'];
|
|
7
|
+
const strStr = ['1', '2'];
|
|
8
|
+
const str = strStr[0];
|
|
9
|
+
const num = numStrStr[0];
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=DropFirst.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DropFirst.test.js","sourceRoot":"","sources":["../../src/types/DropFirst.test.ts"],"names":[],"mappings":";;AAEA,sDAAsD;AACtD,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QAEnD,MAAM,SAAS,GAAuB,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACpD,MAAM,MAAM,GAAkC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACzD,MAAM,GAAG,GAAW,MAAM,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,GAAG,GAAW,SAAS,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/types/PickOne.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
describe('PickOne', () => {
|
|
13
|
+
it('should constrain type correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const findWrench = ({}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
// ...
|
|
16
|
+
});
|
|
17
|
+
// you can find by metric
|
|
18
|
+
yield findWrench({
|
|
19
|
+
size: {
|
|
20
|
+
metric: { millimeters: 16 },
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
// you can find by imperial
|
|
24
|
+
yield findWrench({
|
|
25
|
+
size: {
|
|
26
|
+
imperial: { inches: '5/16' },
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
// you can't find by both
|
|
30
|
+
// await findWrench({
|
|
31
|
+
// size: {
|
|
32
|
+
// metric: { millimeters: 16 },
|
|
33
|
+
// imperial: { inches: '5/16' },
|
|
34
|
+
// },
|
|
35
|
+
// });
|
|
36
|
+
}));
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=PickOne.test.js.map
|
|
@@ -0,0 +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,CAAO,EAezB,EAAE,EAAE;YACH,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,qBAAqB;QACrB,YAAY;QACZ,mCAAmC;QACnC,oCAAoC;QACpC,OAAO;QACP,MAAM;IACR,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serviceClientStage = exports.stage = exports.Stage = void 0;
|
|
4
|
+
var Stage;
|
|
5
|
+
(function (Stage) {
|
|
6
|
+
Stage["PRODUCTION"] = "prod";
|
|
7
|
+
Stage["DEVELOPMENT"] = "dev";
|
|
8
|
+
Stage["TEST"] = "test";
|
|
9
|
+
})(Stage = exports.Stage || (exports.Stage = {}));
|
|
10
|
+
/**
|
|
11
|
+
* this allows us to infer what the stage should be in environments that do not have STAGE specified
|
|
12
|
+
* - e.g., when running locally
|
|
13
|
+
* - e.g., when running tests
|
|
14
|
+
*/
|
|
15
|
+
const inferStageFromNodeEnv = () => {
|
|
16
|
+
const nodeEnv = process.env.NODE_ENV; // default to test if not defined
|
|
17
|
+
if (!nodeEnv)
|
|
18
|
+
throw new Error('process.env.NODE_ENV must be defined');
|
|
19
|
+
if (nodeEnv === 'production')
|
|
20
|
+
return Stage.PRODUCTION;
|
|
21
|
+
if (nodeEnv === 'development')
|
|
22
|
+
return Stage.DEVELOPMENT;
|
|
23
|
+
if (nodeEnv === 'test')
|
|
24
|
+
return Stage.TEST;
|
|
25
|
+
throw new Error(`unexpected nodeEnv '${nodeEnv}'`);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* a method that exposes relevant environmental variables in a standard way
|
|
29
|
+
*/
|
|
30
|
+
const getEnvironment = () => {
|
|
31
|
+
var _a;
|
|
32
|
+
const stage = (_a = process.env.STAGE) !== null && _a !== void 0 ? _a : inferStageFromNodeEnv(); // figure it out from NODE_ENV if not explicitly defined
|
|
33
|
+
if (!stage)
|
|
34
|
+
throw new Error('process.env.STAGE must be defined');
|
|
35
|
+
return { stage };
|
|
36
|
+
};
|
|
37
|
+
// export stage immediately, since it does not change
|
|
38
|
+
exports.stage = getEnvironment().stage;
|
|
39
|
+
// export service client stage
|
|
40
|
+
exports.serviceClientStage = exports.stage === Stage.PRODUCTION ? Stage.PRODUCTION : Stage.DEVELOPMENT; // i.e., if its prod, hit prod. otherwise, dev
|
|
41
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":";;;AAAA,IAAY,KAIX;AAJD,WAAY,KAAK;IACf,4BAAmB,CAAA;IACnB,4BAAmB,CAAA;IACnB,sBAAa,CAAA;AACf,CAAC,EAJW,KAAK,GAAL,aAAK,KAAL,aAAK,QAIhB;AAED;;;;GAIG;AACH,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACjC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,iCAAiC;IACvE,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACtE,IAAI,OAAO,KAAK,YAAY;QAAE,OAAO,KAAK,CAAC,UAAU,CAAC;IACtD,IAAI,OAAO,KAAK,aAAa;QAAE,OAAO,KAAK,CAAC,WAAW,CAAC;IACxD,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC;IAC1C,MAAM,IAAI,KAAK,CAAC,uBAAuB,OAAO,GAAG,CAAC,CAAC;AACrD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,cAAc,GAAG,GAAG,EAAE;;IAC1B,MAAM,KAAK,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,KAAK,mCAAI,qBAAqB,EAAE,CAAC,CAAC,wDAAwD;IACpH,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACjE,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC,CAAC;AAEF,qDAAqD;AACtC,aAAK,GAAK,cAAc,EAAE,OAAC;AAE1C,8BAA8B;AACjB,QAAA,kBAAkB,GAC7B,aAAK,KAAK,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,8CAA8C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UnexpectedCodePath errors are used to indicate that we've reached a code path that should never have been reached
|
|
3
|
+
*
|
|
4
|
+
* Purpose of having a dedicated class for this type of error is to allow us to easily add metadata about what was going on when we reached this code path
|
|
5
|
+
* - e.g., the variables in memory at the time
|
|
6
|
+
*/
|
|
7
|
+
export declare class UnexpectedCodePathError extends Error {
|
|
8
|
+
constructor(message: string, metadata?: Record<string, any>);
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnexpectedCodePathError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* UnexpectedCodePath errors are used to indicate that we've reached a code path that should never have been reached
|
|
6
|
+
*
|
|
7
|
+
* Purpose of having a dedicated class for this type of error is to allow us to easily add metadata about what was going on when we reached this code path
|
|
8
|
+
* - e.g., the variables in memory at the time
|
|
9
|
+
*/
|
|
10
|
+
class UnexpectedCodePathError extends Error {
|
|
11
|
+
constructor(message, metadata) {
|
|
12
|
+
const fullMessage = `UnexpectedCodePath: ${message}${metadata ? `\n\n${JSON.stringify(metadata)}` : ''}}`;
|
|
13
|
+
super(fullMessage);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.UnexpectedCodePathError = UnexpectedCodePathError;
|
|
17
|
+
//# sourceMappingURL=UnexpectedCodePathError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnexpectedCodePathError.js","sourceRoot":"","sources":["../../../src/utils/errors/UnexpectedCodePathError.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,OAAe,EAAE,QAA8B;QACzD,MAAM,WAAW,GAAG,uBAAuB,OAAO,GAChD,QAAQ,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EACjD,GAAG,CAAC;QACJ,KAAK,CAAC,WAAW,CAAC,CAAC;IACrB,CAAC;CACF;AAPD,0DAOC"}
|
package/dist/wrappers/withNot.js
CHANGED
|
@@ -11,5 +11,6 @@ exports.withNot = void 0;
|
|
|
11
11
|
* const invalidOptions = objects.filter(withNot(isOfStatus));
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
const withNot = (is) => (args) => !is(args);
|
|
15
|
+
exports.withNot = withNot;
|
|
15
16
|
//# sourceMappingURL=withNot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withNot.js","sourceRoot":"","sources":["../../src/wrappers/withNot.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"withNot.js","sourceRoot":"","sources":["../../src/wrappers/withNot.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACI,MAAM,OAAO,GAClB,CAAI,EAAwB,EAA0B,EAAE,CACxD,CAAC,IAAO,EAAE,EAAE,CACV,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAHD,QAAA,OAAO,WAGN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const hasId_1 = require("../checks/hasId");
|
|
4
|
+
const withNot_1 = require("./withNot");
|
|
5
|
+
describe('withNot', () => {
|
|
6
|
+
it('should return false if an object has an id after wrapping hasId', () => {
|
|
7
|
+
const obj = { id: 821, name: 'bob' };
|
|
8
|
+
const itDoesNotHaveId = (0, withNot_1.withNot)(hasId_1.hasId)(obj);
|
|
9
|
+
expect(itDoesNotHaveId).toEqual(false);
|
|
10
|
+
});
|
|
11
|
+
it('should return false if an object does not have an id', () => {
|
|
12
|
+
const obj = { name: 'bob' };
|
|
13
|
+
const itDoesNotHaveId = (0, withNot_1.withNot)(hasId_1.hasId)(obj);
|
|
14
|
+
expect(itDoesNotHaveId).toEqual(true);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=withNot.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withNot.test.js","sourceRoot":"","sources":["../../src/wrappers/withNot.test.ts"],"names":[],"mappings":";;AAAA,2CAAwC;AACxC,uCAAoC;AAEpC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;QACzE,MAAM,GAAG,GAAkC,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QACpE,MAAM,eAAe,GAAG,IAAA,iBAAO,EAAC,aAAK,CAAC,CAAC,GAAG,CAAC,CAAC;QAC5C,MAAM,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,GAAG,GAAkC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAC3D,MAAM,eAAe,GAAG,IAAA,iBAAO,EAAC,aAAK,CAAC,CAAC,GAAG,CAAC,CAAC;QAC5C,MAAM,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
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
|
-
"
|
|
6
|
-
"license": "MIT",
|
|
5
|
+
"version": "0.9.0",
|
|
7
6
|
"repository": "ehmpathy/type-fns",
|
|
8
7
|
"homepage": "https://github.com/ehmpathy/type-fns",
|
|
9
8
|
"keywords": [
|
|
@@ -25,40 +24,61 @@
|
|
|
25
24
|
"/dist"
|
|
26
25
|
],
|
|
27
26
|
"scripts": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"test": "
|
|
27
|
+
"commit:with-cli": "npx cz",
|
|
28
|
+
"fix:format:prettier": "prettier --write '**/*.ts' --config ./prettier.config.js",
|
|
29
|
+
"fix:format": "npm run fix:format:prettier",
|
|
30
|
+
"fix:lint": "eslint -c ./.eslintrc.js src/**/*.ts --fix",
|
|
31
|
+
"build:artifact": "echo 'no artifact'",
|
|
32
|
+
"build:clean": "rm dist/ -rf",
|
|
33
|
+
"build:compile": "tsc -p ./tsconfig.build.json",
|
|
34
|
+
"build": "npm run build:clean && npm run build:compile",
|
|
35
|
+
"test:commits": "LAST_TAG=$(git describe --tags --abbrev=0 @^ 2> /dev/null || git rev-list --max-parents=0 HEAD) && npx commitlint --from $LAST_TAG --to HEAD --verbose",
|
|
36
|
+
"test:types": "tsc -p ./tsconfig.build.json --noEmit",
|
|
37
37
|
"prepublish": "npm run build",
|
|
38
|
-
"
|
|
38
|
+
"test:format:prettier": "prettier --parser typescript --check 'src/**/*.ts' --config ./prettier.config.js",
|
|
39
|
+
"test:format": "npm run test:format:prettier",
|
|
40
|
+
"test:lint:deps": "npx depcheck -c ./depcheckrc.yml",
|
|
41
|
+
"test:lint:eslint": "eslint -c ./.eslintrc.js src/**/*.ts",
|
|
42
|
+
"test:lint": "npm run test:lint:eslint && npm run test:lint:deps",
|
|
43
|
+
"test:unit": "jest -c ./jest.unit.config.ts --forceExit --verbose --passWithNoTests",
|
|
44
|
+
"test:integration": "jest -c ./jest.integration.config.ts --forceExit --verbose --passWithNoTests",
|
|
45
|
+
"test:acceptance:locally": "npm run build && LOCALLY=true jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests",
|
|
46
|
+
"test": "npm run test:commits && npm run test:types && npm run test:format && npm run test:lint && npm run test:unit && npm run test:integration && npm run test:acceptance:locally",
|
|
47
|
+
"test:acceptance": "npm run build && jest -c ./jest.acceptance.config.ts --forceExit --verbose --runInBand --passWithNoTests",
|
|
48
|
+
"prepush": "npm run test && npm run build",
|
|
49
|
+
"preversion": "npm run prepush",
|
|
39
50
|
"postversion": "git push origin HEAD --tags --no-verify"
|
|
40
51
|
},
|
|
41
52
|
"devDependencies": {
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
48
|
-
"eslint": "
|
|
49
|
-
"eslint
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"prettier": "
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
53
|
+
"@commitlint/cli": "13.1.0",
|
|
54
|
+
"@commitlint/config-conventional": "13.1.0",
|
|
55
|
+
"@trivago/prettier-plugin-sort-imports": "2.0.4",
|
|
56
|
+
"@tsconfig/node-lts-strictest": "18.12.1",
|
|
57
|
+
"@types/jest": "29.2.4",
|
|
58
|
+
"@types/uuid": "9.0.0",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "5.46.1",
|
|
60
|
+
"@typescript-eslint/parser": "5.46.1",
|
|
61
|
+
"core-js": "3.26.1",
|
|
62
|
+
"cz-conventional-changelog": "3.3.0",
|
|
63
|
+
"declapract": "0.11.2",
|
|
64
|
+
"declapract-typescript-ehmpathy": "0.23.7",
|
|
65
|
+
"depcheck": "1.4.3",
|
|
66
|
+
"eslint": "8.30.0",
|
|
67
|
+
"eslint-config-airbnb-typescript": "17.0.0",
|
|
68
|
+
"eslint-config-prettier": "8.5.0",
|
|
69
|
+
"eslint-plugin-import": "2.26.0",
|
|
70
|
+
"eslint-plugin-prettier": "4.2.1",
|
|
71
|
+
"husky": "7.0.2",
|
|
72
|
+
"jest": "29.3.1",
|
|
73
|
+
"prettier": "2.8.1",
|
|
74
|
+
"ts-jest": "29.0.3",
|
|
75
|
+
"ts-node": "10.9.1",
|
|
76
|
+
"typescript": "4.9.4",
|
|
77
|
+
"uuid": "^3.3.3"
|
|
62
78
|
},
|
|
63
|
-
"
|
|
79
|
+
"config": {
|
|
80
|
+
"commitizen": {
|
|
81
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
64
84
|
}
|
package/{README.md → readme.md}
RENAMED
|
@@ -89,6 +89,20 @@ await findWrench({
|
|
|
89
89
|
})
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
+
### `DropFirst`
|
|
93
|
+
|
|
94
|
+
The generic type `DropFirst` lets you exclude the first element of an array.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
type NumberStringString = [number, string, string];
|
|
98
|
+
const numStrStr: NumberStringString = [1, '2', '3'];
|
|
99
|
+
const strStr: DropFirst<NumberStringString> = ['1', '2'];
|
|
100
|
+
const str: string = strStr[0];
|
|
101
|
+
const num: number = numStrStr[0];
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Useful, for example, if you want to change the first parameter of a function while keeping the rest the same.
|
|
105
|
+
|
|
92
106
|
## type guards
|
|
93
107
|
|
|
94
108
|
### `isPresent`
|
package/changelog.md
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## [0.7.0](https://www.github.com/ehmpathy/type-fns/compare/v0.6.0...v0.7.0) (2022-11-26)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
### Features
|
|
7
|
-
|
|
8
|
-
* **checks:** define the hasMetadata type check function ([64b788f](https://www.github.com/ehmpathy/type-fns/commit/64b788fcf1348c654d920750a56bbc77dc3e6dad))
|
|
9
|
-
|
|
10
|
-
## [0.6.0](https://www.github.com/ehmpathy/type-fns/compare/v0.5.1...v0.6.0) (2022-11-25)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
### Features
|
|
14
|
-
|
|
15
|
-
* **checks:** add isNotUndefined and isNotNull checks ([e810bdf](https://www.github.com/ehmpathy/type-fns/commit/e810bdf5e2ec6b9caa3e289aa8a7c693524b5e65))
|
|
16
|
-
|
|
17
|
-
### [0.5.1](https://www.github.com/ehmpathy/type-fns/compare/v0.5.0...v0.5.1) (2022-11-25)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
### Bug Fixes
|
|
21
|
-
|
|
22
|
-
* **exports:** actually export NotUndefined ([1869b05](https://www.github.com/ehmpathy/type-fns/commit/1869b05e59764b3b822298dac223b9cb09b02fc0))
|
|
23
|
-
|
|
24
|
-
## [0.5.0](https://www.github.com/ehmpathy/type-fns/compare/v0.4.1...v0.5.0) (2022-11-25)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
### Features
|
|
28
|
-
|
|
29
|
-
* **types:** add the NotUndefined generic type ([bd613c2](https://www.github.com/ehmpathy/type-fns/commit/bd613c27ced111eb44c971734ab343a9cd2fbe8e))
|
|
30
|
-
|
|
31
|
-
### [0.4.1](https://www.github.com/ehmpathy/type-fns/compare/v0.4.0...v0.4.1) (2022-11-24)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
### Bug Fixes
|
|
35
|
-
|
|
36
|
-
* **exports:** actually export isAPromise, isAFunction, PickOne ([ad5b28f](https://www.github.com/ehmpathy/type-fns/commit/ad5b28f1d2da9fe382d1245d38d970b1b0e7bd1c))
|
|
37
|
-
|
|
38
|
-
## [0.4.0](https://www.github.com/ehmpathy/type-fns/compare/v0.3.0...v0.4.0) (2022-11-24)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Features
|
|
42
|
-
|
|
43
|
-
* **checks:** add isAFunction, isAPromise, and PickOne type checks and generic type ([981ae42](https://www.github.com/ehmpathy/type-fns/commit/981ae4275530bdae203b9013bed193f1afda6b8d))
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
### Bug Fixes
|
|
47
|
-
|
|
48
|
-
* **cicd:** update github actions, test scripts, and swap repo org to ehmpathy ([b6a1458](https://www.github.com/ehmpathy/type-fns/commit/b6a1458b6d2d5423255fc8eaee2e3181d0c14850))
|
|
49
|
-
* **doc:** fix comment describing has metadata in code ([d7d2e55](https://www.github.com/ehmpathy/type-fns/commit/d7d2e556ba03ad5a573f90d6ea75c5696f493058))
|
|
50
|
-
* **name:** rename package to type-fns ([66258d9](https://www.github.com/ehmpathy/type-fns/commit/66258d93e7964c675b92f50061ddcb11a79f2b69))
|
|
51
|
-
* **tests:** remove example of type error from tests ([326123c](https://www.github.com/ehmpathy/type-fns/commit/326123cf845b31e82edb0d3d50cd6034217df2fa))
|
|
52
|
-
|
|
53
|
-
## [0.3.0](https://www.github.com/ehmpathy/type-fns/compare/v0.2.1...v0.3.0) (2022-01-03)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
### Features
|
|
57
|
-
|
|
58
|
-
* **checks:** add the HasMetadata type modifier ([85f0ca4](https://www.github.com/ehmpathy/type-fns/commit/85f0ca467983ea6f1fc5845990f98dbe9cbe5e8f))
|
|
59
|
-
|
|
60
|
-
### [0.2.1](https://www.github.com/ehmpathy/type-fns/compare/v0.2.0...v0.2.1) (2021-11-16)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
### Bug Fixes
|
|
64
|
-
|
|
65
|
-
* **enum:** forbid giving isOfEnum functions null or undefined as an input ([98ec621](https://www.github.com/ehmpathy/type-fns/commit/98ec6216bc5775cbb2015f400358fe7d5fffc303))
|