-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (48 loc) · 1.1 KB
/
index.js
File metadata and controls
60 lines (48 loc) · 1.1 KB
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
57
58
59
60
"use strict";
function format_string(options,arg)
{
var re_format = /^((Cl?)|(Fl?)|(fU?)|[Ul])?$/;
arg = String(arg);
var fmt = options.format;
if ( fmt === undefined )
{
fmt = "U";
}
if ( !re_format.test(fmt) )
{
throw new SyntaxError(format_string.sprintf("[ext-str] unknown format '%s'",fmt));
}
if ( fmt.indexOf("l") !== -1 )
{
arg = arg.toLowerCase();
}
else if ( fmt.indexOf("U") !== -1 )
{
arg = arg.toUpperCase();
}
switch (fmt[0])
{
case "F":
if ( arg.length >= 1 )
{
arg = arg[0].toUpperCase() + arg.substring(1);
}
break;
case "f":
if ( arg.length >= 1 )
{
arg = arg[0].toLowerCase() + arg.substring(1);
}
break;
case "C":
arg = arg.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
break;
}
return arg;
}
function bind(sprintf,specifier)
{
format_string.sprintf = sprintf;
sprintf.register_extension(specifier || "S",format_string);
}
exports.bind = bind;