repl.txt (2213B)
1 2 {{alias}}( obj[, options] ) 3 Flattens an object. 4 5 Parameters 6 ---------- 7 obj: ObjectLike 8 Object to flatten. 9 10 options: Object (optional) 11 Options. 12 13 options.depth: integer (optional) 14 Maximum depth to flatten. 15 16 options.copy: boolean (optional) 17 Boolean indicating whether to deep copy. Default: false. 18 19 options.flattenArrays: boolean (optional) 20 Boolean indicating whether to flatten arrays. Default: false. 21 22 options.delimiter: string (optional) 23 Key path delimiter. Default: '.'. 24 25 Returns 26 ------- 27 out: ObjectLike 28 Flattened object. 29 30 Examples 31 -------- 32 > var obj = { 'a': { 'b': { 'c': 'd' } } }; 33 > var out = {{alias}}( obj ) 34 { 'a.b.c': 'd' } 35 36 // Set the `depth` option to flatten to a specified depth: 37 > obj = { 'a': { 'b': { 'c': 'd' } } }; 38 > out = {{alias}}( obj, { 'depth': 1 } ) 39 { 'a.b': { 'c': 'd' } } 40 > var bool = ( obj.a.b === out[ 'a.b' ] ) 41 true 42 43 // Set the `delimiter` option: 44 > obj = { 'a': { 'b': { 'c': 'd' } } }; 45 > out = {{alias}}( obj, { 'delimiter': '-|-' } ) 46 { 'a-|-b-|-c': 'd' } 47 48 // Flatten arrays: 49 > obj = { 'a': { 'b': [ 1, 2, 3 ] } }; 50 > out = {{alias}}( obj, { 'flattenArrays': true } ) 51 { 'a.b.0': 1, 'a.b.1': 2, 'a.b.2': 3 } 52 53 54 {{alias}}.factory( [options] ) 55 Returns a function to flatten an object. 56 57 Parameters 58 ---------- 59 options: Object (optional) 60 Options. 61 62 options.depth: integer (optional) 63 Maximum depth to flatten. 64 65 options.copy: boolean (optional) 66 Boolean indicating whether to deep copy. Default: false. 67 68 options.flattenArrays: boolean (optional) 69 Boolean indicating whether to flatten arrays. Default: false. 70 71 options.delimiter: string (optional) 72 Key path delimiter. Default: '.'. 73 74 Returns 75 ------- 76 fcn: Function 77 Flatten function. 78 79 Examples 80 -------- 81 > var flatten = {{alias}}.factory({ 82 ... 'depth': 1, 83 ... 'copy': true, 84 ... 'delimiter': '|' 85 ... }); 86 > var obj = { 'a': { 'b': { 'c': 'd' } } }; 87 > var out = flatten( obj ) 88 { 'a|b': { 'c': 'd' } } 89 90 See Also 91 -------- 92