123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- /*!
- * prr
- * (c) 2013 Rod Vagg <[email protected]>
- * https://github.com/rvagg/prr
- * License: MIT
- */
- (function (name, context, definition) {
- if (typeof module != 'undefined' && module.exports)
- module.exports = definition()
- else
- context[name] = definition()
- })('prr', this, function() {
- var setProperty = typeof Object.defineProperty == 'function'
- ? function (obj, key, options) {
- Object.defineProperty(obj, key, options)
- return obj
- }
- : function (obj, key, options) { // < es5
- obj[key] = options.value
- return obj
- }
- , makeOptions = function (value, options) {
- var oo = typeof options == 'object'
- , os = !oo && typeof options == 'string'
- , op = function (p) {
- return oo
- ? !!options[p]
- : os
- ? options.indexOf(p[0]) > -1
- : false
- }
- return {
- enumerable : op('enumerable')
- , configurable : op('configurable')
- , writable : op('writable')
- , value : value
- }
- }
- , prr = function (obj, key, value, options) {
- var k
- options = makeOptions(value, options)
- if (typeof key == 'object') {
- for (k in key) {
- if (Object.hasOwnProperty.call(key, k)) {
- options.value = key[k]
- setProperty(obj, k, options)
- }
- }
- return obj
- }
- return setProperty(obj, key, options)
- }
- return prr
- })
|