@powfix/core-js 0.24.6 → 0.25.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.
@@ -0,0 +1 @@
1
+ 'use strict';
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Makes all properties required and strips `null` from property types.
3
+ *
4
+ * @example
5
+ * type Input = {
6
+ * a?: string | null
7
+ * b: number | null
8
+ * }
9
+ * type Result = CustomRequired<Input>
10
+ * // {
11
+ * // a: string
12
+ * // b: number
13
+ * // }
14
+ */
15
+ type CustomRequired<T> = {
16
+ [P in keyof T]-?: T[P] extends infer A | null ? A : T[P];
17
+ };
18
+ type R = Record<string, any>;
19
+ /**
20
+ * Extracts keys of properties whose value is an object (but not arrays).
21
+ *
22
+ * @example
23
+ * type Example = {
24
+ * id: number
25
+ * info: { name: string }
26
+ * tags: string[]
27
+ * }
28
+ * type ObjKeys = ObjectKeys<Example> // "info"
29
+ */
30
+ export type ObjectKeys<T, RT = CustomRequired<T>> = keyof {
31
+ [P in keyof RT as RT[P] extends any[] ? never : RT[P] extends R ? P : never]: RT[P];
32
+ };
33
+ /**
34
+ * Extracts keys of properties whose value is an array of objects.
35
+ *
36
+ * @example
37
+ * type Example = {
38
+ * id: number
39
+ * posts: { title: string }[]
40
+ * scores: number[]
41
+ * }
42
+ * type ArrayObjKeys = ArrayObjectKeys<Example> // "posts"
43
+ */
44
+ export type ArrayObjectKeys<T, RT = CustomRequired<T>> = keyof {
45
+ [P in keyof RT as RT[P] extends R[] ? P : never]: RT[P];
46
+ };
47
+ type DepthLevel = [never, 0, 1, 2, 3, 4, 5];
48
+ type DepthType = DepthLevel[number];
49
+ /**
50
+ * Recursively collects nested object keys (`a.b.c`) up to a defined depth.
51
+ *
52
+ * Default depth = 5.
53
+ *
54
+ * @example
55
+ * type Example = {
56
+ * user: {
57
+ * profile: {
58
+ * email: string
59
+ * }
60
+ * }
61
+ * tags: string[]
62
+ * }
63
+ *
64
+ * type Keys = NestedObjectKeys<Example>
65
+ * // "user" | "user.profile" | "user.profile.email"
66
+ */
67
+ export type NestedObjectKeys<T, Depth extends DepthType = 5, RT = CustomRequired<T>> = keyof {
68
+ [P in keyof RT & string as Depth extends never ? never : RT[P] extends any[] ? never : RT[P] extends R ? P | `${P}.${NestedObjectKeys<RT[P], DepthLevel[Depth]>}` : never]: RT[P];
69
+ };
70
+ /**
71
+ * Recursively collects nested object keys inside array properties.
72
+ *
73
+ * Keys include the root array field name and dot paths inside array item objects.
74
+ *
75
+ * @example
76
+ * type Example = {
77
+ * comments: {
78
+ * users: {
79
+ * name: string,
80
+ * addresses: {
81
+ * name
82
+ * }[]
83
+ * }[]
84
+ * }[]
85
+ * }
86
+ *
87
+ * type Keys = NestedArrayObjectKeys<Example>
88
+ * // "comments" | "comments.users" | "comments.users.addresses"
89
+ */
90
+ export type NestedArrayObjectKeys<T, Depth extends DepthType = 5, RT = CustomRequired<T>> = keyof {
91
+ [P in keyof RT & string as Depth extends never ? never : RT[P] extends R[] ? P | `${P}.${NestedArrayObjectKeys<RT[P][number], DepthLevel[Depth]>}` : never]: RT[P];
92
+ };
93
+ /**
94
+ * Picks only properties that are objects (not arrays).
95
+ *
96
+ * @example
97
+ * type Example = {
98
+ * id: number
99
+ * settings: { dark: boolean }
100
+ * history: string[]
101
+ * }
102
+ *
103
+ * type Result = PickObjects<Example>
104
+ * // { settings: { dark: boolean } }
105
+ */
106
+ export type PickObjects<T> = Pick<T, ObjectKeys<T>>;
107
+ /**
108
+ * Picks only properties that are arrays of objects.
109
+ *
110
+ * @example
111
+ * type Example = {
112
+ * users: { name: string }[]
113
+ * count: number
114
+ * }
115
+ *
116
+ * type Result = PickArrayObjects<Example>
117
+ * // { users: { name: string }[] }
118
+ */
119
+ export type PickArrayObjects<T> = Pick<T, ArrayObjectKeys<T>>;
120
+ export {};
File without changes
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
  var IntRage = require('./IntRage');
3
3
  var PartialExcept = require('./PartialExcept');
4
+ var Object$1 = require('./Object');
4
5
  Object.keys(IntRage).forEach(function(k) {
5
6
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
7
  enumerable: true,
@@ -17,3 +18,11 @@ Object.keys(PartialExcept).forEach(function(k) {
17
18
  }
18
19
  });
19
20
  });
21
+ Object.keys(Object$1).forEach(function(k) {
22
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
23
+ enumerable: true,
24
+ get: function get() {
25
+ return Object$1[k];
26
+ }
27
+ });
28
+ });
@@ -1,2 +1,3 @@
1
1
  export * from './IntRage.js';
2
2
  export * from './PartialExcept.js';
3
+ export * from './Object.js';
@@ -1,2 +1,3 @@
1
1
  export * from './IntRage.js';
2
2
  export * from './PartialExcept.js';
3
+ export * from './Object.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powfix/core-js",
3
- "version": "0.24.6",
3
+ "version": "0.25.0",
4
4
  "description": "core package",
5
5
  "author": "Kwon Kyung-Min <powfix@gmail.com>",
6
6
  "private": false,