Version.html
14.2 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-Version'>/**
</span> * @author Jacky Nguyen <jacky@sencha.com>
* @docauthor Jacky Nguyen <jacky@sencha.com>
* @class Ext.Version
*
* A utility class that wrap around a string version number and provide convenient
* method to perform comparison. See also: {@link Ext.Version#compare compare}. Example:
*
* var version = new Ext.Version('1.0.2beta');
* console.log("Version is " + version); // Version is 1.0.2beta
*
* console.log(version.getMajor()); // 1
* console.log(version.getMinor()); // 0
* console.log(version.getPatch()); // 2
* console.log(version.getBuild()); // 0
* console.log(version.getRelease()); // beta
*
* console.log(version.isGreaterThan('1.0.1')); // True
* console.log(version.isGreaterThan('1.0.2alpha')); // True
* console.log(version.isGreaterThan('1.0.2RC')); // False
* console.log(version.isGreaterThan('1.0.2')); // False
* console.log(version.isLessThan('1.0.2')); // True
*
* console.log(version.match(1.0)); // True
* console.log(version.match('1.0.2')); // True
*
*/
(function() {
// Current core version
var version = '4.1.1', Version;
Ext.Version = Version = Ext.extend(Object, {
<span id='Ext-Version-method-constructor'> /**
</span> * @param {String/Number} version The version number in the following standard format:
*
* major[.minor[.patch[.build[release]]]]
*
* Examples:
*
* 1.0
* 1.2.3beta
* 1.2.3.4RC
*
* @return {Ext.Version} this
*/
constructor: function(version) {
var parts, releaseStartIndex;
if (version instanceof Version) {
return version;
}
this.version = this.shortVersion = String(version).toLowerCase().replace(/_/g, '.').replace(/[\-+]/g, '');
releaseStartIndex = this.version.search(/([^\d\.])/);
if (releaseStartIndex !== -1) {
this.release = this.version.substr(releaseStartIndex, version.length);
this.shortVersion = this.version.substr(0, releaseStartIndex);
}
this.shortVersion = this.shortVersion.replace(/[^\d]/g, '');
parts = this.version.split('.');
this.major = parseInt(parts.shift() || 0, 10);
this.minor = parseInt(parts.shift() || 0, 10);
this.patch = parseInt(parts.shift() || 0, 10);
this.build = parseInt(parts.shift() || 0, 10);
return this;
},
<span id='Ext-Version-method-toString'> /**
</span> * Override the native toString method
* @private
* @return {String} version
*/
toString: function() {
return this.version;
},
<span id='Ext-Version-method-valueOf'> /**
</span> * Override the native valueOf method
* @private
* @return {String} version
*/
valueOf: function() {
return this.version;
},
<span id='Ext-Version-method-getMajor'> /**
</span> * Returns the major component value
* @return {Number} major
*/
getMajor: function() {
return this.major || 0;
},
<span id='Ext-Version-method-getMinor'> /**
</span> * Returns the minor component value
* @return {Number} minor
*/
getMinor: function() {
return this.minor || 0;
},
<span id='Ext-Version-method-getPatch'> /**
</span> * Returns the patch component value
* @return {Number} patch
*/
getPatch: function() {
return this.patch || 0;
},
<span id='Ext-Version-method-getBuild'> /**
</span> * Returns the build component value
* @return {Number} build
*/
getBuild: function() {
return this.build || 0;
},
<span id='Ext-Version-method-getRelease'> /**
</span> * Returns the release component value
* @return {Number} release
*/
getRelease: function() {
return this.release || '';
},
<span id='Ext-Version-method-isGreaterThan'> /**
</span> * Returns whether this version if greater than the supplied argument
* @param {String/Number} target The version to compare with
* @return {Boolean} True if this version if greater than the target, false otherwise
*/
isGreaterThan: function(target) {
return Version.compare(this.version, target) === 1;
},
<span id='Ext-Version-method-isGreaterThanOrEqual'> /**
</span> * Returns whether this version if greater than or equal to the supplied argument
* @param {String/Number} target The version to compare with
* @return {Boolean} True if this version if greater than or equal to the target, false otherwise
*/
isGreaterThanOrEqual: function(target) {
return Version.compare(this.version, target) >= 0;
},
<span id='Ext-Version-method-isLessThan'> /**
</span> * Returns whether this version if smaller than the supplied argument
* @param {String/Number} target The version to compare with
* @return {Boolean} True if this version if smaller than the target, false otherwise
*/
isLessThan: function(target) {
return Version.compare(this.version, target) === -1;
},
<span id='Ext-Version-method-isLessThanOrEqual'> /**
</span> * Returns whether this version if less than or equal to the supplied argument
* @param {String/Number} target The version to compare with
* @return {Boolean} True if this version if less than or equal to the target, false otherwise
*/
isLessThanOrEqual: function(target) {
return Version.compare(this.version, target) <= 0;
},
<span id='Ext-Version-method-equals'> /**
</span> * Returns whether this version equals to the supplied argument
* @param {String/Number} target The version to compare with
* @return {Boolean} True if this version equals to the target, false otherwise
*/
equals: function(target) {
return Version.compare(this.version, target) === 0;
},
<span id='Ext-Version-method-match'> /**
</span> * Returns whether this version matches the supplied argument. Example:
*
* var version = new Ext.Version('1.0.2beta');
* console.log(version.match(1)); // True
* console.log(version.match(1.0)); // True
* console.log(version.match('1.0.2')); // True
* console.log(version.match('1.0.2RC')); // False
*
* @param {String/Number} target The version to compare with
* @return {Boolean} True if this version matches the target, false otherwise
*/
match: function(target) {
target = String(target);
return this.version.substr(0, target.length) === target;
},
<span id='Ext-Version-method-toArray'> /**
</span> * Returns this format: [major, minor, patch, build, release]. Useful for comparison
* @return {Number[]}
*/
toArray: function() {
return [this.getMajor(), this.getMinor(), this.getPatch(), this.getBuild(), this.getRelease()];
},
<span id='Ext-Version-method-getShortVersion'> /**
</span> * Returns shortVersion version without dots and release
* @return {String}
*/
getShortVersion: function() {
return this.shortVersion;
},
<span id='Ext-Version-method-gt'> /**
</span> * Convenient alias to {@link Ext.Version#isGreaterThan isGreaterThan}
* @param {String/Number} target
* @return {Boolean}
*/
gt: function() {
return this.isGreaterThan.apply(this, arguments);
},
<span id='Ext-Version-method-lt'> /**
</span> * Convenient alias to {@link Ext.Version#isLessThan isLessThan}
* @param {String/Number} target
* @return {Boolean}
*/
lt: function() {
return this.isLessThan.apply(this, arguments);
},
<span id='Ext-Version-method-gtEq'> /**
</span> * Convenient alias to {@link Ext.Version#isGreaterThanOrEqual isGreaterThanOrEqual}
* @param {String/Number} target
* @return {Boolean}
*/
gtEq: function() {
return this.isGreaterThanOrEqual.apply(this, arguments);
},
<span id='Ext-Version-method-ltEq'> /**
</span> * Convenient alias to {@link Ext.Version#isLessThanOrEqual isLessThanOrEqual}
* @param {String/Number} target
* @return {Boolean}
*/
ltEq: function() {
return this.isLessThanOrEqual.apply(this, arguments);
}
});
Ext.apply(Version, {
// @private
releaseValueMap: {
'dev': -6,
'alpha': -5,
'a': -5,
'beta': -4,
'b': -4,
'rc': -3,
'#': -2,
'p': -1,
'pl': -1
},
<span id='Ext-Version-static-method-getComponentValue'> /**
</span> * Converts a version component to a comparable value
*
* @static
* @param {Object} value The value to convert
* @return {Object}
*/
getComponentValue: function(value) {
return !value ? 0 : (isNaN(value) ? this.releaseValueMap[value] || value : parseInt(value, 10));
},
<span id='Ext-Version-static-method-compare'> /**
</span> * Compare 2 specified versions, starting from left to right. If a part contains special version strings,
* they are handled in the following order:
* 'dev' < 'alpha' = 'a' < 'beta' = 'b' < 'RC' = 'rc' < '#' < 'pl' = 'p' < 'anything else'
*
* @static
* @param {String} current The current version to compare to
* @param {String} target The target version to compare to
* @return {Number} Returns -1 if the current version is smaller than the target version, 1 if greater, and 0 if they're equivalent
*/
compare: function(current, target) {
var currentValue, targetValue, i;
current = new Version(current).toArray();
target = new Version(target).toArray();
for (i = 0; i < Math.max(current.length, target.length); i++) {
currentValue = this.getComponentValue(current[i]);
targetValue = this.getComponentValue(target[i]);
if (currentValue < targetValue) {
return -1;
} else if (currentValue > targetValue) {
return 1;
}
}
return 0;
}
});
<span id='Ext'> /**
</span> * @class Ext
*/
Ext.apply(Ext, {
<span id='Ext-property-versions'> /**
</span> * @private
*/
versions: {},
<span id='Ext-property-lastRegisteredVersion'> /**
</span> * @private
*/
lastRegisteredVersion: null,
<span id='Ext-method-setVersion'> /**
</span> * Set version number for the given package name.
*
* @param {String} packageName The package name, for example: 'core', 'touch', 'extjs'
* @param {String/Ext.Version} version The version, for example: '1.2.3alpha', '2.4.0-dev'
* @return {Ext}
*/
setVersion: function(packageName, version) {
Ext.versions[packageName] = new Version(version);
Ext.lastRegisteredVersion = Ext.versions[packageName];
return this;
},
<span id='Ext-method-getVersion'> /**
</span> * Get the version number of the supplied package name; will return the last registered version
* (last Ext.setVersion call) if there's no package name given.
*
* @param {String} packageName (Optional) The package name, for example: 'core', 'touch', 'extjs'
* @return {Ext.Version} The version
*/
getVersion: function(packageName) {
if (packageName === undefined) {
return Ext.lastRegisteredVersion;
}
return Ext.versions[packageName];
},
<span id='Ext-method-deprecate'> /**
</span> * Create a closure for deprecated code.
*
* // This means Ext.oldMethod is only supported in 4.0.0beta and older.
* // If Ext.getVersion('extjs') returns a version that is later than '4.0.0beta', for example '4.0.0RC',
* // the closure will not be invoked
* Ext.deprecate('extjs', '4.0.0beta', function() {
* Ext.oldMethod = Ext.newMethod;
*
* ...
* });
*
* @param {String} packageName The package name
* @param {String} since The last version before it's deprecated
* @param {Function} closure The callback function to be executed with the specified version is less than the current version
* @param {Object} scope The execution scope (`this`) if the closure
*/
deprecate: function(packageName, since, closure, scope) {
if (Version.compare(Ext.getVersion(packageName), since) < 1) {
closure.call(scope);
}
}
}); // End Versioning
Ext.setVersion('core', version);
}());
</pre>
</body>
</html>