@kakasoo/proto-typescript
Advanced tools
Comparing version 1.16.0 to 1.16.1
@@ -13,3 +13,3 @@ import { ToPrimitive } from '../interfaces/to-primitive.interface'; | ||
* | ||
* @param format 'int' | 'decimal' | ||
* @param format 'int' | 'decimal' | 'decimal(n,n)' | 'float' | ||
* @example | ||
@@ -16,0 +16,0 @@ * ```ts |
import { ArrayType } from './array.type'; | ||
import { NumberType } from './number.type'; | ||
import { StringType } from './string.type'; | ||
@@ -8,2 +9,3 @@ export interface StringToNumberMap { | ||
'3': 3; | ||
'4': 4; | ||
'5': 5; | ||
@@ -15,2 +17,14 @@ '6': 6; | ||
} | ||
export interface CeilingMap { | ||
'0': '1'; | ||
'1': '2'; | ||
'2': '3'; | ||
'3': '4'; | ||
'4': '5'; | ||
'5': '6'; | ||
'6': '7'; | ||
'7': '8'; | ||
'8': '9'; | ||
'9': '0'; | ||
} | ||
/** | ||
@@ -27,10 +41,43 @@ * 자리수를 의미하며, T가 1의 자리면 1, 10의 자리면 2, 100의 자리면 3, 이런 식으로 10의 N승 이상, N + 1 승 미만을 의미 | ||
export type StringToNumberStringTuple<T extends string> = T extends `${infer F}${infer Rest}` ? F extends keyof StringToNumberMap ? [StringToNumberMap[F], ...StringToNumberStringTuple<Rest>] : never : []; | ||
/** | ||
* 숫자와 문자 타입이 서로 오갈 수 있게 보조하는 두 타입 | ||
*/ | ||
export type NumberToString<N extends number> = `${N}`; | ||
export type StringToNumber<S extends string> = S extends NumberToString<infer P> ? P : never; | ||
export type Falsy = false | 0 | '' | null | undefined; | ||
export type Truthy<T> = T extends Falsy ? false : true; | ||
export type Conditional<Condition, T, F> = Truthy<Condition> extends true ? T : F; | ||
export declare namespace Math { | ||
type _FindLastCeilTarget<T extends `${number}`[], IndexFromLast extends number = 0> = T extends [ | ||
...infer Rest extends (keyof CeilingMap)[], | ||
infer BeforeLast extends keyof CeilingMap, | ||
infer Last | ||
] ? CeilingMap[BeforeLast] extends '0' ? _FindLastCeilTarget<[...Rest, BeforeLast], NumberType.Add<IndexFromLast, 1>> : IndexFromLast : never; | ||
/** | ||
* Throw away the last digit and add 1 to the next digit. | ||
* | ||
* @example | ||
* _Ceil<'230'> // 24 | ||
* _Ceil<'231'> // 24 | ||
* _Ceil<'232'> // 24 | ||
* _Ceil<'233'> // 24 | ||
* _Ceil<'234'> // 24 | ||
* _Ceil<'235'> // 24 | ||
* _Ceil<'236'> // 24 | ||
* _Ceil<'237'> // 24 | ||
* _Ceil<'238'> // 24 | ||
* _Ceil<'239'> // 24 | ||
*/ | ||
type _Ceil<N extends string> = StringType.Split<N> extends [ | ||
...infer Rest extends (keyof CeilingMap)[], | ||
infer BeforeLast extends keyof CeilingMap, | ||
infer Last extends keyof CeilingMap | ||
] ? CeilingMap[BeforeLast] extends '0' ? _Ceil<StringType.ThrowAway<N, _FindLastCeilTarget<StringType.Split<N>>>> : ArrayType.Join<[...Rest, CeilingMap[BeforeLast]], ''> : ''; | ||
/** | ||
* 여기서 말하는 N은 소숫점 이하의 숫자들임에 주의하라. | ||
*/ | ||
export type CeilFractional<N extends string, Length extends number = StringType.Length<N>> = StringType.PadEnd<_Ceil<N>, Length, '0'>; | ||
/** | ||
* Enter a number and round it to a certain digit. | ||
* If there is no decimal point, the original number must be returned without rounding. | ||
*/ | ||
export type _Round<N extends number, TargetDigit extends number> = N extends StringType.IsDecimal<N, number, number> ? StringType.InsertedFractional<N> extends string ? StringType.At<StringType.InsertedFractional<N>, TargetDigit> extends '5' | '6' | '7' | '8' | '9' ? `${StringType.InsertedInteger<N>}.${CeilFractional<StringType.InsertedFractional<N>, TargetDigit>}` : `${StringType.InsertedInteger<N>}.${StringType.ThrowAway<StringType.InsertedFractional<N>, NumberType.Sub<TargetDigit, 2>>}` : N : N; | ||
export type Round<N extends number, TargetDigit extends number> = _Round<StringType.ToNumber<StringType.Take<`${N}`, NumberType.Add<TargetDigit, 3>>>, TargetDigit>; | ||
export {}; | ||
} | ||
//# sourceMappingURL=arithmetic.type.d.ts.map |
@@ -108,3 +108,3 @@ import { NumberType } from './number.type'; | ||
*/ | ||
export type NTuple<N extends number, T extends ReadonlyOrNot<any[]> = []> = T['length'] extends N ? T : NTuple<N, ArrayType.Push<T, any>>; | ||
export type NTuple<N extends number, T extends ReadonlyOrNot<any[]> = [], defaultType = any> = T['length'] extends N ? T : NTuple<N, ArrayType.Push<T, defaultType>>; | ||
/** | ||
@@ -111,0 +111,0 @@ * N1 * N2 크기의 NTuple을 반환하는 타입으로, 최적화를 위해 N1, N2 숫자를 비교하는 과정이 포함된 타입 |
import { ArrayType, NNTuple, NTuple } from './array.type'; | ||
import { ReadonlyOrNot } from './primitive.type'; | ||
import { RegExpType } from './regexp.type'; | ||
import { StringType } from './string.type'; | ||
export declare namespace NumberType { | ||
/** | ||
* @todo Math.round type needed. | ||
*/ | ||
type ToFixed<N extends number, Length extends ArrayType.Values<LessThan<21>> = 0> = `${StringType.InsertedInteger<N>}.${StringType.PadEnd<`${ArrayType.Join<StringType.Split<`${StringType.InsertedFractional<N>}`, '', Length>, ''>}`, Length, '0'>}`; | ||
type NToNumber<N> = N extends number ? N : never; | ||
@@ -6,0 +11,0 @@ type NToNumberTuple<N> = N extends number[] ? N : never; |
@@ -63,7 +63,10 @@ import { Conditional } from './arithmetic.type'; | ||
export type IsInt<T extends number> = Includes<`${T}`, '.'> extends true ? ErrorType.IS_NOT_INT_FORMAT : T; | ||
type InsertedInteger<T extends number> = Split<`${T}`, '.'>[0]; | ||
type InsertedFractional<T extends number> = Split<`${T}`, '.'>[1]; | ||
export type InsertedInteger<T extends number> = Includes<`${T}`, '.'> extends true ? Split<`${T}`, '.'>[0] : ''; | ||
export type InsertedFractional<T extends number> = Includes<`${T}`, '.'> extends true ? Split<`${T}`, '.'>[1] : ''; | ||
export type IsDecimal<T extends number, Integer extends number, Fractional extends number> = InsertedInteger<T> extends `${number}` ? NumberType.Compare<Length<InsertedInteger<T>>, '=', Integer> extends true ? InsertedFractional<T> extends `${number}` ? NumberType.Compare<Length<InsertedFractional<T>>, '=', Fractional> extends true ? T : `INSERTED FRACTIONAL DOES NOT EQUAL. : ${InsertedFractional<T>}` : `INSERTED FRACTIONAL IS NOT NUMBER FORMAT. : ${InsertedFractional<T>}` : `INSERTED INTEGER DOES NOT EQUAL. : ${InsertedInteger<T>}` : `INSERTED INTEGER IS NOT NUMBER FORMAT. : ${InsertedInteger<T>}`; | ||
export type PadEnd<Container extends string, TargetLength extends number, PadString extends string = ' '> = NumberType.Compare<Length<Container>, '>=', TargetLength> extends true ? Container : NumberType.Compare<NumberType.Add<Length<Container>, Length<PadString>>, '<', TargetLength> extends true ? PadEnd<`${Container}${PadString}`, TargetLength, PadString> : `${Container}${ArrayType.Join<ArrayType.Take<Split<PadString>, NumberType.Sub<TargetLength, Length<Container>>>, ''>}`; | ||
export type Take<T extends string, P extends number> = ArrayType.Join<Split<T, '', P>, ''>; | ||
export type ThrowAway<T extends string, P extends number> = ArrayType.Join<Split<T, '', NumberType.Sub<StringType.Length<T>, P>>, ''>; | ||
export {}; | ||
} | ||
//# sourceMappingURL=string.type.d.ts.map |
{ | ||
"name": "@kakasoo/proto-typescript", | ||
"version": "1.16.0", | ||
"version": "1.16.1", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
116994
1320
0