-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path3.modifier.js
56 lines (35 loc) · 988 Bytes
/
3.modifier.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
/*
* yod-mock
* https://github.com/qiu8310/yod-mock
*
* Copyright (c) 2015 Zhonglei Qiu
* Licensed under the MIT license.
*/
var yod = require('..');
var assert = require('should');
// Use defined modifier
assert.equal(yod('@(abc).upper'), 'ABC');
// Use lodash modifier
assert.deepEqual(yod('@([a, a, b, b]).uniq'), ['a', 'b']);
// Use native js modifier
assert.equal(yod('@(abc).toUpperCase'), 'ABC');
//-----------------------------------------------
// Define a normal modifier
yod.modifier('foo', function(lastValue) {
if (typeof lastValue === 'string') {
return lastValue.replace('foo', '');
}
return lastValue;
});
// Define a pre-filter modifier
yod.modifier('String', 'bar', function(lastValue) {
return lastValue.replace('bar', '');
});
// Define a pre-hook modifier
yod.modifier(':foobar', function(lastGenerator) {
var val = lastGenerator();
if (typeof val === 'string') {
return val.replace('foobar', '');
}
return val;
});