11/**
22@module @ember /array
33*/
4- import { DEBUG } from '@glimmer/env' ;
5- import { PROXY_CONTENT } from '@ember/-internals/metal/lib/property_get' ;
64import { objectAt } from '@ember/-internals/metal/lib/object-at' ;
75import { replaceInNativeArray , replace } from '@ember/-internals/metal/lib/array' ;
86import computed from '@ember/-internals/metal/lib/computed' ;
@@ -17,11 +15,11 @@ import { assert } from '@ember/debug';
1715import Enumerable from '@ember/enumerable' ;
1816import MutableEnumerable from '@ember/enumerable/mutable' ;
1917import compare from '@ember/utils/lib/compare' ;
20- import typeOf from '@ember/utils/lib/type-of' ;
2118import Observable from '@ember/object/observable' ;
2219import type { MethodNamesOf , MethodParams , MethodReturns } from '@ember/-internals/utility-types' ;
2320import type { ComputedPropertyCallback } from '@ember/-internals/metal/lib/computed' ;
2421import { isEmberArray , setEmberArray } from '@ember/array/-internals' ;
22+ import isArray from './lib/is-array' ;
2523
2624export { default as makeArray } from './make' ;
2725
@@ -137,65 +135,7 @@ function insertAt<T>(array: MutableArray<T>, index: number, item: T) {
137135 return item ;
138136}
139137
140- /**
141- Returns true if the passed object is an array or Array-like.
142-
143- Objects are considered Array-like if any of the following are true:
144-
145- - the object is a native Array
146- - the object has an objectAt property
147- - the object is an Object, and has a length property
148-
149- Unlike `typeOf` this method returns true even if the passed object is
150- not formally an array but appears to be array-like (i.e. implements `Array`)
151-
152- ```javascript
153- import { isArray } from '@ember/array';
154- import ArrayProxy from '@ember/array/proxy';
155-
156- isArray(); // false
157- isArray([]); // true
158- isArray(ArrayProxy.create({ content: [] })); // true
159- ```
160-
161- @method isArray
162- @static
163- @for @ember /array
164- @param {Object } obj The object to test
165- @return {Boolean } true if the passed object is an array or Array-like
166- @public
167- */
168- export function isArray ( obj : unknown ) : obj is ArrayLike < unknown > | EmberArray < unknown > {
169- if ( DEBUG && typeof obj === 'object' && obj !== null ) {
170- // SAFETY: Property read checks are safe if it's an object
171- let possibleProxyContent = ( obj as any ) [ PROXY_CONTENT ] ;
172- if ( possibleProxyContent !== undefined ) {
173- obj = possibleProxyContent ;
174- }
175- }
176-
177- // SAFETY: Property read checks are safe if it's an object
178- if ( ! obj || ( obj as any ) . setInterval ) {
179- return false ;
180- }
181-
182- if ( Array . isArray ( obj ) || EmberArray . detect ( obj ) ) {
183- return true ;
184- }
185-
186- let type = typeOf ( obj ) ;
187- if ( 'array' === type ) {
188- return true ;
189- }
190-
191- // SAFETY: Property read checks are safe if it's an object
192- let length = ( obj as any ) . length ;
193- if ( typeof length === 'number' && length === length && 'object' === type ) {
194- return true ;
195- }
196-
197- return false ;
198- }
138+ export { isArray } ;
199139
200140/*
201141 This allows us to define computed properties that are not enumerable.
0 commit comments