Commit 371b3cc5 authored by isaacs's avatar isaacs

first

parents
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.
# own-or
Either use the object's own property, or a fallback
Useful for setting default values.
## API
`ownOr(object, key, fallback)`
## USAGE
```js
var ownOr = require('own-or')
var config = { some: 'configs' }
var foo = ownOr(config, 'bar', 'baz') // 'baz'
var some = ownOr(config, 'some', 'quux') // 'configs'
```
module.exports = function ownOr (object, field, fallback) {
if (Object.prototype.hasOwnProperty.call(object, field))
return object[field]
else
return fallback
}
{
"name": "own-or",
"version": "1.0.0",
"description": "Either use the object's own property, or a fallback",
"main": "own-or.js",
"scripts": {
"test": "node test.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/isaacs/own-or.git"
},
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
"license": "ISC",
"bugs": {
"url": "https://github.com/isaacs/own-or/issues"
},
"homepage": "https://github.com/isaacs/own-or#readme"
}
var ownOr = require('./')
var assert = require('assert')
var foo = { bar: 'baz' }
assert.equal(ownOr(foo, 'bar', 'boo'), 'baz')
assert.equal(ownOr(foo, 'boo', 'boo'), 'boo')
var bar = Object.create(foo)
bar.bat = 'boo'
assert.equal(ownOr(bar, 'bar', 'boo'), 'boo')
assert.equal(ownOr(bar, 'bat', 'qux'), 'boo')
console.log('TAP version 13\nok\n1..1')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment