UNPKG

@stdlib/assert

Version:

Standard assertion utilities.

143 lines (90 loc) 3.92 kB
<!-- @license Apache-2.0 Copyright (c) 2021 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> # isEmptyCollection > Test if a value is an empty collection. <section class="usage"> ## Usage ```javascript var isEmptyCollection = require( '@stdlib/assert/is-empty-collection' ); ``` #### isEmptyCollection( value ) Tests if a value is an empty collection. ```javascript var bool = isEmptyCollection( [] ); // returns true ``` </section> <!-- /.usage --> <section class="examples"> ## Examples <!-- eslint-disable object-curly-newline --> <!-- eslint no-undef: "error" --> ```javascript var Int8Array = require( '@stdlib/array/int8' ); var Uint8Array = require( '@stdlib/array/uint8' ); var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); var Int16Array = require( '@stdlib/array/int16' ); var Uint16Array = require( '@stdlib/array/uint16' ); var Int32Array = require( '@stdlib/array/int32' ); var Uint32Array = require( '@stdlib/array/uint32' ); var Float32Array = require( '@stdlib/array/float32' ); var Float64Array = require( '@stdlib/array/float64' ); var isEmptyCollection = require( '@stdlib/assert/is-empty-collection' ); var bool = isEmptyCollection( [] ); // returns true bool = isEmptyCollection( new Float64Array( [] ) ); // returns true bool = isEmptyCollection( new Float32Array( [] ) ); // returns true bool = isEmptyCollection( new Int32Array( [] ) ); // returns true bool = isEmptyCollection( new Uint32Array( [] ) ); // returns true bool = isEmptyCollection( new Int16Array( [] ) ); // returns true bool = isEmptyCollection( new Uint16Array( [] ) ); // returns true bool = isEmptyCollection( new Int8Array( [] ) ); // returns true bool = isEmptyCollection( new Uint8Array( [] ) ); // returns true bool = isEmptyCollection( new Uint8ClampedArray( [] ) ); // returns true bool = isEmptyCollection( { 'length': 0 } ); // returns true bool = isEmptyCollection( [ 1, 2, 3, 4 ] ); // returns false bool = isEmptyCollection( {} ); // returns false ``` </section> <!-- /.examples --> <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> <section class="related"> * * * ## See Also - <span class="package-name">[`@stdlib/assert/is-collection`][@stdlib/assert/is-collection]</span><span class="delimiter">: </span><span class="description">test if a value is a collection.</span> - <span class="package-name">[`@stdlib/assert/is-empty-array`][@stdlib/assert/is-empty-array]</span><span class="delimiter">: </span><span class="description">test if a value is an empty array.</span> - <span class="package-name">[`@stdlib/assert/is-empty-array-like-object`][@stdlib/assert/is-empty-array-like-object]</span><span class="delimiter">: </span><span class="description">test if a value is an empty array-like object.</span> </section> <!-- /.related --> <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> <section class="links"> <!-- <related-links> --> [@stdlib/assert/is-collection]: https://github.com/stdlib-js/assert/tree/main/is-collection [@stdlib/assert/is-empty-array]: https://github.com/stdlib-js/assert/tree/main/is-empty-array [@stdlib/assert/is-empty-array-like-object]: https://github.com/stdlib-js/assert/tree/main/is-empty-array-like-object <!-- </related-links> --> </section> <!-- /.links -->