@kakasoo/proto-typescript
Advanced tools
Comparing version 1.16.1 to 1.17.0
@@ -11,3 +11,3 @@ import { ToPrimitive } from '../interfaces/to-primitive.interface'; | ||
*/ | ||
export declare class TypedString<T extends string | number | boolean = ''> extends TypedObject<T> implements Pick<FunctionType.MethodsFrom<String>, 'split' | 'at' | 'concat' | 'trimStart' | 'trimEnd' | 'trim'>, ToPrimitive<T | `${T}`> { | ||
export declare class TypedString<T extends string | number | boolean = ''> extends TypedObject<T> implements Pick<FunctionType.MethodsFrom<String>, 'split' | 'at' | 'concat' | 'trimStart' | 'trimEnd' | 'trim' | 'padEnd' | 'padStart'>, ToPrimitive<T | `${T}`> { | ||
private readonly string; | ||
@@ -18,2 +18,10 @@ constructor(data?: T); | ||
*/ | ||
padStart<TargetLength extends number, PadString extends string>(targetLength: TargetLength, padString: PadString): TypedString<ReturnType<typeof StringPrototype.padStart<`${T}`, TargetLength, PadString>>>; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
padEnd<TargetLength extends number, PadString extends string>(targetLength: TargetLength, padString: PadString): TypedString<ReturnType<typeof StringPrototype.padEnd<`${T}`, TargetLength, PadString>>>; | ||
/** | ||
* @inheritdoc | ||
*/ | ||
trim(): TypedString<ReturnType<typeof StringPrototype.trim<`${T}`>>>; | ||
@@ -32,2 +40,4 @@ /** | ||
concat<Strings extends ReadonlyOrNot<(string | TypedString<string>)[]>>(...strings: Strings): TypedString<ReturnType<typeof StringPrototype.concat<`${T}`, TypedString.ValueTypes<Strings>>>>; | ||
typedLength(): TypedNumber<StringType.Length<`${T}`>>; | ||
get length(): StringType.Length<`${T}`>; | ||
/** | ||
@@ -34,0 +44,0 @@ * If a value greater than the length of the current data is given as an index, it is inferred as underdefined that no wrapper exists. |
@@ -20,2 +20,16 @@ "use strict"; | ||
*/ | ||
padStart(targetLength, padString) { | ||
const initialValue = prototypes_1.StringPrototype.padStart(this.string, targetLength, padString ?? ' '); | ||
return new TypedString(initialValue); | ||
} | ||
/** | ||
* @inheritdoc | ||
*/ | ||
padEnd(targetLength, padString) { | ||
const initialValue = prototypes_1.StringPrototype.padEnd(this.string, targetLength, padString ?? ' '); | ||
return new TypedString(initialValue); | ||
} | ||
/** | ||
* @inheritdoc | ||
*/ | ||
trim() { | ||
@@ -47,2 +61,9 @@ const initialValue = prototypes_1.StringPrototype.trim(this.string); | ||
} | ||
typedLength() { | ||
return new typed_number_class_1.TypedNumber(this.length); | ||
} | ||
get length() { | ||
const primitiveLength = this.string.length; | ||
return primitiveLength; | ||
} | ||
/** | ||
@@ -49,0 +70,0 @@ * If a value greater than the length of the current data is given as an index, it is inferred as underdefined that no wrapper exists. |
@@ -5,2 +5,26 @@ import { ArrayType, StringType } from '../types'; | ||
/** | ||
* Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. | ||
* The padding is applied from the start (left) of the current string. | ||
* | ||
* @param targetLength The length of the resulting string once the current string has been padded. | ||
* If this parameter is smaller than the current string's length, the current string will be returned as it is. | ||
* | ||
* @param padString The string to pad the current string with. | ||
* If this string is too long, it will be truncated and the left-most part will be applied. | ||
* The default value for this parameter is " " (U+0020). | ||
*/ | ||
padStart<Conatiner extends string, TargetLength extends number, PadString extends string>(container: Conatiner, targetLength: TargetLength, padString: PadString): StringType.PadStart<Conatiner, TargetLength, PadString>; | ||
/** | ||
* Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. | ||
* The padding is applied from the end (right) of the current string. | ||
* | ||
* @param targetLength The length of the resulting string once the current string has been padded. | ||
* If this parameter is smaller than the current string's length, the current string will be returned as it is. | ||
* | ||
* @param padString The string to pad the current string with. | ||
* If this string is too long, it will be truncated and the left-most part will be applied. | ||
* The default value for this parameter is " " (U+0020). | ||
*/ | ||
padEnd<Conatiner_1 extends string, TargetLength_1 extends number, PadString_1 extends string>(container: Conatiner_1, targetLength: TargetLength_1, padString: PadString_1): StringType.PadEnd<Conatiner_1, TargetLength_1, PadString_1>; | ||
/** | ||
* Returns true if searchString appears as a substring of the result of converting this | ||
@@ -20,3 +44,3 @@ * object to a String, at one or more positions that are | ||
*/ | ||
trimStart<Conatiner extends string>(container: Conatiner): StringType.TrimStart<Conatiner>; | ||
trimStart<Conatiner_2 extends string>(container: Conatiner_2): StringType.TrimStart<Conatiner_2>; | ||
/** | ||
@@ -27,3 +51,3 @@ * Removes the trailing white space and line terminator characters from a string. | ||
*/ | ||
trimEnd<Conatiner_1 extends string>(container: Conatiner_1): StringType.TrimEnd<Conatiner_1>; | ||
trimEnd<Conatiner_3 extends string>(container: Conatiner_3): StringType.TrimEnd<Conatiner_3>; | ||
/** | ||
@@ -34,3 +58,3 @@ * Removes the leading and trailing white space and line terminator characters from a string. | ||
*/ | ||
trim<Conatiner_2 extends string>(container: Conatiner_2): StringType.TrimEnd<StringType.TrimStart<Conatiner_2>>; | ||
trim<Conatiner_4 extends string>(container: Conatiner_4): StringType.TrimEnd<StringType.TrimStart<Conatiner_4>>; | ||
/** | ||
@@ -37,0 +61,0 @@ * Returns a string that contains the concatenation of two or more strings. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.StringPrototype = void 0; | ||
String.prototype.includes; | ||
exports.StringPrototype = { | ||
/** | ||
* Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. | ||
* The padding is applied from the start (left) of the current string. | ||
* | ||
* @param targetLength The length of the resulting string once the current string has been padded. | ||
* If this parameter is smaller than the current string's length, the current string will be returned as it is. | ||
* | ||
* @param padString The string to pad the current string with. | ||
* If this string is too long, it will be truncated and the left-most part will be applied. | ||
* The default value for this parameter is " " (U+0020). | ||
*/ | ||
padStart(container, targetLength, padString) { | ||
return container.padStart(targetLength, padString ?? ' '); | ||
}, | ||
/** | ||
* Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. | ||
* The padding is applied from the end (right) of the current string. | ||
* | ||
* @param targetLength The length of the resulting string once the current string has been padded. | ||
* If this parameter is smaller than the current string's length, the current string will be returned as it is. | ||
* | ||
* @param padString The string to pad the current string with. | ||
* If this string is too long, it will be truncated and the left-most part will be applied. | ||
* The default value for this parameter is " " (U+0020). | ||
*/ | ||
padEnd(container, targetLength, padString) { | ||
return container.padEnd(targetLength, padString ?? ' '); | ||
}, | ||
/** | ||
* Returns true if searchString appears as a substring of the result of converting this | ||
@@ -8,0 +35,0 @@ * object to a String, at one or more positions that are |
@@ -61,3 +61,3 @@ import { Conditional } from './arithmetic.type'; | ||
export type At<Container extends string, Index extends number> = ArrayType.At<Split<Container>, Index>; | ||
export type Length<T extends string> = ArrayType.Length<Split<T>>; | ||
export type Length<T extends string> = ArrayType.Includes<Split<T>, string> extends true ? number : ArrayType.Length<Split<T>>; | ||
export type IsInt<T extends number> = Includes<`${T}`, '.'> extends true ? ErrorType.IS_NOT_INT_FORMAT : T; | ||
@@ -68,2 +68,3 @@ export type InsertedInteger<T extends number> = Includes<`${T}`, '.'> extends true ? Split<`${T}`, '.'>[0] : ''; | ||
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 PadStart<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 ? PadStart<`${PadString}${Container}`, TargetLength, PadString> : `${ArrayType.Join<ArrayType.Take<Split<PadString>, NumberType.Sub<TargetLength, Length<Container>>>, ''>}${Container}`; | ||
export type Take<T extends string, P extends number> = ArrayType.Join<Split<T, '', P>, ''>; | ||
@@ -70,0 +71,0 @@ export type ThrowAway<T extends string, P extends number> = ArrayType.Join<Split<T, '', NumberType.Sub<StringType.Length<T>, P>>, ''>; |
{ | ||
"name": "@kakasoo/proto-typescript", | ||
"version": "1.16.1", | ||
"version": "1.17.0", | ||
"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
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
124340
1404