@powfix/core-js 0.24.6 → 0.25.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.
- package/dist/browser/index.cjs +9 -0
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.js +1 -0
- package/dist/browser/utils/SearchParamsUtils.cjs +103 -0
- package/dist/browser/utils/SearchParamsUtils.d.ts +13 -0
- package/dist/browser/utils/SearchParamsUtils.js +103 -0
- package/dist/browser/utils/index.cjs +10 -0
- package/dist/browser/utils/index.d.ts +1 -0
- package/dist/browser/utils/index.js +1 -0
- package/dist/shared/types/Object.cjs +1 -0
- package/dist/shared/types/Object.d.ts +120 -0
- package/dist/shared/types/Object.js +0 -0
- package/dist/shared/types/index.cjs +9 -0
- package/dist/shared/types/index.d.ts +1 -0
- package/dist/shared/types/index.js +1 -0
- package/package.json +2 -2
package/dist/browser/index.cjs
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
var utils = require('./utils');
|
|
3
|
+
Object.keys(utils).forEach(function(k) {
|
|
4
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: function get() {
|
|
7
|
+
return utils[k];
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
});
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './utils/index.js';
|
package/dist/browser/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils/index.js';
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
function _class_call_check(instance, Constructor) {
|
|
3
|
+
if (!(instance instanceof Constructor)) {
|
|
4
|
+
throw new TypeError("Cannot call a class as a function");
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function _defineProperties(target, props) {
|
|
8
|
+
for(var i = 0; i < props.length; i++){
|
|
9
|
+
var descriptor = props[i];
|
|
10
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
11
|
+
descriptor.configurable = true;
|
|
12
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
13
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
17
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
18
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
19
|
+
return Constructor;
|
|
20
|
+
}
|
|
21
|
+
var chunkJE77HYXB_cjs = require('../../chunk-JE77HYXB.cjs');
|
|
22
|
+
var uuid = require('@powfix/uuid');
|
|
23
|
+
var _searchParams;
|
|
24
|
+
var _SearchParamsUtils = /*#__PURE__*/ function() {
|
|
25
|
+
function _SearchParamsUtils(searchParams) {
|
|
26
|
+
_class_call_check(this, _SearchParamsUtils);
|
|
27
|
+
chunkJE77HYXB_cjs.__privateAdd(this, _searchParams);
|
|
28
|
+
chunkJE77HYXB_cjs.__privateSet(this, _searchParams, searchParams);
|
|
29
|
+
}
|
|
30
|
+
_create_class(_SearchParamsUtils, [
|
|
31
|
+
{
|
|
32
|
+
key: "getString",
|
|
33
|
+
value: function getString(key) {
|
|
34
|
+
return _SearchParamsUtils.getString(chunkJE77HYXB_cjs.__privateGet(this, _searchParams), key);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "getStrings",
|
|
39
|
+
value: function getStrings(key) {
|
|
40
|
+
return _SearchParamsUtils.getStrings(chunkJE77HYXB_cjs.__privateGet(this, _searchParams), key);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
], [
|
|
44
|
+
{
|
|
45
|
+
key: "urlSearchParams",
|
|
46
|
+
get: function get() {
|
|
47
|
+
return new URL(window.location.href).searchParams;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
key: "getString",
|
|
52
|
+
value: function getString(searchParams, key) {
|
|
53
|
+
if (!searchParams.has(key)) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return searchParams.get(key);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: "getStrings",
|
|
61
|
+
value: function getStrings(searchParams, key) {
|
|
62
|
+
if (!searchParams.has(key)) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return searchParams.getAll(key);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
key: "getUuid",
|
|
70
|
+
value: function getUuid(searchParams, key) {
|
|
71
|
+
var value = this.getString(searchParams, key);
|
|
72
|
+
if (!uuid.UUID.isValid(value)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return uuid.UUID.from(value);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
key: "getUuids",
|
|
80
|
+
value: function getUuids(searchParams, key) {
|
|
81
|
+
var values = this.getStrings(searchParams, key);
|
|
82
|
+
if (values == null) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return values.filter(function(value) {
|
|
86
|
+
return uuid.UUID.isValid(value);
|
|
87
|
+
}).map(function(value) {
|
|
88
|
+
return uuid.UUID.from(value);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: "from",
|
|
94
|
+
value: function from(searchParams) {
|
|
95
|
+
return new _SearchParamsUtils(searchParams);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
]);
|
|
99
|
+
return _SearchParamsUtils;
|
|
100
|
+
}();
|
|
101
|
+
_searchParams = new WeakMap();
|
|
102
|
+
var SearchParamsUtils = _SearchParamsUtils;
|
|
103
|
+
exports.SearchParamsUtils = SearchParamsUtils;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UUID } from "@powfix/uuid";
|
|
2
|
+
export declare class SearchParamsUtils {
|
|
3
|
+
#private;
|
|
4
|
+
private static get urlSearchParams();
|
|
5
|
+
static getString(searchParams: URLSearchParams, key: string): string | null;
|
|
6
|
+
static getStrings(searchParams: URLSearchParams, key: string): string[] | null;
|
|
7
|
+
static getUuid(searchParams: URLSearchParams, key: string): UUID | null;
|
|
8
|
+
static getUuids(searchParams: URLSearchParams, key: string): UUID[] | null;
|
|
9
|
+
static from(searchParams: URLSearchParams): SearchParamsUtils;
|
|
10
|
+
constructor(searchParams: URLSearchParams);
|
|
11
|
+
getString(key: string): string | null;
|
|
12
|
+
getStrings(key: string): string[] | null;
|
|
13
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
function _class_call_check(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
function _defineProperties(target, props) {
|
|
7
|
+
for(var i = 0; i < props.length; i++){
|
|
8
|
+
var descriptor = props[i];
|
|
9
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
+
descriptor.configurable = true;
|
|
11
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
12
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
16
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
+
return Constructor;
|
|
19
|
+
}
|
|
20
|
+
import { __privateAdd, __privateSet, __privateGet } from '../../chunk-AQ5VUG5P.js';
|
|
21
|
+
import { UUID } from '@powfix/uuid';
|
|
22
|
+
var _searchParams;
|
|
23
|
+
var _SearchParamsUtils = /*#__PURE__*/ function() {
|
|
24
|
+
"use strict";
|
|
25
|
+
function _SearchParamsUtils(searchParams) {
|
|
26
|
+
_class_call_check(this, _SearchParamsUtils);
|
|
27
|
+
__privateAdd(this, _searchParams);
|
|
28
|
+
__privateSet(this, _searchParams, searchParams);
|
|
29
|
+
}
|
|
30
|
+
_create_class(_SearchParamsUtils, [
|
|
31
|
+
{
|
|
32
|
+
key: "getString",
|
|
33
|
+
value: function getString(key) {
|
|
34
|
+
return _SearchParamsUtils.getString(__privateGet(this, _searchParams), key);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "getStrings",
|
|
39
|
+
value: function getStrings(key) {
|
|
40
|
+
return _SearchParamsUtils.getStrings(__privateGet(this, _searchParams), key);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
], [
|
|
44
|
+
{
|
|
45
|
+
key: "urlSearchParams",
|
|
46
|
+
get: function get() {
|
|
47
|
+
return new URL(window.location.href).searchParams;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
key: "getString",
|
|
52
|
+
value: function getString(searchParams, key) {
|
|
53
|
+
if (!searchParams.has(key)) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return searchParams.get(key);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: "getStrings",
|
|
61
|
+
value: function getStrings(searchParams, key) {
|
|
62
|
+
if (!searchParams.has(key)) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return searchParams.getAll(key);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
key: "getUuid",
|
|
70
|
+
value: function getUuid(searchParams, key) {
|
|
71
|
+
var value = this.getString(searchParams, key);
|
|
72
|
+
if (!UUID.isValid(value)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return UUID.from(value);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
key: "getUuids",
|
|
80
|
+
value: function getUuids(searchParams, key) {
|
|
81
|
+
var values = this.getStrings(searchParams, key);
|
|
82
|
+
if (values == null) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return values.filter(function(value) {
|
|
86
|
+
return UUID.isValid(value);
|
|
87
|
+
}).map(function(value) {
|
|
88
|
+
return UUID.from(value);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: "from",
|
|
94
|
+
value: function from(searchParams) {
|
|
95
|
+
return new _SearchParamsUtils(searchParams);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
]);
|
|
99
|
+
return _SearchParamsUtils;
|
|
100
|
+
}();
|
|
101
|
+
_searchParams = new WeakMap();
|
|
102
|
+
var SearchParamsUtils = _SearchParamsUtils;
|
|
103
|
+
export { SearchParamsUtils };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var SearchParamsUtils = require('./SearchParamsUtils');
|
|
3
|
+
Object.keys(SearchParamsUtils).forEach(function(k) {
|
|
4
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: function get() {
|
|
7
|
+
return SearchParamsUtils[k];
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SearchParamsUtils.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SearchParamsUtils.js';
|
|
@@ -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
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powfix/core-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.1",
|
|
4
4
|
"description": "core package",
|
|
5
5
|
"author": "Kwon Kyung-Min <powfix@gmail.com>",
|
|
6
6
|
"private": false,
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"uuid": "9.0.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@powfix/uuid": "^0.2.
|
|
65
|
+
"@powfix/uuid": "^0.2.17",
|
|
66
66
|
"@swc/core": "^1.13.5",
|
|
67
67
|
"@types/base-64": "1.0.2",
|
|
68
68
|
"@types/node": "^24.5.1",
|