1 |
|
2 | 'use strict';
|
3 |
|
4 | var _Object$keys = require('babel-runtime/core-js/object/keys')['default'];
|
5 |
|
6 | var _getIterator = require('babel-runtime/core-js/get-iterator')['default'];
|
7 |
|
8 | exports.__esModule = true;
|
9 | exports.is_object = is_object;
|
10 | exports.extend = extend;
|
11 | exports.merge = merge;
|
12 | exports.clone = clone;
|
13 | exports.convert_from_camel_case = convert_from_camel_case;
|
14 | exports.replace_all = replace_all;
|
15 | exports.starts_with = starts_with;
|
16 | exports.ends_with = ends_with;
|
17 | var exists = function exists(what) {
|
18 | return typeof what !== 'undefined';
|
19 | };
|
20 |
|
21 | exports.exists = exists;
|
22 |
|
23 | var object_constructor = ({}).constructor;
|
24 |
|
25 |
|
26 |
|
27 | function is_object(object) {
|
28 | return exists(object) && object !== null && object.constructor === object_constructor;
|
29 | }
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | function extend() {
|
35 | var _this = this,
|
36 | _arguments = arguments;
|
37 |
|
38 | var _again = true;
|
39 |
|
40 | _function: while (_again) {
|
41 | _again = false;
|
42 |
|
43 | for (var _len = _arguments.length, objects = Array(_len), _key = 0; _key < _len; _key++) {
|
44 | objects[_key] = _arguments[_key];
|
45 | }
|
46 |
|
47 | var to = objects[0];
|
48 | var from = objects[1];
|
49 |
|
50 | if (objects.length > 2) {
|
51 | var last = objects.pop();
|
52 | var intermediary_result = extend.apply(_this, objects);
|
53 | _this = undefined;
|
54 | _arguments = [intermediary_result, last];
|
55 | _again = true;
|
56 | _len = objects = _key = to = from = last = intermediary_result = undefined;
|
57 | continue _function;
|
58 | }
|
59 |
|
60 | for (var _iterator = _Object$keys(from), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _getIterator(_iterator);;) {
|
61 | var _ref;
|
62 |
|
63 | if (_isArray) {
|
64 | if (_i >= _iterator.length) break;
|
65 | _ref = _iterator[_i++];
|
66 | } else {
|
67 | _i = _iterator.next();
|
68 | if (_i.done) break;
|
69 | _ref = _i.value;
|
70 | }
|
71 |
|
72 | var key = _ref;
|
73 |
|
74 | if (is_object(from[key])) {
|
75 | if (!is_object(to[key])) {
|
76 | to[key] = {};
|
77 | }
|
78 |
|
79 | extend(to[key], from[key]);
|
80 | } else {
|
81 | to[key] = from[key];
|
82 | }
|
83 | }
|
84 |
|
85 | return to;
|
86 | }
|
87 | }
|
88 |
|
89 | function merge() {
|
90 | var parameters = Array.prototype.slice.call(arguments, 0);
|
91 | parameters.unshift({});
|
92 | return extend.apply(this, parameters);
|
93 | }
|
94 |
|
95 | function clone(object) {
|
96 | return merge({}, object);
|
97 | }
|
98 |
|
99 |
|
100 |
|
101 | function convert_from_camel_case(object) {
|
102 | for (var _iterator2 = _Object$keys(object), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _getIterator(_iterator2);;) {
|
103 | var _ref2;
|
104 |
|
105 | if (_isArray2) {
|
106 | if (_i2 >= _iterator2.length) break;
|
107 | _ref2 = _iterator2[_i2++];
|
108 | } else {
|
109 | _i2 = _iterator2.next();
|
110 | if (_i2.done) break;
|
111 | _ref2 = _i2.value;
|
112 | }
|
113 |
|
114 | var key = _ref2;
|
115 |
|
116 | if (/[A-Z]/.test(key))
|
117 |
|
118 | {
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | var lo_dashed_key = key.replace(/([A-Z])/g, function (match, group_1) {
|
131 | return '_' + group_1.toLowerCase();
|
132 | });
|
133 |
|
134 | if (!exists(object[lo_dashed_key])) {
|
135 | object[lo_dashed_key] = object[key];
|
136 | delete object[key];
|
137 | }
|
138 | }
|
139 | }
|
140 |
|
141 | return object;
|
142 | }
|
143 |
|
144 | function escape_regexp(string) {
|
145 | var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", 'g');
|
146 | return string.replace(specials, "\\$&");
|
147 | }
|
148 |
|
149 | function replace_all(where, what, with_what) {
|
150 | var regexp = new RegExp(escape_regexp(what), 'g');
|
151 | return where.replace(regexp, with_what);
|
152 | }
|
153 |
|
154 | function starts_with(string, substring) {
|
155 | return string.indexOf(substring) === 0;
|
156 | }
|
157 |
|
158 | function ends_with(string, substring) {
|
159 | var index = string.lastIndexOf(substring);
|
160 | return index >= 0 && index === string.length - substring.length;
|
161 | }
|
162 |
|
\ | No newline at end of file |