-
Notifications
You must be signed in to change notification settings - Fork 1
/
chai-null.js
136 lines (118 loc) · 2.77 KB
/
chai-null.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
!function (name, definition) {
if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
else this[name] = definition();
}('chai_null', function () {
// CommonJS require()
function require(p){
var path = require.resolve(p)
, mod = require.modules[path];
if (!mod) throw new Error('failed to require "' + p + '"');
if (!mod.exports) {
mod.exports = {};
mod.call(mod.exports, mod, mod.exports, require.relative(path));
}
return mod.exports;
}
require.modules = {};
require.resolve = function (path){
var orig = path
, reg = path + '.js'
, index = path + '/index.js';
return require.modules[reg] && reg
|| require.modules[index] && index
|| orig;
};
require.register = function (path, fn){
require.modules[path] = fn;
};
require.relative = function (parent) {
return function(p){
if ('.' != p[0]) return require(p);
var path = parent.split('/')
, segs = p.split('/');
path.pop();
for (var i = 0; i < segs.length; i++) {
var seg = segs[i];
if ('..' == seg) path.pop();
else if ('.' != seg) path.push(seg);
}
return require(path.join('/'));
};
};
require.register("null", function (module, exports, require) {
/**
* Null Object builder.
*
* @param {Object|Function} [optional] subject
* @api public
*/
function NullObject(subject) {
this.object = Object.create(null);
this.handle(subject);
};
/**
* Handle supplied subject.
*
* @param {Object|Function} subject
* @api private
*/
NullObject.prototype.handle = function(object) {
switch (typeof object) {
case 'object': this.object = new Objekt(object); break;
case 'function': this.object = new Klass(object); break;
}
};
/**
* Builds a null method.
*
* @param {String} name.
* @returns `this`
* @api public
*/
NullObject.prototype.method = function(name) {
this.object[name] = function() { return null; };
return this;
};
/**
* Returns the null object.
*
* @returns {Object}
*/
NullObject.prototype.create = function() {
return this.object;
};
/**
* Null Object builder for objects.
*
* @param {Object} subject
* @api private
*/
function Objekt(subject) {
for (var property in subject) {
subject[property] = ('function' === typeof subject[property])
? function () { return null; }
: null;
}
return subject;
};
/**
* Null Object builder for classes.
*
* @param {Object} subject
* @api private
*/
function Klass(subject) {
return new Objekt(new subject);
};
/**
* Register `NullObject` as a chai plugin.
*/
module.exports = function(chai, _) {
chai.Null = function(subject) {
return new NullObject(subject);
};
};
}); // module null
return require('null');
});
chai.use(chai_null);