package/package.json000644 000765 000024 0000001115 13040001133012774 0ustar00000000 000000 { "name": "own-or-env", "version": "1.0.0", "description": "Use an objects own property, or an environment variable. Optionally treat as a boolean if the env should be set to 1 or 0.", "main": "own-or-env.js", "scripts": { "test": "node test.js" }, "repository": { "type": "git", "url": "git+https://github.com/isaacs/own-or-env.git" }, "author": "Isaac Z. Schlueter (http://blog.izs.me/)", "license": "ISC", "bugs": { "url": "https://github.com/isaacs/own-or-env/issues" }, "homepage": "https://github.com/isaacs/own-or-env#readme" } package/README.md000644 000765 000024 0000001232 13040000604011767 0ustar00000000 000000 # own-or-env Use an objects own property, or an environment variable. Optionally treat as a boolean if the env should be set to 1 or 0. ## API `ownOrEnv(object, field, env, boolean)` Use the `object[field]` if it's an own property, otherwise use the named environent variable. If `boolean` is set to `true`, then cast to a boolean flag. ## USAGE ```js // will set doTheThing to true based on config.doThing, falling back // to reading process.env.DO_THING, where '0' is treated as false. var doTheThing = ownOrEnv(config, 'doThing', 'DO_THING', true) // just treat this one as a string, not a boolean flag var file = ownOrEnv(config, 'file', 'MY_FILE') ``` package/LICENSE000644 000765 000024 0000001375 13040001142011523 0ustar00000000 000000 The ISC License Copyright (c) Isaac Z. Schlueter and Contributors Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. package/own-or-env.js000644 000765 000024 0000000277 13040001056013067 0ustar00000000 000000 var ownOr = require('own-or') module.exports = function ownOrEnv (object, field, env, bool) { var res = ownOr(object, field, process.env[env]) if (bool) res = !!+(res) return res } package/test.js000644 000765 000024 0000001173 13040001050012025 0ustar00000000 000000 var assert = require('assert') var ownOrEnv = require('./') process.env.OWN_OR_BOOL_TRUE = '1' process.env.OWN_OR_BOOL_FALSE = '0' process.env.OWN_OR_STRING = 'foo' var conf = { t: true, f: false, s: 'bar' } assert.equal(ownOrEnv(conf, 't', 'OWN_OR_BOOL_FALSE', true), true) assert.equal(ownOrEnv(conf, 'x', 'OWN_OR_BOOL_FALSE', true), false) assert.equal(ownOrEnv(conf, 'f', 'OWN_OR_BOOL_TRUE', true), false) assert.equal(ownOrEnv(conf, 'x', 'OWN_OR_BOOL_TRUE', true), true) assert.equal(ownOrEnv(conf, 's', 'OWN_OR_STRING'), 'bar') assert.equal(ownOrEnv(conf, 'x', 'OWN_OR_STRING'), 'foo') console.log('TAP version 13\nok\n1..1')