]> git.r.bdr.sh - rbdr/dotfiles/blob
076ae465f60c4bc61111bcbe88fc5481e47797b7
[rbdr/dotfiles] /
1 'use strict';
2
3 var assign = require('es5-ext/object/assign')
4 , normalizeOpts = require('es5-ext/object/normalize-options')
5 , isCallable = require('es5-ext/object/is-callable')
6 , contains = require('es5-ext/string/#/contains')
7
8 , d;
9
10 d = module.exports = function (dscr, value/*, options*/) {
11 var c, e, w, options, desc;
12 if ((arguments.length < 2) || (typeof dscr !== 'string')) {
13 options = value;
14 value = dscr;
15 dscr = null;
16 } else {
17 options = arguments[2];
18 }
19 if (dscr == null) {
20 c = w = true;
21 e = false;
22 } else {
23 c = contains.call(dscr, 'c');
24 e = contains.call(dscr, 'e');
25 w = contains.call(dscr, 'w');
26 }
27
28 desc = { value: value, configurable: c, enumerable: e, writable: w };
29 return !options ? desc : assign(normalizeOpts(options), desc);
30 };
31
32 d.gs = function (dscr, get, set/*, options*/) {
33 var c, e, options, desc;
34 if (typeof dscr !== 'string') {
35 options = set;
36 set = get;
37 get = dscr;
38 dscr = null;
39 } else {
40 options = arguments[3];
41 }
42 if (get == null) {
43 get = undefined;
44 } else if (!isCallable(get)) {
45 options = get;
46 get = set = undefined;
47 } else if (set == null) {
48 set = undefined;
49 } else if (!isCallable(set)) {
50 options = set;
51 set = undefined;
52 }
53 if (dscr == null) {
54 c = true;
55 e = false;
56 } else {
57 c = contains.call(dscr, 'c');
58 e = contains.call(dscr, 'e');
59 }
60
61 desc = { get: get, set: set, configurable: c, enumerable: e };
62 return !options ? desc : assign(normalizeOpts(options), desc);
63 };