README.md (2201B)
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 # isCircular 22 23 > Test if an object-like value contains a circular reference. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isCircular = require( '@stdlib/assert/is-circular' ); 31 ``` 32 33 #### isCircular( value ) 34 35 Test if an object-like `value` contains a circular reference. 36 37 ```javascript 38 var obj = { 39 'beep': 'boop' 40 }; 41 var bool = isCircular( obj ); 42 // returns false 43 44 obj.self = obj; 45 bool = isCircular( obj ); 46 // returns true 47 ``` 48 49 </section> 50 51 <!-- /.usage --> 52 53 <!-- /.usage --> 54 55 <section class="notes"> 56 57 ## Notes 58 59 - Object-like values include `objects` (except for `null`), `arrays`, `functions`, regular expressions, `Date` objects, and any other JavaScript object to which properties may be bound. 60 61 </section> 62 63 <!-- /.notes --> 64 65 <section class="examples"> 66 67 ## Examples 68 69 <!-- eslint-disable no-empty-function --> 70 71 <!-- eslint no-undef: "error" --> 72 73 ```javascript 74 var isCircular = require( '@stdlib/assert/is-circular' ); 75 76 var obj1 = { 77 'a': 'beep', 78 'b': { 79 'c': 'boop' 80 } 81 }; 82 obj1.b.self = obj1; 83 var bool = isCircular( obj1 ); 84 // returns true 85 86 var obj2 = { 87 'a': {}, 88 'b': obj1 89 }; 90 bool = isCircular( obj2 ); 91 // returns true 92 93 var arr = [ 1, 2, 3 ]; 94 arr.push( arr ); 95 bool = isCircular( arr ); 96 // returns true 97 98 function circ() {} 99 circ.self = circ; 100 bool = isCircular( circ ); 101 // returns true 102 103 var obj3 = { 104 'beep': 'boop' 105 }; 106 bool = isCircular({ 107 'a': obj3, 108 'b': obj3 109 }); 110 // returns false 111 112 bool = isCircular( {} ); 113 // returns false 114 115 bool = isCircular( null ); 116 // returns false 117 ``` 118 119 </section> 120 121 <!-- /.examples --> 122 123 <section class="links"> 124 125 </section> 126 127 <!-- /.links -->