extension 0.2.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -17
- package/README.md +80 -135
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +16 -0
- package/dist/module.d.ts +1 -0
- package/dist/module.js +28 -0
- package/package.json +40 -15
- package/.npmignore +0 -2
- package/lib/array.js +0 -77
- package/lib/extension.js +0 -122
- package/lib/object.js +0 -60
- package/lib/string.js +0 -102
- package/test/array.js +0 -118
- package/test/extension.js +0 -239
- package/test/object.js +0 -160
- package/test/string.js +0 -228
package/lib/string.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var objext = require('./object');
|
|
4
|
-
|
|
5
|
-
exports.contains = function (source, string, options) {
|
|
6
|
-
return match.call(this, source, string, options, function(src, str) {
|
|
7
|
-
return src.indexOf(str) > -1;
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
exports.startsWith = function (source, string, options) {
|
|
12
|
-
return match.call(this, source, string, options, function(src, str) {
|
|
13
|
-
return src.indexOf(str) === 0;
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
exports.endsWith = function (source, string, options) {
|
|
18
|
-
return match.call(this, source, string, options, function(src, str) {
|
|
19
|
-
return src.lastIndexOf(str) === (src.length - str.length);
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
exports.capitalize = function (source) {
|
|
24
|
-
if (source === null) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
if (source === '') {
|
|
28
|
-
return source;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
source = source || this;
|
|
32
|
-
|
|
33
|
-
if (source.length === 1) {
|
|
34
|
-
return source.toUpperCase();
|
|
35
|
-
}
|
|
36
|
-
return source.substring(0, 1).toUpperCase() + source.substring(1);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
exports.decapitalize = function (source) {
|
|
40
|
-
if (source === null) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
if (source === '') {
|
|
44
|
-
return source;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
source = source || this;
|
|
48
|
-
|
|
49
|
-
if (source.length === 1) {
|
|
50
|
-
return source.toLowerCase();
|
|
51
|
-
}
|
|
52
|
-
return source.substring(0, 1).toLowerCase() + source.substring(1);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
exports.camelize = function (source) {
|
|
56
|
-
if (source === null) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
if (source === '') {
|
|
60
|
-
return source;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
source = source || this;
|
|
64
|
-
|
|
65
|
-
if (source.length < 2) {
|
|
66
|
-
return source.toLowerCase();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
var parts = source.split(/[-_]+/);
|
|
70
|
-
parts[0] = parts[0].substring(0, 1).toLowerCase() + parts[0].substring(1);
|
|
71
|
-
|
|
72
|
-
for (var i = 1; i < parts.length; i++) {
|
|
73
|
-
parts[i] = exports.capitalize(parts[i]);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return parts.join('');
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
function match(source, str, options, fn) {
|
|
80
|
-
if (isNotPresent(source)) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
if (this.constructor === String) {
|
|
84
|
-
options = str;
|
|
85
|
-
str = source;
|
|
86
|
-
source = this;
|
|
87
|
-
}
|
|
88
|
-
if (!objext.isString(str)) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
options = options || {};
|
|
93
|
-
source = options.ignoreCase ? source.toLowerCase() : source;
|
|
94
|
-
str = options.ignoreCase ? str.toLowerCase(): str;
|
|
95
|
-
|
|
96
|
-
return fn(source, str);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function isNotPresent(obj) {
|
|
100
|
-
return obj === null || obj === undefined;
|
|
101
|
-
}
|
|
102
|
-
|
package/test/array.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
var expect = require('chai').expect;
|
|
2
|
-
var arrext = require('../lib/array');
|
|
3
|
-
|
|
4
|
-
describe('array', function () {
|
|
5
|
-
describe('#contains', function () {
|
|
6
|
-
it('should return false when the array is empty', function (done) {
|
|
7
|
-
expect(arrext.contains([], 1)).to.be.false;
|
|
8
|
-
expect(arrext.contains.call([], 1)).to.be.false;
|
|
9
|
-
done();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should return false when the array does not contain the value', function (done) {
|
|
13
|
-
expect(arrext.contains([1, 2], 3)).to.be.false;
|
|
14
|
-
expect(arrext.contains.call([1, 2], 3)).to.be.false;
|
|
15
|
-
done();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should return true when the array contains the value', function (done) {
|
|
19
|
-
expect(arrext.contains([1, 2], 2)).to.be.true;
|
|
20
|
-
expect(arrext.contains.call([1, 2], 2)).to.be.true;
|
|
21
|
-
done();
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe('#isEmpty', function () {
|
|
26
|
-
it('should return true when empty', function (done) {
|
|
27
|
-
expect(arrext.isEmpty([])).to.be.true;
|
|
28
|
-
expect(arrext.isEmpty.call([])).to.be.true;
|
|
29
|
-
done();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should return false when not empty', function (done) {
|
|
33
|
-
expect(arrext.isEmpty([1])).to.be.false;
|
|
34
|
-
expect(arrext.isEmpty.call([1])).to.be.false;
|
|
35
|
-
done();
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('#first', function () {
|
|
40
|
-
it('should return nothing when empty', function (done) {
|
|
41
|
-
expect(arrext.first([], function () {})).to.not.be.present;
|
|
42
|
-
expect(arrext.first.call([], function () {})).to.not.be.present;
|
|
43
|
-
done();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should return nothing when no match is found', function (done) {
|
|
47
|
-
expect(arrext.first([1, 2], function () { return false; })).to.not.be.present;
|
|
48
|
-
expect(arrext.first.call([1, 2], function () { return false; })).to.not.be.present;
|
|
49
|
-
done();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should the first value for which the passed function returns true', function (done) {
|
|
53
|
-
expect(arrext.first([1, 2, 3], function (item) { return item > 1; })).to.equal(2);
|
|
54
|
-
expect(arrext.first.call([1, 2, 3], function (item) { return item > 1; })).to.equal(2);
|
|
55
|
-
done();
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('#sortCaseInsensitive', function () {
|
|
60
|
-
it('should return true when empty', function (done) {
|
|
61
|
-
var result = arrext.sortCaseInsensitive(['az', 'Ab', 'aa', 1]);
|
|
62
|
-
expect(result).to.eql([1, 'aa', 'Ab', 'az']);
|
|
63
|
-
done();
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('#groupBy', function () {
|
|
68
|
-
it('should group by name', function (done) {
|
|
69
|
-
var result = arrext.groupBy([
|
|
70
|
-
{ name: 'bin1', value: 1 },
|
|
71
|
-
{ name: 'bin2', value: 2 },
|
|
72
|
-
{ name: 'bin1', value: 3 },
|
|
73
|
-
{ name: 'bin3', value: 4 },
|
|
74
|
-
{ name: 'bin2', value: 5 }
|
|
75
|
-
], function (item) { return item.name });
|
|
76
|
-
|
|
77
|
-
expect(result).to.eql({
|
|
78
|
-
'bin1': [
|
|
79
|
-
{ name: 'bin1', value: 1 },
|
|
80
|
-
{ name: 'bin1', value: 3 }
|
|
81
|
-
],
|
|
82
|
-
'bin2': [
|
|
83
|
-
{ name: 'bin2', value: 2 },
|
|
84
|
-
{ name: 'bin2', value: 5 }
|
|
85
|
-
],
|
|
86
|
-
'bin3': [
|
|
87
|
-
{ name: 'bin3', value: 4 }
|
|
88
|
-
]
|
|
89
|
-
});
|
|
90
|
-
done();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should group by name (this)', function (done) {
|
|
94
|
-
var result = arrext.groupBy.call([
|
|
95
|
-
{ name: 'bin1', value: 1 },
|
|
96
|
-
{ name: 'bin2', value: 2 },
|
|
97
|
-
{ name: 'bin1', value: 3 },
|
|
98
|
-
{ name: 'bin3', value: 4 },
|
|
99
|
-
{ name: 'bin2', value: 5 }
|
|
100
|
-
], function (item) { return item.name });
|
|
101
|
-
|
|
102
|
-
expect(result).to.eql({
|
|
103
|
-
'bin1': [
|
|
104
|
-
{ name: 'bin1', value: 1 },
|
|
105
|
-
{ name: 'bin1', value: 3 }
|
|
106
|
-
],
|
|
107
|
-
'bin2': [
|
|
108
|
-
{ name: 'bin2', value: 2 },
|
|
109
|
-
{ name: 'bin2', value: 5 }
|
|
110
|
-
],
|
|
111
|
-
'bin3': [
|
|
112
|
-
{ name: 'bin3', value: 4 }
|
|
113
|
-
]
|
|
114
|
-
});
|
|
115
|
-
done();
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
});
|
package/test/extension.js
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
var expect = require('chai').expect;
|
|
2
|
-
var ext = require('../lib/extension');
|
|
3
|
-
|
|
4
|
-
describe('extension', function () {
|
|
5
|
-
describe('#register', function () {
|
|
6
|
-
it('should throw an exception if given a null or undefined object to extend', function (done) {
|
|
7
|
-
expect(ext.register.bind(this, null)).to.
|
|
8
|
-
throw(Error);
|
|
9
|
-
expect(ext.register.bind(this, undefined)).to.
|
|
10
|
-
throw(Error);
|
|
11
|
-
done();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should throw an exception if given a null or undefined extension object', function (done) {
|
|
15
|
-
expect(ext.register.bind(this, String.prototype, null)).to.
|
|
16
|
-
throw(Error);
|
|
17
|
-
expect(ext.register.bind(this, String.prototype, undefined)).to.
|
|
18
|
-
throw(Error);
|
|
19
|
-
done();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should do nothing if passed an empty extension object', function (done) {
|
|
23
|
-
var obj = {};
|
|
24
|
-
ext.register(obj, {});
|
|
25
|
-
ext.use(obj);
|
|
26
|
-
expect(Object.keys(obj)).to.be.empty;
|
|
27
|
-
done();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should create a new empty set of extensions the first time an object is extended', function (done) {
|
|
31
|
-
var obj = {};
|
|
32
|
-
var exts = ext.find(obj);
|
|
33
|
-
expect(exts).to.be.undefined;
|
|
34
|
-
ext.register(obj, { hello: true });
|
|
35
|
-
exts = ext.find(obj);
|
|
36
|
-
expect(exts).to.have.keys('hello');
|
|
37
|
-
done();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should register the extension given valid arguments', function (done) {
|
|
41
|
-
var obj = {};
|
|
42
|
-
ext.register(obj, { hello: true });
|
|
43
|
-
ext.register(obj, { goodbye: true });
|
|
44
|
-
var exts = ext.find(obj);
|
|
45
|
-
expect(Object.keys(exts)).to.have.length(2);
|
|
46
|
-
expect(exts).to.have.keys('hello', 'goodbye');
|
|
47
|
-
expect(exts).to.have.keys('hello', 'goodbye');
|
|
48
|
-
expect(exts.hello).to.be.true;
|
|
49
|
-
expect(exts.goodbye).to.be.true;
|
|
50
|
-
done();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('#find', function () {
|
|
55
|
-
it('should throw an exception if passed a null or undefined value', function (done) {
|
|
56
|
-
expect(ext.find.bind(this, null)).to.
|
|
57
|
-
throw(Error);
|
|
58
|
-
expect(ext.find.bind(this, undefined)).to.
|
|
59
|
-
throw(Error);
|
|
60
|
-
done();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should return undefined if no extensions are registered for the object', function (done) {
|
|
64
|
-
expect(ext.find({})).to.be.undefined;
|
|
65
|
-
done();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should return the registered extensions as an object', function (done) {
|
|
69
|
-
var obj = {};
|
|
70
|
-
ext.register(obj, { hello: true });
|
|
71
|
-
ext.register(obj, { goodbye: true });
|
|
72
|
-
var exts = ext.find(obj);
|
|
73
|
-
expect(Object.keys(exts)).to.have.length(2);
|
|
74
|
-
expect(exts).to.have.keys('hello', 'goodbye');
|
|
75
|
-
expect(exts).to.have.keys('hello', 'goodbye');
|
|
76
|
-
expect(exts.hello).to.be.true;
|
|
77
|
-
expect(exts.goodbye).to.be.true;
|
|
78
|
-
done();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe('#use', function () {
|
|
83
|
-
it('should throw an exception if given a null or undefined object on which to use extensions', function (done) {
|
|
84
|
-
expect(ext.use.bind(this, null)).to.
|
|
85
|
-
throw(Error);
|
|
86
|
-
expect(ext.use.bind(this, undefined)).to.
|
|
87
|
-
throw(Error);
|
|
88
|
-
done();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should permantly apply an extension to an object if not passed a scoping function', function (done) {
|
|
92
|
-
var obj = {};
|
|
93
|
-
ext.register(obj, { hello: function () {
|
|
94
|
-
done();
|
|
95
|
-
}});
|
|
96
|
-
expect(obj.hello).to.be.undefined;
|
|
97
|
-
ext.use(obj, 'hello');
|
|
98
|
-
expect(obj.hello).not.to.be.undefined;
|
|
99
|
-
obj.hello();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should remove used extensions from an object after the scoping function has executed', function (done) {
|
|
103
|
-
var obj = {};
|
|
104
|
-
var run = false;
|
|
105
|
-
ext.register(obj, { hello: function () {
|
|
106
|
-
run = true;
|
|
107
|
-
}});
|
|
108
|
-
expect(obj.hello).to.be.undefined;
|
|
109
|
-
ext.use(obj, 'hello', function () {
|
|
110
|
-
obj.hello();
|
|
111
|
-
});
|
|
112
|
-
expect(obj.hello).to.be.undefined;
|
|
113
|
-
expect(run).to.be.true;
|
|
114
|
-
done();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should not overwrite existing properties', function (done) {
|
|
118
|
-
var obj = {
|
|
119
|
-
hello: true
|
|
120
|
-
};
|
|
121
|
-
ext.register(obj, { hello: false });
|
|
122
|
-
|
|
123
|
-
ext.use(obj, 'hello');
|
|
124
|
-
expect(obj.hello).to.be.true;
|
|
125
|
-
ext.use(obj, 'hello', function () {
|
|
126
|
-
expect(obj.hello).to.be.true;
|
|
127
|
-
});
|
|
128
|
-
done();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should allow multiple property extensions to be applied at once within a scope', function (done) {
|
|
132
|
-
var obj = {};
|
|
133
|
-
var runHello = false;
|
|
134
|
-
var runWorld = false;
|
|
135
|
-
|
|
136
|
-
ext.register(obj, { hello: function () {
|
|
137
|
-
runHello = true;
|
|
138
|
-
}});
|
|
139
|
-
ext.register(obj, { world: function () {
|
|
140
|
-
runWorld = true;
|
|
141
|
-
}});
|
|
142
|
-
|
|
143
|
-
expect(obj.hello).to.be.undefined;
|
|
144
|
-
expect(obj.world).to.be.undefined;
|
|
145
|
-
|
|
146
|
-
ext.use(obj, ['hello', 'world'], function () {
|
|
147
|
-
obj.hello();
|
|
148
|
-
obj.world();
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
expect(obj.hello).to.be.undefined;
|
|
152
|
-
expect(obj.world).to.be.undefined;
|
|
153
|
-
expect(runHello).to.be.true;
|
|
154
|
-
expect(runWorld).to.be.true;
|
|
155
|
-
done();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('should use all registered extensions if none are specified', function (done) {
|
|
159
|
-
var obj = {};
|
|
160
|
-
var runHello = false;
|
|
161
|
-
var runWorld = false;
|
|
162
|
-
|
|
163
|
-
ext.register(obj, { hello: function () {
|
|
164
|
-
runHello = true;
|
|
165
|
-
}});
|
|
166
|
-
ext.register(obj, { world: function () {
|
|
167
|
-
runWorld = true;
|
|
168
|
-
}});
|
|
169
|
-
|
|
170
|
-
expect(obj.hello).to.be.undefined;
|
|
171
|
-
expect(obj.world).to.be.undefined;
|
|
172
|
-
|
|
173
|
-
ext.use(obj, function () {
|
|
174
|
-
obj.hello();
|
|
175
|
-
obj.world();
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
expect(obj.hello).to.be.undefined;
|
|
179
|
-
expect(obj.world).to.be.undefined;
|
|
180
|
-
expect(runHello).to.be.true;
|
|
181
|
-
expect(runWorld).to.be.true;
|
|
182
|
-
done();
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
it('should not show up in a foreach', function (done) {
|
|
186
|
-
var obj = {};
|
|
187
|
-
|
|
188
|
-
ext.register(obj, { hello: function () {
|
|
189
|
-
}});
|
|
190
|
-
|
|
191
|
-
ext.use(obj, function () {
|
|
192
|
-
var keys = [];
|
|
193
|
-
for (var k in obj) {
|
|
194
|
-
keys.push(k);
|
|
195
|
-
}
|
|
196
|
-
expect(keys).to.be.eql([]);
|
|
197
|
-
expect(obj.hello).not.to.be.undefined;
|
|
198
|
-
done();
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe('#registerAndUse', function () {
|
|
204
|
-
it('should throw an exception if given a null or undefined object to extend', function (done) {
|
|
205
|
-
expect(ext.registerAndUse.bind(this, null)).to.
|
|
206
|
-
throw(Error);
|
|
207
|
-
expect(ext.registerAndUse.bind(this, undefined)).to.
|
|
208
|
-
throw(Error);
|
|
209
|
-
done();
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('should throw an exception if given a null or undefined extension object', function (done) {
|
|
213
|
-
expect(ext.registerAndUse.bind(this, String.prototype, null)).to.
|
|
214
|
-
throw(Error);
|
|
215
|
-
expect(ext.registerAndUse.bind(this, String.prototype, undefined)).to.
|
|
216
|
-
throw(Error);
|
|
217
|
-
done();
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('should do nothing if passed an empty extension object', function (done) {
|
|
221
|
-
var obj = {};
|
|
222
|
-
ext.registerAndUse(obj, {});
|
|
223
|
-
expect(Object.keys(obj)).to.be.empty;
|
|
224
|
-
done();
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it('should not have a conflict with keys having the same toString value', function (done) {
|
|
228
|
-
var obj1 = {};
|
|
229
|
-
var obj2 = {};
|
|
230
|
-
ext.registerAndUse(obj1, { a: true });
|
|
231
|
-
ext.registerAndUse(obj2, { b: true });
|
|
232
|
-
expect(obj1.a).to.be.true;
|
|
233
|
-
expect(obj1.b).to.be.undefined;
|
|
234
|
-
expect(obj2.a).to.be.undefined;
|
|
235
|
-
expect(obj2.b).to.be.true;
|
|
236
|
-
done();
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
});
|
package/test/object.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
var expect = require('chai').expect;
|
|
2
|
-
var objext = require('../lib/object');
|
|
3
|
-
|
|
4
|
-
describe('object', function () {
|
|
5
|
-
describe('#isString', function () {
|
|
6
|
-
it('should return false when passed a null or undefined value', function (done) {
|
|
7
|
-
expect(objext.isString(null)).to.be.false;
|
|
8
|
-
expect(objext.isString(undefined)).to.be.false;
|
|
9
|
-
done();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should return true when passed a string', function (done) {
|
|
13
|
-
expect(objext.isString('')).to.be.true;
|
|
14
|
-
expect(objext.isString.call('')).to.be.true;
|
|
15
|
-
done();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should return false when passed anything other than a string', function (done) {
|
|
19
|
-
expect(objext.isString(4)).to.be.false;
|
|
20
|
-
expect(objext.isString([])).to.be.false;
|
|
21
|
-
expect(objext.isString(function () {})).to.be.false;
|
|
22
|
-
expect(objext.isString({})).to.be.false;
|
|
23
|
-
done();
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('#isFunction', function () {
|
|
28
|
-
it('should return false when passed a null or undefined value', function (done) {
|
|
29
|
-
expect(objext.isFunction(null)).to.be.false;
|
|
30
|
-
expect(objext.isFunction(undefined)).to.be.false;
|
|
31
|
-
done();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should return true when passed a function', function (done) {
|
|
35
|
-
expect(objext.isFunction(function () {})).to.be.true;
|
|
36
|
-
expect(objext.isFunction.call(function () {})).to.be.true;
|
|
37
|
-
done();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should return false when passed anything other than a function', function (done) {
|
|
41
|
-
expect(objext.isFunction(4)).to.be.false;
|
|
42
|
-
expect(objext.isFunction([])).to.be.false;
|
|
43
|
-
expect(objext.isFunction({})).to.be.false;
|
|
44
|
-
expect(objext.isFunction('')).to.be.false;
|
|
45
|
-
done();
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('#isArray', function () {
|
|
50
|
-
it('should return false when passed a null or undefined value', function (done) {
|
|
51
|
-
expect(objext.isArray(null)).to.be.false;
|
|
52
|
-
expect(objext.isArray(undefined)).to.be.false;
|
|
53
|
-
done();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should return true when passed an array', function (done) {
|
|
57
|
-
expect(objext.isArray([])).to.be.true;
|
|
58
|
-
expect(objext.isArray.call([])).to.be.true;
|
|
59
|
-
done();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should return false when passed anything other than an array', function (done) {
|
|
63
|
-
expect(objext.isArray(4)).to.be.false;
|
|
64
|
-
expect(objext.isArray(function () {})).to.be.false;
|
|
65
|
-
expect(objext.isArray({})).to.be.false;
|
|
66
|
-
expect(objext.isArray('')).to.be.false;
|
|
67
|
-
done();
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('#isNumber', function () {
|
|
72
|
-
it('should return false when passed a null or undefined value', function (done) {
|
|
73
|
-
expect(objext.isNumber(null)).to.be.false;
|
|
74
|
-
expect(objext.isNumber(undefined)).to.be.false;
|
|
75
|
-
done();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should return true when passed a number', function (done) {
|
|
79
|
-
expect(objext.isNumber(7)).to.be.true;
|
|
80
|
-
expect(objext.isNumber.call(7)).to.be.true;
|
|
81
|
-
done();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should return false when passed anything other than a number', function (done) {
|
|
85
|
-
expect(objext.isNumber(function () {})).to.be.false;
|
|
86
|
-
expect(objext.isNumber([])).to.be.false;
|
|
87
|
-
expect(objext.isNumber({})).to.be.false;
|
|
88
|
-
expect(objext.isNumber('')).to.be.false;
|
|
89
|
-
done();
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe('#isObject', function () {
|
|
94
|
-
it('should return false when passed a null or undefined value', function (done) {
|
|
95
|
-
expect(objext.isObject(null)).to.be.false;
|
|
96
|
-
expect(objext.isObject(undefined)).to.be.false;
|
|
97
|
-
done();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('should return true when passed an object', function (done) {
|
|
101
|
-
expect(objext.isObject({})).to.be.true;
|
|
102
|
-
expect(objext.isObject.call({})).to.be.true;
|
|
103
|
-
done();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should return false when passed anything other than an object', function (done) {
|
|
107
|
-
expect(objext.isObject(function () {})).to.be.false;
|
|
108
|
-
expect(objext.isObject([])).to.be.false;
|
|
109
|
-
expect(objext.isObject(4)).to.be.false;
|
|
110
|
-
expect(objext.isObject('')).to.be.false;
|
|
111
|
-
done();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('#isEmpty', function () {
|
|
116
|
-
it('should return true if passed a null or undefined value', function (done) {
|
|
117
|
-
expect(objext.isEmpty(null)).to.be.true;
|
|
118
|
-
expect(objext.isEmpty.call(null)).to.be.true;
|
|
119
|
-
expect(objext.isEmpty(undefined)).to.be.true;
|
|
120
|
-
expect(objext.isEmpty.call(undefined)).to.be.true;
|
|
121
|
-
done();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('should return true if the object has no keys', function (done) {
|
|
125
|
-
expect(objext.isEmpty({})).to.be.true;
|
|
126
|
-
expect(objext.isEmpty.call({})).to.be.true;
|
|
127
|
-
expect(objext.isEmpty({ a: 1 })).to.be.false;
|
|
128
|
-
expect(objext.isEmpty.call({ a: 1 })).to.be.false;
|
|
129
|
-
done();
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('should return false if not null, undefined, an array, or an object containing keys', function (done) {
|
|
133
|
-
expect(objext.isEmpty(4)).to.be.false;
|
|
134
|
-
expect(objext.isEmpty(function () {})).to.be.false;
|
|
135
|
-
done();
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('should return true for an empty array', function (done) {
|
|
139
|
-
expect(objext.isEmpty([])).to.be.true;
|
|
140
|
-
expect(objext.isEmpty.call([])).to.be.true;
|
|
141
|
-
expect(objext.isEmpty([1])).to.be.false;
|
|
142
|
-
expect(objext.isEmpty.call([1])).to.be.false;
|
|
143
|
-
done();
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('#toArray', function () {
|
|
148
|
-
it('should create an array of key, value objects', function (done) {
|
|
149
|
-
expect(objext.toArray({ a: 1, b: 2 })).to.be.eql([
|
|
150
|
-
{ key: 'a', value: 1 },
|
|
151
|
-
{ key: 'b', value: 2 }
|
|
152
|
-
]);
|
|
153
|
-
expect(objext.toArray.call({ a: 1, b: 2 })).to.be.eql([
|
|
154
|
-
{ key: 'a', value: 1 },
|
|
155
|
-
{ key: 'b', value: 2 }
|
|
156
|
-
]);
|
|
157
|
-
done();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
});
|