@kakasoo/proto-typescript
Advanced tools
Comparing version 1.8.0 to 1.9.0
@@ -1,10 +0,29 @@ | ||
import { At, Concat, Join } from '../types'; | ||
import { At, Concat, Join, ArraySome } from '../types'; | ||
import { ReadonlyOrNot } from '../types/primitive.type'; | ||
export declare const ArrayPrototype: { | ||
push<Conatiner extends ReadonlyOrNot<any[]>, Items extends ReadonlyOrNot<any[]>>(container: Conatiner, ...items: Items): [...Conatiner, ...Items]; | ||
/** | ||
* @param container | ||
* @param items | ||
* @returns | ||
*/ | ||
unshift<Conatiner extends ReadonlyOrNot<any[]>, Items extends ReadonlyOrNot<any[]>>(container: Conatiner, ...items: Items): [...Items, ...Conatiner]; | ||
/** | ||
* @todo add paramter of this method, named `thisArg`. | ||
* | ||
* @param container | ||
* @param predicate | ||
* @returns | ||
*/ | ||
some<Target, Conatiner_1 extends ReadonlyOrNot<any[]>>(container: Conatiner_1, predicate: <INNER_TARGET = Target, Index extends number = number>(value: At<Conatiner_1, Index>, index: Index, array: Conatiner_1) => ArraySome<INNER_TARGET, Conatiner_1>): boolean; | ||
/** | ||
* @param container | ||
* @param items | ||
* @returns | ||
*/ | ||
push<Conatiner_2 extends ReadonlyOrNot<any[]>, Items_1 extends ReadonlyOrNot<any[]>>(container: Conatiner_2, ...items: Items_1): [...Conatiner_2, ...Items_1]; | ||
/** | ||
* @inheritdoc | ||
* @param container | ||
*/ | ||
at<Container extends ReadonlyOrNot<any[]>, Index extends number>(container: Container, index: Index): At<Container, Index>; | ||
at<Container extends ReadonlyOrNot<any[]>, Index_1 extends number>(container: Container, index: Index_1): At<Container, Index_1>; | ||
/** | ||
@@ -11,0 +30,0 @@ * type-safe join. |
@@ -5,2 +5,30 @@ "use strict"; | ||
exports.ArrayPrototype = { | ||
/** | ||
* @param container | ||
* @param items | ||
* @returns | ||
*/ | ||
unshift(container, ...items) { | ||
return [...items, ...container]; | ||
}, | ||
/** | ||
* @todo add paramter of this method, named `thisArg`. | ||
* | ||
* @param container | ||
* @param predicate | ||
* @returns | ||
*/ | ||
some(container, predicate) { | ||
for (let i = 0; i < container.length; i++) { | ||
if (predicate(container[i], i, container)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}, | ||
/** | ||
* @param container | ||
* @param items | ||
* @returns | ||
*/ | ||
push(container, ...items) { | ||
@@ -7,0 +35,0 @@ return [...container, ...items]; |
@@ -5,5 +5,5 @@ import { toPrimitive } from './interfaces/to-primitive.interface'; | ||
import { TypedString } from './typed-string.class'; | ||
import { ElementOf, MethodsFrom } from './types'; | ||
import { ArraySome, At, ElementOf, MethodsFrom } from './types'; | ||
import { ReadonlyOrNot } from './types/primitive.type'; | ||
export declare class TypedArray<T extends ReadonlyOrNot<any[]>> implements Pick<MethodsFrom<Array<any>>, 'join' | 'at' | 'push'>, toPrimitive<[...T]>, Iterable<ElementOf<T>> { | ||
export declare class TypedArray<T extends ReadonlyOrNot<any[]>> implements Pick<MethodsFrom<Array<ElementOf<T>>>, 'join' | 'at' | 'push' | 'some' | 'unshift'>, toPrimitive<[...T]>, Iterable<ElementOf<T>> { | ||
private readonly data; | ||
@@ -14,4 +14,21 @@ constructor(data: T); | ||
/** | ||
* Appends new elements to the end of an array | ||
* @inheritdoc | ||
* @example | ||
* ```ts | ||
* new TypedArray([1, 2, 3] as const).unshift(4 as const); // [4, 1, 2, 3] | ||
* ``` | ||
* | ||
* @param items | ||
* @returns Unlike JavaScript's Array.prototype.unshift, it returns a new TypeArray instance rather than the length of the inserted data. | ||
*/ | ||
unshift<Items extends ReadonlyOrNot<ElementOf<T>[]>>(...items: Items): TypedArray<ReturnType<typeof ArrayPrototype.unshift<T, Items>>>; | ||
/** | ||
* @inheritdoc | ||
* | ||
* I'm reviewing whether internal functions that are different from the existing som should be provided by default for type inference. | ||
* @todo add function named `IsSameElement` for type inference. | ||
*/ | ||
some<Target>(predicate: <INNER_TARGET = Target, Index extends number = number>(value: At<T, Index>, index: Index, array: T) => ArraySome<INNER_TARGET, T>): ReturnType<typeof ArrayPrototype.some>; | ||
/** | ||
* @inheritdoc | ||
* @example | ||
@@ -23,3 +40,3 @@ * ```ts | ||
* @param items | ||
* @returns Unlike JavaScript's Array.prototype.join, it returns a new TypeArray instance rather than the length of the inserted data. | ||
* @returns Unlike JavaScript's Array.prototype.push, it returns a new TypeArray instance rather than the length of the inserted data. | ||
*/ | ||
@@ -26,0 +43,0 @@ push<Items extends ReadonlyOrNot<ElementOf<T>[]>>(...items: Items): TypedArray<ReturnType<typeof ArrayPrototype.push<T, Items>>>; |
@@ -23,4 +23,25 @@ "use strict"; | ||
/** | ||
* Appends new elements to the end of an array | ||
* @inheritdoc | ||
* @example | ||
* ```ts | ||
* new TypedArray([1, 2, 3] as const).unshift(4 as const); // [4, 1, 2, 3] | ||
* ``` | ||
* | ||
* @param items | ||
* @returns Unlike JavaScript's Array.prototype.unshift, it returns a new TypeArray instance rather than the length of the inserted data. | ||
*/ | ||
unshift(...items) { | ||
return new TypedArray([...items, ...this.data]); | ||
} | ||
/** | ||
* @inheritdoc | ||
* | ||
* I'm reviewing whether internal functions that are different from the existing som should be provided by default for type inference. | ||
* @todo add function named `IsSameElement` for type inference. | ||
*/ | ||
some(predicate) { | ||
return prototypes_1.ArrayPrototype.some(this.data, predicate); | ||
} | ||
/** | ||
* @inheritdoc | ||
* @example | ||
@@ -32,3 +53,3 @@ * ```ts | ||
* @param items | ||
* @returns Unlike JavaScript's Array.prototype.join, it returns a new TypeArray instance rather than the length of the inserted data. | ||
* @returns Unlike JavaScript's Array.prototype.push, it returns a new TypeArray instance rather than the length of the inserted data. | ||
*/ | ||
@@ -35,0 +56,0 @@ push(...items) { |
@@ -106,2 +106,10 @@ import { Add, Divide, Multiply, NToNumber, Remainder, Sub } from './number.type'; | ||
export type At<Tuple extends ReadonlyOrNot<any[]>, Index extends number> = Tuple[Index]; | ||
/** | ||
* If any of the type elements constituting Union Type U correspond to `If`, it returns true or false. | ||
*/ | ||
export type UnionSome<If, U, T, F> = T extends (U extends If ? T : F) ? T : F; | ||
/** | ||
* If any of the type elements constituting Tuple Type U correspond to `If`, it returns true or false. | ||
*/ | ||
export type ArraySome<Target, Tuple extends ReadonlyOrNot<any[]>> = UnionSome<Target, Tuple[number], true, false> | boolean; | ||
//# sourceMappingURL=array.type.d.ts.map |
{ | ||
"name": "@kakasoo/proto-typescript", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
# proto-typescript | ||
Utility types and implementations based on JavaScript prototypes. | ||
I plan to share the features that are officially available from 2.0.0. |
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
66371
732
5