Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: node_modules/vulcanize/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type/int.js

Issue 877193002: Upgrade vulcanize to 0.7.6. (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: node_modules/vulcanize/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type/int.js
diff --git a/node_modules/vulcanize/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type/int.js b/node_modules/vulcanize/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type/int.js
index 81b1ef8b1fcfc5e15295e3cfab69eb090bb939c2..efada887e44524b0f39340c3166c86438917382f 100644
--- a/node_modules/vulcanize/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type/int.js
+++ b/node_modules/vulcanize/node_modules/update-notifier/node_modules/configstore/node_modules/js-yaml/lib/js-yaml/type/int.js
@@ -1,50 +1,143 @@
'use strict';
+var common = require('../common');
+var Type = require('../type');
-var Type = require('../type');
+function isHexCode(c) {
+ return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) ||
+ ((0x41/* A */ <= c) && (c <= 0x46/* F */)) ||
+ ((0x61/* a */ <= c) && (c <= 0x66/* f */));
+}
+function isOctCode(c) {
+ return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */));
+}
-var YAML_INTEGER_PATTERN = new RegExp(
- '^(?:[-+]?0b[0-1_]+' +
- '|[-+]?0[0-7_]+' +
- '|[-+]?(?:0|[1-9][0-9_]*)' +
- '|[-+]?0x[0-9a-fA-F_]+' +
- '|[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$');
+function isDecCode(c) {
+ return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */));
+}
+function resolveYamlInteger(data) {
+ if (null === data) {
+ return false;
+ }
-function resolveYamlInteger(state) {
- var value, sign, base, digits,
- object = state.result;
+ var max = data.length,
+ index = 0,
+ hasDigits = false,
+ ch;
- if (!YAML_INTEGER_PATTERN.test(object)) {
- return false;
+ if (!max) { return false; }
+
+ ch = data[index];
+
+ // sign
+ if (ch === '-' || ch === '+') {
+ ch = data[++index];
+ }
+
+ if (ch === '0') {
+ // 0
+ if (index+1 === max) { return true; }
+ ch = data[++index];
+
+ // base 2, base 8, base 16
+
+ if (ch === 'b') {
+ // base 2
+ index++;
+
+ for (; index < max; index++) {
+ ch = data[index];
+ if (ch === '_') { continue; }
+ if (ch !== '0' && ch !== '1') {
+ return false;
+ }
+ hasDigits = true;
+ }
+ return hasDigits;
+ }
+
+
+ if (ch === 'x') {
+ // base 16
+ index++;
+
+ for (; index < max; index++) {
+ ch = data[index];
+ if (ch === '_') { continue; }
+ if (!isHexCode(data.charCodeAt(index))) {
+ return false;
+ }
+ hasDigits = true;
+ }
+ return hasDigits;
+ }
+
+ // base 8
+ for (; index < max; index++) {
+ ch = data[index];
+ if (ch === '_') { continue; }
+ if (!isOctCode(data.charCodeAt(index))) {
+ return false;
+ }
+ hasDigits = true;
+ }
+ return hasDigits;
+ }
+
+ // base 10 (except 0) or base 60
+
+ for (; index < max; index++) {
+ ch = data[index];
+ if (ch === '_') { continue; }
+ if (ch === ':') { break; }
+ if (!isDecCode(data.charCodeAt(index))) {
+ return false;
+ }
+ hasDigits = true;
}
- value = object.replace(/_/g, '');
- sign = '-' === value[0] ? -1 : 1;
- digits = [];
+ if (!hasDigits) { return false; }
- if (0 <= '+-'.indexOf(value[0])) {
+ // if !base60 - done;
+ if (ch !== ':') { return true; }
+
+ // base60 almost not used, no needs to optimize
+ return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
+}
+
+function constructYamlInteger(data) {
+ var value = data, sign = 1, ch, base, digits = [];
+
+ if (value.indexOf('_') !== -1) {
+ value = value.replace(/_/g, '');
+ }
+
+ ch = value[0];
+
+ if (ch === '-' || ch === '+') {
+ if (ch === '-') { sign = -1; }
value = value.slice(1);
+ ch = value[0];
}
if ('0' === value) {
- state.result = 0;
- return true;
-
- } else if (/^0b/.test(value)) {
- state.result = sign * parseInt(value.slice(2), 2);
- return true;
+ return 0;
+ }
- } else if (/^0x/.test(value)) {
- state.result = sign * parseInt(value, 16);
- return true;
+ if (ch === '0') {
+ if (value[1] === 'b') {
+ return sign * parseInt(value.slice(2), 2);
+ }
+ if (value[1] === 'x') {
+ return sign * parseInt(value, 16);
+ }
+ return sign * parseInt(value, 8);
- } else if ('0' === value[0]) {
- state.result = sign * parseInt(value, 8);
- return true;
+ }
- } else if (0 <= value.indexOf(':')) {
+ if (value.indexOf(':') !== -1) {
value.split(':').forEach(function (v) {
digits.unshift(parseInt(v, 10));
});
@@ -57,34 +150,31 @@ function resolveYamlInteger(state) {
base *= 60;
});
- state.result = sign * value;
- return true;
+ return sign * value;
- } else {
- state.result = sign * parseInt(value, 10);
- return true;
}
-}
+ return sign * parseInt(value, 10);
+}
function isInteger(object) {
return ('[object Number]' === Object.prototype.toString.call(object)) &&
- (0 === object % 1);
+ (0 === object % 1 && !common.isNegativeZero(object));
}
-
module.exports = new Type('tag:yaml.org,2002:int', {
- loadKind: 'scalar',
- loadResolver: resolveYamlInteger,
- dumpPredicate: isInteger,
- dumpRepresenter: {
+ kind: 'scalar',
+ resolve: resolveYamlInteger,
+ construct: constructYamlInteger,
+ predicate: isInteger,
+ represent: {
binary: function (object) { return '0b' + object.toString(2); },
octal: function (object) { return '0' + object.toString(8); },
decimal: function (object) { return object.toString(10); },
hexadecimal: function (object) { return '0x' + object.toString(16).toUpperCase(); }
},
- dumpDefaultStyle: 'decimal',
- dumpStyleAliases: {
+ defaultStyle: 'decimal',
+ styleAliases: {
binary: [ 2, 'bin' ],
octal: [ 8, 'oct' ],
decimal: [ 10, 'dec' ],

Powered by Google App Engine
This is Rietveld 408576698