@inzero/ts-ut 0.1.2 → 0.2.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 +7 -1
- package/dist/_internal.d.ts +21 -3
- package/dist/dict/index.d.ts +8 -8
- package/dist/func/index.d.ts +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/list/index.d.ts +1 -1
- package/dist/number/index.d.ts +2 -2
- package/dist/other/index.d.ts +2 -2
- package/dist/other/utils.d.ts +2 -5
- package/dist/string/index.d.ts +5 -5
- package/dist/tuple/index.d.ts +2 -2
- package/dist/tuple/push.d.ts +2 -18
- package/package.json +6 -2
package/CHANGELOG.md
CHANGED
package/dist/_internal.d.ts
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { Mutable } from "./dict";
|
|
2
|
+
import type { List, ROList } from "./list";
|
|
3
|
+
import type { Decrement, Increment, ToNumber } from "./number";
|
|
4
|
+
import type { AreEqual, IsAny, IsNever, IsSubtype, IsUnknown } from "./other";
|
|
5
|
+
import type { EnsurePrefix, Stringify } from "./string";
|
|
4
6
|
export type IsNegative<T extends string | number> = T extends T ? StartsWith<Stringify<T>, "-"> extends true ? true : false : never;
|
|
5
7
|
export type StartsWith<T extends string, P extends string> = T extends `${P}${string}` ? true : false;
|
|
6
8
|
export type As<T, U> = Extract<U, T>;
|
|
7
9
|
export type NormalizeIndex<I extends number, L extends number | ROList> = (L extends ROList ? L["length"] : L) extends infer Length extends number ? IsNegative<I> extends false ? IsNegative<Decrement<I, Length>> extends false ? Decrement<Length> : I : Increment<Length, I> extends infer Result extends number ? IsNegative<Result> extends true ? 0 : Result : never : never;
|
|
10
|
+
export type NegAbs<T extends number> = T extends 0 ? 0 : ToNumber<EnsurePrefix<Stringify<T>, "-">>;
|
|
11
|
+
export type FOE<T extends ROList, _C extends List = []> = T extends Required<T> ? -1 : T extends readonly [unknown, ...infer R extends ROList] ? FOE<R, [..._C, any]> : _C["length"];
|
|
12
|
+
export type SetFOE<T extends ROList, I extends number> = _SetFOE<T, NormalizeIndex<I, T["length"]>>;
|
|
13
|
+
export type _SetFOE<T extends ROList, I extends number, _I extends List = []> = T extends readonly [
|
|
14
|
+
infer F,
|
|
15
|
+
...infer R
|
|
16
|
+
] ? I extends _I["length"] ? [F?, ...Partial<R>] : [F, ..._SetFOE<R, I, [..._I, any]>] : T;
|
|
17
|
+
export type MatchTuple<T extends ROList, R extends ROList, D extends number = 0> = MatchRO<MatchFOI<T, R, D>, R>;
|
|
18
|
+
export type MatchFOI<T extends ROList, R extends ROList, D extends number = 0> = FOE<R> extends -1 ? BetterRequired<T> : SetFOE<BetterRequired<T>, Increment<FOE<R>, D>> extends infer R extends ROList ? R : never;
|
|
19
|
+
export type MatchRO<T extends ROList, R extends ROList> = Readonly<R> extends R ? Readonly<T> : Mutable<T>;
|
|
20
|
+
type BetterRequired<T> = T extends T ? Required<T> : never;
|
|
21
|
+
export type IsTuple<T> = T extends T ? Required<T> extends readonly [] | readonly [unknown, ...unknown[]] ? true : false : never;
|
|
22
|
+
export type IsPrimitive<T> = IsAny<T> | IsUnknown<T> | IsNever<T> extends false ? _IsPrimitive<_Wrap<T>> : false;
|
|
23
|
+
type _IsPrimitive<T> = T extends T ? AreEqual<T, [string]> | AreEqual<T, [number]> | AreEqual<T, [boolean]> extends false ? false : true : never;
|
|
24
|
+
type _Wrap<T> = (T extends T ? [T] : never) extends infer R ? IsSubtype<[true], R> | IsSubtype<[false], R> extends true ? [boolean] | Exclude<R, [boolean]> : R : never;
|
|
25
|
+
export {};
|
package/dist/dict/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
1
|
+
export * from './get';
|
|
2
|
+
export * from './keyof';
|
|
3
|
+
export * from './merge';
|
|
4
|
+
export * from './modifiers';
|
|
5
|
+
export * from './pick';
|
|
6
|
+
export * from './prefix';
|
|
7
|
+
export * from './rename';
|
|
8
|
+
export * from './utils';
|
package/dist/func/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './utils';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from './dict';
|
|
2
|
+
export * from './func';
|
|
3
|
+
export * from './list';
|
|
4
|
+
export * from './number';
|
|
5
|
+
export * from './other';
|
|
6
|
+
export * from './string';
|
|
7
|
+
export * from './tuple';
|
package/dist/list/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './utils';
|
package/dist/number/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './increment';
|
|
2
|
+
export * from './utils';
|
package/dist/other/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './utils';
|
|
2
|
+
export * from './validation';
|
package/dist/other/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IsPrimitive } from "../_internal";
|
|
2
|
+
import type { IsAny, IsUnknown } from "./validation";
|
|
2
3
|
/**
|
|
3
4
|
* An alias for `any`.
|
|
4
5
|
*/
|
|
@@ -33,7 +34,3 @@ export type Not<T extends boolean> = T extends true ? false : true;
|
|
|
33
34
|
* when `T` is `unknown`, `any` or a **primitive type** (string, number, boolean).
|
|
34
35
|
*/
|
|
35
36
|
export type SmartExtract<T, U> = T extends T ? IsUnknown<T> | IsAny<T> | IsPrimitive<T> extends false ? Extract<T, U> : Extract<U, T> : never;
|
|
36
|
-
type IsPrimitive<T> = IsAny<T> | IsUnknown<T> | IsNever<T> extends false ? _IsPrimitive<_Wrap<T>> : false;
|
|
37
|
-
type _IsPrimitive<T> = T extends T ? AreEqual<T, [string]> | AreEqual<T, [number]> | AreEqual<T, [boolean]> extends false ? false : true : never;
|
|
38
|
-
type _Wrap<T> = (T extends T ? [T] : never) extends infer R ? IsSubtype<[true], R> | IsSubtype<[false], R> extends true ? [boolean] | Exclude<R, [boolean]> : R : never;
|
|
39
|
-
export {};
|
package/dist/string/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from './extract';
|
|
2
|
+
export * from './firstChar';
|
|
3
|
+
export * from './prefix';
|
|
4
|
+
export * from './split';
|
|
5
|
+
export * from './utils';
|
package/dist/tuple/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './push';
|
|
2
|
+
export * from './utils';
|
package/dist/tuple/push.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type { As,
|
|
2
|
-
import type {
|
|
3
|
-
import type { List, ROList } from "../list";
|
|
4
|
-
import type { Increment, ToNumber } from "../number";
|
|
1
|
+
import type { As, IsTuple, MatchTuple, NegAbs } from "../_internal";
|
|
2
|
+
import type { ROList } from "../list";
|
|
5
3
|
import type { IsSubtype } from "../other";
|
|
6
|
-
import type { EnsurePrefix, Stringify } from "../string";
|
|
7
4
|
import type { Tuple } from "./utils";
|
|
8
5
|
/**
|
|
9
6
|
* Pushes an element to the end of a tuple.
|
|
@@ -45,16 +42,3 @@ export type Unshift<T extends ROList, E, S extends boolean = false> = [
|
|
|
45
42
|
* type R2 = Shift<[1, 2, 3?]>; // [2, 3?]
|
|
46
43
|
*/
|
|
47
44
|
export type Shift<T extends ROList, N extends number = 1> = Required<T> extends readonly [...Tuple<N>, ...infer Rest extends ROList] ? MatchTuple<Rest, T, NegAbs<N>> : [];
|
|
48
|
-
type NegAbs<T extends number> = T extends 0 ? 0 : ToNumber<EnsurePrefix<Stringify<T>, "-">>;
|
|
49
|
-
type FOE<T extends ROList, _C extends List = []> = T extends Required<T> ? -1 : T extends readonly [unknown, ...infer R extends ROList] ? FOE<R, [..._C, any]> : _C["length"];
|
|
50
|
-
type SetFOE<T extends ROList, I extends number> = _SetFOE<T, NormalizeIndex<I, T["length"]>>;
|
|
51
|
-
type _SetFOE<T extends ROList, I extends number, _I extends List = []> = T extends readonly [
|
|
52
|
-
infer F,
|
|
53
|
-
...infer R
|
|
54
|
-
] ? I extends _I["length"] ? [F?, ...Partial<R>] : [F, ..._SetFOE<R, I, [..._I, any]>] : T;
|
|
55
|
-
type MatchTuple<T extends ROList, R extends ROList, D extends number = 0> = MatchRO<MatchFOI<T, R, D>, R>;
|
|
56
|
-
type MatchFOI<T extends ROList, R extends ROList, D extends number = 0> = FOE<R> extends -1 ? BetterRequired<T> : SetFOE<BetterRequired<T>, Increment<FOE<R>, D>> extends infer R extends ROList ? R : never;
|
|
57
|
-
type MatchRO<T extends ROList, R extends ROList> = Readonly<R> extends R ? Readonly<T> : Mutable<T>;
|
|
58
|
-
type BetterRequired<T> = T extends T ? Required<T> : never;
|
|
59
|
-
type IsTuple<T> = T extends T ? Required<T> extends readonly [] | readonly [unknown, ...unknown[]] ? true : false : never;
|
|
60
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inzero/ts-ut",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "TypeScript Utility Types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"author": "InZero",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": "./dist/index.d.ts",
|
|
14
|
+
"./_internal": "./dist/_internal.d.ts",
|
|
14
15
|
"./string": "./dist/string/index.d.ts",
|
|
15
16
|
"./number": "./dist/number/index.d.ts",
|
|
16
17
|
"./func": "./dist/func/index.d.ts",
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
"CHANGELOG.md"
|
|
29
30
|
],
|
|
30
31
|
"devDependencies": {
|
|
32
|
+
"@inzero/barrel": "0.0.2",
|
|
31
33
|
"prettier": "^3.9.10",
|
|
32
34
|
"prettier-plugin-packagejson": "^3.0.2",
|
|
33
35
|
"typescript": "^7.0.2"
|
|
@@ -42,6 +44,8 @@
|
|
|
42
44
|
"scripts": {
|
|
43
45
|
"build": "tsc",
|
|
44
46
|
"dev": "tsc --watch",
|
|
45
|
-
"format": "prettier --write ."
|
|
47
|
+
"format": "prettier --write .",
|
|
48
|
+
"gen-barrel": "barrel src/index.ts src/*/index.ts",
|
|
49
|
+
"prepublish": "pnpm gen-barrel; pnpm build"
|
|
46
50
|
}
|
|
47
51
|
}
|