README.md (3201B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # isCollection 22 23 > Test if a value is a collection. 24 25 <section class="intro"> 26 27 A collection is defined as either an [`Array`][mdn-array], [`Typed Array`][mdn-typed-array], or an array-like [`Object`][mdn-object] (excluding `strings` and `functions`). 28 29 </section> 30 31 <!-- ./intro --> 32 33 <section class="usage"> 34 35 ## Usage 36 37 ```javascript 38 var isCollection = require( '@stdlib/assert/is-collection' ); 39 ``` 40 41 #### isCollection( value ) 42 43 Tests if a value is a collection. 44 45 ```javascript 46 var bool = isCollection( [] ); 47 // returns true 48 ``` 49 50 </section> 51 52 <!-- /.usage --> 53 54 <section class="examples"> 55 56 ## Examples 57 58 <!-- eslint-disable object-curly-newline --> 59 60 <!-- eslint no-undef: "error" --> 61 62 ```javascript 63 var Int8Array = require( '@stdlib/array/int8' ); 64 var Uint8Array = require( '@stdlib/array/uint8' ); 65 var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); 66 var Int16Array = require( '@stdlib/array/int16' ); 67 var Uint16Array = require( '@stdlib/array/uint16' ); 68 var Int32Array = require( '@stdlib/array/int32' ); 69 var Uint32Array = require( '@stdlib/array/uint32' ); 70 var Float32Array = require( '@stdlib/array/float32' ); 71 var Float64Array = require( '@stdlib/array/float64' ); 72 var isCollection = require( '@stdlib/assert/is-collection' ); 73 74 var bool = isCollection( [] ); 75 // returns true 76 77 bool = isCollection( new Float64Array( 10 ) ); 78 // returns true 79 80 bool = isCollection( new Float32Array( 10 ) ); 81 // returns true 82 83 bool = isCollection( new Int32Array( 10 ) ); 84 // returns true 85 86 bool = isCollection( new Uint32Array( 10 ) ); 87 // returns true 88 89 bool = isCollection( new Int16Array( 10 ) ); 90 // returns true 91 92 bool = isCollection( new Uint16Array( 10 ) ); 93 // returns true 94 95 bool = isCollection( new Int8Array( 10 ) ); 96 // returns true 97 98 bool = isCollection( new Uint8Array( 10 ) ); 99 // returns true 100 101 bool = isCollection( new Uint8ClampedArray( 10 ) ); 102 // returns true 103 104 bool = isCollection( { 'length': 0 } ); 105 // returns true 106 107 bool = isCollection( {} ); 108 // returns false 109 110 bool = isCollection( 'beep' ); 111 // returns false 112 113 bool = isCollection( isCollection ); 114 // returns false 115 116 bool = isCollection( null ); 117 // returns false 118 119 bool = isCollection( void 0 ); 120 // returns false 121 122 bool = isCollection( 3.14 ); 123 // returns false 124 ``` 125 126 </section> 127 128 <!-- /.examples --> 129 130 <section class="links"> 131 132 [mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array 133 134 [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray 135 136 [mdn-object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object 137 138 </section> 139 140 <!-- /.links -->