├── assets └── demo.gif ├── .github ├── FUNDING.yml └── workflows │ └── test.yml ├── .gitignore ├── .prettierrc ├── .npmignore ├── examples └── point.js ├── package.json ├── LICENSE ├── test └── ocat.js ├── README.md └── ocat.js /assets/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thlorenz/ocat/HEAD/assets/demo.gif -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: thlorenz 2 | patreon: thlorenz 3 | custom: ['paypal.me/thlorenz'] 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules 16 | .idea/ 17 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "trailingComma": "es5", 5 | "useTabs": false, 6 | "tabWidth": 2, 7 | "arrowParens": "avoid", 8 | "printWidth": 80 9 | } 10 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules 16 | assets/ 17 | .idea/ 18 | .github/ 19 | examples/ 20 | test/ 21 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Node CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | strategy: 11 | matrix: 12 | node-version: [12.x, 13.x] 13 | 14 | steps: 15 | - uses: actions/checkout@v1 16 | - name: Use Node.js ${{ matrix.node-version }} 17 | uses: actions/setup-node@v1 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | - name: npm install, lint and test 21 | run: | 22 | npm install 23 | npm run lint 24 | npm test 25 | env: 26 | CI: true 27 | -------------------------------------------------------------------------------- /examples/point.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var test = require('tape') 4 | var ocat = require('../') 5 | 6 | function Point(x, y, z) { 7 | if (!(this instanceof Point)) return new Point(x, y, z) 8 | 9 | this.x = x 10 | this.y = y 11 | this.z = z 12 | } 13 | 14 | var proto = Point.prototype 15 | 16 | function add(p1, p2) { 17 | return new Point(p1.x + p2.x, p1.y + p2.y, p1.z + p2.z) 18 | } 19 | 20 | var deepEqualOpts = { 21 | prefix: ' t.deepEqual(p3, ', 22 | suffix: ", 'adds points correctly')", 23 | indent: '', 24 | } 25 | ocat.opts = deepEqualOpts 26 | 27 | test('\nPoint(100, 200, 300) + Point(1000, 2000, 3000 ) == Point(1100, 2200, 3300) ', function(t) { 28 | var p1 = new Point(100, 200, 300) 29 | var p2 = new Point(1000, 2000, 3000) 30 | var p3 = add(p1, p2) 31 | 32 | ocat.file(p3) 33 | ocat.log(p3) 34 | t.end() 35 | }) 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ocat", 3 | "version": "0.3.0", 4 | "description": "Inspect an object various ways in order to easily generate test cases.", 5 | "main": "ocat.js", 6 | "scripts": { 7 | "test": "tape test/*.js", 8 | "lint": "prettier -c test/*.js examples/*.js *.js", 9 | "lint:fix": "prettier --write test/*.js examples/*.js *.js" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git://github.com/thlorenz/ocat.git" 14 | }, 15 | "homepage": "https://github.com/thlorenz/ocat", 16 | "dependencies": { 17 | "xtend": "~4.0.0" 18 | }, 19 | "devDependencies": { 20 | "prettier": "^1.19.1", 21 | "tape": "~4.0.0" 22 | }, 23 | "keywords": [ 24 | "inspect", 25 | "log", 26 | "test", 27 | "generate" 28 | ], 29 | "author": { 30 | "name": "Thorsten Lorenz", 31 | "email": "thlorenz@gmx.de", 32 | "url": "http://thlorenz.com" 33 | }, 34 | "license": { 35 | "type": "MIT", 36 | "url": "https://github.com/thlorenz/ocat/blob/master/LICENSE" 37 | }, 38 | "engine": { 39 | "node": ">=8" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 Thorsten Lorenz. 2 | All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /test/ocat.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const test = require('tape') 4 | const ocat = require('../') 5 | const fs = require('fs') 6 | 7 | function inspect(obj, depth) { 8 | console.error(require('util').inspect(obj, false, depth || 5, true)) 9 | } 10 | 11 | const obj = { 12 | uno: 1, 13 | dos: 'zwei', 14 | tres: { num: 'drei' }, 15 | hello: 'world', 16 | array: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 17 | } 18 | 19 | function nonEmptyLines(lines) { 20 | return lines.split('\n').filter(function(x) { 21 | return x.length 22 | }) 23 | } 24 | 25 | // don't use color in tests 26 | ocat.opts.color = false 27 | test('\ndefault opts (no color)', function(t) { 28 | ocat.rm() 29 | ocat.file(obj) 30 | const logged = fs.readFileSync(ocat.tmpFile).toString() 31 | 32 | t.deepEqual( 33 | nonEmptyLines(logged), 34 | [ 35 | ' { uno: 1', 36 | " , dos: 'zwei'", 37 | " , tres: { num: 'drei' }", 38 | " , hello: 'world'", 39 | ' , array: [', 40 | ' 0, 1, 2, 3, 4', 41 | ' , 5, 6, 7, 8, 9', 42 | ' ] }', 43 | ], 44 | 'logs correct output' 45 | ) 46 | t.end() 47 | }) 48 | 49 | test('\nper method overrides', function(t) { 50 | ocat.rm() 51 | ocat.file(obj, { 52 | prefix: 'pre-\n', 53 | suffix: '\n-suf', 54 | indent: ' ', 55 | commaFirst: false, 56 | }) 57 | 58 | const logged = fs.readFileSync(ocat.tmpFile).toString() 59 | t.deepEqual( 60 | nonEmptyLines(logged), 61 | [ 62 | 'pre-', 63 | ' { uno: 1,', 64 | " dos: 'zwei',", 65 | " tres: { num: 'drei' },", 66 | " hello: 'world',", 67 | ' array: [', 68 | ' 0, 1, 2, 3, 4,', 69 | ' 5, 6, 7, 8, 9', 70 | ' ] }', 71 | '-suf', 72 | ], 73 | 'logs correct output' 74 | ) 75 | 76 | t.end() 77 | }) 78 | 79 | test('\nglobal settings', function(t) { 80 | ocat.opts.indent = ' ' 81 | ocat.opts.prefix = '---pre: \n' 82 | ocat.opts.suffix = '\n---suf' 83 | 84 | ocat.rm() 85 | ocat.file(obj) 86 | 87 | const logged = fs.readFileSync(ocat.tmpFile).toString() 88 | t.deepEqual( 89 | nonEmptyLines(logged), 90 | [ 91 | '---pre: ', 92 | ' { uno: 1', 93 | " , dos: 'zwei'", 94 | " , tres: { num: 'drei' }", 95 | " , hello: 'world'", 96 | ' , array: [', 97 | ' 0, 1, 2, 3, 4', 98 | ' , 5, 6, 7, 8, 9', 99 | ' ] }', 100 | '---suf', 101 | ], 102 | 'logs correct output' 103 | ) 104 | t.end() 105 | }) 106 | 107 | test('\nglobal settings and overrides', function(t) { 108 | ocat.opts.indent = ' ' 109 | ocat.opts.prefix = '---pre: \n' 110 | ocat.opts.suffix = '\n---suf' 111 | 112 | ocat.rm() 113 | ocat.file(obj, { 114 | prefix: 'pre-\n', 115 | commaFirst: false, 116 | }) 117 | 118 | const logged = fs.readFileSync(ocat.tmpFile).toString() 119 | t.deepEqual( 120 | nonEmptyLines(logged), 121 | [ 122 | 'pre-', 123 | ' { uno: 1,', 124 | " dos: 'zwei',", 125 | " tres: { num: 'drei' },", 126 | " hello: 'world',", 127 | ' array: [', 128 | ' 0, 1, 2, 3, 4,', 129 | ' 5, 6, 7, 8, 9', 130 | ' ] }', 131 | '---suf', 132 | ], 133 | 'logs correct output' 134 | ) 135 | t.end() 136 | }) 137 | 138 | test('\nbag', function(t) { 139 | ocat.resetOpts() 140 | ocat.opts.color = false 141 | 142 | ocat.bag(obj) 143 | const logged = ocat._bagged[0] 144 | 145 | t.deepEqual( 146 | nonEmptyLines(logged), 147 | [ 148 | ' { uno: 1', 149 | " , dos: 'zwei'", 150 | " , tres: { num: 'drei' }", 151 | " , hello: 'world'", 152 | ' , array: [', 153 | ' 0, 1, 2, 3, 4', 154 | ' , 5, 6, 7, 8, 9', 155 | ' ] }', 156 | ], 157 | 'logs correct output' 158 | ) 159 | t.end() 160 | }) 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ocat [![](https://github.com/thlorenz/ocat/workflows/Node%20CI/badge.svg?branch=master)](https://github.com/thlorenz/ocat/actions) 2 | 3 | Inspect an object various ways in order to easily generate test cases. 4 | 5 | [![assets/demo.gif](assets/demo.gif)](https://raw.githubusercontent.com/thlorenz/ocat/master/assets/demo.gif) 6 | 7 | ## Installation 8 | 9 | npm install ocat 10 | 11 | ## [API](http://thlorenz.github.io/ocat) 12 | 13 | 14 | 15 | ### ocat.inspect 16 | 17 | Inspects object and returns result. 18 | 19 | **Parameters** 20 | 21 | - `obj` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** to inspect 22 | - `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** options (same as @see ocat.log) 23 | 24 | ### ocat.bag 25 | 26 | Inspects object and adds results to a bag. 27 | This entire bag is logged at `process.on('exit')`. 28 | 29 | **Parameters** 30 | 31 | - `obj` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** to inspect 32 | - `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** options (same as @see ocat.log) 33 | 34 | ### ocat.file 35 | 36 | Same as @see ocat.log, but writes to ocat.tmpFile \* at `/tmp/ocat.txt` 37 | on Unixes and who knows on Windows (`os.tmpdir()/ocat.txt`). 38 | 39 | This is useful if you want to read isolated ocat output into your editor 40 | without other output, i.e. by your test runner. 41 | 42 | **Vim Example**: 43 | 44 | :r !OCAT_COLOR=0 OCAT_DEPTH=0 OCAT_RM=1 node % 2>&1 > /dev/null && cat /tmp/ocat.txt 45 | 46 | will read the ocat printed output right into your editor. 47 | You should probably bind that to a shortcut. ;) 48 | 49 | **Tail Example**: 50 | 51 | In another terminal pane do: 52 | 53 | tail -f /tmp/ocat.txt 54 | 55 | to see logged objects every time you run your tests/code. 56 | 57 | **Parameters** 58 | 59 | - `obj` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** to inspect 60 | - `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** options (same as @see ocat.log) with `color: false` 61 | 62 | ### ocat.log 63 | 64 | Inspects object and logs it to _stderr_ immediately. 65 | 66 | The given opts override all other options for each supplied property, which are derived as follows: 67 | 68 | 1. ocat.opts, the default opts: 69 | `prefix: '', suffix: '', indent: '', color: true, depth: 1, commaFirst: true` 70 | 2. `OCAT_COLOR` and `OCAT_COMMAFIRST` to override the related defaults, i.e. 71 | `OCAT_COLOR=0 node my.js` includes no colors 72 | 3. opts passed to `ocat.create` for that `ocat` instance only 73 | 4. opts passed to `ocat.log` and `ocat.bag` 74 | 75 | **Parameters** 76 | 77 | - `obj` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** object to inspect 78 | - `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** options inherit from opts passed to `create` and then `ocat.opts`. 79 | - `opts.prefix` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** the prefix to insert before the logged object 80 | - `opts.suffix` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** the suffix to insert after the logged object 81 | - `opts.indent` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** the indentation to apply to each line 82 | - `opts.color` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** if `true` logging in colors 83 | - `opts.depth` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** depth to which the object is inspected 84 | - `opts.commaFirst` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** if `true` commaFirst style is used when logging without color\*\* (default: `true`) 85 | 86 | ### ocat.applyRes5Opts 87 | 88 | Applies preconfigured opts with prefix + indentation and depth 89 | that work well in lots of scenarios. 90 | 91 | #### Example 92 | 93 | ```js 94 | const ocat = require('ocat').applyRes5Opts() 95 | ``` 96 | 97 | Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** ocat 98 | 99 | ### ocat.opts 100 | 101 | Start out as default options @see ocat.log. 102 | Allow overriding ocat options for **all** instances. 103 | 104 | ### ocat.resetOpts 105 | 106 | Resets ocat.opts to default opts. 107 | 108 | ### ocat.create 109 | 110 | Creates an ocat instance with the supplied options. 111 | 112 | **Parameters** 113 | 114 | - `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** options (same as @see ocat.log) 115 | 116 | Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** ocat instance 117 | 118 | ### ocat.tmpFile 119 | 120 | The file into which ocat.file writes. 121 | Set it to any other path you like to use instead. 122 | 123 | ### ocat.rm 124 | 125 | Removes the ocat.tmpFile 126 | If the an env var `OCAT_RM=1` is present, the file is removed on startup. 127 | 128 | ## License 129 | 130 | MIT 131 | -------------------------------------------------------------------------------- /ocat.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const xtend = require('xtend') 4 | const utilInspect = require('util').inspect 5 | const fs = require('fs') 6 | const path = require('path') 7 | const os = require('os') 8 | 9 | const isOperatingSystem = !/^win/.test(process.platform) 10 | const tmpFile = isOperatingSystem 11 | ? path.join('/tmp', 'ocat.txt') 12 | : path.join(os.tmpdir(), 'ocat.txt') 13 | 14 | const env = process.env 15 | 16 | const defaultOpts = { 17 | prefix: '', 18 | suffix: '', 19 | indent: '', 20 | color: typeof env.OCAT_COLOR !== 'undefined' ? env.OCAT_COLOR !== '0' : true, 21 | depth: typeof env.OCAT_DEPTH !== 'undefined' ? parseInt(env.OCAT_DEPTH) : 1, 22 | commaFirst: 23 | typeof env.OCAT_COMMAFIRST !== 'undefined' 24 | ? env.OCAT_COMMAFIRST === '1' 25 | : true, 26 | } 27 | 28 | function logstderr(item) { 29 | console.error(item) 30 | } 31 | 32 | function Ocat(opts) { 33 | if (!(this instanceof Ocat)) return new Ocat(opts) 34 | this._registered = false 35 | this._bagged = [] 36 | 37 | this._opts = opts 38 | } 39 | 40 | const proto = Ocat.prototype 41 | 42 | /** 43 | * Inspects object and adds results to a bag. 44 | * This entire bag is logged at `process.on('exit')`. 45 | * 46 | * @name ocat.bag 47 | * @function 48 | * @param {Object} obj to inspect 49 | * @param {Object} opts options (same as @see ocat.log) 50 | */ 51 | proto.bag = function bag(obj, opts) { 52 | this._bagged.push(this.inspect(obj, opts)) 53 | this._registerExit() 54 | } 55 | 56 | /** 57 | * Same as @see ocat.log, but writes to ocat.tmpFile * at `/tmp/ocat.txt` 58 | * on Unixes and who knows on Windows (`os.tmpdir()/ocat.txt`). 59 | * 60 | * This is useful if you want to read isolated ocat output into your editor 61 | * without other output, i.e. by your test runner. 62 | * 63 | * **Vim Example**: 64 | * 65 | * ``` 66 | * :r !OCAT_COLOR=0 OCAT_DEPTH=0 OCAT_RM=1 node % 2>&1 > /dev/null && cat /tmp/ocat.txt 67 | * ``` 68 | * 69 | * will read the ocat printed output right into your editor. 70 | * You should probably bind that to a shortcut. ;) 71 | * 72 | * **Tail Example**: 73 | * 74 | * In another terminal pane do: 75 | * 76 | * ``` 77 | * tail -f /tmp/ocat.txt 78 | * ``` 79 | * 80 | * to see logged objects every time you run your tests/code. 81 | * 82 | * 83 | * @name ocat.file 84 | * @function 85 | * @param {Object} obj to inspect 86 | * @param {Object} opts options (same as @see ocat.log) with `color: false` 87 | */ 88 | proto.file = function file(obj, opts) { 89 | const inspected = this.inspect(obj, opts) 90 | fs.appendFileSync(tmpFile, inspected + '\n\n') 91 | } 92 | 93 | /** 94 | * Inspects object and logs it to *stderr* immediately. 95 | * 96 | * The given opts override all other options for each supplied property, which are derived as follows: 97 | * 98 | * 1. ocat.opts, the default opts: 99 | * `prefix: '', suffix: '', indent: '', color: true, depth: 1, commaFirst: true` 100 | * 2. `OCAT_COLOR` and `OCAT_COMMAFIRST` to override the related defaults, i.e. 101 | * `OCAT_COLOR=0 node my.js` includes no colors 102 | * 3. opts passed to `ocat.create` for that `ocat` instance only 103 | * 4. opts passed to `ocat.log` and `ocat.bag` 104 | * 105 | * @name ocat.log 106 | * @function 107 | * @param {Object} obj object to inspect 108 | * @param {Object} opts options inherit from opts passed to `create` and then `ocat.opts`. 109 | * @param {String=} opts.prefix the prefix to insert before the logged object 110 | * @param {String=} opts.suffix the suffix to insert after the logged object 111 | * @param {String=} opts.indent the indentation to apply to each line 112 | * @param {Boolean=} opts.color if `true` logging in colors 113 | * @param {Number=} opts.depth depth to which the object is inspected 114 | * @param {Boolean=} opts.commaFirst if `true` commaFirst style is used when logging without color** (default: `true`) 115 | * 116 | */ 117 | proto.log = function log(obj, opts) { 118 | console.error(this.inspect(obj, opts)) 119 | } 120 | 121 | proto.inspect = function _inspect(obj, opts) { 122 | // provide shortcut to trigger colors 123 | if (typeof opts === 'boolean') opts = { color: opts } 124 | opts = xtend(defaultOpts, exports.opts, this._opts, opts) 125 | 126 | let inspected = utilInspect(obj, null, opts.depth, opts.color) 127 | // We don't like extra newlines for object start and end 128 | inspected = inspected.replace(/^ *{\n /, '{').replace(/\n}/, ' }') 129 | 130 | // when we're run in no color mode adjust style to comma first if so preferred 131 | inspected = 132 | !opts.color && opts.commaFirst 133 | ? ' ' + inspected.replace(/,\n(:? +?) {1,2}(:?[^ ])/gm, '\n$1, $2') 134 | : inspected 135 | 136 | function addIndent(x) { 137 | return opts.indent + x 138 | } 139 | 140 | if (opts.indent && opts.indent.length) { 141 | inspected = inspected 142 | .split('\n') 143 | .map(addIndent) 144 | .join('\n') 145 | } 146 | 147 | return opts.prefix + inspected + opts.suffix 148 | } 149 | 150 | proto._registerExit = function _registerExit() { 151 | // make sure we log the bagged ocats on process exit 152 | // only need to register this once of course 153 | if (this._registered) return 154 | 155 | const self = this 156 | function logAll() { 157 | if (self._loggedOnExit) return 158 | self._bagged.forEach(logstderr) 159 | self._loggedOnExit = true 160 | } 161 | // need beforeExit for tape which seems to mess with exit 162 | // in that case we don't log at very end of output though 163 | process.once('beforeExit', logAll) 164 | process.once('exit', logAll) 165 | 166 | this._registered = true 167 | } 168 | 169 | exports = module.exports = new Ocat() 170 | 171 | const RES5_OPTS = { 172 | prefix: ' spok(t, res, \n', 173 | suffix: ')', 174 | indent: ' ', 175 | depth: 5, 176 | } 177 | 178 | /** 179 | * Applies preconfigured opts with prefix + indentation and depth 180 | * that work well in lots of scenarios. 181 | * 182 | * ### Example 183 | * 184 | * ```js 185 | * const ocat = require('ocat').applyRes5Opts() 186 | * ``` 187 | * 188 | * @name ocat.applyRes5Opts 189 | * @function 190 | * @return {Object} ocat 191 | */ 192 | exports.applyRes5Opts = function applyRes5Opts() { 193 | exports.opts = xtend(RES5_OPTS) 194 | return exports 195 | } 196 | 197 | /** 198 | * Start out as default options @see ocat.log. 199 | * Allow overriding ocat options for **all** instances. 200 | * 201 | * @name ocat.opts 202 | */ 203 | exports.opts = xtend(defaultOpts) 204 | 205 | /** 206 | * Resets ocat.opts to default opts. 207 | * 208 | * @name ocat.resetOpts 209 | * @function 210 | */ 211 | exports.resetOpts = function resetOpts() { 212 | exports.opts = xtend(defaultOpts) 213 | } 214 | 215 | /** 216 | * Creates an ocat instance with the supplied options. 217 | * @name ocat.create 218 | * @function 219 | * @param {Object} opts options (same as @see ocat.log) 220 | * @return {Object} ocat instance 221 | */ 222 | exports.create = Ocat 223 | 224 | /** 225 | * The file into which ocat.file writes. 226 | * Set it to any other path you like to use instead. 227 | * 228 | * @name ocat.tmpFile 229 | */ 230 | exports.tmpFile = tmpFile 231 | 232 | /** 233 | * Removes the ocat.tmpFile 234 | * If the an env const `OCAT_RM=1` is present, the file is removed on startup. 235 | * 236 | * @name ocat.rm 237 | * @function 238 | */ 239 | exports.rm = function rm() { 240 | try { 241 | fs.unlinkSync(exports.tmpFile) 242 | } catch (_) { 243 | /* don't care */ 244 | } 245 | } 246 | 247 | if (env.OCAT_RM === '1') exports.rm() 248 | --------------------------------------------------------------------------------