Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / source-map / lib / source-map / base64.js
1 /* -*- Mode: js; js-indent-level: 2; -*- */
2 /*
3  * Copyright 2011 Mozilla Foundation and contributors
4  * Licensed under the New BSD license. See LICENSE or:
5  * http://opensource.org/licenses/BSD-3-Clause
6  */
7 if (typeof define !== 'function') {
8     var define = require('amdefine')(module, require);
9 }
10 define(function (require, exports, module) {
11
12   var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
13
14   /**
15    * Encode an integer in the range of 0 to 63 to a single base 64 digit.
16    */
17   exports.encode = function (number) {
18     if (0 <= number && number < intToCharMap.length) {
19       return intToCharMap[number];
20     }
21     throw new TypeError("Must be between 0 and 63: " + aNumber);
22   };
23
24   /**
25    * Decode a single base 64 character code digit to an integer. Returns -1 on
26    * failure.
27    */
28   exports.decode = function (charCode) {
29     var bigA = 65;     // 'A'
30     var bigZ = 90;     // 'Z'
31
32     var littleA = 97;  // 'a'
33     var littleZ = 122; // 'z'
34
35     var zero = 48;     // '0'
36     var nine = 57;     // '9'
37
38     var plus = 43;     // '+'
39     var slash = 47;    // '/'
40
41     var littleOffset = 26;
42     var numberOffset = 52;
43
44     // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
45     if (bigA <= charCode && charCode <= bigZ) {
46       return (charCode - bigA);
47     }
48
49     // 26 - 51: abcdefghijklmnopqrstuvwxyz
50     if (littleA <= charCode && charCode <= littleZ) {
51       return (charCode - littleA + littleOffset);
52     }
53
54     // 52 - 61: 0123456789
55     if (zero <= charCode && charCode <= nine) {
56       return (charCode - zero + numberOffset);
57     }
58
59     // 62: +
60     if (charCode == plus) {
61       return 62;
62     }
63
64     // 63: /
65     if (charCode == slash) {
66       return 63;
67     }
68
69     // Invalid base64 digit.
70     return -1;
71   };
72
73 });