webfontloader 1.5.21 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/src/core/version.js DELETED
@@ -1,180 +0,0 @@
1
- goog.provide('webfont.Version');
2
-
3
- /**
4
- * Represents a version as used in user agent strings. Note
5
- * that this does not represent any sort of reliable versioning
6
- * scheme (like Semantic Versioning) but merely a best effort
7
- * at parsing a large amount of wildly different version strings.
8
- *
9
- * @constructor
10
- * @param {?number=} opt_major
11
- * @param {?number=} opt_minor
12
- * @param {?number=} opt_patch
13
- * @param {?(number|string)=} opt_build
14
- */
15
- webfont.Version = function(opt_major, opt_minor, opt_patch, opt_build) {
16
- /**
17
- * @type {?number}
18
- */
19
- this.major = goog.isDefAndNotNull(opt_major) ? opt_major : null;
20
-
21
- /**
22
- * @type {?number}
23
- */
24
- this.minor = goog.isDefAndNotNull(opt_minor) ? opt_minor : null;
25
-
26
- /**
27
- * @type {?number}
28
- */
29
- this.patch = goog.isDefAndNotNull(opt_patch) ? opt_patch : null;
30
-
31
- /**
32
- * @type {?(number|string)}
33
- */
34
- this.build = goog.isDefAndNotNull(opt_build) ? opt_build : null;
35
- }
36
-
37
- goog.scope(function () {
38
- var Version = webfont.Version;
39
-
40
- Version.TOKENIZER = new RegExp(
41
- "^" +
42
- "([0-9]+)" + // major
43
- "(?:" +
44
- "[\\._-]([0-9]+)" + // minor
45
- ")?" +
46
- "(?:" +
47
- "[\\._-]([0-9]+)" + // patch
48
- ")?" +
49
- "(?:" +
50
- "[\\._+-]?(.*)" + // build
51
- ")?$"
52
- );
53
-
54
- /**
55
- * Returns true if the version is valid. A
56
- * version is considered valid if it has at
57
- * least a major version number.
58
- *
59
- * @return {boolean}
60
- */
61
- Version.prototype.isValid = function () {
62
- return !goog.isNull(this.major);
63
- };
64
-
65
- /**
66
- * Compares two versions. Returns -1 if this
67
- * is smaller than version. Returns 1 if this
68
- * is greater than version. Returns 0 if this
69
- * equals version.
70
- *
71
- * Build strings or numbers are ignored when
72
- * comparing versions.
73
- *
74
- * @param {webfont.Version} version
75
- * @return {number}
76
- */
77
- Version.prototype.compare = function (version) {
78
- if (this.major > version.major ||
79
- ((this.major === version.major && this.minor > version.minor) ||
80
- (this.major === version.major && this.minor === version.minor && this.patch > version.patch))) {
81
- return 1;
82
- } else if (this.major < version.major ||
83
- ((this.major === version.major && this.minor < version.minor) ||
84
- (this.major === version.major && this.minor === version.minor && this.patch < version.patch))) {
85
- return -1;
86
- }
87
- return 0;
88
- };
89
-
90
- /**
91
- * @param {webfont.Version} version
92
- * @return {boolean}
93
- */
94
- Version.prototype.gt = function (version) {
95
- return this.compare(version) === 1;
96
- };
97
-
98
- /**
99
- * @param {webfont.Version} version
100
- * @return {boolean}
101
- */
102
- Version.prototype.lt = function (version) {
103
- return this.compare(version) === -1;
104
- };
105
-
106
- /**
107
- * @param {webfont.Version} version
108
- * @return {boolean}
109
- */
110
- Version.prototype.ge = function (version) {
111
- return this.compare(version) === 0 || this.compare(version) === 1;
112
- };
113
-
114
- /**
115
- * @param {webfont.Version} version
116
- * @return {boolean}
117
- */
118
- Version.prototype.le = function (version) {
119
- return this.compare(version) === 0 || this.compare(version) === -1;
120
- };
121
-
122
- /**
123
- * @param {webfont.Version} version
124
- * @return {boolean}
125
- */
126
- Version.prototype.eq = function (version) {
127
- return this.compare(version) === 0;
128
- };
129
-
130
- /**
131
- * @param {webfont.Version} version
132
- * @return {boolean}
133
- */
134
- Version.prototype.ne = function (version) {
135
- return this.compare(version) !== 0;
136
- };
137
-
138
- /**
139
- * @return {string}
140
- */
141
- Version.prototype.toString = function () {
142
- return [this.major, this.minor || '', this.patch || '', this.build || ''].join('');
143
- };
144
-
145
- /**
146
- * @param {string} str
147
- * @return {!webfont.Version}
148
- */
149
- Version.parse = function (str) {
150
- var match = Version.TOKENIZER.exec(str),
151
- major = null,
152
- minor = null,
153
- patch = null,
154
- build = null;
155
-
156
- if (match) {
157
- if (!goog.isNull(match[1]) && !!match[1]) {
158
- major = parseInt(match[1], 10);
159
- }
160
-
161
- if (!goog.isNull(match[2]) && !!match[2]) {
162
- minor = parseInt(match[2], 10);
163
- }
164
-
165
- if (!goog.isNull(match[3]) && !!match[3]) {
166
- patch = parseInt(match[3], 10);
167
- }
168
-
169
- if (!goog.isNull(match[4]) && !!match[4]) {
170
- if (/^[0-9]+$/.test(match[4])) {
171
- build = parseInt(match[4], 10);
172
- } else {
173
- build = match[4];
174
- }
175
- }
176
- }
177
-
178
- return new Version(major, minor, patch, build);
179
- };
180
- });