@silvermine/toolbox 0.5.0 → 0.6.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/CHANGELOG.md +16 -0
- package/dist/commonjs/index.js +1 -0
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/utils/group-by.js +31 -0
- package/dist/commonjs/utils/group-by.js.map +1 -0
- package/dist/commonjs/utils/has-defined.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/group-by.js +27 -0
- package/dist/esm/utils/group-by.js.map +1 -0
- package/dist/esm/utils/has-defined.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/group-by.d.ts +7 -0
- package/dist/types/utils/has-defined.d.ts +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/utils/group-by.ts +32 -0
- package/src/utils/has-defined.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [our coding standards][commit-messages] for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.6.0](https://github.com/silvermine/toolbox/compare/v0.5.1...v0.6.0) (2025-11-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add groupBy util ([e828ca8](https://github.com/silvermine/toolbox/commit/e828ca8f54e18b7513034cee12ec5eb4e5ed2159))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### [0.5.1](https://github.com/silvermine/toolbox/compare/v0.5.0...v0.5.1) (2025-11-08)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* ensure hasDefined is called on an object ([e532ebf](https://github.com/silvermine/toolbox/commit/e532ebf571481d38a0a6d22890e08e18eba3f807))
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [0.5.0](https://github.com/silvermine/toolbox/compare/v0.4.0...v0.5.0) (2025-10-24)
|
|
7
23
|
|
|
8
24
|
|
package/dist/commonjs/index.js
CHANGED
|
@@ -36,6 +36,7 @@ tslib_1.__exportStar(require("./utils/pick"), exports);
|
|
|
36
36
|
tslib_1.__exportStar(require("./utils/pluck"), exports);
|
|
37
37
|
tslib_1.__exportStar(require("./utils/delay"), exports);
|
|
38
38
|
tslib_1.__exportStar(require("./utils/get"), exports);
|
|
39
|
+
tslib_1.__exportStar(require("./utils/group-by"), exports);
|
|
39
40
|
tslib_1.__exportStar(require("./utils/escape-html"), exports);
|
|
40
41
|
tslib_1.__exportStar(require("./utils/make-template"), exports);
|
|
41
42
|
tslib_1.__exportStar(require("./utils/uniq"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C;AAC7C,uDAA6B;AAC7B,2DAAiC;AACjC,gEAAsC;AACtC,iEAAuC;AACvC,kEAAwC;AACxC,8DAAoC;AACpC,0EAAgD;AAChD,4DAAkC;AAClC,mEAAyC;AACzC,2DAAiC;AAEjC,8DAAoC;AACpC,+DAAqC;AACrC,2DAAiC;AACjC,sEAA4C;AAC5C,6DAAmC;AACnC,2DAAiC;AACjC,gEAAsC;AACtC,6EAAmD;AACnD,4DAAkC;AAClC,4DAAkC;AAClC,6DAAmC;AACnC,kEAAwC;AACxC,yDAA+B;AAC/B,4DAAkC;AAClC,+DAAqC;AACrC,0DAAgC;AAChC,2EAAiD;AAEjD,wDAA8B;AAC9B,0DAAgC;AAChC,0DAAgC;AAChC,uDAA6B;AAC7B,wDAA8B;AAC9B,wDAA8B;AAC9B,sDAA4B;AAC5B,8DAAoC;AACpC,gEAAsC;AACtC,uDAA6B;AAC7B,wDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uEAA6C;AAC7C,uDAA6B;AAC7B,2DAAiC;AACjC,gEAAsC;AACtC,iEAAuC;AACvC,kEAAwC;AACxC,8DAAoC;AACpC,0EAAgD;AAChD,4DAAkC;AAClC,mEAAyC;AACzC,2DAAiC;AAEjC,8DAAoC;AACpC,+DAAqC;AACrC,2DAAiC;AACjC,sEAA4C;AAC5C,6DAAmC;AACnC,2DAAiC;AACjC,gEAAsC;AACtC,6EAAmD;AACnD,4DAAkC;AAClC,4DAAkC;AAClC,6DAAmC;AACnC,kEAAwC;AACxC,yDAA+B;AAC/B,4DAAkC;AAClC,+DAAqC;AACrC,0DAAgC;AAChC,2EAAiD;AAEjD,wDAA8B;AAC9B,0DAAgC;AAChC,0DAAgC;AAChC,uDAA6B;AAC7B,wDAA8B;AAC9B,wDAA8B;AAC9B,sDAA4B;AAC5B,2DAAiC;AACjC,8DAAoC;AACpC,gEAAsC;AACtC,uDAA6B;AAC7B,wDAA8B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.groupBy = void 0;
|
|
4
|
+
const has_defined_1 = require("./has-defined");
|
|
5
|
+
const is_string_1 = require("./is-string");
|
|
6
|
+
/**
|
|
7
|
+
* Given an array of items and a function that returns a key, groups the items by the key.
|
|
8
|
+
* If the returned key is `undefined`, the item is not included in the result. If a string
|
|
9
|
+
* is passed as the second argument, the item is grouped by the values of that property.
|
|
10
|
+
*/
|
|
11
|
+
function groupBy(items, fn) {
|
|
12
|
+
const keyFn = typeof fn === 'function' ? fn : (item) => {
|
|
13
|
+
const key = item[fn];
|
|
14
|
+
return is_string_1.isString(key) ? key : undefined;
|
|
15
|
+
};
|
|
16
|
+
return items.reduce((memo, item) => {
|
|
17
|
+
const key = keyFn(item);
|
|
18
|
+
if (key === undefined) {
|
|
19
|
+
return memo;
|
|
20
|
+
}
|
|
21
|
+
if (has_defined_1.hasDefined(memo, key)) {
|
|
22
|
+
memo[key].push(item);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
memo[key] = [item];
|
|
26
|
+
}
|
|
27
|
+
return memo;
|
|
28
|
+
}, {});
|
|
29
|
+
}
|
|
30
|
+
exports.groupBy = groupBy;
|
|
31
|
+
//# sourceMappingURL=group-by.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-by.js","sourceRoot":"","sources":["../../../src/utils/group-by.ts"],"names":[],"mappings":";;;AACA,+CAA2C;AAC3C,2CAAuC;AAEvC;;;;GAIG;AACH,SAAgB,OAAO,CAAsB,KAAU,EAAE,EAAgE;IACtH,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAO,EAAE,EAAE;QACvD,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;QAErB,OAAO,oBAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1C,CAAC,CAAC;IAEF,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QAChC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QAExB,IAAI,GAAG,KAAK,SAAS,EAAE;YACpB,OAAO,IAAI,CAAC;SACd;QAED,IAAI,wBAAU,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE;YACxB,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACvB;aAAM;YACJ,IAAI,CAAC,GAAG,CAAC,GAAG,CAAE,IAAI,CAAE,CAAC;SACvB;QAED,OAAO,IAAI,CAAC;IACf,CAAC,EAAE,EAAqC,CAAC,CAAC;AAC7C,CAAC;AAtBD,0BAsBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has-defined.js","sourceRoot":"","sources":["../../../src/utils/has-defined.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAI7C;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,UAAU,
|
|
1
|
+
{"version":3,"file":"has-defined.js","sourceRoot":"","sources":["../../../src/utils/has-defined.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAI7C;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,UAAU,CAAqD,CAAI,EAAE,QAAW;IAC7F,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,0BAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AACzF,CAAC;AAFD,gCAEC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -33,6 +33,7 @@ export * from './utils/pick';
|
|
|
33
33
|
export * from './utils/pluck';
|
|
34
34
|
export * from './utils/delay';
|
|
35
35
|
export * from './utils/get';
|
|
36
|
+
export * from './utils/group-by';
|
|
36
37
|
export * from './utils/escape-html';
|
|
37
38
|
export * from './utils/make-template';
|
|
38
39
|
export * from './utils/uniq';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC;AAChD,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kCAAkC,CAAC;AAEjD,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC;AAChD,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kCAAkC,CAAC;AAEjD,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { hasDefined } from './has-defined';
|
|
2
|
+
import { isString } from './is-string';
|
|
3
|
+
/**
|
|
4
|
+
* Given an array of items and a function that returns a key, groups the items by the key.
|
|
5
|
+
* If the returned key is `undefined`, the item is not included in the result. If a string
|
|
6
|
+
* is passed as the second argument, the item is grouped by the values of that property.
|
|
7
|
+
*/
|
|
8
|
+
export function groupBy(items, fn) {
|
|
9
|
+
const keyFn = typeof fn === 'function' ? fn : (item) => {
|
|
10
|
+
const key = item[fn];
|
|
11
|
+
return isString(key) ? key : undefined;
|
|
12
|
+
};
|
|
13
|
+
return items.reduce((memo, item) => {
|
|
14
|
+
const key = keyFn(item);
|
|
15
|
+
if (key === undefined) {
|
|
16
|
+
return memo;
|
|
17
|
+
}
|
|
18
|
+
if (hasDefined(memo, key)) {
|
|
19
|
+
memo[key].push(item);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
memo[key] = [item];
|
|
23
|
+
}
|
|
24
|
+
return memo;
|
|
25
|
+
}, {});
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=group-by.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-by.js","sourceRoot":"","sources":["../../../src/utils/group-by.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAsB,KAAU,EAAE,EAAgE;IACtH,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAO,EAAE,EAAE;QACvD,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;QAErB,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1C,CAAC,CAAC;IAEF,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QAChC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QAExB,IAAI,GAAG,KAAK,SAAS,EAAE;YACpB,OAAO,IAAI,CAAC;SACd;QAED,IAAI,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE;YACxB,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACvB;aAAM;YACJ,IAAI,CAAC,GAAG,CAAC,GAAG,CAAE,IAAI,CAAE,CAAC;SACvB;QAED,OAAO,IAAI,CAAC;IACf,CAAC,EAAE,EAAqC,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has-defined.js","sourceRoot":"","sources":["../../../src/utils/has-defined.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,UAAU,
|
|
1
|
+
{"version":3,"file":"has-defined.js","sourceRoot":"","sources":["../../../src/utils/has-defined.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,UAAU,CAAqD,CAAI,EAAE,QAAW;IAC7F,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AACzF,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export * from './utils/pick';
|
|
|
33
33
|
export * from './utils/pluck';
|
|
34
34
|
export * from './utils/delay';
|
|
35
35
|
export * from './utils/get';
|
|
36
|
+
export * from './utils/group-by';
|
|
36
37
|
export * from './utils/escape-html';
|
|
37
38
|
export * from './utils/make-template';
|
|
38
39
|
export * from './utils/uniq';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PropsWithType } from '../types/PropsWithType';
|
|
2
|
+
/**
|
|
3
|
+
* Given an array of items and a function that returns a key, groups the items by the key.
|
|
4
|
+
* If the returned key is `undefined`, the item is not included in the result. If a string
|
|
5
|
+
* is passed as the second argument, the item is grouped by the values of that property.
|
|
6
|
+
*/
|
|
7
|
+
export declare function groupBy<T, U extends string>(items: T[], fn: ((item: T) => string | undefined) | PropsWithType<T, string>): Record<U, T[] | undefined>;
|
|
@@ -17,6 +17,6 @@ import { UnionKeys } from '../types/UnionKeys';
|
|
|
17
17
|
* @param propName the name of the optional or possibly-undefined property that you want
|
|
18
18
|
* to be required
|
|
19
19
|
*/
|
|
20
|
-
export declare function hasDefined<T, U extends keyof T | UnionKeys<T>>(o: T, propName: U): o is RequireDefined<Extract<T, {
|
|
20
|
+
export declare function hasDefined<T extends object, U extends keyof T | UnionKeys<T>>(o: T, propName: U): o is RequireDefined<Extract<T, {
|
|
21
21
|
[key in U]?: unknown;
|
|
22
22
|
}>, U>;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -35,6 +35,7 @@ export * from './utils/pick';
|
|
|
35
35
|
export * from './utils/pluck';
|
|
36
36
|
export * from './utils/delay';
|
|
37
37
|
export * from './utils/get';
|
|
38
|
+
export * from './utils/group-by';
|
|
38
39
|
export * from './utils/escape-html';
|
|
39
40
|
export * from './utils/make-template';
|
|
40
41
|
export * from './utils/uniq';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PropsWithType } from '../types/PropsWithType';
|
|
2
|
+
import { hasDefined } from './has-defined';
|
|
3
|
+
import { isString } from './is-string';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Given an array of items and a function that returns a key, groups the items by the key.
|
|
7
|
+
* If the returned key is `undefined`, the item is not included in the result. If a string
|
|
8
|
+
* is passed as the second argument, the item is grouped by the values of that property.
|
|
9
|
+
*/
|
|
10
|
+
export function groupBy<T, U extends string>(items: T[], fn: ((item: T) => string | undefined) | PropsWithType<T, string>): Record<U, T[] | undefined> {
|
|
11
|
+
const keyFn = typeof fn === 'function' ? fn : (item: T) => {
|
|
12
|
+
const key = item[fn];
|
|
13
|
+
|
|
14
|
+
return isString(key) ? key : undefined;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return items.reduce((memo, item) => {
|
|
18
|
+
const key = keyFn(item);
|
|
19
|
+
|
|
20
|
+
if (key === undefined) {
|
|
21
|
+
return memo;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (hasDefined(memo, key)) {
|
|
25
|
+
memo[key].push(item);
|
|
26
|
+
} else {
|
|
27
|
+
memo[key] = [ item ];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return memo;
|
|
31
|
+
}, {} as Record<string, T[] | undefined>);
|
|
32
|
+
}
|
package/src/utils/has-defined.ts
CHANGED
|
@@ -19,6 +19,6 @@ import { UnionKeys } from '../types/UnionKeys';
|
|
|
19
19
|
* @param propName the name of the optional or possibly-undefined property that you want
|
|
20
20
|
* to be required
|
|
21
21
|
*/
|
|
22
|
-
export function hasDefined<T, U extends keyof T | UnionKeys<T>>(o: T, propName: U): o is RequireDefined<Extract<T, { [key in U]?: unknown }>, U> {
|
|
22
|
+
export function hasDefined<T extends object, U extends keyof T | UnionKeys<T>>(o: T, propName: U): o is RequireDefined<Extract<T, { [key in U]?: unknown }>, U> {
|
|
23
23
|
return Object.prototype.hasOwnProperty.call(o, propName) && !isUndefined(o[propName]);
|
|
24
24
|
}
|