mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-16 00:11:28 +00:00
Add isArrayLike builtin (#453)
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
@builtin export declare function isReference<T>(value?: T): bool;
|
||||
@builtin export declare function isString<T>(value?: T): bool;
|
||||
@builtin export declare function isArray<T>(value?: T): bool;
|
||||
@builtin export declare function isArrayLike<T>(value?: T): bool;
|
||||
@builtin export declare function isFunction<T>(value?: T): bool;
|
||||
@builtin export declare function isNullable<T>(value?: T): bool;
|
||||
@builtin export declare function isDefined(expression: void): bool;
|
||||
|
7
std/assembly/index.d.ts
vendored
7
std/assembly/index.d.ts
vendored
@ -128,6 +128,8 @@ declare function isReference<T>(value?: any): value is object | string;
|
||||
declare function isString<T>(value?: any): value is string | String;
|
||||
/** Tests if the specified type *or* expression can be used as an array. Compiles to a constant. */
|
||||
declare function isArray<T>(value?: any): value is Array<any>;
|
||||
/** Tests if the specified type *or* expression can be used as an array like object. Compiles to a constant. */
|
||||
declare function isArrayLike<T>(value?: any): value is ArrayLike<any>;
|
||||
/** Tests if the specified type *or* expression is of a function type. Compiles to a constant. */
|
||||
declare function isFunction<T>(value?: any): value is (...args: any) => any;
|
||||
/** Tests if the specified type *or* expression is of a nullable reference type. Compiles to a constant. */
|
||||
@ -559,6 +561,11 @@ declare class DataView {
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
interface ArrayLike<T> {
|
||||
length: i32;
|
||||
// [key: number]: T;
|
||||
}
|
||||
|
||||
/** Interface for a typed view on an array buffer. */
|
||||
interface ArrayBufferView<T> {
|
||||
[key: number]: T;
|
||||
|
7
std/portable/index.d.ts
vendored
7
std/portable/index.d.ts
vendored
@ -106,6 +106,8 @@ declare function isReference(value: any): value is object | string;
|
||||
declare function isString(value: any): value is string | String;
|
||||
/** Tests if the specified value can be used as an array. */
|
||||
declare function isArray(value: any): value is Array<any>;
|
||||
/** Tests if the specified type *or* expression can be used as an array like object. Compiles to a constant. */
|
||||
declare function isArrayLike(value: any): value is ArrayLike<any>;
|
||||
/** Tests if the specified expression resolves to a defined element. */
|
||||
declare function isDefined(expression: any): bool;
|
||||
/** Tests if the specified expression evaluates to a constant value. */
|
||||
@ -411,6 +413,11 @@ declare class Int32Array extends Array<i32> {}
|
||||
declare class Float32Array extends Array<f32> {}
|
||||
declare class Float64Array extends Array<f64> {}
|
||||
|
||||
interface ArrayLike<T> {
|
||||
length: i32;
|
||||
[key: number]: T;
|
||||
}
|
||||
|
||||
/** Interface for a typed view on an array buffer. */
|
||||
interface ArrayBufferView<T> {
|
||||
[key: number]: T;
|
||||
|
@ -215,6 +215,13 @@ globalScope["isString"] = function isString(arg) {
|
||||
};
|
||||
|
||||
globalScope["isArray"] = Array.isArray;
|
||||
globalScope["isArrayLike"] = function isArrayLike(expr) {
|
||||
return expr
|
||||
&& typeof expr === 'object'
|
||||
&& typeof expr.length === 'number'
|
||||
&& expr.length >= 0
|
||||
&& Math.trunc(expr.length) === expr.length;
|
||||
}
|
||||
|
||||
globalScope["isDefined"] = function isDefined(expr) {
|
||||
return typeof expr !== "undefined";
|
||||
|
Reference in New Issue
Block a user