1 | import number from "./number";
|
2 |
|
3 | var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
|
4 | reB = new RegExp(reA.source, "g");
|
5 |
|
6 | function zero(b) {
|
7 | return function() {
|
8 | return b;
|
9 | };
|
10 | }
|
11 |
|
12 | function one(b) {
|
13 | return function(t) {
|
14 | return b(t) + "";
|
15 | };
|
16 | }
|
17 |
|
18 | export default function(a, b) {
|
19 | var bi = reA.lastIndex = reB.lastIndex = 0,
|
20 | am,
|
21 | bm,
|
22 | bs,
|
23 | i = -1,
|
24 | s = [],
|
25 | q = [];
|
26 |
|
27 |
|
28 | a = a + "", b = b + "";
|
29 |
|
30 |
|
31 | while ((am = reA.exec(a))
|
32 | && (bm = reB.exec(b))) {
|
33 | if ((bs = bm.index) > bi) {
|
34 | bs = b.slice(bi, bs);
|
35 | if (s[i]) s[i] += bs;
|
36 | else s[++i] = bs;
|
37 | }
|
38 | if ((am = am[0]) === (bm = bm[0])) {
|
39 | if (s[i]) s[i] += bm;
|
40 | else s[++i] = bm;
|
41 | } else {
|
42 | s[++i] = null;
|
43 | q.push({i: i, x: number(am, bm)});
|
44 | }
|
45 | bi = reB.lastIndex;
|
46 | }
|
47 |
|
48 |
|
49 | if (bi < b.length) {
|
50 | bs = b.slice(bi);
|
51 | if (s[i]) s[i] += bs;
|
52 | else s[++i] = bs;
|
53 | }
|
54 |
|
55 |
|
56 |
|
57 | return s.length < 2 ? (q[0]
|
58 | ? one(q[0].x)
|
59 | : zero(b))
|
60 | : (b = q.length, function(t) {
|
61 | for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
|
62 | return s.join("");
|
63 | });
|
64 | }
|