1 | import match from 'MATCH/match';
|
2 | const expect = require('chai').expect;
|
3 |
|
4 |
|
5 |
|
6 | var params = {
|
7 | type: 1
|
8 | };
|
9 |
|
10 | var enumConf = {
|
11 | typeOptions: [
|
12 | {
|
13 | id: 1,
|
14 | name: 'one'
|
15 | },
|
16 | {
|
17 | id: 2,
|
18 | name: 'two'
|
19 | }
|
20 | ]
|
21 | };
|
22 |
|
23 | var format = function (options, id, key, value) {
|
24 | let k = '';
|
25 |
|
26 | for (let i of options) {
|
27 | if (i[key] === id) {
|
28 | k = i[value];
|
29 | }
|
30 | }
|
31 |
|
32 | return k;
|
33 | };
|
34 |
|
35 | match.register(format, 'format');
|
36 |
|
37 | var data = match.parse(params, {
|
38 | typeId: '$${{type}}',
|
39 | typeName: function (data, format) {
|
40 | return format(enumConf.typeOptions, this.typeId, 'id', 'name');
|
41 | },
|
42 | typeNameAgain: (data, format) => format(enumConf.typeOptions, data.type, 'id', 'name')
|
43 | });
|
44 |
|
45 | expect(data).to.be.eql({
|
46 | typeId: 1,
|
47 | typeName: 'one',
|
48 | typeNameAgain: 'one'
|
49 | });
|