@ls-stack/utils 3.2.9 → 3.2.10
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/lib/saferTyping.cjs +52 -0
- package/lib/saferTyping.d.cts +27 -0
- package/lib/saferTyping.d.ts +27 -0
- package/lib/saferTyping.js +23 -0
- package/lib/typingUtils.d.cts +7 -1
- package/lib/typingUtils.d.ts +7 -1
- package/package.json +5 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/saferTyping.ts
|
|
21
|
+
var saferTyping_exports = {};
|
|
22
|
+
__export(saferTyping_exports, {
|
|
23
|
+
__FIX_THIS_CASTING__: () => __FIX_THIS_CASTING__,
|
|
24
|
+
__FIX_THIS_TYPING__: () => __FIX_THIS_TYPING__,
|
|
25
|
+
__LEGIT_ANY_CAST__: () => __LEGIT_ANY_CAST__,
|
|
26
|
+
__LEGIT_CAST__: () => __LEGIT_CAST__,
|
|
27
|
+
__REFINE_CAST__: () => __REFINE_CAST__
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(saferTyping_exports);
|
|
30
|
+
function __LEGIT_ANY_CAST__(value) {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
function __LEGIT_CAST__(value) {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
function __REFINE_CAST__(value) {
|
|
37
|
+
return () => value;
|
|
38
|
+
}
|
|
39
|
+
function __FIX_THIS_CASTING__(value) {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
function __FIX_THIS_TYPING__(value) {
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
__FIX_THIS_CASTING__,
|
|
48
|
+
__FIX_THIS_TYPING__,
|
|
49
|
+
__LEGIT_ANY_CAST__,
|
|
50
|
+
__LEGIT_CAST__,
|
|
51
|
+
__REFINE_CAST__
|
|
52
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Use this only when you have 100% of certainty that this will not break the types */
|
|
2
|
+
type __LEGIT_ANY__ = any;
|
|
3
|
+
/**
|
|
4
|
+
* Cast a value to `any` type. Use this when you have legit usage of `any` casting.
|
|
5
|
+
*
|
|
6
|
+
* @template V (optional) - When used enforces that the casted value is assignable to the type V, use it for safer casts
|
|
7
|
+
*/
|
|
8
|
+
declare function __LEGIT_ANY_CAST__<V = unknown>(value: V): __LEGIT_ANY__;
|
|
9
|
+
/**
|
|
10
|
+
* Cast a value to a specific type T. Use this when you have legit usage of type assertion.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The type to cast to
|
|
13
|
+
* @template V (optional) - When used enforces that the casted value is assignable to the type V, use it for safer casts
|
|
14
|
+
*/
|
|
15
|
+
declare function __LEGIT_CAST__<T, V = unknown>(value: V): T;
|
|
16
|
+
/**
|
|
17
|
+
* Refine a value to a specific type T. Use this when you have legit usage of type assertion.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type to cast to
|
|
20
|
+
* @template V (optional) - When used enforces that the casted value is assignable to the type V, use it for safer casts
|
|
21
|
+
*/
|
|
22
|
+
declare function __REFINE_CAST__<T>(value: T): <R extends T>() => R;
|
|
23
|
+
declare function __FIX_THIS_CASTING__<T>(value: unknown): T;
|
|
24
|
+
type __FIX_THIS_TYPING__ = any;
|
|
25
|
+
declare function __FIX_THIS_TYPING__(value: unknown): __LEGIT_ANY__;
|
|
26
|
+
|
|
27
|
+
export { __FIX_THIS_CASTING__, __FIX_THIS_TYPING__, __LEGIT_ANY_CAST__, type __LEGIT_ANY__, __LEGIT_CAST__, __REFINE_CAST__ };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Use this only when you have 100% of certainty that this will not break the types */
|
|
2
|
+
type __LEGIT_ANY__ = any;
|
|
3
|
+
/**
|
|
4
|
+
* Cast a value to `any` type. Use this when you have legit usage of `any` casting.
|
|
5
|
+
*
|
|
6
|
+
* @template V (optional) - When used enforces that the casted value is assignable to the type V, use it for safer casts
|
|
7
|
+
*/
|
|
8
|
+
declare function __LEGIT_ANY_CAST__<V = unknown>(value: V): __LEGIT_ANY__;
|
|
9
|
+
/**
|
|
10
|
+
* Cast a value to a specific type T. Use this when you have legit usage of type assertion.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The type to cast to
|
|
13
|
+
* @template V (optional) - When used enforces that the casted value is assignable to the type V, use it for safer casts
|
|
14
|
+
*/
|
|
15
|
+
declare function __LEGIT_CAST__<T, V = unknown>(value: V): T;
|
|
16
|
+
/**
|
|
17
|
+
* Refine a value to a specific type T. Use this when you have legit usage of type assertion.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type to cast to
|
|
20
|
+
* @template V (optional) - When used enforces that the casted value is assignable to the type V, use it for safer casts
|
|
21
|
+
*/
|
|
22
|
+
declare function __REFINE_CAST__<T>(value: T): <R extends T>() => R;
|
|
23
|
+
declare function __FIX_THIS_CASTING__<T>(value: unknown): T;
|
|
24
|
+
type __FIX_THIS_TYPING__ = any;
|
|
25
|
+
declare function __FIX_THIS_TYPING__(value: unknown): __LEGIT_ANY__;
|
|
26
|
+
|
|
27
|
+
export { __FIX_THIS_CASTING__, __FIX_THIS_TYPING__, __LEGIT_ANY_CAST__, type __LEGIT_ANY__, __LEGIT_CAST__, __REFINE_CAST__ };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/saferTyping.ts
|
|
2
|
+
function __LEGIT_ANY_CAST__(value) {
|
|
3
|
+
return value;
|
|
4
|
+
}
|
|
5
|
+
function __LEGIT_CAST__(value) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
function __REFINE_CAST__(value) {
|
|
9
|
+
return () => value;
|
|
10
|
+
}
|
|
11
|
+
function __FIX_THIS_CASTING__(value) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function __FIX_THIS_TYPING__(value) {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
__FIX_THIS_CASTING__,
|
|
19
|
+
__FIX_THIS_TYPING__,
|
|
20
|
+
__LEGIT_ANY_CAST__,
|
|
21
|
+
__LEGIT_CAST__,
|
|
22
|
+
__REFINE_CAST__
|
|
23
|
+
};
|
package/lib/typingUtils.d.cts
CHANGED
|
@@ -10,5 +10,11 @@ type ObjKeysWithValuesOfType<Obj extends Record<PropertyKey, unknown>, ValueType
|
|
|
10
10
|
type IsAny<T> = unknown extends T ? [
|
|
11
11
|
keyof T
|
|
12
12
|
] extends [never] ? false : true : false;
|
|
13
|
+
type Prettify<T extends Record<string, unknown>> = {
|
|
14
|
+
[P in keyof T]: T[P];
|
|
15
|
+
} & {};
|
|
16
|
+
type DeepPrettify<T> = {
|
|
17
|
+
[K in keyof T]: T[K] extends Record<string, unknown> ? DeepPrettify<T[K]> : T[K];
|
|
18
|
+
} & {};
|
|
13
19
|
|
|
14
|
-
export type { IsAny, NonPartial, ObjKeysWithValuesOfType, PartialRecord };
|
|
20
|
+
export type { DeepPrettify, IsAny, NonPartial, ObjKeysWithValuesOfType, PartialRecord, Prettify };
|
package/lib/typingUtils.d.ts
CHANGED
|
@@ -10,5 +10,11 @@ type ObjKeysWithValuesOfType<Obj extends Record<PropertyKey, unknown>, ValueType
|
|
|
10
10
|
type IsAny<T> = unknown extends T ? [
|
|
11
11
|
keyof T
|
|
12
12
|
] extends [never] ? false : true : false;
|
|
13
|
+
type Prettify<T extends Record<string, unknown>> = {
|
|
14
|
+
[P in keyof T]: T[P];
|
|
15
|
+
} & {};
|
|
16
|
+
type DeepPrettify<T> = {
|
|
17
|
+
[K in keyof T]: T[K] extends Record<string, unknown> ? DeepPrettify<T[K]> : T[K];
|
|
18
|
+
} & {};
|
|
13
19
|
|
|
14
|
-
export type { IsAny, NonPartial, ObjKeysWithValuesOfType, PartialRecord };
|
|
20
|
+
export type { DeepPrettify, IsAny, NonPartial, ObjKeysWithValuesOfType, PartialRecord, Prettify };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ls-stack/utils",
|
|
3
3
|
"description": "Typescript utils",
|
|
4
|
-
"version": "3.2.
|
|
4
|
+
"version": "3.2.10",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib"
|
|
@@ -106,6 +106,10 @@
|
|
|
106
106
|
"import": "./lib/safeJson.js",
|
|
107
107
|
"require": "./lib/safeJson.cjs"
|
|
108
108
|
},
|
|
109
|
+
"./saferTyping": {
|
|
110
|
+
"import": "./lib/saferTyping.js",
|
|
111
|
+
"require": "./lib/saferTyping.cjs"
|
|
112
|
+
},
|
|
109
113
|
"./shallowEqual": {
|
|
110
114
|
"import": "./lib/shallowEqual.js",
|
|
111
115
|
"require": "./lib/shallowEqual.cjs"
|