-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfast-format.js
50 lines (45 loc) · 1.27 KB
/
fast-format.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
/**
* @preserve fast-format.js (C) KNOWLEDGECODE | MIT
*/
(function (global) {
'use strict';
var f = function (format) {
var argc = arguments.length, v = (argc ? format + '' : '').split('%s'), i = 1, len = v.length, r = v[0];
if (argc > len) {
argc = len;
}
while (i < argc) {
r += arguments[i] + v[i++];
}
while (i < len) {
r += '%s' + v[i++];
}
return r;
};
f.compile = function (format) {
var v = (arguments.length ? format + '' : '').split('%s'), len = v.length;
return function () {
var i = 0, argc = arguments.length, r = v[0];
if (argc > len - 1) {
argc = len - 1;
}
while (i < argc) {
r += arguments[i] + v[++i];
}
i++;
while (i < len) {
r += '%s' + v[i++];
}
return r;
};
};
if (typeof module === 'object' && typeof module.exports === 'object') {
module.exports = f;
} else if (typeof global.define === 'function' && global.define.amd) {
global.define([], function () {
return f;
});
} else {
global.format = f;
}
}(this));