1 | 'use strict';
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.camelcase = camelcase;
|
5 | exports.hyphenate = hyphenate;
|
6 | exports.template = template;
|
7 |
|
8 | var _log = require('./log');
|
9 |
|
10 | var _object = require('./object');
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function camelcase(str) {
|
18 | if (!/-/.test(str)) {
|
19 | return str || '';
|
20 | }
|
21 | return str.toLowerCase().replace(/-([a-z])/g, function ($0, $1) {
|
22 | return $1.toUpperCase();
|
23 | });
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function hyphenate(str) {
|
32 | var strType = (0, _object.typeOf)(str);
|
33 | if (strType !== 'String') {
|
34 | (0, _log.warning)('[ hyphenate(str: string): string ] ' + ('Expected arguments[0] to be a string but get a ' + strType + '.') + 'It will return an empty string without any processing.');
|
35 | return '';
|
36 | }
|
37 | return str.replace(/([A-Z])/g, function ($0) {
|
38 | return '-' + $0.toLowerCase();
|
39 | });
|
40 | }
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | function template(tpl) {
|
49 | var object = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
50 |
|
51 | var tplType = (0, _object.typeOf)(tpl);
|
52 | if (tplType !== 'String') {
|
53 | (0, _log.warning)('[ template(tpl: string, object: object): string ] ' + ('Expected arguments[0] to be a string but get a ' + tplType + '.') + 'It will return an empty string without any processing.');
|
54 | return '';
|
55 | }
|
56 |
|
57 | return tpl.replace(/\{[a-z]*\}/g, function (str) {
|
58 | var key = str.substring(1, str.length - 1);
|
59 | return object[key] || '';
|
60 | });
|
61 | } |
\ | No newline at end of file |